package ckelling.baukasten;

import java.awt.*;

/**
 *  Editor_CoordRechnerKomponente.java
 *
 *  Zeigt ein Fenster an, in dem X- und Y-Koordinate,
 *  Breite, Höhe und Anfasspunkt ("grabMode") einer
 *  RechnerKomponente eingestellt werden können.
 *
 *  @author   Carsten Kelling
 *  @version  0.9.0, 29.06.97
 */
public class Editor_CoordRechnerKomponente extends Frame {
	void choiceGrabMode_Action(Event event) {
		useValues();
	}

	void textFieldHeightRelOffset_Action(Event event) {
		rb_heightRel.setState(true); useValues();
	}

	void choiceHeightSourceQualifier_Action(Event event) {
		rb_heightRel.setState(true); useValues();
	}

	void choiceHeightSourceName_Action(Event event) {
		rb_heightRel.setState(true);
		String sourceName = choice_heightSourceName.getSelectedItem();
		choice_heightSourceQualifier = parent_editor.setChoiceItems(choice_heightSourceQualifier, panelHeight, sourceName);
		if ( (parent.d != null) && (sourceName.equals(parent.d.getQualifierHeight())) )
			choice_heightSourceQualifier.select(sourceName);
		useValues();
	}

	void textFieldHeightAbs_Action(Event event) {
		rb_heightAbs.setState(true); useValues();
	}

	void textFieldWidthRelOffset_Action(Event event) {
		rb_widthRel.setState(true); useValues();
	}

	void choiceWidthSourceQualifier_Action(Event event) {
		rb_widthRel.setState(true); useValues();
	}

	void choiceWidthSourceName_Action(Event event) {
		rb_widthRel.setState(true);
		String sourceName = choice_widthSourceName.getSelectedItem();
		choice_widthSourceQualifier = parent_editor.setChoiceItems(choice_widthSourceQualifier, panelWidth, sourceName);
		if ( (parent.d != null) && (sourceName.equals(parent.d.getQualifierWidth())) )
			choice_widthSourceQualifier.select(sourceName);
		useValues();
	}

	void textFieldWidthAbs_Action(Event event) {
		rb_widthAbs.setState(true); useValues();
	}

	void textFieldYRelOffset_Action(Event event) {
		rb_yRel.setState(true); useValues();
	}

	void choiceYSourceQualifier_Action(Event event) {
		rb_yRel.setState(true); useValues();
	}

	void choiceYSourceName_Action(Event event) {
		rb_yRel.setState(true);
		String sourceName = choice_ySourceName.getSelectedItem();
		choice_ySourceQualifier = parent_editor.setChoiceItems(choice_ySourceQualifier, panelY, sourceName);
		if ( (parent.d != null) && (sourceName.equals(parent.d.getQualifierY())) )
			choice_ySourceQualifier.select(sourceName);
		useValues();
	}

	void textFieldYAbs_Action(Event event) {
		rb_yAbs.setState(true); useValues();
	}

	void textFieldXRelOffset_Action(Event event) {
		rb_xRel.setState(true); useValues();
	}

	void choiceXSourceQualifier_Action(Event event) {
		rb_xRel.setState(true); useValues();
	}

	void choiceXSourceName_Action(Event event) {
		rb_xRel.setState(true);
		String sourceName = choice_xSourceName.getSelectedItem();
		choice_xSourceQualifier = parent_editor.setChoiceItems(choice_xSourceQualifier, panelX, sourceName);
		if ( (parent.d != null) && (sourceName.equals(parent.d.getQualifierX())) )
			choice_xSourceQualifier.select(sourceName);
		useValues();
	}

	void textFieldXAbs_Action(Event event) {
		rb_xAbs.setState(true); useValues();
	}


	private	Editor_PropertiesRechnerKomponente	parent;
	private Editor						parent_editor;


	void buttonOK_Clicked(Event event) {
		parent.setCoordEntered(true);

		parent.show();
		hide();
	}

	void buttonUse_Clicked(Event event) {
		useValues();
	}

	private void useValues()
	{
		if (buttonUse.isEnabled())
		{
			parent.removeRessources();
			parent.parseCoordWindow();
			parent_editor.repaint();
		}
	}



	public Editor_CoordRechnerKomponente(Editor_PropertiesRechnerKomponente parent, Editor parent_editor) {

		this.parent = parent;
		this.parent_editor = parent_editor;

		//{{INIT_CONTROLS
		GridBagLayout gridBagLayout;
		gridBagLayout = new GridBagLayout();
		setLayout(gridBagLayout);
		addNotify();
		resize(insets().left + insets().right + 440,insets().top + insets().bottom + 267);
		setFont(new Font("Helvetica", Font.PLAIN, 12));
		setBackground(new Color(12632256));
		tabPanel1 = new symantec.itools.awt.TabPanel();
		tabPanel1.setLayout(null);
		tabPanel1.reshape(insets().left + 10,insets().top + 10,420,204);
		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(tabPanel1, gbc);
		add(tabPanel1);
		{
			java.lang.String[] tempString = new java.lang.String[5];
			tempString[0] = new java.lang.String("X");
			tempString[1] = new java.lang.String("Y");
			tempString[2] = new java.lang.String("Breite");
			tempString[3] = new java.lang.String("Höhe");
			tempString[4] = new java.lang.String("Bezugspunkt");
			tabPanel1.setPanelLabels(tempString);
		}
		panelX = new java.awt.Panel();
		panelX.setLayout(null);
		panelX.reshape(12,33,396,184);
		tabPanel1.add(panelX);
		textField_xRelOffset = new java.awt.TextField();
		textField_xRelOffset.setText("0");
		textField_xRelOffset.reshape(110,113,60,23);
		textField_xRelOffset.setBackground(new Color(16777215));
		panelX.add(textField_xRelOffset);
		choice_xSourceQualifier = new java.awt.Choice();
		panelX.add(choice_xSourceQualifier);
		choice_xSourceQualifier.reshape(266,77,100,23);
		choice_xSourceQualifier.setBackground(new Color(16777215));
		choice_xSourceName = new java.awt.Choice();
		panelX.add(choice_xSourceName);
		choice_xSourceName.reshape(86,77,100,23);
		choice_xSourceName.setBackground(new Color(16777215));
		textField_xAbs = new java.awt.TextField();
		textField_xAbs.setText("20");
		textField_xAbs.reshape(86,17,60,23);
		textField_xAbs.setBackground(new Color(16777215));
		panelX.add(textField_xAbs);
		label3 = new java.awt.Label(").x");
		label3.reshape(374,77,26,23);
		panelX.add(label3);
		label2 = new java.awt.Label(".getCoord(");
		label2.reshape(194,77,72,23);
		panelX.add(label2);
		label1 = new java.awt.Label("+");
		label1.reshape(86,113,21,23);
		panelX.add(label1);
		radioButtonGroupPanelX = new symantec.itools.awt.RadioButtonGroupPanel();
		radioButtonGroupPanelX.setLayout(null);
		radioButtonGroupPanelX.reshape(2,17,84,96);
		panelX.add(radioButtonGroupPanelX);
		Group1 = new CheckboxGroup();
		rb_xRel = new java.awt.Checkbox("Relativ:", Group1, false);
		rb_xRel.reshape(12,60,70,23);
		radioButtonGroupPanelX.add(rb_xRel);
		rb_xAbs = new java.awt.Checkbox("Absolut:", Group1, true);
		rb_xAbs.reshape(12,0,70,23);
		radioButtonGroupPanelX.add(rb_xAbs);
		panelY = new java.awt.Panel();
		panelY.setLayout(null);
		panelY.reshape(12,33,396,184);
		tabPanel1.add(panelY);
		textField_yRelOffset = new java.awt.TextField();
		textField_yRelOffset.setText("0");
		textField_yRelOffset.reshape(110,113,60,23);
		textField_yRelOffset.setBackground(new Color(16777215));
		panelY.add(textField_yRelOffset);
		choice_ySourceQualifier = new java.awt.Choice();
		panelY.add(choice_ySourceQualifier);
		choice_ySourceQualifier.reshape(266,77,100,23);
		choice_ySourceQualifier.setBackground(new Color(16777215));
		choice_ySourceName = new java.awt.Choice();
		panelY.add(choice_ySourceName);
		choice_ySourceName.reshape(86,77,100,23);
		choice_ySourceName.setBackground(new Color(16777215));
		textField_yAbs = new java.awt.TextField();
		textField_yAbs.setText("40");
		textField_yAbs.reshape(86,17,60,23);
		textField_yAbs.setBackground(new Color(16777215));
		panelY.add(textField_yAbs);
		label4 = new java.awt.Label("+");
		label4.reshape(86,113,12,23);
		panelY.add(label4);
		label6 = new java.awt.Label(".getCoord(");
		label6.reshape(194,77,72,23);
		panelY.add(label6);
		label5 = new java.awt.Label(").y");
		label5.reshape(374,77,26,23);
		panelY.add(label5);
		radioButtonGroupPanelY = new symantec.itools.awt.RadioButtonGroupPanel();
		radioButtonGroupPanelY.setLayout(null);
		radioButtonGroupPanelY.reshape(2,5,78,108);
		panelY.add(radioButtonGroupPanelY);
		rb_yAbs = new java.awt.Checkbox("Absolut:", Group1, true);
		rb_yAbs.reshape(12,12,70,23);
		radioButtonGroupPanelY.add(rb_yAbs);
		rb_yRel = new java.awt.Checkbox("Relativ:", Group1, false);
		rb_yRel.reshape(12,72,72,23);
		radioButtonGroupPanelY.add(rb_yRel);
		panelWidth = new java.awt.Panel();
		panelWidth.setLayout(null);
		panelWidth.reshape(12,33,396,174);
		tabPanel1.add(panelWidth);
		textField_widthRelOffset = new java.awt.TextField();
		textField_widthRelOffset.setText("0");
		textField_widthRelOffset.reshape(146,113,60,23);
		textField_widthRelOffset.setBackground(new Color(16777215));
		panelWidth.add(textField_widthRelOffset);
		choice_widthSourceQualifier = new java.awt.Choice();
		panelWidth.add(choice_widthSourceQualifier);
		choice_widthSourceQualifier.reshape(266,77,100,23);
		choice_widthSourceQualifier.setBackground(new Color(16777215));
		choice_widthSourceName = new java.awt.Choice();
		panelWidth.add(choice_widthSourceName);
		choice_widthSourceName.reshape(86,77,100,23);
		choice_widthSourceName.setBackground(new Color(16777215));
		textField_widthAbs = new java.awt.TextField();
		textField_widthAbs.setText("100");
		textField_widthAbs.reshape(86,17,60,23);
		textField_widthAbs.setBackground(new Color(16777215));
		panelWidth.add(textField_widthAbs);
		radioButtonGroupPanelWidth = new symantec.itools.awt.RadioButtonGroupPanel();
		radioButtonGroupPanelWidth.setLayout(null);
		radioButtonGroupPanelWidth.reshape(2,5,78,108);
		panelWidth.add(radioButtonGroupPanelWidth);
		rb_widthAbs = new java.awt.Checkbox("Absolut:", Group1, true);
		rb_widthAbs.reshape(12,12,70,23);
		radioButtonGroupPanelWidth.add(rb_widthAbs);
		rb_widthRel = new java.awt.Checkbox("Relativ:", Group1, false);
		rb_widthRel.reshape(12,72,70,23);
		radioButtonGroupPanelWidth.add(rb_widthRel);
		label8 = new java.awt.Label(".getCoord(");
		label8.reshape(194,77,72,23);
		panelWidth.add(label8);
		label9 = new java.awt.Label(").x");
		label9.reshape(374,77,26,23);
		panelWidth.add(label9);
		label10 = new java.awt.Label("- startX +");
		label10.reshape(86,113,62,23);
		panelWidth.add(label10);
		panelHeight = new java.awt.Panel();
		panelHeight.setLayout(null);
		panelHeight.reshape(12,33,396,174);
		tabPanel1.add(panelHeight);
		textField_heightRelOffset = new java.awt.TextField();
		textField_heightRelOffset.setText("0");
		textField_heightRelOffset.reshape(146,113,60,23);
		textField_heightRelOffset.setBackground(new Color(16777215));
		panelHeight.add(textField_heightRelOffset);
		choice_heightSourceQualifier = new java.awt.Choice();
		panelHeight.add(choice_heightSourceQualifier);
		choice_heightSourceQualifier.reshape(266,77,100,23);
		choice_heightSourceQualifier.setBackground(new Color(16777215));
		choice_heightSourceName = new java.awt.Choice();
		panelHeight.add(choice_heightSourceName);
		choice_heightSourceName.reshape(86,77,100,23);
		choice_heightSourceName.setBackground(new Color(16777215));
		textField_heightAbs = new java.awt.TextField();
		textField_heightAbs.setText("0");
		textField_heightAbs.reshape(86,17,60,23);
		textField_heightAbs.setBackground(new Color(16777215));
		panelHeight.add(textField_heightAbs);
		radioButtonGroupPanelHeight = new symantec.itools.awt.RadioButtonGroupPanel();
		radioButtonGroupPanelHeight.setLayout(null);
		radioButtonGroupPanelHeight.reshape(2,5,78,108);
		panelHeight.add(radioButtonGroupPanelHeight);
		rb_heightAbs = new java.awt.Checkbox("Absolut:", Group1, true);
		rb_heightAbs.reshape(12,12,70,23);
		radioButtonGroupPanelHeight.add(rb_heightAbs);
		rb_heightRel = new java.awt.Checkbox("Relativ:", Group1, false);
		rb_heightRel.reshape(12,72,70,23);
		radioButtonGroupPanelHeight.add(rb_heightRel);
		label7 = new java.awt.Label(".getCoord(");
		label7.reshape(194,89,72,23);
		panelHeight.add(label7);
		label11 = new java.awt.Label(").y");
		label11.reshape(374,77,26,23);
		panelHeight.add(label11);
		label12 = new java.awt.Label("- startX +");
		label12.reshape(86,113,62,23);
		panelHeight.add(label12);
		panelGrabMode = new java.awt.Panel();
		panelGrabMode.setLayout(null);
		panelGrabMode.reshape(12,33,396,174);
		tabPanel1.add(panelGrabMode);
		label_grabMode = new java.awt.Label("Bezugspunkt");
		label_grabMode.reshape(14,17,85,23);
		panelGrabMode.add(label_grabMode);
		choice_grabMode = new java.awt.Choice();
		panelGrabMode.add(choice_grabMode);
		choice_grabMode.reshape(110,17,108,23);
		choice_grabMode.setBackground(new Color(16777215));
		buttonPanel = new java.awt.Panel();
		buttonPanel.setLayout(new GridLayout(1,0,20,0));
		buttonPanel.reshape(insets().left + 10,insets().top + 234,420,23);
		gbc = new GridBagConstraints();
		gbc.gridx = 0;
		gbc.gridy = 1;
		gbc.weightx = 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,126,10);
		buttonPanel.add(buttonOK);
		buttonUse = new java.awt.Button("Übernehmen");
		buttonUse.reshape(146,0,126,10);
		buttonPanel.add(buttonUse);
		buttonCancel = new java.awt.Button("Abbrechen");
		buttonCancel.reshape(292,0,126,10);
		buttonPanel.add(buttonCancel);
		setTitle("Untitled");
		//}}

		rb_xAbs.setState(true);
		rb_yAbs.setState(true);
		rb_widthAbs.setState(true);
		rb_heightAbs.setState(true);

		//{{INIT_MENUS
		//}}

	}

	public Editor_CoordRechnerKomponente(String title, Editor_PropertiesRechnerKomponente parent, Editor parent_editor) {
	    this(parent, parent_editor);
	    setTitle(title);
	}

    public synchronized void show() {
    	//Rectangle pb = parent.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 == buttonOK && event.id == Event.ACTION_EVENT) {
			buttonOK_Clicked(event);
			return true;
		}
		if (event.target == buttonUse && event.id == Event.ACTION_EVENT) {
			buttonUse_Clicked(event);
			return true;
		}
		if (event.target == buttonCancel && event.id == Event.ACTION_EVENT) {
			hide();
			parent.show();
			//dispose();
			return true;
		}
		if (event.target == choice_grabMode && event.id == Event.ACTION_EVENT) {
			choiceGrabMode_Action(event);
			return true;
		}
		if (event.target == textField_xAbs && event.id == Event.ACTION_EVENT) {
			textFieldXAbs_Action(event);
			return true;
		}
		if (event.target == choice_xSourceName && event.id == Event.ACTION_EVENT) {
			choiceXSourceName_Action(event);
			return true;
		}
		if (event.target == choice_xSourceQualifier && event.id == Event.ACTION_EVENT) {
			choiceXSourceQualifier_Action(event);
			return true;
		}
		if (event.target == textField_xRelOffset && event.id == Event.ACTION_EVENT) {
			textFieldXRelOffset_Action(event);
			return true;
		}
		if (event.target == textField_yAbs && event.id == Event.ACTION_EVENT) {
			textFieldYAbs_Action(event);
			return true;
		}
		if (event.target == choice_ySourceName && event.id == Event.ACTION_EVENT) {
			choiceYSourceName_Action(event);
			return true;
		}
		if (event.target == choice_ySourceQualifier && event.id == Event.ACTION_EVENT) {
			choiceYSourceQualifier_Action(event);
			return true;
		}
		if (event.target == textField_yRelOffset && event.id == Event.ACTION_EVENT) {
			textFieldYRelOffset_Action(event);
			return true;
		}
		if (event.target == textField_widthAbs && event.id == Event.ACTION_EVENT) {
			textFieldWidthAbs_Action(event);
			return true;
		}
		if (event.target == choice_widthSourceName && event.id == Event.ACTION_EVENT) {
			choiceWidthSourceName_Action(event);
			return true;
		}
		if (event.target == choice_widthSourceQualifier && event.id == Event.ACTION_EVENT) {
			choiceWidthSourceQualifier_Action(event);
			return true;
		}
		if (event.target == textField_widthRelOffset && event.id == Event.ACTION_EVENT) {
			textFieldWidthRelOffset_Action(event);
			return true;
		}
		if (event.target == textField_heightAbs && event.id == Event.ACTION_EVENT) {
			textFieldHeightAbs_Action(event);
			return true;
		}
		if (event.target == choice_heightSourceName && event.id == Event.ACTION_EVENT) {
			choiceHeightSourceName_Action(event);
			return true;
		}
		if (event.target == choice_heightSourceQualifier && event.id == Event.ACTION_EVENT) {
			choiceHeightSourceQualifier_Action(event);
			return true;
		}
		if (event.target == textField_heightRelOffset && event.id == Event.ACTION_EVENT) {
			textFieldHeightRelOffset_Action(event);
			return true;
		}
		return super.handleEvent(event);
	}


	protected void removeButtonUse()
	{
		//remove(buttonUse);
		buttonUse.disable();
	}



	//{{DECLARE_CONTROLS
	symantec.itools.awt.TabPanel tabPanel1;
	java.awt.Panel panelX;
	java.awt.TextField textField_xRelOffset;
	java.awt.Choice choice_xSourceQualifier;
	java.awt.Choice choice_xSourceName;
	java.awt.TextField textField_xAbs;
	java.awt.Label label3;
	java.awt.Label label2;
	java.awt.Label label1;
	symantec.itools.awt.RadioButtonGroupPanel radioButtonGroupPanelX;
	java.awt.Checkbox rb_xRel;
	CheckboxGroup Group1;
	java.awt.Checkbox rb_xAbs;
	java.awt.Panel panelY;
	java.awt.TextField textField_yRelOffset;
	java.awt.Choice choice_ySourceQualifier;
	java.awt.Choice choice_ySourceName;
	java.awt.TextField textField_yAbs;
	java.awt.Label label4;
	java.awt.Label label6;
	java.awt.Label label5;
	symantec.itools.awt.RadioButtonGroupPanel radioButtonGroupPanelY;
	java.awt.Checkbox rb_yAbs;
	java.awt.Checkbox rb_yRel;
	java.awt.Panel panelWidth;
	java.awt.TextField textField_widthRelOffset;
	java.awt.Choice choice_widthSourceQualifier;
	java.awt.Choice choice_widthSourceName;
	java.awt.TextField textField_widthAbs;
	symantec.itools.awt.RadioButtonGroupPanel radioButtonGroupPanelWidth;
	java.awt.Checkbox rb_widthAbs;
	java.awt.Checkbox rb_widthRel;
	java.awt.Label label8;
	java.awt.Label label9;
	java.awt.Label label10;
	java.awt.Panel panelHeight;
	java.awt.TextField textField_heightRelOffset;
	java.awt.Choice choice_heightSourceQualifier;
	java.awt.Choice choice_heightSourceName;
	java.awt.TextField textField_heightAbs;
	symantec.itools.awt.RadioButtonGroupPanel radioButtonGroupPanelHeight;
	java.awt.Checkbox rb_heightAbs;
	java.awt.Checkbox rb_heightRel;
	java.awt.Label label7;
	java.awt.Label label11;
	java.awt.Label label12;
	java.awt.Panel panelGrabMode;
	java.awt.Label label_grabMode;
	java.awt.Choice choice_grabMode;
	java.awt.Panel buttonPanel;
	java.awt.Button buttonOK;
	java.awt.Button buttonUse;
	java.awt.Button buttonCancel;
	//}}

	//{{DECLARE_MENUS
	//}}
}
