001: /*
002: * Created on 28.06.2005 for PIROL
003: *
004: * SVN header information:
005: * $Author: javamap $
006: * $Rev: 856 $
007: * $Date: 2007-06-18 21:15:27 -0700 (Mon, 18 Jun 2007) $
008: * $Id: AddFormulaPartToTextArea_Action.java 856 2007-06-19 04:15:27Z javamap $
009: */
010: package de.fho.jump.pirol.plugins.EditAttributeByFormula;
011:
012: import java.awt.event.ActionEvent;
013:
014: import javax.swing.AbstractAction;
015: import javax.swing.JTextArea;
016:
017: import com.vividsolutions.jump.feature.FeatureSchema;
018:
019: /**
020: * Action to add a button's text to a given JTextArea, when the button is pressed.
021: *
022: * @author Ole Rahn
023: * <br>
024: * <br>FH Osnabrück - University of Applied Sciences Osnabrück,
025: * <br>Project: PIROL (2005),
026: * <br>Subproject: Daten- und Wissensmanagement
027: *
028: * @version $Rev: 856 $
029: *
030: */
031: public class AddFormulaPartToTextArea_Action extends AbstractAction {
032:
033: private static final long serialVersionUID = 3157240050072519462L;
034:
035: protected JTextArea textArea = null;
036: protected String[] mathSigns = null;
037: protected String formulaPart = null;
038:
039: protected boolean isMathSign = false;
040:
041: protected FeatureSchema featureSchema = null;
042:
043: /**
044: *
045: *@param textArea text area to add the button text to
046: */
047: public AddFormulaPartToTextArea_Action(String formulaPart,
048: JTextArea textArea, String[] mathSigns,
049: FeatureSchema featureSchema) {
050: super ();
051: this .textArea = textArea;
052: this .mathSigns = mathSigns;
053: this .formulaPart = formulaPart;
054:
055: this .isMathSign = this .isOperator(this .formulaPart);
056:
057: this .featureSchema = featureSchema;
058:
059: this .putValue(AbstractAction.NAME, this .formulaPart);
060: this .putValue(AbstractAction.SHORT_DESCRIPTION,
061: this .formulaPart);
062: }
063:
064: protected boolean isOperator(String op) {
065: for (int i = 0; i < this .mathSigns.length; i++) {
066: if (op.equals(this .mathSigns[i]))
067: return true;
068: }
069: return false;
070: }
071:
072: /**
073: *@inheritDoc
074: */
075: public void actionPerformed(ActionEvent event) {
076: String buttonText = this .formulaPart;
077:
078: if (this .featureSchema.hasAttribute(buttonText)
079: && buttonText.indexOf(" ") > -1) {
080: buttonText = "\"" + buttonText + "\"";
081: }
082:
083: if (textArea.getText().length() != 0
084: && buttonText.length() != 0)
085: buttonText = " " + buttonText;
086:
087: if (buttonText.length() != 0) {
088: boolean formulaOk = true;
089:
090: // TODO: prüfen ob zwei operatoren oder zwei operanden hintereinander benutzt wurden...
091:
092: if (formulaOk) {
093: //this.textArea.append(buttonText);
094: this.textArea.setText(this.textArea.getText()
095: + buttonText);
096: }
097: }
098: }
099:
100: }
|