Revision 420

View differences:

org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/buildNumber.properties
1
#Mon Jan 28 17:48:55 CET 2019
2
buildNumber=2156
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/test/java/org/gvsig/expressionfield/AllTests.java
1
package org.gvsig.expressionfield;
2

  
3
import junit.framework.Test;
4
import junit.framework.TestSuite;
5

  
6
public class AllTests {
7

  
8
	public static Test suite() {
9
		TestSuite suite = new TestSuite(
10
				"Test for com.iver.cit.gvsig.expressionField");
11
		//$JUnit-BEGIN$
12

  
13
		//$JUnit-END$
14
		return suite;
15
	}
16

  
17
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/ExpressionFieldExtension.java
1
/**
2
 * *****************************************************************************
3
 *
4
 * gvSIG. Desktop Geographic Information System.
5
 *
6
 * Copyright (C) 2007-2013 gvSIG Association.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 3
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
 * MA 02110-1301, USA.
22
 *
23
 * For any additional information, do not hesitate to contact us
24
 * at info AT gvsig.com, or visit our website www.gvsig.com.
25
 *
26
 ******************************************************************************
27
 */
28
package org.gvsig.expressionfield;
29

  
30
import java.awt.Component;
31
import java.util.ArrayList;
32
import java.util.Iterator;
33

  
34
import javax.swing.JOptionPane;
35

  
36
import org.apache.bsf.BSFManager;
37

  
38
import org.gvsig.andami.IconThemeHelper;
39
import org.gvsig.andami.PluginServices;
40
import org.gvsig.andami.messages.NotificationManager;
41
import org.gvsig.andami.plugins.Extension;
42
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
43
import org.gvsig.expressionfield.gui.FieldExpressionPage;
44
import org.gvsig.expressionfield.project.documents.table.IOperator;
45
import org.gvsig.expressionfield.project.documents.table.gui.EvalExpressionDialog;
46
import org.gvsig.expressionfield.project.documents.table.operators.Abs;
47
import org.gvsig.expressionfield.project.documents.table.operators.Acos;
48
import org.gvsig.expressionfield.project.documents.table.operators.After;
49
import org.gvsig.expressionfield.project.documents.table.operators.Area;
50
import org.gvsig.expressionfield.project.documents.table.operators.Asin;
51
import org.gvsig.expressionfield.project.documents.table.operators.Atan;
52
import org.gvsig.expressionfield.project.documents.table.operators.Before;
53
import org.gvsig.expressionfield.project.documents.table.operators.Ceil;
54
import org.gvsig.expressionfield.project.documents.table.operators.Cos;
55
import org.gvsig.expressionfield.project.documents.table.operators.DateToString;
56
import org.gvsig.expressionfield.project.documents.table.operators.Distinct;
57
import org.gvsig.expressionfield.project.documents.table.operators.Division;
58
import org.gvsig.expressionfield.project.documents.table.operators.E;
59
import org.gvsig.expressionfield.project.documents.table.operators.EndsWith;
60
import org.gvsig.expressionfield.project.documents.table.operators.Equal;
61
import org.gvsig.expressionfield.project.documents.table.operators.Equals;
62
import org.gvsig.expressionfield.project.documents.table.operators.Exp;
63
import org.gvsig.expressionfield.project.documents.table.operators.Floor;
64
import org.gvsig.expressionfield.project.documents.table.operators.Geometry;
65
import org.gvsig.expressionfield.project.documents.table.operators.GetTimeDate;
66
import org.gvsig.expressionfield.project.documents.table.operators.IndexOf;
67
import org.gvsig.expressionfield.project.documents.table.operators.IsNumber;
68
import org.gvsig.expressionfield.project.documents.table.operators.LastIndexOf;
69
import org.gvsig.expressionfield.project.documents.table.operators.Length;
70
import org.gvsig.expressionfield.project.documents.table.operators.LessEquals;
71
import org.gvsig.expressionfield.project.documents.table.operators.LessThan;
72
import org.gvsig.expressionfield.project.documents.table.operators.Log;
73
import org.gvsig.expressionfield.project.documents.table.operators.Max;
74
import org.gvsig.expressionfield.project.documents.table.operators.Min;
75
import org.gvsig.expressionfield.project.documents.table.operators.Minus;
76
import org.gvsig.expressionfield.project.documents.table.operators.MoreEquals;
77
import org.gvsig.expressionfield.project.documents.table.operators.MoreThan;
78
import org.gvsig.expressionfield.project.documents.table.operators.Perimeter;
79
import org.gvsig.expressionfield.project.documents.table.operators.Pi;
80
import org.gvsig.expressionfield.project.documents.table.operators.Plus;
81
import org.gvsig.expressionfield.project.documents.table.operators.PointX;
82
import org.gvsig.expressionfield.project.documents.table.operators.PointY;
83
import org.gvsig.expressionfield.project.documents.table.operators.Pow;
84
import org.gvsig.expressionfield.project.documents.table.operators.Random;
85
import org.gvsig.expressionfield.project.documents.table.operators.RecordIndex;
86
import org.gvsig.expressionfield.project.documents.table.operators.Replace;
87
import org.gvsig.expressionfield.project.documents.table.operators.Round;
88
import org.gvsig.expressionfield.project.documents.table.operators.SetTimeDate;
89
import org.gvsig.expressionfield.project.documents.table.operators.Sin;
90
import org.gvsig.expressionfield.project.documents.table.operators.Sqrt;
91
import org.gvsig.expressionfield.project.documents.table.operators.StartsWith;
92
import org.gvsig.expressionfield.project.documents.table.operators.SubString;
93
import org.gvsig.expressionfield.project.documents.table.operators.Tan;
94
import org.gvsig.expressionfield.project.documents.table.operators.Times;
95
import org.gvsig.expressionfield.project.documents.table.operators.ToDate;
96
import org.gvsig.expressionfield.project.documents.table.operators.ToDegrees;
97
import org.gvsig.expressionfield.project.documents.table.operators.ToLowerCase;
98
import org.gvsig.expressionfield.project.documents.table.operators.ToNumber;
99
import org.gvsig.expressionfield.project.documents.table.operators.ToRadians;
100
import org.gvsig.expressionfield.project.documents.table.operators.ToString;
101
import org.gvsig.expressionfield.project.documents.table.operators.ToUpperCase;
102
import org.gvsig.expressionfield.project.documents.table.operators.Trim;
103
import org.gvsig.fmap.dal.exception.DataException;
104
import org.gvsig.tools.ToolsLocator;
105
import org.gvsig.tools.extensionpoint.ExtensionPoint;
106
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
107
import org.gvsig.utils.swing.threads.AbstractMonitorableTask;
108

  
109
import org.slf4j.Logger;
110
import org.slf4j.LoggerFactory;
111

  
112
/**
113
 * @author Vicente Caballero Navarro
114
 */
115
public class ExpressionFieldExtension extends Extension {
116

  
117
    private static Logger logger = LoggerFactory.getLogger(ExpressionFieldExtension.class);
118

  
119
    public static final String JYTHON = "jython";
120
    private static BSFManager interpreter = new BSFManager();
121
    private FeatureTableDocumentPanel table = null;
122
    private static ArrayList<IOperator> operators = new ArrayList<IOperator>();
123

  
124
    public void initialize() {
125
        registerIcons();
126
        registerOperations();
127
    }
128

  
129
    public void execute(String actionCommand) {
130
        if ( "table-expression-field".equalsIgnoreCase(actionCommand) ) {
131
            org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager().getActiveWindow();
132
            table = (FeatureTableDocumentPanel) window;
133
            if ( !table.getModel().getStore().isEditing() ) {
134
                int option = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), PluginServices.getText(this, "is_not_in_editing_are_you_sure"));
135
                if ( option != JOptionPane.OK_OPTION ) {
136
                    return;
137
                }
138
            }
139
            if ( operators.isEmpty() ) {
140
                PluginServices.cancelableBackgroundExecution(new EvalOperatorsTask());
141
            } else {
142
                EvalExpressionDialog eed = new EvalExpressionDialog(table, interpreter, operators);
143
                PluginServices.getMDIManager().addWindow(eed);
144
            }
145
        }
146
    }
147

  
148
    public void postInitialize() {
149

  
150
    }
151

  
152
    public boolean isEnabled() {
153
        org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager().getActiveWindow();
154
        if ( window instanceof FeatureTableDocumentPanel ) {
155
            FeatureTableDocumentPanel table = (FeatureTableDocumentPanel) window;
156
            int columnSelected = 0;
157
            try {
158
                columnSelected = table.getTablePanel().getTable().getSelectedColumnCount();
159
            } catch (DataException e) {
160
                logger.error("Can't get selected column in table.", e);
161
            }
162
            if ( columnSelected > 0 && table.getModel().getStore().isEditing() ) {
163
                return true;
164
            }
165
        }
166
        return false;
167
    }
168

  
169
    public boolean isVisible() {
170

  
171
        org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager().getActiveWindow();
172
        if ( window instanceof FeatureTableDocumentPanel ) {
173
            return true;
174
        }
175
        return false;
176
    }
177

  
178
    private void registerOperations() {
179
        ExtensionPointManager extensionPointsManager =ToolsLocator.getExtensionPointManager();
180
        ExtensionPoint ep = extensionPointsManager.add("AplicationPreferences", "");
181
        ep.append("fieldExpression", "", new FieldExpressionPage());
182

  
183
        ExtensionPoint extensionPoints = ToolsLocator.getExtensionPointManager().add(
184
                "ColumnOperators", "");
185
        extensionPoints.append(Abs.class.toString(), "", Abs.class);
186
        extensionPoints.append(Acos.class.toString(), "", Acos.class);
187
        extensionPoints.append(After.class.toString(), "", After.class);
188
        extensionPoints.append(Area.class.toString(), "", Area.class);
189
        extensionPoints.append(Asin.class.toString(), "", Asin.class);
190
        extensionPoints.append(Atan.class.toString(), "", Atan.class);
191
        extensionPoints.append(Acos.class.toString(), "", Acos.class);
192
        extensionPoints.append(Before.class.toString(), "", Before.class);
193
        extensionPoints.append(Ceil.class.toString(), "", Ceil.class);
194
        extensionPoints.append(Cos.class.toString(), "", Cos.class);
195
        extensionPoints.append(DateToString.class.toString(), "", DateToString.class);
196
        extensionPoints.append(Distinct.class.toString(), "", Distinct.class);
197
        extensionPoints.append(Division.class.toString(), "", Division.class);
198
        extensionPoints.append(E.class.toString(), "", E.class);
199
        extensionPoints.append(EndsWith.class.toString(), "", EndsWith.class);
200
        extensionPoints.append(Equal.class.toString(), "", Equal.class);
201
        extensionPoints.append(Equals.class.toString(), "", Equals.class);
202
        extensionPoints.append(Exp.class.toString(), "", Exp.class);
203
        extensionPoints.append(Floor.class.toString(), "", Floor.class);
204
        extensionPoints.append(Geometry.class.toString(), "", Geometry.class);
205
        extensionPoints.append(GetTimeDate.class.toString(), "", GetTimeDate.class);
206
        extensionPoints.append(IndexOf.class.toString(), "", IndexOf.class);
207
        extensionPoints.append(IsNumber.class.toString(), "", IsNumber.class);
208
        extensionPoints.append(LastIndexOf.class.toString(), "", LastIndexOf.class);
209
        extensionPoints.append(Length.class.toString(), "", Length.class);
210
        extensionPoints.append(LessEquals.class.toString(), "", LessEquals.class);
211
        extensionPoints.append(LessThan.class.toString(), "", LessThan.class);
212
        extensionPoints.append(Log.class.toString(), "", Log.class);
213
        extensionPoints.append(Max.class.toString(), "", Max.class);
214
        extensionPoints.append(Min.class.toString(), "", Min.class);
215
        extensionPoints.append(Minus.class.toString(), "", Minus.class);
216
        extensionPoints.append(MoreEquals.class.toString(), "", MoreEquals.class);
217
        extensionPoints.append(MoreThan.class.toString(), "", MoreThan.class);
218
        extensionPoints.append(Perimeter.class.toString(), "", Perimeter.class);
219
        extensionPoints.append(Pi.class.toString(), "", Pi.class);
220
        extensionPoints.append(Plus.class.toString(), "", Plus.class);
221
        extensionPoints.append(PointX.class.toString(), "", PointX.class);
222
        extensionPoints.append(PointY.class.toString(), "", PointY.class);
223
        extensionPoints.append(Pow.class.toString(), "", Pow.class);
224
        extensionPoints.append(Random.class.toString(), "", Random.class);
225

  
226
        // Added November 2013
227
        extensionPoints.append(RecordIndex.class.toString(), "", RecordIndex.class);
228

  
229
        extensionPoints.append(Replace.class.toString(), "", Replace.class);
230
        extensionPoints.append(Round.class.toString(), "", Round.class);
231
        extensionPoints.append(SetTimeDate.class.toString(), "", SetTimeDate.class);
232
        extensionPoints.append(Sin.class.toString(), "", Sin.class);
233
        extensionPoints.append(Sqrt.class.toString(), "", Sqrt.class);
234
        extensionPoints.append(StartsWith.class.toString(), "", StartsWith.class);
235
        extensionPoints.append(SubString.class.toString(), "", SubString.class);
236
        extensionPoints.append(Tan.class.toString(), "", Tan.class);
237
        extensionPoints.append(Times.class.toString(), "", Times.class);
238
        extensionPoints.append(ToDate.class.toString(), "", ToDate.class);
239
        extensionPoints.append(ToDegrees.class.toString(), "", ToDegrees.class);
240
        extensionPoints.append(ToLowerCase.class.toString(), "", ToLowerCase.class);
241
        extensionPoints.append(ToNumber.class.toString(), "", ToNumber.class);
242
        extensionPoints.append(ToRadians.class.toString(), "", ToRadians.class);
243
        extensionPoints.append(ToString.class.toString(), "", ToString.class);
244
        extensionPoints.append(ToUpperCase.class.toString(), "", ToUpperCase.class);
245
        extensionPoints.append(Trim.class.toString(), "", Trim.class);
246
    }
247

  
248
    private void registerIcons() {
249
        IconThemeHelper.registerIcon("action", "table-expression-field", this);
250
        IconThemeHelper.registerIcon("preferences", "expression-field-preferences", this);
251
    }
252

  
253
    private class EvalOperatorsTask extends AbstractMonitorableTask {
254

  
255
        private ExtensionPoint extensionPoint;
256

  
257
        public EvalOperatorsTask() {
258
            setInitialStep(0);
259
            setDeterminatedProcess(true);
260
            setStatusMessage(PluginServices.getText(this, "charging_operators") + "...");
261
            this.extensionPoint = ToolsLocator.getExtensionPointManager().get(
262
                    "ColumnOperators");
263
            setFinalStep(extensionPoint.getCount() + 1);
264
        }
265

  
266
        public void run() throws Exception {
267
            NotificationManager.addInfo(PluginServices.getText(this, "charging_operators"));
268
            long t1 = System.currentTimeMillis();
269
            Iterator iterator = extensionPoint.iterator();
270
            while ( iterator.hasNext() ) {
271
                try {
272
                    if ( isCanceled() ) {
273
                        return;
274
                    }
275
                    org.gvsig.tools.extensionpoint.ExtensionPoint.Extension obj = (org.gvsig.tools.extensionpoint.ExtensionPoint.Extension) iterator.next();
276
                    IOperator operator = (IOperator) extensionPoint.create(obj.getName());
277

  
278
                    operator.eval(interpreter);
279
                    operators.add(operator);
280
                    reportStep();
281
                    setNote(operator.getClass().getName());
282
                } catch (InstantiationException e) {
283
                    e.printStackTrace();
284
                } catch (IllegalAccessException e) {
285
                    e.printStackTrace();
286
                } catch (ClassCastException e) {
287
                    e.printStackTrace();
288
                }
289
            }
290
            long t2 = System.currentTimeMillis();
291
            System.out.println("Tiempo en evaluar y crear del extension point = " + (t2 - t1));
292
            long t3 = System.currentTimeMillis();
293
            System.out.println("Tiempo en a?adir los operadores correctos = " + (t3 - t2));
294
            reportStep();
295
        }
296

  
297
        public void finished() {
298
            if ( isCanceled() ) {
299
                return;
300
            }
301
            NotificationManager.addInfo(PluginServices.getText(this, "charged_operators"));
302
            EvalExpressionDialog eed = new EvalExpressionDialog(table, interpreter, operators);
303
            PluginServices.getMDIManager().addWindow(eed);
304
        }
305

  
306
    }
307
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/gui/FieldExpressionPage.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.gui;
27

  
28
import java.awt.event.MouseEvent;
29
import java.awt.event.MouseListener;
30
import java.util.prefs.Preferences;
31

  
32
import javax.swing.ImageIcon;
33
import javax.swing.JCheckBox;
34
import javax.swing.JPanel;
35
import javax.swing.JTextArea;
36
import javax.swing.JTextField;
37

  
38
import org.gvsig.andami.IconThemeHelper;
39
import org.gvsig.andami.PluginServices;
40
import org.gvsig.andami.preferences.AbstractPreferencePage;
41
import org.gvsig.andami.preferences.StoreException;
42

  
43

  
44
/**
45
 * @author Vicente Caballero Navarro
46
 */
47
public class FieldExpressionPage extends AbstractPreferencePage {
48
	private static Preferences prefs = Preferences.userRoot().node( "fieldExpressionOptions" );
49
	private JTextArea jTextArea = null;
50
	private JTextField txtLimit;
51
	private JCheckBox ckLimit=null;
52
	private ImageIcon icon;
53

  
54
	public FieldExpressionPage() {
55
		super();
56
		
57
		icon = IconThemeHelper.getImageIcon("expression-field-preferences");
58
		
59
		addComponent(getJTextArea());
60

  
61
		addComponent(PluginServices.getText(this, "limit_rows_in_memory") + ":",
62
			txtLimit = new JTextField("", 15));
63
		addComponent(ckLimit = new JCheckBox(PluginServices.getText(this, "without_limit")));
64
		ckLimit.addMouseListener(new MouseListener() {
65
			public void mouseClicked(MouseEvent e) {
66
				if (ckLimit.isSelected()) {
67
					txtLimit.setText(PluginServices.getText(this, "without_limit"));
68
				}else {
69
					if (txtLimit.getText().equals(PluginServices.getText(this, "without_limit")))
70
					txtLimit.setText("500000");
71
				}
72

  
73
			}
74
			public void mouseEntered(MouseEvent e) {
75
			}
76
			public void mouseExited(MouseEvent e) {
77
			}
78
			public void mousePressed(MouseEvent e) {
79
			}
80
			public void mouseReleased(MouseEvent e) {
81
			}
82

  
83
		});
84
	}
85

  
86
	public void initializeValues() {
87
		int limit = prefs.getInt("limit_rows_in_memory",-1);
88
		if (limit==-1) {
89
			ckLimit.setSelected(true);
90
			txtLimit.setText(PluginServices.getText(this,"without_limit"));
91
		}else {
92
			ckLimit.setSelected(false);
93
			txtLimit.setText(String.valueOf(limit));
94
		}
95
	}
96

  
97
	public String getID() {
98
		return this.getClass().getName();
99
	}
100

  
101
	public String getTitle() {
102
		return PluginServices.getText(this, "limit_rows_in_memory");
103
	}
104

  
105
	public JPanel getPanel() {
106
		return this;
107
	}
108

  
109
	public void storeValues() throws StoreException {
110
		int limit;
111
		try{
112
			if (ckLimit.isSelected()) {
113
				limit=-1;
114
			}else {
115
//			if (txtLimit.getText().equals(PluginServices.getText(this,"without_limit"))) {
116
//				limit=-1;
117
//			}else {
118
				limit=Integer.parseInt(txtLimit.getText());
119
			}
120
		}catch (Exception e) {
121
			throw new StoreException(PluginServices.getText(this,"limit_rows_in_memory")+PluginServices.getText(this,"error"));
122
		}
123
		prefs.putInt("limit_rows_in_memory", limit);
124
	}
125

  
126
	public void initializeDefaults() {
127
		int limit=prefs.getInt("limit_rows_in_memory",-1);
128
		if (limit==-1) {
129
			ckLimit.setSelected(true);
130
			txtLimit.setText(PluginServices.getText(this,"without_limit"));
131
		}else {
132
			ckLimit.setSelected(false);
133
			txtLimit.setText(String.valueOf(limit));
134
		}
135
	}
136

  
137
	public ImageIcon getIcon() {
138
		return icon;
139
	}
140
	/**
141
	 * This method initializes jTextArea
142
	 *
143
	 * @return javax.swing.JTextArea
144
	 */
145
	private JTextArea getJTextArea() {
146
		if (jTextArea == null) {
147
			jTextArea = new JTextArea();
148
			jTextArea.setBounds(new java.awt.Rectangle(13,7,285,57));
149
			jTextArea.setForeground(java.awt.Color.black);
150
			jTextArea.setBackground(java.awt.SystemColor.control);
151
			jTextArea.setRows(3);
152
			jTextArea.setWrapStyleWord(true);
153
			jTextArea.setLineWrap(true);
154
			jTextArea.setEditable(false);
155
			jTextArea.setText(PluginServices.getText(this,"specifies_the_limit_rows_in_memory_when_the_program_eval_the_expression"));
156
		}
157
		return jTextArea;
158
	}
159

  
160
	public boolean isValueChanged() {
161
		return super.hasChanged();
162
	}
163

  
164
	public void setChangesApplied() {
165
		setChanged(false);
166
	}
167
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/GraphicOperator.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table;
27

  
28
import java.awt.geom.PathIterator;
29
import java.util.ArrayList;
30

  
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.GeometryManager;
34
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public abstract class GraphicOperator extends AbstractOperator{
40
	private FLyrVect lv=null;
41
	protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
42
	
43
	public void setLayer(FLyrVect lv) {
44
		this.lv=lv;
45
	}
46
	public FLyrVect getLayer() {
47
		return lv;
48
	}
49
	public abstract double process(org.gvsig.fmap.dal.feature.Feature feature);
50
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Plus.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
32
import org.gvsig.expressionfield.project.documents.table.IOperator;
33

  
34
/**
35
 * @author Vicente Caballero Navarro
36
 */
37
public class Plus extends AbstractOperator{
38

  
39
	public String addText(String s) {
40
		return s.concat(toString());
41
	}
42
	public String toString() {
43
		return "+";
44
	}
45
	public void eval(BSFManager interpreter) throws BSFException {
46
	}
47
	public boolean isEnable() {
48
		return (getType()==IOperator.NUMBER || getType()==IOperator.STRING);
49
	}
50
	public String getTooltip(){
51
		return PluginServices.getText(this,"operator")+":  "+addText("")+"\n"+getDescription();
52
	}
53
	public String getDescription() {
54
        return PluginServices.getText(this, "returns") + ": " +
55
        PluginServices.getText(this, "numeric_value") + "\n" +
56
        PluginServices.getText(this, "description") + ": " +
57
        "Returns the result of sum.";
58
    }
59
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Atan.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public class Atan extends AbstractOperator{
40

  
41
	public String addText(String s) {
42
		return toString()+"("+s+")";
43
	}
44
	public String toString() {
45
		return "atan";
46
	}
47
	public void eval(BSFManager interpreter) throws BSFException {
48
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double atan(double value){return java.lang.Math.atan(value);};");
49
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def atan(value):\n" +
50
				"  import java.lang.Math\n" +
51
				"  return java.lang.Math.atan(value)");
52
	}
53
	public boolean isEnable() {
54
		return (getType()==IOperator.NUMBER);
55
	}
56
	public String getDescription() {
57
        return PluginServices.getText(this, "parameter") + ": " +
58
        PluginServices.getText(this, "numeric_value") + "\n" +
59
        PluginServices.getText(this, "returns") + ": " +
60
        PluginServices.getText(this, "numeric_value") + "\n" +
61
        PluginServices.getText(this, "description") + ": " +
62
        "Returns the arc tangent of an angle, in the range of -pi/2 through pi/2. Special cases:\n" +
63
        "* If the argument is NaN, then the result is NaN.\n" +
64
        "* If the argument is zero, then the result is a zero with the same sign as the argument.\n";
65
    }
66
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Min.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35
/**
36
 * @author Vicente Caballero Navarro
37
 */
38
public class Min extends AbstractOperator{
39

  
40
	public String addText(String s) {
41
		return toString()+"("+s+")";
42
	}
43
	public String toString() {
44
		return "min";
45
	}
46
	public void eval(BSFManager interpreter) throws BSFException {
47
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double min(double value1,double value2){return java.lang.Math.min(value1,value2);};");
48
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def min(value1, value2):\n" +
49
				"  import java.lang.Math\n" +
50
				"  return java.lang.Math.min(value1,value2)");
51
	}
52
	public boolean isEnable() {
53
		return (getType()==IOperator.NUMBER);
54
	}
55
	public String getTooltip(){
56
		return PluginServices.getText(this,"operator")+":  "+toString()+ "("+ PluginServices.getText(this,"parameter")+"1,"+PluginServices.getText(this,"parameter")+"2"+")\n"+getDescription();
57
	}
58
	public String getDescription() {
59
        return PluginServices.getText(this, "parameter") + "1"+": " +
60
        PluginServices.getText(this, "numeric_value") + "\n"+
61
        PluginServices.getText(this, "parameter") + "2"+": " +
62
        PluginServices.getText(this, "numeric_value") + "\n"+
63
        PluginServices.getText(this, "returns") + ": " +
64
        PluginServices.getText(this, "numeric_value") + "\n" +
65
        PluginServices.getText(this, "description") + ": " +
66
        "Returns the smaller of two int values. That is, the result the argument closer to the value of Integer.MIN_VALUE.\n" +
67
        "If the arguments have the same value, the result is that same value.";
68
    }
69
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Field.java
1
/**
2
 * *****************************************************************************
3
 *
4
 * gvSIG. Desktop Geographic Information System.
5
 *
6
 * Copyright (C) 2007-2013 gvSIG Association.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 3
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
 * MA 02110-1301, USA.
22
 *
23
 * For any additional information, do not hesitate to contact us
24
 * at info AT gvsig.com, or visit our website www.gvsig.com.
25
 *
26
 ******************************************************************************
27
 */
28
package org.gvsig.expressionfield.project.documents.table.operators;
29

  
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.fmap.dal.DataTypes;
32
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
33

  
34
/**
35
 * @author Vicente Caballero Navarro
36
 */
37
public class Field extends AbstractField {
38

  
39
    private FeatureAttributeDescriptor fd;
40
    private String typeField;
41

  
42
    public Field() {
43
    }
44

  
45
    public void setFieldDescription(FeatureAttributeDescriptor fd) {
46
        this.fd = fd;
47
        switch (fd.getType()) {
48
        case DataTypes.INT:
49
        case DataTypes.LONG:
50
        case DataTypes.FLOAT:
51
        case DataTypes.DOUBLE:
52
            typeField = PluginServices.getText(this, "numeric_value");
53
            break;
54
        case DataTypes.STRING:
55
            typeField = PluginServices.getText(this, "string_value");
56
            break;
57
        case DataTypes.BOOLEAN:
58
            typeField = PluginServices.getText(this, "boolean_value");
59
            break;
60
        case DataTypes.DATE:
61
            typeField = PluginServices.getText(this, "date_value");
62
            break;
63
        }
64

  
65
    }
66

  
67
    public String addText(String s) {
68
        return s.concat(toString());
69
    }
70

  
71
    public String toString() {
72
        return "[" + fd.getName() + "]";
73
    }
74

  
75
    public boolean isEnable() {
76
        return true;
77
    }
78

  
79
    public String getTooltip() {
80
        return PluginServices.getText(this, "field") + ":  " + fd.getName() + "\n" + getDescription();
81
    }
82

  
83
    public String getDescription() {
84
        return PluginServices.getText(this, "type") + ": "
85
                + typeField;
86
    }
87

  
88
    public String getName() {
89
        return this.fd.getName();
90
    }
91
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/ToRadians.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public class ToRadians extends AbstractOperator{
40

  
41
	public String addText(String s) {
42
		return toString()+"("+s+")";
43
	}
44
	public String toString() {
45
		return "toRadians";
46
	}
47
	public void eval(BSFManager interpreter) throws BSFException {
48
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double toRadians(double value){return java.lang.Math.toRadians(value);};");
49
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def toRadians(value):\n" +
50
				"  import java.lang.Math\n" +
51
				"  return java.lang.Math.toRadians(value)");
52
	}
53
	public boolean isEnable() {
54
		return (getType()==IOperator.NUMBER);
55
	}
56
	public String getDescription() {
57
        return PluginServices.getText(this, "parameter") + ": " +
58
        PluginServices.getText(this, "numeric_value") + "\n" +
59
        PluginServices.getText(this, "returns") + ": " +
60
        PluginServices.getText(this, "numeric_value") + "\n" +
61
        PluginServices.getText(this, "description") + ": " +
62
        "Converts an angle measured in degrees to an approximately equivalent angle measured in radians. The conversion from degrees to radians is generally inexact.";
63
    }
64
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Max.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35
/**
36
 * @author Vicente Caballero Navarro
37
 */
38
public class Max extends AbstractOperator{
39

  
40
	public String addText(String s) {
41
		return toString()+"("+s+")";
42
	}
43
	public String toString() {
44
		return "max";
45
	}
46
	public void eval(BSFManager interpreter) throws BSFException {
47
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double max(double value1,double value2){return java.lang.Math.max(value1,value2);};");
48
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def max(value1,value2):\n" +
49
				"  import java.lang.Math\n" +
50
				"  return java.lang.Math.max(value1,value2)");
51
	}
52
	public boolean isEnable() {
53
		return (getType()==IOperator.NUMBER);
54
	}
55
	public String getTooltip(){
56
		return PluginServices.getText(this,"operator")+":  "+toString()+ "("+ PluginServices.getText(this,"parameter")+"1,"+PluginServices.getText(this,"parameter")+"2"+")\n"+getDescription();
57
	}
58
	public String getDescription() {
59
        return PluginServices.getText(this, "parameter") + "1"+": " +
60
        PluginServices.getText(this, "numeric_value") + "\n"+
61
        PluginServices.getText(this, "parameter") + "2"+": " +
62
        PluginServices.getText(this, "numeric_value") + "\n"+
63
        PluginServices.getText(this, "returns") + ": " +
64
        PluginServices.getText(this, "numeric_value") + "\n" +
65
        PluginServices.getText(this, "description") + ": " +
66
        "Returns the greater of two double values. That is, the result is the argument closer to positive infinity. \n" +
67
        "If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN.\n" +
68
        "Unlike the the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero.\n" +
69
        "If one argument is positive zero and the other negative zero, the result is positive zero.";
70
    }
71
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Acos.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public class Acos extends AbstractOperator{
40

  
41
	public String addText(String s) {
42
		return toString()+"("+s+")";
43
	}
44
	public String toString() {
45
		return "acos";
46
	}
47
	public void eval(BSFManager interpreter) throws BSFException {
48
		interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1,
49
	            "def acos(value):\n" +
50
	            "  import java.lang.Math\n"+
51
	            "  return java.lang.Math.acos(value)\n");
52
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double acos(double value){return java.lang.Math.acos(value);};");
53
	}
54
	public boolean isEnable() {
55
		return (getType()==IOperator.NUMBER);
56
	}
57
	public String getDescription() {
58
        return PluginServices.getText(this, "parameter") + ": " +
59
        PluginServices.getText(this, "numeric_value") + "\n" +
60
        PluginServices.getText(this, "returns") + ": " +
61
        PluginServices.getText(this, "numeric_value") + "\n" +
62
        PluginServices.getText(this, "description") + ": " +
63
        "Returns the arc cosine of an angle, in the range of 0.0 through pi. Special case:\n" +
64
        "* If the argument is NaN or its absolute value is greater than 1, then the result is NaN.";
65
    }
66
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Sin.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public class Sin extends AbstractOperator{
40

  
41
	public String addText(String s) {
42
		return toString()+"("+s+")";
43
	}
44
	public String toString() {
45
		return "sin";
46
	}
47
	public void eval(BSFManager interpreter) throws BSFException {
48
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double sin(double value){return java.lang.Math.sin(value);};");
49
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def sin(value):\n" +
50
				"  import java.lang.Math\n" +
51
				"  return java.lang.Math.sin(value)");
52
	}
53
	public boolean isEnable() {
54
		return (getType()==IOperator.NUMBER);
55
	}
56
	public String getDescription() {
57
        return PluginServices.getText(this, "parameter") + ": " +
58
        PluginServices.getText(this, "numeric_value") + "\n" +
59
        PluginServices.getText(this, "returns") + ": " +
60
        PluginServices.getText(this, "numeric_value") + "\n" +
61
        PluginServices.getText(this, "description") + ": " +
62
        "Returns the trigonometric sine of an angle. Special cases:\n" +
63
        "* If the argument is NaN or an infinity, then the result is NaN.\n" +
64
        "* If the argument is zero, then the result is a zero with the same sign as the argument.";
65
    }
66
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Sqrt.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public class Sqrt extends AbstractOperator{
40

  
41
	public String addText(String s) {
42
		return toString()+"("+s+")";
43
	}
44
	public String toString() {
45
		return "sqrt";
46
	}
47
	public void eval(BSFManager interpreter) throws BSFException {
48
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double sqrt(double value){return java.lang.Math.sqrt(value);};");
49
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def sqrt(value):\n" +
50
				"  import java.lang.Math\n" +
51
				"  return java.lang.Math.sqrt(value)");
52
	}
53
	public boolean isEnable() {
54
		return (getType()==IOperator.NUMBER);
55
	}
56
	public String getDescription() {
57
        return PluginServices.getText(this, "parameter") + ": " +
58
        PluginServices.getText(this, "numeric_value") + "\n" +
59
        PluginServices.getText(this, "returns") + ": " +
60
        PluginServices.getText(this, "numeric_value") + "\n" +
61
        PluginServices.getText(this, "description") + ": " +
62
        "Returns the correctly rounded positive square root of a double value. Special cases:\n" +
63
        "* If the argument is NaN or less than zero, then the result is NaN.\n" +
64
        "* If the argument is positive infinity, then the result is positive infinity.\n" +
65
        "* If the argument is positive zero or negative zero, then the result is the same as the argument.";
66
    }
67
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Equals.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.ExpressionFieldExtension;
32
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
33
import org.gvsig.expressionfield.project.documents.table.IOperator;
34

  
35

  
36
/**
37
 * @author Vicente Caballero Navarro
38
 */
39
public class Equals extends AbstractOperator{
40

  
41
	public String addText(String s) {
42
		return toString()+"("+s+")";
43
	}
44
	public String toString() {
45
		return "equals";
46
	}
47
	public void eval(BSFManager interpreter) throws BSFException {
48
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"boolean equals(java.lang.Object value1,java.lang.Object value2){return value1.equals(value2);};");
49
		interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,
50
				"def equals(value1,value2):\n" +
51
				"  return value1 == value2");
52
	}
53
	public boolean isEnable() {
54
		return (getType()==IOperator.STRING || getType()==IOperator.DATE);
55
	}
56
	public String getTooltip(){
57
		return PluginServices.getText(this,"operator")+":  "+toString()+"("+PluginServices.getText(this,"parameter")+"1,"+PluginServices.getText(this,"parameter")+"2"+")"+"\n"+getDescription();
58
	}
59
	public String getDescription() {
60
        return PluginServices.getText(this, "parameter") + "1"+": " +
61
//        PluginServices.getText(this, "string_value") + "\n"+
62
        PluginServices.getText(this, "parameter") + "2"+": " +
63
//        PluginServices.getText(this, "string_value") + "\n"+
64
        PluginServices.getText(this, "returns") + ": " +
65
        PluginServices.getText(this, "boolean_value") + "\n" +
66
        PluginServices.getText(this, "description") + ": " +
67
        "Compares the parameter1 to the parameter2. The result is true if and only if the arguments are not null and represents the same object.";
68
    }
69
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Minus.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.expressionfield.project.documents.table.operators;
27

  
28
import org.apache.bsf.BSFException;
29
import org.apache.bsf.BSFManager;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.expressionfield.project.documents.table.AbstractOperator;
32
import org.gvsig.expressionfield.project.documents.table.IOperator;
33

  
34
/**
35
 * @author Vicente Caballero Navarro
36
 */
37
public class Minus extends AbstractOperator{
38

  
39
	public String addText(String s) {
40
		return s.concat(toString());
41
	}
42
	public String toString() {
43
		return "-";
44
	}
45
	public void eval(BSFManager interpreter) throws BSFException {
46
	}
47
	public boolean isEnable() {
48
		return (getType()==IOperator.NUMBER);
49
	}
50
	public String getTooltip(){
51
		return PluginServices.getText(this,"operator")+":  "+addText("")+"\n"+getDescription();
52
	}
53
	public String getDescription() {
54
        return PluginServices.getText(this, "returns") + ": " +
55
        PluginServices.getText(this, "numeric_value") + "\n" +
56
        PluginServices.getText(this, "description") + ": " +
57
        "Returns the result of rest.";
58
    }
59
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/Perimeter.java
1
/**
2
 * *****************************************************************************
3
 *
4
 * gvSIG. Desktop Geographic Information System.
5
 *
6
 * Copyright (C) 2007-2013 gvSIG Association.
7
 *
8
 * This program is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License as published by the Free Software
10
 * Foundation; either version 3 of the License, or (at your option) any later
11
 * version.
12
 *
13
 * This program is distributed in the hope that it will be useful, but WITHOUT
14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16
 * details.
17
 *
18
 * You should have received a copy of the GNU General Public License along with
19
 * this program; if not, write to the Free Software Foundation, Inc., 51
20
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
 *
22
 * For any additional information, do not hesitate to contact us at info AT
23
 * gvsig.com, or visit our website www.gvsig.com.
24
 *
25
 ******************************************************************************
26
 */
27
package org.gvsig.expressionfield.project.documents.table.operators;
28

  
29

  
30
import org.apache.bsf.BSFException;
31
import org.apache.bsf.BSFManager;
32
import org.cresques.cts.IProjection;
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.expressionfield.ExpressionFieldExtension;
35
import org.gvsig.expressionfield.project.documents.table.GraphicOperator;
36
import org.gvsig.expressionfield.project.documents.table.IOperator;
37
import org.gvsig.fmap.dal.exception.DataException;
38
import org.gvsig.fmap.dal.feature.Feature;
39
import org.gvsig.fmap.dal.feature.FeatureStore;
40
import org.gvsig.fmap.geom.GeometryLocator;
41
import org.gvsig.fmap.geom.GeometryManager;
42
import org.gvsig.fmap.mapcontext.MapContext;
43
import org.gvsig.fmap.mapcontrol.MapControlLocator;
44
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
46

  
47
/**
48
 * @author Vicente Caballero Navarro
49
 */
50
public class Perimeter extends GraphicOperator {
51

  
52
    private static final Logger logger = LoggerFactory.getLogger(Area.class);
53
    
54
    public String addText(String s) {
55
        return s.concat(toString() + "()");
56
    }
57

  
58
    public double process(Feature feature) {
59
        org.gvsig.fmap.geom.Geometry geom = null;
60
        geom = feature.getDefaultGeometry();
61
        MapContext mapContext = getLayer().getMapContext();
62
        IProjection proj = mapContext.getProjection();
63
        int distanceUnits = mapContext.getViewPort().getDistanceArea();
64
        return MapControlLocator.getMapControlManager().perimeter(geom, proj, distanceUnits);
65
    }
66

  
67
    public void eval(BSFManager interpreter) throws BSFException {
68
        interpreter.declareBean("jperimeter", this, Perimeter.class);
69
//		interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double perimeter(){return jperimeter.process(indexRow);};");
70
        interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1, "def perimeter():\n"
71
                + "  return jperimeter.process(featureContainer.getFeature())");
72
    }
73

  
74
    public String toString() {
75
        return "perimeter";
76
    }
77

  
78
    public boolean isEnable() {
79
        if (getLayer() == null) {
80
            return false;
81
        }
82
        int geomType = org.gvsig.fmap.geom.Geometry.TYPES.POINT;
83
        try {
84
            FeatureStore store = getLayer().getFeatureStore();
85
            geomType = store.getDefaultFeatureType().getDefaultGeometryAttribute().getGeomType().getType();
86
        } catch (DataException e) {
87
            logger.warn("Can't get geometry type for default geometry attribute of layer '"+getLayer().getName()+"'.",e);
88
        }
89
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
90

  
91
        return getType() == IOperator.NUMBER && (
92
            geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.CURVE, geomType) ||
93
            geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTICURVE, geomType) ||
94
            geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.SURFACE, geomType) ||
95
            geomManager.isSubtype(org.gvsig.fmap.geom.Geometry.TYPES.MULTISURFACE, geomType) 
96
        );
97
    }
98

  
99
    public String getTooltip() {
100
        return PluginServices.getText(this, "operator") + ":  " + addText("") + "\n" + getDescription();
101
    }
102

  
103
    public String getDescription() {
104
        return PluginServices.getText(this, "returns") + ": "
105
                + PluginServices.getText(this, "numeric_value") + "\n"
106
                + PluginServices.getText(this, "description") + ": "
107
                + "Returns the perimeter of polygon or line geometry  of this row in the units of the view.";
108
    }
109
}
org.gvsig.expressionfield/tags/org.gvsig.expressionfield-2.0.78/src/main/java/org/gvsig/expressionfield/project/documents/table/operators/IndexOf.java
1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff