001: /*
002: * Created on 20.06.2005
003: *
004: * CVS information:
005: * $Author: javamap $
006: * $Date: 2007-06-18 21:15:27 -0700 (Mon, 18 Jun 2007) $
007: * $ID$
008: * $Rev: 856 $
009: * $Id: EditAttributeByFormulaDialog.java 856 2007-06-19 04:15:27Z javamap $
010: *
011: */
012: package de.fho.jump.pirol.plugins.EditAttributeByFormula;
013:
014: import java.awt.Frame;
015: import java.awt.GridBagConstraints;
016: import java.awt.GridBagLayout;
017: import java.awt.HeadlessException;
018: import java.awt.Insets;
019:
020: import javax.swing.JDialog;
021: import javax.swing.JPanel;
022:
023: import com.vividsolutions.jump.feature.AttributeType;
024: import com.vividsolutions.jump.feature.FeatureSchema;
025:
026: import de.fho.jump.pirol.ui.eventHandling.OKCancelListener;
027: import de.fho.jump.pirol.ui.panels.NewAttributePanel;
028: import de.fho.jump.pirol.ui.panels.OkCancelButtonPanel;
029: import de.fho.jump.pirol.ui.tools.DialogTools;
030: import de.fho.jump.pirol.utilities.FormulaParsing.FormulaValue;
031: import de.fho.jump.pirol.utilities.Properties.PropertiesHandler;
032: import de.fho.jump.pirol.utilities.attributes.AttributeInfo;
033:
034: /**
035: *
036: * Dialog to ask the user for information on the new attribute and for a formular,
037: * that represents a blue print to generate attribute values with.
038: *
039: * @author Ole Rahn
040: * <br>
041: * <br>FH Osnabrück - University of Applied Sciences Osnabrück,
042: * <br>Project: PIROL (2005),
043: * <br>Subproject: Daten- und Wissensmanagement
044: *
045: * @version $Rev: 856 $
046: */
047: public class EditAttributeByFormulaDialog extends JDialog {
048:
049: private static final long serialVersionUID = 3581710389701646491L;
050:
051: protected NewAttributePanel newAttrPanel = null;
052: protected OkCancelButtonPanel okCancelPanel = null;
053: protected FormulaEditingPanel formPanel = null;
054:
055: protected OKCancelListener okCancelListener = null;
056:
057: protected String text = null;
058:
059: protected FeatureSchema featureSchema = null;
060:
061: protected PropertiesHandler storedFormulas = null;
062:
063: /**
064: * @param parentFrame
065: * @param title
066: * @param modal
067: * @throws java.awt.HeadlessException
068: */
069: public EditAttributeByFormulaDialog(Frame parentFrame,
070: String title, boolean modal, String text,
071: FeatureSchema featureSchema,
072: PropertiesHandler storedFormulas) throws HeadlessException {
073: super (parentFrame, title, modal);
074:
075: this .text = text;
076: this .featureSchema = featureSchema;
077: this .storedFormulas = storedFormulas;
078:
079: this .okCancelListener = new OKCancelListener(this );
080:
081: this .setupUI();
082: }
083:
084: //[sstein 24.March 2007] new - since we dont have stored formulas
085: public EditAttributeByFormulaDialog(Frame parentFrame,
086: String title, boolean modal, String text,
087: FeatureSchema featureSchema) throws HeadlessException {
088: super (parentFrame, title, modal);
089:
090: this .text = text;
091: this .featureSchema = featureSchema;
092:
093: this .okCancelListener = new OKCancelListener(this );
094:
095: this .setupUI();
096: }
097:
098: protected void setupUI() {
099: JPanel content = new JPanel();
100: GridBagLayout gridbagLayout = new GridBagLayout();
101: GridBagConstraints c = new GridBagConstraints();
102: c.insets = new Insets(5, 5, 5, 5);
103:
104: int gridy = 1;
105: c.gridx = 1;
106: c.anchor = GridBagConstraints.NORTHWEST;
107: c.fill = GridBagConstraints.HORIZONTAL;
108: c.ipady = 20;
109: content.setLayout(gridbagLayout);
110:
111: c.gridy = gridy++;
112: content.add(DialogTools.getPanelWithLabels(this .text, 50), c);
113:
114: this .newAttrPanel = new NewAttributePanel(true,
115: new AttributeType[] { AttributeType.DOUBLE }, false);
116: c.gridy = gridy++;
117: content.add(this .newAttrPanel, c);
118:
119: //[sstein 24.March 2007] we dont have stored formulas
120: if (this .storedFormulas != null) {
121: this .formPanel = new FormulaEditingPanel(
122: this .featureSchema, this .storedFormulas,
123: this .newAttrPanel);
124: } else {
125: this .formPanel = new FormulaEditingPanel(
126: this .featureSchema, this .newAttrPanel);
127: }
128: this .okCancelListener.addValueChecker(this .formPanel);
129: c.gridy = gridy++;
130: content.add(this .formPanel, c);
131:
132: this .okCancelPanel = new OkCancelButtonPanel();
133: this .okCancelPanel.addActionListener(this .okCancelListener);
134: c.gridy = gridy++;
135: content.add(this .okCancelPanel, c);
136:
137: content.doLayout();
138:
139: this .getContentPane().add(content);
140: this .pack();
141:
142: }
143:
144: public FormulaValue getParsedFormula() {
145: return formPanel.getParsedFormula();
146: }
147:
148: public String getFormula() {
149: return formPanel.getFormula();
150: }
151:
152: /**
153: * @see NewAttributePanel#getAttributeInfo()
154: * @return Info on the new attribute
155: */
156: public AttributeInfo getAttributeInfo() {
157: return newAttrPanel.getAttributeInfo();
158: }
159:
160: /**
161: * @see OKCancelListener#wasOkClicked()
162: */
163: public boolean wasOkClicked() {
164: return okCancelListener.wasOkClicked();
165: }
166: }
|