package ckelling.baukasten;

import java.awt.*;

/**
 * Editor_PropertiesRechnerKomponente.java
 *
 * Fenster, um Eigenschaften eines SimpleBus (und nur dieser Art
 * von RechnerKomponente) anzugeben.
 *
 *	@author		Carsten Kelling
 *	@version	0.2.0, 05.06.97
 */
public class Editor_PropertiesSimpleBus extends Editor_Properties {

    protected Editor				parent;
    private SimpleBus				s;
    protected Editor_DescriptionSimpleBus	d;

    private Editor_CoordSimpleBus	coordEnter;

    private boolean					createNew = false;
    private boolean					coordEntered = true;

    private boolean					disposeFinally;


	void button_Coordinates_Clicked(Event event) {
		//{{CONNECTION
		// Create and show the Frame
		coordEnter.show();
		//}}
	}

	void buttonOK_Clicked(Event event) {
		//{{CONNECTION
		if (createNew == true)
		{
			if (coordEntered)
			{
				//createAtOnce d = new Editor_DescriptionSimpleBus();
				//createAtOnce s = new SimpleBus("", 10, 10, 10, 0, SimpleBus.NONE, (Rechner) parent);

				parseWindows();

				//createAtOnce parent.e_SimpleBus.addElement(new Editor_Source((RechnerKomponente) s));
				//createAtOnce parent.d_SimpleBus.addElement(d);

				parent.updateTree("SimpleBus", d.getInstanceName());
				parent.repaint();

				hide();
				coordEnter.hide();
				coordEnter.dispose();
				if (disposeFinally)
					dispose();
			}
			else  // Koordinaten fuer neuen Bus muessen noch eingegeben werden
			{
				hide();
				button_Coordinates_Clicked(event);
			}
		}
		else  // ein existierender Bus wird geaendert
		{
			parseWindows();

			parent.updateTree("SimpleBus", d.getInstanceName());
			parent.repaint();

			hide();
			coordEnter.hide();
			coordEnter.dispose();
			if (disposeFinally)
				dispose();
		}

		//}}
	}


	public void initialize()
	{
		initialize(null, null);
	}

	public void initialize(SimpleBus bus, Editor_DescriptionSimpleBus desc)
	{
	    this.s = bus;
	    this.d = desc;

    	Rectangle pb = parent.editor_Control.bounds();
    	move(pb.x, pb.y);
    	coordEnter.move(pb.x, pb.y);

		if ( (s != null) && (d != null) )
		{
			createNew = false;
			prepareWindows();
		}
		else
		{
		    createNew = true;
		    buttonAddEdge.disable();
		    coordEntered = false;
		    //createAtOnce coordEnter.removeButtonUse();

			d = new Editor_DescriptionSimpleBus();
			s = new SimpleBus("", 10, 10, 10, 0, SimpleBus.NONE, (Rechner) parent);
			prepareWindows();
			parseWindows();

			parent.e_SimpleBus.addElement(new Editor_Source((RechnerKomponente) s));
			parent.d_SimpleBus.addElement(d);

			parent.repaint();
		}

		show();

	} /* end initialize */


	public Editor_PropertiesSimpleBus(Editor parent, boolean disposeFinally) {

	    this.parent = parent;
		this.disposeFinally = disposeFinally;

	    coordEnter = new Editor_CoordSimpleBus(this, parent);
	    coordEnter.hide();

		//{{INIT_CONTROLS
		GridBagLayout gridBagLayout;
		gridBagLayout = new GridBagLayout();
		setLayout(gridBagLayout);
		addNotify();
		resize(insets().left + insets().right + 245,insets().top + insets().bottom + 330);
		setFont(new Font("Helvetica", Font.PLAIN, 12));
		setBackground(new Color(12632256));
		propertiesPanel = new java.awt.Panel();
		propertiesPanel.setLayout(null);
		propertiesPanel.reshape(insets().left + 10,insets().top + 10,225,267);
		GridBagConstraints gbc;
		gbc = new GridBagConstraints();
		gbc.gridx = 0;
		gbc.gridy = 0;
		gbc.weightx = 1.0;
		gbc.weighty = 1.0;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.insets = new Insets(10,10,10,10);
		gridBagLayout.setConstraints(propertiesPanel, gbc);
		add(propertiesPanel);
		label1 = new java.awt.Label("Name");
		label1.reshape(2,50,48,23);
		propertiesPanel.add(label1);
		label2 = new java.awt.Label("Text");
		label2.reshape(2,86,36,23);
		propertiesPanel.add(label2);
		button_Coordinates = new java.awt.Button("Koordinaten...");
		button_Coordinates.reshape(2,2,90,23);
		propertiesPanel.add(button_Coordinates);
		textField_Name = new java.awt.TextField();
		textField_Name.setText("bus1");
		textField_Name.reshape(62,50,108,23);
		textField_Name.setBackground(new Color(16777215));
		propertiesPanel.add(textField_Name);
		label3 = new java.awt.Label("Textposition");
		label3.reshape(2,158,80,23);
		propertiesPanel.add(label3);
		choice_labelPosHorz = new java.awt.Choice();
		choice_labelPosHorz.addItem("start, top");
		choice_labelPosHorz.addItem("start, bottom");
		choice_labelPosHorz.addItem("end, top");
		choice_labelPosHorz.addItem("end, bottom");
		propertiesPanel.add(choice_labelPosHorz);
		choice_labelPosHorz.reshape(86,158,84,23);
		choice_labelPosHorz.setBackground(new Color(16777215));
		choice_labelPosVert = new java.awt.Choice();
		choice_labelPosVert.addItem("left, start");
		choice_labelPosVert.addItem("right, start");
		choice_labelPosVert.addItem("left, end");
		choice_labelPosVert.addItem("right, end");
		propertiesPanel.add(choice_labelPosVert);
		choice_labelPosVert.reshape(86,158,84,23);
		choice_labelPosVert.setBackground(new Color(16777215));
		cb_BLACK_ROOT = new java.awt.Checkbox("  BLACK_ROOT");
		cb_BLACK_ROOT.reshape(2,194,110,14);
		propertiesPanel.add(cb_BLACK_ROOT);
		cb_BLACK_ROOT.setState(true);
		buttonAddEdge = new java.awt.Button("Neuer Ast...");
		buttonAddEdge.reshape(122,2,77,23);
		propertiesPanel.add(buttonAddEdge);
		textArea1 = new java.awt.TextArea();
		textArea1.reshape(62,86,108,60);
		textArea1.setBackground(new Color(16777215));
		propertiesPanel.add(textArea1);
		cb_WITH_GATES = new symantec.itools.awt.StateCheckBox();
		cb_WITH_GATES.reshape(2,218,14,14);
		propertiesPanel.add(cb_WITH_GATES);
		cb_WITH_GATES.setStyle(symantec.itools.awt.StateCheckBox.THREE_STATE);
		cb_WITH_SOLDER_DOTS = new symantec.itools.awt.StateCheckBox();
		cb_WITH_SOLDER_DOTS.reshape(2,242,14,14);
		propertiesPanel.add(cb_WITH_SOLDER_DOTS);
		cb_WITH_SOLDER_DOTS.setStyle(symantec.itools.awt.StateCheckBox.THREE_STATE);
		label4 = new java.awt.Label("WITH_GATES");
		label4.reshape(26,218,90,14);
		propertiesPanel.add(label4);
		label10 = new java.awt.Label("WITH_SOLDER_DOTS");
		label10.reshape(26,242,141,14);
		propertiesPanel.add(label10);
		buttonPanel = new java.awt.Panel();
		buttonPanel.setLayout(new GridLayout(1,0,20,0));
		buttonPanel.reshape(insets().left + 10,insets().top + 297,225,23);
		gbc = new GridBagConstraints();
		gbc.gridx = 0;
		gbc.gridy = 1;
		gbc.weightx = 1.0;
		gbc.weighty = 1.0;
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.insets = new Insets(10,10,10,10);
		gridBagLayout.setConstraints(buttonPanel, gbc);
		add(buttonPanel);
		buttonOK = new java.awt.Button("OK");
		buttonOK.reshape(0,0,102,23);
		buttonPanel.add(buttonOK);
		buttonCancel = new java.awt.Button("Abbrechen");
		buttonCancel.reshape(122,0,102,23);
		buttonPanel.add(buttonCancel);
		setTitle("Eigenschaften für SimpleBus");
		//}}

    	hide();

		//{{INIT_MENUS
		//}}
	} /* end init */


	public Editor_PropertiesSimpleBus(String title, Editor parent, boolean disposeFinally) {
	    this(parent, disposeFinally);
	    setTitle(title);
	}


	private void prepareWindows()
	{
		String[] allInstances;
		allInstances = parent.getAllInstanceNames(d.getInstanceName());

		for (int i = 0; i < allInstances.length; i++)
		{
			coordEnter.choice_xSourceName.addItem(allInstances[i]);
			coordEnter.choice_ySourceName.addItem(allInstances[i]);
			coordEnter.choice_widthSourceName.addItem(allInstances[i]);
			coordEnter.choice_heightSourceName.addItem(allInstances[i]);
		}
		if (allInstances.length > 0)
		{
			coordEnter.choice_xSourceName.select(0);
			coordEnter.choice_xSourceQualifier = parent.setChoiceItems(coordEnter.choice_xSourceQualifier, coordEnter.panelX, allInstances[0]);
			coordEnter.choice_ySourceName.select(0);
			coordEnter.choice_ySourceQualifier = parent.setChoiceItems(coordEnter.choice_ySourceQualifier, coordEnter.panelY, allInstances[0]);
			coordEnter.choice_widthSourceName.select(0);
			coordEnter.choice_widthSourceQualifier = parent.setChoiceItems(coordEnter.choice_widthSourceQualifier, coordEnter.panelWidth, allInstances[0]);
			coordEnter.choice_heightSourceName.select(0);
			coordEnter.choice_heightSourceQualifier = parent.setChoiceItems(coordEnter.choice_heightSourceQualifier, coordEnter.panelHeight, allInstances[0]);
		}


		//createAtOnce if ( (s == null) || (d == null) )
		if (createNew)  // Ein Eigenschaftenfenster fuer einen neuen Bus wurde geoeffnet
		{
			setTitle("Eigenschaften für neuen Bus");
			coordEnter.setTitle("Koordinaten für neuen Bus");

			textField_Name.setText("bus" + Integer.toString(parent.e_SimpleBus.size()+1, 10));
			textArea1.setText("Another\nbus");

			coordEnter.textField_yAbs.setText(Integer.toString(40 * (parent.e_SimpleBus.size()+1)));

			label3.hide();
			choice_labelPosHorz.hide();
			choice_labelPosVert.hide();
		}
		else  // Eigenschaften eines bestehenden Busses aendern
		{
			setTitle("Eigenschaften für " + d.getInstanceName());
			coordEnter.setTitle("Koordinaten für " + d.getInstanceName());

			textField_Name.setText(d.getInstanceName());
			String temp = new String("");
			String[] label = s.getLabel();
			for (int i = 0; i < label.length; i++)
			{
				if (i == label.length-1)
					temp = temp + label[i];
				else
					temp = temp + label[i] + "\n";
			}
			textArea1.setText(temp);

			String[] lp = s.getLabelPosition();
			if (d.evaluateWidth() == 0)  // vertical bus
			{
				choice_labelPosHorz.hide();
				choice_labelPosVert.show();
				choice_labelPosHorz.select(0);
				choice_labelPosVert.select(lp[0] + ", " + lp[1]);
			}
			else  // horizontal bus
			{
				choice_labelPosHorz.show();
				choice_labelPosVert.hide();
				choice_labelPosHorz.select(lp[0] + ", " + lp[1]);
				choice_labelPosVert.select(0);
            }

			int flags = s.getFlags();
			int uFlags = s.getUniqueFlags();

			cb_BLACK_ROOT.setState( (flags & SimpleBus.BLACK_ROOT) == SimpleBus.BLACK_ROOT );

			if ((uFlags & SimpleBus.WITH_GATES) != SimpleBus.WITH_GATES)
				cb_WITH_GATES.setState(symantec.itools.awt.StateCheckBox.STATE_DEFAULT);
			else if ((flags & SimpleBus.WITH_GATES) == SimpleBus.WITH_GATES)
				cb_WITH_GATES.setState(symantec.itools.awt.StateCheckBox.STATE_CHECKED);
			else
				cb_WITH_GATES.setState(symantec.itools.awt.StateCheckBox.STATE_UNCHECKED);

			if ((uFlags & SimpleBus.WITH_SOLDER_DOTS) != SimpleBus.WITH_SOLDER_DOTS)
				cb_WITH_SOLDER_DOTS.setState(symantec.itools.awt.StateCheckBox.STATE_DEFAULT);
			else if ((flags & SimpleBus.WITH_SOLDER_DOTS) == SimpleBus.WITH_SOLDER_DOTS)
				cb_WITH_SOLDER_DOTS.setState(symantec.itools.awt.StateCheckBox.STATE_CHECKED);
			else
				cb_WITH_SOLDER_DOTS.setState(symantec.itools.awt.StateCheckBox.STATE_UNCHECKED);


			// Aktualisieren des Koordinaten-Fensters
			String sourceName;

			// X-Koordinate
			if (d.isConstantOnlyX())
				coordEnter.rb_xAbs.setState(true);
			else
			{
				coordEnter.rb_xRel.setState(true);
				coordEnter.textField_xRelOffset.setText(Integer.toString(d.getOffsetX()));
			}
			coordEnter.textField_xAbs.setText(Integer.toString(d.evaluateX()));
			sourceName = parent.getDescription(d.getSourceX()).getInstanceName();
			coordEnter.choice_xSourceName.select(sourceName);
			coordEnter.choice_xSourceQualifier = parent.setChoiceItems(coordEnter.choice_xSourceQualifier, coordEnter.panelX, sourceName);
			coordEnter.choice_xSourceQualifier.select(d.getQualifierX());

			// Y-Koordinate
			if (d.isConstantOnlyY())
				coordEnter.rb_yAbs.setState(true);
			else
			{
				coordEnter.rb_yRel.setState(true);
				coordEnter.textField_yRelOffset.setText(Integer.toString(d.getOffsetY()));
			}
			coordEnter.textField_yAbs.setText(Integer.toString(d.evaluateY()));
			sourceName = parent.getDescription(d.getSourceY()).getInstanceName();
			coordEnter.choice_ySourceName.select(sourceName);
			coordEnter.choice_ySourceQualifier = parent.setChoiceItems(coordEnter.choice_ySourceQualifier, coordEnter.panelY, sourceName);
			coordEnter.choice_ySourceQualifier.select(d.getQualifierY());

			// Breite
			if (d.isConstantOnlyWidth())
				coordEnter.rb_widthAbs.setState(true);
			else
			{
				coordEnter.rb_widthRel.setState(true);
				coordEnter.textField_widthRelOffset.setText(Integer.toString(d.getOffsetWidth()));
			}
			coordEnter.textField_widthAbs.setText(Integer.toString(d.evaluateWidth()));
			sourceName = parent.getDescription(d.getSourceWidth()).getInstanceName();
			coordEnter.choice_widthSourceName.select(sourceName);
			coordEnter.choice_widthSourceQualifier = parent.setChoiceItems(coordEnter.choice_widthSourceQualifier, coordEnter.panelWidth, sourceName);
			coordEnter.choice_widthSourceQualifier.select(d.getQualifierWidth());

			// Hoehe
			if (d.isConstantOnlyHeight())
				coordEnter.rb_heightAbs.setState(true);
			else
			{
				coordEnter.rb_heightRel.setState(true);
				coordEnter.textField_heightRelOffset.setText(Integer.toString(d.getOffsetHeight()));
			}
			coordEnter.textField_heightAbs.setText(Integer.toString(d.evaluateHeight()));
			sourceName = parent.getDescription(d.getSourceHeight()).getInstanceName();
			coordEnter.choice_heightSourceName.select(sourceName);
			coordEnter.choice_heightSourceQualifier = parent.setChoiceItems(coordEnter.choice_heightSourceQualifier, coordEnter.panelHeight, sourceName);
			coordEnter.choice_heightSourceQualifier.select(d.getQualifierHeight());

		} // Ende von "Eigenschaften eines bestehenden Busses aendern"

	} /* end prepareWindow */


	public Editor_DescriptionSimpleBus getDescription()
	{
		return d;
	}

	public boolean getCoordEntered()
	{
		return coordEntered;
	}

	public void setCoordEntered(boolean b)
	{
		coordEntered = b;
	}

	public boolean getCreateNew()
	{
		return createNew;
	}

	//public void setCreateNew(boolean b)
	//{
	//	createNew = b;
	//}

	public boolean isHorizontalBus()
	{
		if (d == null)
			return true;
		else
		{
			return d.isHorizontalBus();
		}
	}



    public synchronized void show() {
    	//Rectangle pb = parent.editor_Control.bounds();
    	//move(pb.x, pb.y);
    	super.show();
    }

	public boolean handleEvent(Event event) {
    	if (event.id == Event.WINDOW_DESTROY) {
            hide();         // hide the Frame
            return true;
    	}
		if (event.target == button_Coordinates && event.id == Event.ACTION_EVENT) {
			button_Coordinates_Clicked(event);
			return true;
		}
		if (event.target == buttonOK && event.id == Event.ACTION_EVENT) {
			buttonOK_Clicked(event);
			return true;
		}
		if (event.target == buttonCancel && event.id == Event.ACTION_EVENT) {
			hide();

			if (createNew)
			// neu angelegten Bus wieder loeschen
			{
				int index = parent.d_SimpleBus.indexOf((Object) d);
				parent.d_SimpleBus.removeElementAt(index);
				parent.e_SimpleBus.removeElementAt(index);

				parent.repaint();
			}

			if (disposeFinally)
				dispose();
			return true;
		}
		if (event.target == buttonAddEdge && event.id == Event.ACTION_EVENT) {
			(new Editor_PropertiesSimpleEdge(s, this)).show();
			return true;
		}
		return super.handleEvent(event);
	}



	private void parseWindows()
	{
		parseCoordWindow();

		String str = textArea1.getText();
		int numberOfCRs = 0;
		for (int i = 0; i < str.length(); i++)
		{
			if (str.substring(i, i+1).equals("\n"))
				numberOfCRs++;
		}
		String[] strArray = new String[numberOfCRs + 1];
		int j = 0;
		for (int i = 0; i <= numberOfCRs; i++)
			strArray[i] = new String("");
		for (int i = 0; i < str.length(); i++)
		{
			if (str.substring(i, i+1).equals("\n"))
				j++;
			else
				strArray[j] = strArray[j] + str.substring(i, i+1);
		}
		s.setLabel(strArray);

		d.setInstanceName(textField_Name.getText());


		int flags = 0;
		int flagMask = 0;  // welche Flags sollen geaendert werden?
		if (cb_BLACK_ROOT.getState())
			flags += SimpleBus.BLACK_ROOT;

		if (cb_WITH_SOLDER_DOTS.getState() == symantec.itools.awt.StateCheckBox.STATE_CHECKED)
		{
			flags += SimpleBus.WITH_SOLDER_DOTS;
			flagMask += SimpleBus.WITH_SOLDER_DOTS;
		}
		else if (cb_WITH_SOLDER_DOTS.getState() == symantec.itools.awt.StateCheckBox.STATE_UNCHECKED)
			flagMask += SimpleBus.WITH_SOLDER_DOTS;

		if (cb_WITH_GATES.getState() == symantec.itools.awt.StateCheckBox.STATE_CHECKED)
		{
			flags += SimpleBus.WITH_GATES;
			flagMask += SimpleBus.WITH_GATES;
		}
		else if (cb_WITH_GATES.getState() == symantec.itools.awt.StateCheckBox.STATE_UNCHECKED)
			flagMask += SimpleBus.WITH_GATES;

		s.setFlags(flags, flagMask);


		String labelPos;
		String labelPosX = new String("");
		String labelPosY = new String("");
		if (d.evaluateWidth() == 0)  // vertical bus
			labelPos = choice_labelPosVert.getSelectedItem();
		else  // horizontal bus
			labelPos = choice_labelPosHorz.getSelectedItem();
		boolean firstPart = true;
		for (int i = 0; i < labelPos.length(); i++)
		{
			if (labelPos.substring(i, i+1).equals(","))
			{
				i++;
				firstPart = false;
			}
			else if (firstPart)
				labelPosX = labelPosX + labelPos.substring(i, i+1);
			else
				labelPosY = labelPosY + labelPos.substring(i, i+1);
		}
		s.setLabelPosition(labelPosX, labelPosY);
	} /* end parseWindows */


	protected void parseCoordWindow()
	{
		if (coordEnter == null)
		{
			if (createNew)
				parent.out("FEHLER in Editor_PropertiesSimpleBus.parseCoordWindow(): Neuer Bus, aber keine Koordinaten eingegeben!");
			else
				parent.out("FEHLER in Editor_PropertiesSimpleBus.parseCoordWindow(): Koordinaten des Busses wurden nicht verändert.");
		}
		else
		{
			// X-Koordinate
			d.setX(parent.getComponent(coordEnter.choice_xSourceName.getSelectedItem()),
			                          coordEnter.choice_xSourceQualifier.getSelectedItem(),
			                          Integer.parseInt(coordEnter.textField_xRelOffset.getText()));
			                          // X-Koordinate ergibt sich relativ zu anderer Komponente
			if (coordEnter.rb_xAbs.getState() == true)
				d.setX(Integer.parseInt(coordEnter.textField_xAbs.getText()));

			// Y-Koordinate
			d.setY(parent.getComponent(coordEnter.choice_ySourceName.getSelectedItem()),
			                          coordEnter.choice_ySourceQualifier.getSelectedItem(),
			                          Integer.parseInt(coordEnter.textField_yRelOffset.getText()));
			                          // Y-Koordinate ergibt sich relativ zu anderer Komponente
			if (coordEnter.rb_yAbs.getState() == true)
				d.setY(Integer.parseInt(coordEnter.textField_yAbs.getText()));

			// Breite
			d.setWidth(parent.getComponent(coordEnter.choice_widthSourceName.getSelectedItem()),
			                          coordEnter.choice_widthSourceQualifier.getSelectedItem(),
			                          Integer.parseInt(coordEnter.textField_widthRelOffset.getText()));
			                          // Breite ergibt sich relativ zu anderer Komponente
			if (coordEnter.rb_widthAbs.getState() == true)
				d.setWidth(Integer.parseInt(coordEnter.textField_widthAbs.getText()));

			// Hoehe
			d.setHeight(parent.getComponent(coordEnter.choice_heightSourceName.getSelectedItem()),
			                          coordEnter.choice_heightSourceQualifier.getSelectedItem(),
			                          Integer.parseInt(coordEnter.textField_heightRelOffset.getText()));
			                          // Hoehe ergibt sich relativ zu anderer Komponente
			if (coordEnter.rb_heightAbs.getState() == true)
				d.setHeight(Integer.parseInt(coordEnter.textField_heightAbs.getText()));


			if (createNew == false)
				parent.updateCoordinates();
			else
				s.reshape(d.evaluateX(), d.evaluateY(), d.evaluateWidth(), d.evaluateHeight());
		}

	} /* end parseCoordWindow */


	private SimpleEdge addEdge(Editor_PropertiesSimpleEdge prop)
	{
		if (prop == null)
		{
			parent.out("FEHLER in Editor_PropertiesSimpleEdge.addEdge(): Null übergeben!");
			return null;
		}
		else if (s == null)
		{
			parent.out("FEHLER in Editor_PropertiesSimpleEdge.addEdge(): SimpleBus ist null!");
			return null;
		}
		else if (d == null)
		{
			parent.out("FEHLER in Editor_PropertiesSimpleEdge.addEdge(): Description ist null");
			return null;
		}
		else
		{
			String label;
			int x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
			int flag;
			Editor_DescriptionSimpleEdge dse = new Editor_DescriptionSimpleEdge(d);

			label = prop.textField_Name.getText();
			dse.setLabel(label);

			x1 = y1 = x2 = y2 = x3 = y3 = x4 = y4 = x5 = y5 = -1;
			for (int i = 0; i < 5; i++)
				dse.setCoord(i, -1);

			// Erste Koordinate
			if (prop.rb_c1Abs.getState() == true)
			{
				x1 = Integer.parseInt(prop.textField_c1Abs.getText());
				y1 = 0;
				dse.setCoord(0, x1);
			}
			else
			{
				dse.setCoord(0, parent.getComponent(prop.choice_c1SourceName.getSelectedItem()),
				                prop.choice_c1SourceQualifier.getSelectedItem(),
				                Integer.parseInt(prop.textField_c1RelOffset.getText()));
				x1 = dse.evaluate(0);
				y1 = 0;
			}

			// Zweite Koordinate
			if (prop.rb_c2Abs.getState() == true)
			{
				x2 = 0;
				y2 = Integer.parseInt(prop.textField_c2Abs.getText());
				dse.setCoord(1, y2);
			}
			else
			{
				dse.setCoord(1, parent.getComponent(prop.choice_c2SourceName.getSelectedItem()),
				                prop.choice_c2SourceQualifier.getSelectedItem(),
				                Integer.parseInt(prop.textField_c2RelOffset.getText()));
				x2 = 0;
				y2 = dse.evaluate(1);
			}

			// Dritte Koordinate
			if (prop.rb_c3Off.getState() == false)
			{
				if (prop.rb_c3Abs.getState() == true)
				{
					x3 = Integer.parseInt(prop.textField_c3Abs.getText());
					y3 = 0;
					dse.setCoord(2, x3);
				}
				else
				{
					dse.setCoord(2, parent.getComponent(prop.choice_c3SourceName.getSelectedItem()),
					                prop.choice_c3SourceQualifier.getSelectedItem(),
					                Integer.parseInt(prop.textField_c3RelOffset.getText()));
					x3 = dse.evaluate(2);
					y3 = 0;
				}
			}

			// Vierte Koordinate
			if (prop.rb_c4Off.getState() == false)
			{
				if (prop.rb_c4Abs.getState() == true)
				{
					x4 = 0;
					y4 = Integer.parseInt(prop.textField_c4Abs.getText());
					dse.setCoord(3, y4);
				}
				else
				{
					dse.setCoord(3, parent.getComponent(prop.choice_c4SourceName.getSelectedItem()),
					                prop.choice_c4SourceQualifier.getSelectedItem(),
					                Integer.parseInt(prop.textField_c4RelOffset.getText()));
					x4 = 0;
					y4 = dse.evaluate(3);
				}
			}

			// Fuenfte Koordinate
			if (prop.rb_c5Off.getState() == false)
			{
				if (prop.rb_c5Abs.getState() == true)
				{
					x5 = Integer.parseInt(prop.textField_c5Abs.getText());
					y5 = 0;
					dse.setCoord(4, x5);
				}
				else
				{
					dse.setCoord(4, parent.getComponent(prop.choice_c5SourceName.getSelectedItem()),
					                prop.choice_c5SourceQualifier.getSelectedItem(),
					                Integer.parseInt(prop.textField_c5RelOffset.getText()));
					x5 = dse.evaluate(4);
					y5 = 0;
				}
			}


			flag = SimpleBus.NONE;

			if (prop.cb_WITH_GATE.getState() == true)
			{
				flag += SimpleBus.WITH_GATES;
				if (cb_WITH_GATES.getState() == symantec.itools.awt.StateCheckBox.STATE_UNCHECKED)
					cb_WITH_GATES.setState(symantec.itools.awt.StateCheckBox.STATE_DEFAULT);
			}
			else if (cb_WITH_GATES.getState() == symantec.itools.awt.StateCheckBox.STATE_CHECKED)
				cb_WITH_GATES.setState(symantec.itools.awt.StateCheckBox.STATE_DEFAULT);

			if (prop.cb_WITH_SOLDER_DOT.getState() == true)
			{
				flag += SimpleBus.WITH_SOLDER_DOTS;
				if (cb_WITH_SOLDER_DOTS.getState() == symantec.itools.awt.StateCheckBox.STATE_UNCHECKED)
					cb_WITH_SOLDER_DOTS.setState(symantec.itools.awt.StateCheckBox.STATE_DEFAULT);
			}
			else if (cb_WITH_SOLDER_DOTS.getState() == symantec.itools.awt.StateCheckBox.STATE_CHECKED)
				cb_WITH_SOLDER_DOTS.setState(symantec.itools.awt.StateCheckBox.STATE_DEFAULT);

			cb_WITH_GATES.repaint();
			cb_WITH_SOLDER_DOTS.repaint();

			if (! isHorizontalBus())
			{
				int t;
				t = x1; x1 = y1; y1 = t;
				t = x2; x2 = y2; y2 = t;
				t = x3; x3 = y3; y3 = t;
				t = x4; x4 = y4; y4 = t;
				t = x5; x5 = y5; y5 = t;
			}

			s.addEdge(label, x1, y1, x2, y2, x3, y3, x4, y4, x5, y5);
			s.setFlag(label, flag);
			d.addEdge(dse);

			return s.getEdge(label);
		}
	} /* end addEdge */

	public SimpleEdge changeEdge(SimpleEdge e, Editor_PropertiesSimpleEdge prop)
	{
		if (e != null)
		{
			s.removeEdge(e.getLabel());
			d.removeEdge(e.getLabel());
		}

		SimpleEdge se = addEdge(prop);

		parent.updateCoordinates();
		parent.repaint();

		return se;
	} /* end changeEdge */


	//{{DECLARE_CONTROLS
	java.awt.Panel propertiesPanel;
	java.awt.Label label1;
	java.awt.Label label2;
	java.awt.Button button_Coordinates;
	java.awt.TextField textField_Name;
	java.awt.Label label3;
	java.awt.Choice choice_labelPosHorz;
	java.awt.Choice choice_labelPosVert;
	java.awt.Checkbox cb_BLACK_ROOT;
	java.awt.Button buttonAddEdge;
	java.awt.TextArea textArea1;
	symantec.itools.awt.StateCheckBox cb_WITH_GATES;
	symantec.itools.awt.StateCheckBox cb_WITH_SOLDER_DOTS;
	java.awt.Label label4;
	java.awt.Label label10;
	java.awt.Panel buttonPanel;
	java.awt.Button buttonOK;
	java.awt.Button buttonCancel;
	//}}

	//{{DECLARE_MENUS
	//}}
}
