Revision 23299
trunk/libraries/libExpressions/src/main/java/org/gvsig/gui/EvalExpression.java | ||
---|---|---|
1 |
package org.gvsig.gui; |
|
2 |
|
|
3 |
import java.sql.Types; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.BitSet; |
|
6 |
import java.util.Date; |
|
7 |
import java.util.Iterator; |
|
8 |
import java.util.List; |
|
9 |
import java.util.prefs.Preferences; |
|
10 |
|
|
11 |
import org.gvsig.templates.IEvalListener; |
|
12 |
|
|
13 |
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException; |
|
14 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
15 |
import com.hardcode.gdbms.engine.values.Value; |
|
16 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
17 |
import com.iver.andami.PluginServices; |
|
18 |
import com.iver.andami.messages.NotificationManager; |
|
19 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
|
20 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileWriteException; |
|
21 |
import com.iver.cit.gvsig.exceptions.validate.ValidateRowException; |
|
22 |
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException; |
|
23 |
import com.iver.cit.gvsig.fmap.core.IRow; |
|
24 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
25 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
|
26 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
|
27 |
import com.iver.cit.gvsig.fmap.edition.DefaultRowEdited; |
|
28 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
|
29 |
import com.iver.cit.gvsig.fmap.edition.IEditableSource; |
|
30 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
|
31 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
|
32 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
|
33 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
|
34 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
|
35 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
36 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
|
37 |
/** |
|
38 |
* @author Vicente Caballero Navarro |
|
39 |
*/ |
|
40 |
public class EvalExpression { |
|
41 |
private FieldDescription[] fieldDescriptors; |
|
42 |
private int selectedIndex; |
|
43 |
private FieldDescription fieldDescriptor; |
|
44 |
private FLyrVect lv; |
|
45 |
private IEditableSource ies =null; |
|
46 |
private Table table=null; |
|
47 |
private static Preferences prefs = Preferences.userRoot().node( "fieldExpressionOptions" ); |
|
48 |
private int limit; |
|
49 |
private List evalListenerList; |
|
50 |
public EvalExpression() { |
|
51 |
limit=prefs.getInt("limit_rows_in_memory",-1); |
|
52 |
} |
|
53 |
public void setTable(Table table) { |
|
54 |
BitSet columnSelected = table.getSelectedFieldIndices(); |
|
55 |
fieldDescriptors = table.getModel().getModelo().getFieldsDescription(); |
|
56 |
selectedIndex = columnSelected.nextSetBit(0); |
|
57 |
fieldDescriptor = fieldDescriptors[selectedIndex]; |
|
58 |
this.table=table; |
|
59 |
lv=(FLyrVect)table.getModel().getAssociatedTable(); |
|
60 |
if (lv ==null) |
|
61 |
ies=table.getModel().getModelo(); |
|
62 |
else |
|
63 |
ies = (VectorialEditableAdapter) lv.getSource(); |
|
64 |
} |
|
65 |
|
|
66 |
public FLyrVect getFLyrVect() { |
|
67 |
return lv; |
|
68 |
} |
|
69 |
public void setFLyrVect(FLyrVect lv) { |
|
70 |
this.lv = lv; |
|
71 |
if (lv ==null) |
|
72 |
ies=table.getModel().getModelo(); |
|
73 |
else |
|
74 |
ies = (VectorialEditableAdapter) lv.getSource(); |
|
75 |
|
|
76 |
fieldDescriptors = ies.getFieldsDescription(); |
|
77 |
try { |
|
78 |
selectedIndex = ies.getSelection().nextSetBit(0); |
|
79 |
} catch (ReadDriverException e) { |
|
80 |
// TODO Auto-generated catch block |
|
81 |
e.printStackTrace(); |
|
82 |
} |
|
83 |
} |
|
84 |
public void setValue(Object obj,int i) { |
|
85 |
//VectorialEditableAdapter vea = (VectorialEditableAdapter) lv.getSource(); |
|
86 |
Value value = getValue(obj); |
|
87 |
//System.out.println("num = "+i); |
|
88 |
IRow feat=null; |
|
89 |
try { |
|
90 |
feat = ies.getRow(i).getLinkedRow().cloneRow(); |
|
91 |
} catch (ExpansionFileReadException e) { |
|
92 |
NotificationManager.addError(e); |
|
93 |
} catch (ReadDriverException e) { |
|
94 |
NotificationManager.addError(e); |
|
95 |
} |
|
96 |
Value[] values = feat.getAttributes(); |
|
97 |
values[selectedIndex] = value; |
|
98 |
feat.setAttributes(values); |
|
99 |
|
|
100 |
IRowEdited edRow = new DefaultRowEdited(feat, |
|
101 |
IRowEdited.STATUS_MODIFIED, i); |
|
102 |
try { |
|
103 |
ies.modifyRow(edRow.getIndex(), edRow.getLinkedRow(), "", |
|
104 |
EditionEvent.ALPHANUMERIC); |
|
105 |
} catch (ExpansionFileWriteException e) { |
|
106 |
NotificationManager.addError(e); |
|
107 |
} catch (ExpansionFileReadException e) { |
|
108 |
NotificationManager.addError(e); |
|
109 |
} catch (ValidateRowException e) { |
|
110 |
NotificationManager.addError(e); |
|
111 |
} catch (ReadDriverException e) { |
|
112 |
NotificationManager.addError(e); |
|
113 |
} |
|
114 |
|
|
115 |
} |
|
116 |
/** |
|
117 |
* Returns the value created from object. |
|
118 |
* |
|
119 |
* @param obj value. |
|
120 |
* |
|
121 |
* @return Value. |
|
122 |
*/ |
|
123 |
private Value getValue(Object obj) { |
|
124 |
int typeField = fieldDescriptor.getFieldType(); |
|
125 |
Value value = null;//ValueFactory.createNullValue(); |
|
126 |
|
|
127 |
if (obj instanceof Number) { |
|
128 |
if (typeField == Types.DOUBLE || typeField == Types.NUMERIC) { |
|
129 |
double dv = ((Number) obj).doubleValue(); |
|
130 |
value = ValueFactory.createValue(dv); |
|
131 |
} else if (typeField == Types.FLOAT) { |
|
132 |
float df = ((Number) obj).floatValue(); |
|
133 |
value = ValueFactory.createValue(df); |
|
134 |
} else if (typeField == Types.INTEGER) { |
|
135 |
int di = ((Number) obj).intValue(); |
|
136 |
value = ValueFactory.createValue(di); |
|
137 |
} else if (typeField == Types.BIGINT) { |
|
138 |
long di = ((Number) obj).longValue(); |
|
139 |
value = ValueFactory.createValue(di); |
|
140 |
} else if (typeField == Types.VARCHAR) { |
|
141 |
String s = ((Number) obj).toString(); |
|
142 |
value = ValueFactory.createValue(s); |
|
143 |
} else if (typeField == Types.BOOLEAN) { |
|
144 |
if (((Number) obj).intValue()==0){ |
|
145 |
value=ValueFactory.createValue(false); |
|
146 |
}else{ |
|
147 |
value=ValueFactory.createValue(true); |
|
148 |
} |
|
149 |
} |
|
150 |
} else if (obj instanceof Date) { |
|
151 |
if (typeField == Types.DATE) { |
|
152 |
Date date = (Date) obj; |
|
153 |
value = ValueFactory.createValue(date); |
|
154 |
} else if (typeField == Types.VARCHAR) { |
|
155 |
String s = ((Date) obj).toString(); |
|
156 |
value = ValueFactory.createValue(s); |
|
157 |
} |
|
158 |
} else if (obj instanceof Boolean) { |
|
159 |
if (typeField == Types.BOOLEAN) { |
|
160 |
boolean b = ((Boolean) obj).booleanValue(); |
|
161 |
value = ValueFactory.createValue(b); |
|
162 |
} else if (typeField == Types.VARCHAR) { |
|
163 |
String s = ((Boolean) obj).toString(); |
|
164 |
value = ValueFactory.createValue(s); |
|
165 |
} |
|
166 |
} else if (obj instanceof String) { |
|
167 |
if (typeField == Types.VARCHAR) { |
|
168 |
String s = obj.toString(); |
|
169 |
value = ValueFactory.createValue(s); |
|
170 |
} |
|
171 |
}else{ |
|
172 |
value=ValueFactory.createNullValue(); |
|
173 |
} |
|
174 |
|
|
175 |
return value; |
|
176 |
} |
|
177 |
public FieldDescription getFieldDescriptorSelected() { |
|
178 |
return fieldDescriptor; |
|
179 |
} |
|
180 |
public FieldDescription[] getFieldDescriptors() { |
|
181 |
return fieldDescriptors; |
|
182 |
} |
|
183 |
// public void setFieldValue(Object obj,int i) { |
|
184 |
// try { |
|
185 |
// ((DBFDriver)table.getModel().getModelo().getOriginalDriver()).setFieldValue(i,selectedIndex,obj); |
|
186 |
// } catch (DriverLoadException e) { |
|
187 |
// e.printStackTrace(); |
|
188 |
// } catch (IOException e) { |
|
189 |
// e.printStackTrace(); |
|
190 |
// } |
|
191 |
// } |
|
192 |
public void saveEdits(int numRows) throws ReadDriverException, InitializeWriterException, StopWriterVisitorException { |
|
193 |
|
|
194 |
if (this.evalListenerList != null){ |
|
195 |
for (Iterator iterator = this.evalListenerList.iterator(); iterator.hasNext();) { |
|
196 |
IEvalListener evalListener = (IEvalListener) iterator.next(); |
|
197 |
evalListener.saveEdits(numRows); |
|
198 |
} |
|
199 |
} |
|
200 |
// if (limit==-1 || numRows == 0 || (numRows % limit)!=0) { |
|
201 |
// return; |
|
202 |
// } |
|
203 |
// ies.endComplexRow(PluginServices.getText(this, "expression")); |
|
204 |
// if ((lv != null) && |
|
205 |
// lv.getSource() instanceof VectorialEditableAdapter) { |
|
206 |
// VectorialEditableAdapter vea = (VectorialEditableAdapter) lv.getSource(); |
|
207 |
// ISpatialWriter spatialWriter = (ISpatialWriter) vea.getDriver(); |
|
208 |
// vea.cleanSelectableDatasource(); |
|
209 |
// lv.setRecordset(vea.getRecordset()); // Queremos que el recordset del layer |
|
210 |
// // refleje los cambios en los campos. |
|
211 |
// ILayerDefinition lyrDef = EditionUtilities.createLayerDefinition(lv); |
|
212 |
// spatialWriter.initialize(lyrDef); |
|
213 |
// vea.saveEdits(spatialWriter,EditionEvent.ALPHANUMERIC); |
|
214 |
// vea.getCommandRecord().clearAll(); |
|
215 |
// } else { |
|
216 |
// if (ies instanceof IWriteable){ |
|
217 |
// IWriteable w = (IWriteable) ies; |
|
218 |
// IWriter writer = w.getWriter(); |
|
219 |
// if (writer == null){ |
|
220 |
// }else{ |
|
221 |
// ITableDefinition tableDef = ies.getTableDefinition(); |
|
222 |
// writer.initialize(tableDef); |
|
223 |
// |
|
224 |
// ies.saveEdits(writer,EditionEvent.ALPHANUMERIC); |
|
225 |
// ies.getSelection().clear(); |
|
226 |
// } |
|
227 |
// } |
|
228 |
// ies.getCommandRecord().clearAll(); |
|
229 |
// } |
|
230 |
// ies.startComplexRow(); |
|
231 |
// table.refresh(); |
|
232 |
} |
|
233 |
|
|
234 |
public void addEvalListerner(IEvalListener evalListener){ |
|
235 |
|
|
236 |
if (this.evalListenerList == null){ |
|
237 |
this.evalListenerList = new ArrayList<IEvalListener>(); |
|
238 |
} |
|
239 |
this.evalListenerList.add(evalListener); |
|
240 |
|
|
241 |
} |
|
242 |
|
|
243 |
// public void fireEvent(int row){ |
|
244 |
// |
|
245 |
// } |
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
} |
trunk/libraries/libExpressions/src/main/java/org/gvsig/gui/EvalExpressionDialog.java | ||
---|---|---|
1 |
package org.gvsig.gui; |
|
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.Component; |
|
5 |
import java.awt.event.MouseEvent; |
|
6 |
import java.awt.event.MouseListener; |
|
7 |
import java.io.File; |
|
8 |
import java.io.FileReader; |
|
9 |
import java.io.IOException; |
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.prefs.Preferences; |
|
12 |
|
|
13 |
import javax.swing.BoxLayout; |
|
14 |
import javax.swing.ButtonGroup; |
|
15 |
import javax.swing.JFileChooser; |
|
16 |
import javax.swing.JLabel; |
|
17 |
import javax.swing.JList; |
|
18 |
import javax.swing.JOptionPane; |
|
19 |
import javax.swing.JPanel; |
|
20 |
import javax.swing.JRadioButton; |
|
21 |
import javax.swing.JScrollPane; |
|
22 |
import javax.swing.JTabbedPane; |
|
23 |
import javax.swing.JTextArea; |
|
24 |
import javax.swing.JTextField; |
|
25 |
import javax.swing.UIManager; |
|
26 |
import javax.swing.event.CaretEvent; |
|
27 |
import javax.swing.event.CaretListener; |
|
28 |
|
|
29 |
import org.apache.bsf.BSFException; |
|
30 |
import org.apache.bsf.BSFManager; |
|
31 |
import org.gvsig.baseclasses.GraphicOperator; |
|
32 |
import org.gvsig.baseclasses.IOperator; |
|
33 |
import org.gvsig.baseclasses.Index; |
|
34 |
import org.gvsig.expresions.EvalOperatorsTask; |
|
35 |
import org.gvsig.expresions.ExpressionFieldExtension; |
|
36 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
|
37 |
import org.gvsig.gui.beans.swing.JButton; |
|
38 |
import org.gvsig.operators.Field; |
|
39 |
|
|
40 |
import bsh.EvalError; |
|
41 |
|
|
42 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
43 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
|
44 |
import com.iver.andami.PluginServices; |
|
45 |
import com.iver.andami.messages.NotificationManager; |
|
46 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
47 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
|
48 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
49 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
50 |
import com.iver.cit.gvsig.fmap.edition.IEditableSource; |
|
51 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
|
52 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
|
53 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
54 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
55 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
|
56 |
import com.iver.utiles.GenericFileFilter; |
|
57 |
|
|
58 |
|
|
59 |
/** |
|
60 |
* DOCUMENT ME! |
|
61 |
* |
|
62 |
* @author Vicente Caballero Navarro |
|
63 |
*/ |
|
64 |
public class EvalExpressionDialog extends JPanel implements IWindow { |
|
65 |
private JPanel pNorth = null; |
|
66 |
private JPanel pCentral = null; |
|
67 |
private JScrollPane jScrollPane = null; |
|
68 |
private JTextArea txtExp = null; |
|
69 |
private AcceptCancelPanel acceptCancel; |
|
70 |
private Table table; |
|
71 |
private FLyrVect lv; |
|
72 |
private JLabel lblColumn = null; |
|
73 |
private JPanel pNorthEast = null; |
|
74 |
private JPanel pNorthCenter = null; |
|
75 |
private JPanel pNorthWest = null; |
|
76 |
private JScrollPane jScrollPane1 = null; |
|
77 |
private JList listFields = null; |
|
78 |
private JRadioButton rbNumber = null; |
|
79 |
private JRadioButton rbString = null; |
|
80 |
private JRadioButton rbDate = null; |
|
81 |
private JScrollPane jScrollPane2 = null; |
|
82 |
private JList listCommand = null; |
|
83 |
private BSFManager interpreter = null; // Construct an interpreter |
|
84 |
private Index indexRow = null; |
|
85 |
private SelectableDataSource sds = null; |
|
86 |
private EvalExpression evalExpression=null; |
|
87 |
private IEditableSource ies=null; |
|
88 |
private JPanel pMessage; |
|
89 |
//private JTextArea txtMessage; |
|
90 |
private static ArrayList operators=new ArrayList(); |
|
91 |
// public EvalExpressionDialog(Table table,BSFManager interpreter, ArrayList operators) { |
|
92 |
// super(); |
|
93 |
// this.operators=operators; |
|
94 |
// this.interpreter=interpreter; |
|
95 |
// this.table = table; |
|
96 |
// initialize(); |
|
97 |
// |
|
98 |
// } |
|
99 |
|
|
100 |
public EvalExpressionDialog(FLyrVect lv,BSFManager interpreter, ArrayList operators) { |
|
101 |
super(); |
|
102 |
this.operators=operators; |
|
103 |
this.interpreter=interpreter; |
|
104 |
this.lv = lv; |
|
105 |
initialize(); |
|
106 |
|
|
107 |
} |
|
108 |
/** |
|
109 |
* This method initializes this |
|
110 |
*/ |
|
111 |
private void initialize() { |
|
112 |
try { |
|
113 |
evalExpressions(); |
|
114 |
} catch (BSFException e) { |
|
115 |
NotificationManager.addError(e); |
|
116 |
} catch (ReadDriverException e) { |
|
117 |
NotificationManager.addError(e); |
|
118 |
} |
|
119 |
evalExpression=new EvalExpression(); |
|
120 |
// evalExpression.setTable(table); |
|
121 |
evalExpression.setFLyrVect(lv); |
|
122 |
// lv = (FLyrVect) table.getModel().getAssociatedTable(); |
|
123 |
ButtonGroup bg = new ButtonGroup(); |
|
124 |
bg.add(getRbNumber()); |
|
125 |
bg.add(getRbString()); |
|
126 |
bg.add(getRbDate()); |
|
127 |
this.setLayout(new BorderLayout()); |
|
128 |
this.setSize(549, 480); |
|
129 |
this.add(getTabPrincipal(), java.awt.BorderLayout.CENTER); |
|
130 |
this.add(getPMessage(), java.awt.BorderLayout.NORTH); |
|
131 |
this.add(getAcceptCancel(), java.awt.BorderLayout.SOUTH); |
|
132 |
} |
|
133 |
/** |
|
134 |
* This method initializes pCentral |
|
135 |
* |
|
136 |
* @return javax.swing.JPanel |
|
137 |
*/ |
|
138 |
private JPanel getPNorth() { |
|
139 |
if (pNorth == null) { |
|
140 |
pNorth = new JPanel(); |
|
141 |
pNorth.setLayout(new BorderLayout()); |
|
142 |
pNorth.add(getPNorthEast(), java.awt.BorderLayout.EAST); |
|
143 |
pNorth.add(getPNorthCenter(), java.awt.BorderLayout.CENTER); |
|
144 |
pNorth.add(getPNorthWest(), java.awt.BorderLayout.WEST); |
|
145 |
} |
|
146 |
|
|
147 |
return pNorth; |
|
148 |
} |
|
149 |
|
|
150 |
/** |
|
151 |
* This method initializes pNorth |
|
152 |
* |
|
153 |
* @return javax.swing.JPanel |
|
154 |
*/ |
|
155 |
private JPanel getPCentral() { |
|
156 |
if (pCentral == null) { |
|
157 |
pCentral = new JPanel(); |
|
158 |
pCentral.setBorder(javax.swing.BorderFactory.createTitledBorder( |
|
159 |
null, PluginServices.getText(this,"expression"), |
|
160 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
161 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
162 |
lblColumn = new JLabel(); |
|
163 |
pCentral.add(lblColumn, null); |
|
164 |
|
|
165 |
pCentral.add(getJScrollPane(), null); |
|
166 |
lblColumn.setText(PluginServices.getText(this, "column") + " : " + |
|
167 |
evalExpression.getFieldDescriptorSelected().getFieldAlias()); |
|
168 |
pCentral.add(getBClear(), null); |
|
169 |
} |
|
170 |
|
|
171 |
return pCentral; |
|
172 |
} |
|
173 |
|
|
174 |
/** |
|
175 |
* This method initializes pSouth |
|
176 |
* |
|
177 |
* @return javax.swing.JPanel |
|
178 |
*/ |
|
179 |
private AcceptCancelPanel getAcceptCancel() { |
|
180 |
if (this.acceptCancel == null) { |
|
181 |
this.acceptCancel = new AcceptCancelPanel( |
|
182 |
new java.awt.event.ActionListener() { |
|
183 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
184 |
boolean isAccepted=true; |
|
185 |
Preferences prefs = Preferences.userRoot().node( |
|
186 |
"fieldExpressionOptions"); |
|
187 |
int limit; |
|
188 |
limit = prefs.getInt("limit_rows_in_memory", -1); |
|
189 |
if (limit != -1) { |
|
190 |
int option = JOptionPane |
|
191 |
.showConfirmDialog( |
|
192 |
(Component) PluginServices |
|
193 |
.getMainFrame(), |
|
194 |
PluginServices |
|
195 |
.getText( |
|
196 |
this, |
|
197 |
"it_has_established_a_limit_of_rows_will_lose_the_possibility_to_undo_wants_to_continue")); |
|
198 |
if (option != JOptionPane.OK_OPTION) { |
|
199 |
return; |
|
200 |
} |
|
201 |
} |
|
202 |
try { |
|
203 |
long t1 = System.currentTimeMillis(); |
|
204 |
isAccepted=evalExpression(); |
|
205 |
long t2 = System.currentTimeMillis(); |
|
206 |
System.out |
|
207 |
.println("Tiempo evaluar expresiones = " |
|
208 |
+ (t2 - t1)); |
|
209 |
} catch (BSFException e1) { |
|
210 |
NotificationManager.addError(e1); |
|
211 |
} catch (ReadDriverException e1) { |
|
212 |
NotificationManager.addError(e1); |
|
213 |
} |
|
214 |
if (isAccepted) |
|
215 |
PluginServices.getMDIManager().closeWindow( |
|
216 |
EvalExpressionDialog.this); |
|
217 |
} |
|
218 |
}, new java.awt.event.ActionListener() { |
|
219 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
220 |
PluginServices.getMDIManager().closeWindow( |
|
221 |
EvalExpressionDialog.this); |
|
222 |
} |
|
223 |
}); |
|
224 |
acceptCancel.setOkButtonEnabled(false); |
|
225 |
} |
|
226 |
|
|
227 |
return this.acceptCancel; |
|
228 |
} |
|
229 |
/** |
|
230 |
* Evaluate the expression. |
|
231 |
* @throws ReadDriverException |
|
232 |
* @throws BSFException |
|
233 |
* |
|
234 |
* @throws EvalError |
|
235 |
* @throws DriverException |
|
236 |
* @throws DriverIOException |
|
237 |
* @throws IOException |
|
238 |
* @throws DriverIOException |
|
239 |
* @throws IOException |
|
240 |
* @throws BSFException |
|
241 |
*/ |
|
242 |
private boolean evalExpression() throws ReadDriverException, BSFException{ |
|
243 |
long rowCount = sds.getRowCount(); |
|
244 |
String expression=getTxtExp().getText() |
|
245 |
.replaceAll("\\[","field(\"") |
|
246 |
.replaceAll("\\]","\")"); |
|
247 |
interpreter.exec(EvalOperatorsTask.JYTHON,null,-1,-1,"def expression():\n" + |
|
248 |
" return " +expression+ ""); |
|
249 |
if (rowCount > 0) { |
|
250 |
try { |
|
251 |
interpreter.exec(EvalOperatorsTask.JYTHON,null,-1,-1,"expression()"); |
|
252 |
} catch (BSFException ee) { |
|
253 |
int option=JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), |
|
254 |
PluginServices.getText(this, |
|
255 |
"error_expression")+"\n"+ee.getMessage()+"\n"+PluginServices.getText(this,"continue?")); |
|
256 |
if (option!=JOptionPane.OK_OPTION) { |
|
257 |
return false; |
|
258 |
} |
|
259 |
} |
|
260 |
} |
|
261 |
ies.startComplexRow(); |
|
262 |
interpreter.declareBean("ee",evalExpression,EvalExpression.class); |
|
263 |
ArrayList exceptions=new ArrayList(); |
|
264 |
interpreter.declareBean("exceptions",exceptions,ArrayList.class); |
|
265 |
FBitSet selection=sds.getSelection(); |
|
266 |
if (selection.cardinality() > 0) { |
|
267 |
interpreter.declareBean("selection", selection, FBitSet.class); |
|
268 |
interpreter.exec(EvalOperatorsTask.JYTHON,null,-1,-1,"def p():\n" + |
|
269 |
" i=selection.nextSetBit(0)\n" + |
|
270 |
" while i >=0:\n" + |
|
271 |
" indexRow.set(i)\n" + |
|
272 |
" obj=expression()\n" + |
|
273 |
" ee.setValue(obj,i)\n" + |
|
274 |
" ee.saveEdits(i)\n" + |
|
275 |
" i=selection.nextSetBit(i+1)\n"); |
|
276 |
} else { |
|
277 |
interpreter.exec(EvalOperatorsTask.JYTHON,null,-1,-1,"def p():\n" + |
|
278 |
" for i in xrange("+rowCount +"):\n" + |
|
279 |
" indexRow.set(i)\n" + |
|
280 |
// " print i , expression() , repr (expression())\n" + |
|
281 |
" ee.setValue(expression(),i)\n" + |
|
282 |
" ee.saveEdits(i)\n"); |
|
283 |
} |
|
284 |
try { |
|
285 |
interpreter.eval(EvalOperatorsTask.JYTHON,null,-1,-1,"p()"); |
|
286 |
// interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"p()"); |
|
287 |
} catch (BSFException ee) { |
|
288 |
|
|
289 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
|
290 |
PluginServices.getText(this, "evaluate_expression_with_errors")+" "+(rowCount-indexRow.get())+"\n"+ee.getMessage()); |
|
291 |
} |
|
292 |
|
|
293 |
ies.endComplexRow(PluginServices.getText(this, "expression")); |
|
294 |
table.refresh(); |
|
295 |
return true; |
|
296 |
} |
|
297 |
/** |
|
298 |
* This method initializes pMessage |
|
299 |
* |
|
300 |
* @return javax.swing.JPanel |
|
301 |
*/ |
|
302 |
private JPanel getPMessage() { |
|
303 |
if (pMessage == null) { |
|
304 |
|
|
305 |
pMessage = new JPanel(); |
|
306 |
pMessage.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"information"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
307 |
pMessage.setPreferredSize(new java.awt.Dimension(550,120)); |
|
308 |
pMessage.add(getJScrollPane3(), null); |
|
309 |
} |
|
310 |
return pMessage; |
|
311 |
} |
|
312 |
private void evalExpressions() throws BSFException, ReadDriverException { |
|
313 |
if (lv ==null) |
|
314 |
ies=table.getModel().getModelo(); |
|
315 |
else |
|
316 |
ies = null; |
|
317 |
// ies = (VectorialEditableAdapter) lv.getSource().getRecordset(); |
|
318 |
// ies = table.getModel().getModelo(); |
|
319 |
sds = lv.getRecordset(); |
|
320 |
interpreter.declareBean("sds", sds,SelectableDataSource.class); |
|
321 |
indexRow=new Index(); |
|
322 |
interpreter.declareBean("indexRow", indexRow,Index.class); |
|
323 |
} |
|
324 |
/** |
|
325 |
* Evaluate the fields. |
|
326 |
* |
|
327 |
* @param interpreter |
|
328 |
* |
|
329 |
* @throws EvalError |
|
330 |
*/ |
|
331 |
int lastType=-1; |
|
332 |
private JButton bClear = null; |
|
333 |
private JTabbedPane tabPrincipal = null; |
|
334 |
private JPanel pPrincipal = null; |
|
335 |
private JPanel pAdvanced = null; |
|
336 |
private JPanel pAdvancedNorth = null; |
|
337 |
private JTextField jTextField = null; |
|
338 |
private JButton bFile = null; |
|
339 |
private JPanel pAdvancedCenter = null; |
|
340 |
private JLabel lblLeng = null; |
|
341 |
private JButton bEval = null; |
|
342 |
private JScrollPane jScrollPane3 = null; |
|
343 |
private JTextArea txtMessage2 = null; |
|
344 |
private void refreshOperators(int type) { |
|
345 |
if (lastType!=-1 && lastType==type) |
|
346 |
return; |
|
347 |
lastType=type; |
|
348 |
ListOperatorsModel lom=(ListOperatorsModel)getListCommand().getModel(); |
|
349 |
lom.clear(); |
|
350 |
for (int i=0;i<operators.size();i++) { |
|
351 |
IOperator operator = (IOperator)operators.get(i); |
|
352 |
operator.setType(type); |
|
353 |
//Comprobar si tiene una capa asociada y pasarsela al GraphicOperator. |
|
354 |
if ((lv != null) && operator instanceof GraphicOperator) { |
|
355 |
GraphicOperator igo = (GraphicOperator) operator; |
|
356 |
igo.setLayer(lv); |
|
357 |
} |
|
358 |
if (operator.isEnable()) { |
|
359 |
lom.addOperator(operator); |
|
360 |
//System.out.println("Operator = "+operator.toString()); |
|
361 |
} |
|
362 |
} |
|
363 |
getListCommand().repaint(); |
|
364 |
|
|
365 |
} |
|
366 |
/** |
|
367 |
* This method initializes jScrollPane |
|
368 |
* |
|
369 |
* @return javax.swing.JScrollPane |
|
370 |
*/ |
|
371 |
private JScrollPane getJScrollPane() { |
|
372 |
if (jScrollPane == null) { |
|
373 |
jScrollPane = new JScrollPane(); |
|
374 |
jScrollPane.setPreferredSize(new java.awt.Dimension(480, 80)); |
|
375 |
jScrollPane.setViewportView(getTxtExp()); |
|
376 |
} |
|
377 |
|
|
378 |
return jScrollPane; |
|
379 |
} |
|
380 |
|
|
381 |
/** |
|
382 |
* This method initializes txtExp |
|
383 |
* |
|
384 |
* @return javax.swing.JTextArea |
|
385 |
*/ |
|
386 |
private JTextArea getTxtExp() { |
|
387 |
if (txtExp == null) { |
|
388 |
txtExp = new JTextArea(); |
|
389 |
txtExp.addCaretListener(new CaretListener(){ |
|
390 |
public void caretUpdate(CaretEvent e) { |
|
391 |
if (txtExp.getText().length()>0) |
|
392 |
getAcceptCancel().setOkButtonEnabled(true); |
|
393 |
else |
|
394 |
getAcceptCancel().setOkButtonEnabled(false); |
|
395 |
} |
|
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
}); |
|
401 |
} |
|
402 |
|
|
403 |
return txtExp; |
|
404 |
} |
|
405 |
|
|
406 |
public WindowInfo getWindowInfo() { |
|
407 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG); |
|
408 |
wi.setTitle(PluginServices.getText(this, "calculate_expression")); |
|
409 |
|
|
410 |
return wi; |
|
411 |
} |
|
412 |
|
|
413 |
/** |
|
414 |
* This method initializes pNorthEast |
|
415 |
* |
|
416 |
* @return javax.swing.JPanel |
|
417 |
*/ |
|
418 |
private JPanel getPNorthEast() { |
|
419 |
if (pNorthEast == null) { |
|
420 |
pNorthEast = new JPanel(); |
|
421 |
pNorthEast.setBorder(javax.swing.BorderFactory.createTitledBorder( |
|
422 |
null, PluginServices.getText(this,"commands"), |
|
423 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
424 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
425 |
pNorthEast.add(getJScrollPane2(), null); |
|
426 |
} |
|
427 |
|
|
428 |
return pNorthEast; |
|
429 |
} |
|
430 |
|
|
431 |
/** |
|
432 |
* This method initializes pNorthCenter |
|
433 |
* |
|
434 |
* @return javax.swing.JPanel |
|
435 |
*/ |
|
436 |
private JPanel getPNorthCenter() { |
|
437 |
if (pNorthCenter == null) { |
|
438 |
pNorthCenter = new JPanel(); |
|
439 |
pNorthCenter.setLayout(new BoxLayout(getPNorthCenter(), |
|
440 |
BoxLayout.Y_AXIS)); |
|
441 |
pNorthCenter.setBorder(javax.swing.BorderFactory.createTitledBorder( |
|
442 |
null, PluginServices.getText(this,"type"), |
|
443 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
444 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
445 |
pNorthCenter.add(getRbNumber(), null); |
|
446 |
pNorthCenter.add(getRbString(), null); |
|
447 |
pNorthCenter.add(getRbDate(), null); |
|
448 |
} |
|
449 |
|
|
450 |
return pNorthCenter; |
|
451 |
} |
|
452 |
|
|
453 |
/** |
|
454 |
* This method initializes pNorthWest |
|
455 |
* |
|
456 |
* @return javax.swing.JPanel |
|
457 |
*/ |
|
458 |
private JPanel getPNorthWest() { |
|
459 |
if (pNorthWest == null) { |
|
460 |
pNorthWest = new JPanel(); |
|
461 |
pNorthWest.setBorder(javax.swing.BorderFactory.createTitledBorder( |
|
462 |
null, PluginServices.getText(this,"field"), |
|
463 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
|
464 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
465 |
pNorthWest.add(getJScrollPane1(), null); |
|
466 |
} |
|
467 |
|
|
468 |
return pNorthWest; |
|
469 |
} |
|
470 |
|
|
471 |
/** |
|
472 |
* This method initializes jScrollPane1 |
|
473 |
* |
|
474 |
* @return javax.swing.JScrollPane |
|
475 |
*/ |
|
476 |
private JScrollPane getJScrollPane1() { |
|
477 |
if (jScrollPane1 == null) { |
|
478 |
jScrollPane1 = new JScrollPane(); |
|
479 |
jScrollPane1.setPreferredSize(new java.awt.Dimension(175, 100)); |
|
480 |
jScrollPane1.setViewportView(getListFields()); |
|
481 |
} |
|
482 |
|
|
483 |
return jScrollPane1; |
|
484 |
} |
|
485 |
|
|
486 |
/** |
|
487 |
* This method initializes listFields |
|
488 |
* |
|
489 |
* @return javax.swing.JList |
|
490 |
*/ |
|
491 |
private JList getListFields() { |
|
492 |
if (listFields == null) { |
|
493 |
listFields = new JList(); |
|
494 |
listFields.setModel(new ListOperatorsModel()); |
|
495 |
|
|
496 |
ListOperatorsModel lm = (ListOperatorsModel) listFields.getModel(); |
|
497 |
FieldDescription[] fds=evalExpression.getFieldDescriptors(); |
|
498 |
for (int i = 0; i < fds.length; i++) { |
|
499 |
Field field=new Field(); |
|
500 |
field.setFieldDescription(fds[i]); |
|
501 |
try { |
|
502 |
field.eval(interpreter); |
|
503 |
} catch (BSFException e) { |
|
504 |
e.printStackTrace(); |
|
505 |
} |
|
506 |
lm.addOperator(field); |
|
507 |
} |
|
508 |
|
|
509 |
listFields.addMouseListener(new MouseListener() { |
|
510 |
public void mouseClicked(MouseEvent e) { |
|
511 |
IOperator operator=((IOperator) listFields.getSelectedValue()); |
|
512 |
getTxtMessage2().setText(operator.getTooltip()); |
|
513 |
if (e.getClickCount() == 2) { |
|
514 |
getTxtExp().setText(operator.addText( |
|
515 |
getTxtExp().getText())); |
|
516 |
} |
|
517 |
} |
|
518 |
|
|
519 |
public void mouseEntered(MouseEvent e) { |
|
520 |
} |
|
521 |
|
|
522 |
public void mouseExited(MouseEvent e) { |
|
523 |
} |
|
524 |
|
|
525 |
public void mousePressed(MouseEvent e) { |
|
526 |
} |
|
527 |
|
|
528 |
public void mouseReleased(MouseEvent e) { |
|
529 |
} |
|
530 |
}); |
|
531 |
} |
|
532 |
|
|
533 |
return listFields; |
|
534 |
} |
|
535 |
|
|
536 |
/** |
|
537 |
* This method initializes rbNumber |
|
538 |
* |
|
539 |
* @return javax.swing.JRadioButton |
|
540 |
*/ |
|
541 |
private JRadioButton getRbNumber() { |
|
542 |
if (rbNumber == null) { |
|
543 |
rbNumber = new JRadioButton(); |
|
544 |
rbNumber.setText(PluginServices.getText(this,"numeric")); |
|
545 |
rbNumber.setSelected(true); |
|
546 |
rbNumber.addChangeListener(new javax.swing.event.ChangeListener() { |
|
547 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
|
548 |
if (rbNumber.isSelected()) |
|
549 |
refreshCommands(); |
|
550 |
} |
|
551 |
}); |
|
552 |
} |
|
553 |
|
|
554 |
return rbNumber; |
|
555 |
} |
|
556 |
|
|
557 |
/** |
|
558 |
* This method initializes rbString |
|
559 |
* |
|
560 |
* @return javax.swing.JRadioButton |
|
561 |
*/ |
|
562 |
private JRadioButton getRbString() { |
|
563 |
if (rbString == null) { |
|
564 |
rbString = new JRadioButton(); |
|
565 |
rbString.setText(PluginServices.getText(this,"string")); |
|
566 |
rbString.addChangeListener(new javax.swing.event.ChangeListener() { |
|
567 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
|
568 |
if (rbString.isSelected()) |
|
569 |
refreshCommands(); |
|
570 |
} |
|
571 |
}); |
|
572 |
} |
|
573 |
|
|
574 |
return rbString; |
|
575 |
} |
|
576 |
|
|
577 |
/** |
|
578 |
* This method initializes rbData |
|
579 |
* |
|
580 |
* @return javax.swing.JRadioButton |
|
581 |
*/ |
|
582 |
private JRadioButton getRbDate() { |
|
583 |
if (rbDate == null) { |
|
584 |
rbDate = new JRadioButton(); |
|
585 |
rbDate.setText(PluginServices.getText(this,"date")); |
|
586 |
rbDate.addChangeListener(new javax.swing.event.ChangeListener() { |
|
587 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
|
588 |
if (rbDate.isSelected()) |
|
589 |
refreshCommands(); |
|
590 |
} |
|
591 |
}); |
|
592 |
} |
|
593 |
|
|
594 |
return rbDate; |
|
595 |
} |
|
596 |
|
|
597 |
/** |
|
598 |
* This method initializes jScrollPane2 |
|
599 |
* |
|
600 |
* @return javax.swing.JScrollPane |
|
601 |
*/ |
|
602 |
private JScrollPane getJScrollPane2() { |
|
603 |
if (jScrollPane2 == null) { |
|
604 |
jScrollPane2 = new JScrollPane(); |
|
605 |
jScrollPane2.setPreferredSize(new java.awt.Dimension(175, 100)); |
|
606 |
jScrollPane2.setViewportView(getListCommand()); |
|
607 |
} |
|
608 |
|
|
609 |
return jScrollPane2; |
|
610 |
} |
|
611 |
|
|
612 |
/** |
|
613 |
* Refresh the commands. |
|
614 |
*/ |
|
615 |
private void refreshCommands() { |
|
616 |
int type=IOperator.NUMBER; |
|
617 |
if (getRbNumber().isSelected()) { |
|
618 |
type=IOperator.NUMBER; |
|
619 |
} else if (getRbString().isSelected()) { |
|
620 |
type=IOperator.STRING; |
|
621 |
} else if (getRbDate().isSelected()) { |
|
622 |
type=IOperator.DATE; |
|
623 |
} |
|
624 |
refreshOperators(type); |
|
625 |
|
|
626 |
} |
|
627 |
|
|
628 |
/** |
|
629 |
* This method initializes ListCommand |
|
630 |
* |
|
631 |
* @return javax.swing.JList |
|
632 |
*/ |
|
633 |
private JList getListCommand() { |
|
634 |
if (listCommand == null) { |
|
635 |
listCommand = new JList(); |
|
636 |
listCommand.setModel(new ListOperatorsModel()); |
|
637 |
listCommand.addMouseListener(new MouseListener() { |
|
638 |
public void mouseClicked(MouseEvent e) { |
|
639 |
IOperator operator=((IOperator) listCommand.getSelectedValue()); |
|
640 |
getTxtMessage2().setText(operator.getTooltip()); |
|
641 |
if (e.getClickCount() == 2) { |
|
642 |
if (listCommand.getSelectedValue()==null) |
|
643 |
return; |
|
644 |
getTxtExp().setText(operator.addText( |
|
645 |
getTxtExp().getText())); |
|
646 |
} |
|
647 |
} |
|
648 |
|
|
649 |
public void mouseEntered(MouseEvent e) { |
|
650 |
} |
|
651 |
|
|
652 |
public void mouseExited(MouseEvent e) { |
|
653 |
} |
|
654 |
|
|
655 |
public void mousePressed(MouseEvent e) { |
|
656 |
} |
|
657 |
|
|
658 |
public void mouseReleased(MouseEvent e) { |
|
659 |
} |
|
660 |
}); |
|
661 |
refreshOperators(IOperator.NUMBER); |
|
662 |
} |
|
663 |
|
|
664 |
return listCommand; |
|
665 |
} |
|
666 |
|
|
667 |
/** |
|
668 |
* This method initializes bClear |
|
669 |
* |
|
670 |
* @return javax.swing.JButton |
|
671 |
*/ |
|
672 |
private JButton getBClear() { |
|
673 |
if (bClear == null) { |
|
674 |
bClear = new JButton(); |
|
675 |
bClear.setText(PluginServices.getText(this,"clear_expression")); |
|
676 |
bClear.addActionListener(new java.awt.event.ActionListener() { |
|
677 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
678 |
getTxtExp().setText(""); |
|
679 |
} |
|
680 |
}); |
|
681 |
} |
|
682 |
return bClear; |
|
683 |
} |
|
684 |
/** |
|
685 |
* This method initializes tabPrincipal |
|
686 |
* |
|
687 |
* @return javax.swing.JTabbedPane |
|
688 |
*/ |
|
689 |
private JTabbedPane getTabPrincipal() { |
|
690 |
if (tabPrincipal == null) { |
|
691 |
tabPrincipal = new JTabbedPane(); |
|
692 |
tabPrincipal.addTab(PluginServices.getText(this,"general"), null, getPPrincipal(), null); |
|
693 |
tabPrincipal.addTab(PluginServices.getText(this,"advanced"), null, getPAdvanced(), null); |
|
694 |
} |
|
695 |
return tabPrincipal; |
|
696 |
} |
|
697 |
/** |
|
698 |
* This method initializes pPrincipal |
|
699 |
* |
|
700 |
* @return javax.swing.JPanel |
|
701 |
*/ |
|
702 |
private JPanel getPPrincipal() { |
|
703 |
if (pPrincipal == null) { |
|
704 |
pPrincipal = new JPanel(); |
|
705 |
pPrincipal.setLayout(new BorderLayout()); |
|
706 |
pPrincipal.setPreferredSize(new java.awt.Dimension(540,252)); |
|
707 |
pPrincipal.add(getPNorth(), java.awt.BorderLayout.NORTH); |
|
708 |
pPrincipal.add(getPCentral(), java.awt.BorderLayout.CENTER); |
|
709 |
|
|
710 |
} |
|
711 |
return pPrincipal; |
|
712 |
} |
|
713 |
/** |
|
714 |
* This method initializes pAdvanced |
|
715 |
* |
|
716 |
* @return javax.swing.JPanel |
|
717 |
*/ |
|
718 |
private JPanel getPAdvanced() { |
|
719 |
if (pAdvanced == null) { |
|
720 |
pAdvanced = new JPanel(); |
|
721 |
pAdvanced.setLayout(new BorderLayout()); |
|
722 |
pAdvanced.add(getPAdvancedNorth(), java.awt.BorderLayout.NORTH); |
|
723 |
pAdvanced.add(getPAdvancedCenter(), java.awt.BorderLayout.CENTER); |
|
724 |
} |
|
725 |
return pAdvanced; |
|
726 |
} |
|
727 |
/** |
|
728 |
* This method initializes pAdvancedNorth |
|
729 |
* |
|
730 |
* @return javax.swing.JPanel |
|
731 |
*/ |
|
732 |
private JPanel getPAdvancedNorth() { |
|
733 |
if (pAdvancedNorth == null) { |
|
734 |
pAdvancedNorth = new JPanel(); |
|
735 |
pAdvancedNorth.setPreferredSize(new java.awt.Dimension(873,100)); |
|
736 |
pAdvancedNorth.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"expressions_from_file"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
737 |
pAdvancedNorth.add(getJTextField(), null); |
|
738 |
pAdvancedNorth.add(getBFile(), null); |
|
739 |
pAdvancedNorth.add(getBEval(), null); |
|
740 |
} |
|
741 |
return pAdvancedNorth; |
|
742 |
} |
|
743 |
/** |
|
744 |
* This method initializes jTextField |
|
745 |
* |
|
746 |
* @return javax.swing.JTextField |
|
747 |
*/ |
|
748 |
private JTextField getJTextField() { |
|
749 |
if (jTextField == null) { |
|
750 |
jTextField = new JTextField(); |
|
751 |
jTextField.setPreferredSize(new java.awt.Dimension(250,20)); |
|
752 |
} |
|
753 |
return jTextField; |
|
754 |
} |
|
755 |
/** |
|
756 |
* This method initializes bFile |
|
757 |
* |
|
758 |
* @return javax.swing.JButton |
|
759 |
*/ |
|
760 |
private JButton getBFile() { |
|
761 |
if (bFile == null) { |
|
762 |
bFile = new JButton(); |
|
763 |
bFile.setText(PluginServices.getText(this,"explorer")); |
|
764 |
bFile.addActionListener(new java.awt.event.ActionListener() { |
|
765 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
766 |
JFileChooser jfc = new JFileChooser(); |
|
767 |
jfc.addChoosableFileFilter(new GenericFileFilter("py", |
|
768 |
PluginServices.getText(this, "python"))); |
|
769 |
|
|
770 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
|
771 |
File fileExpression = jfc.getSelectedFile(); |
|
772 |
getJTextField().setText(fileExpression.getAbsolutePath()); |
|
773 |
|
|
774 |
} |
|
775 |
} |
|
776 |
}); |
|
777 |
} |
|
778 |
return bFile; |
|
779 |
} |
|
780 |
private String readFile(File aFile) throws IOException { |
|
781 |
StringBuffer fileContents = new StringBuffer(); |
|
782 |
FileReader fileReader = new FileReader(aFile); |
|
783 |
int c; |
|
784 |
while ((c = fileReader.read()) > -1) { |
|
785 |
fileContents.append((char)c); |
|
786 |
} |
|
787 |
fileReader.close(); |
|
788 |
return fileContents.toString(); |
|
789 |
} |
|
790 |
/** |
|
791 |
* This method initializes pAdvancedCenter |
|
792 |
* |
|
793 |
* @return javax.swing.JPanel |
|
794 |
*/ |
|
795 |
private JPanel getPAdvancedCenter() { |
|
796 |
if (pAdvancedCenter == null) { |
|
797 |
lblLeng = new JLabel(); |
|
798 |
lblLeng.setText(""); |
|
799 |
pAdvancedCenter = new JPanel(); |
|
800 |
pAdvancedCenter.add(lblLeng, null); |
|
801 |
} |
|
802 |
return pAdvancedCenter; |
|
803 |
} |
|
804 |
|
|
805 |
/** |
|
806 |
* This method initializes bEval |
|
807 |
* |
|
808 |
* @return javax.swing.JButton |
|
809 |
*/ |
|
810 |
private JButton getBEval() { |
|
811 |
if (bEval == null) { |
|
812 |
bEval = new JButton(); |
|
813 |
bEval.setText(PluginServices.getText(this,"evaluate")); |
|
814 |
bEval.addActionListener(new java.awt.event.ActionListener() { |
|
815 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
816 |
File file=new File(getJTextField().getText()); |
|
817 |
if (!file.exists()) { |
|
818 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"incorrect_file")); |
|
819 |
return; |
|
820 |
} |
|
821 |
try { |
|
822 |
interpreter.exec(EvalOperatorsTask.JYTHON,null,-1,-1,readFile(file)); |
|
823 |
} catch (IOException e1) { |
|
824 |
e1.printStackTrace(); |
|
825 |
} catch (BSFException e1) { |
|
826 |
e1.printStackTrace(); |
|
827 |
} |
|
828 |
} |
|
829 |
}); |
|
830 |
} |
|
831 |
return bEval; |
|
832 |
} |
|
833 |
/** |
|
834 |
* This method initializes jScrollPane3 |
|
835 |
* |
|
836 |
* @return javax.swing.JScrollPane |
|
837 |
*/ |
|
838 |
private JScrollPane getJScrollPane3() { |
|
839 |
if (jScrollPane3 == null) { |
|
840 |
jScrollPane3 = new JScrollPane(); |
|
841 |
jScrollPane3.setPreferredSize(new java.awt.Dimension(530,80)); |
|
842 |
jScrollPane3.setViewportView(getTxtMessage2()); |
|
843 |
} |
|
844 |
return jScrollPane3; |
|
845 |
} |
|
846 |
/** |
|
847 |
* This method initializes txtMessage2 |
|
848 |
* |
|
849 |
* @return javax.swing.JTextArea |
|
850 |
*/ |
|
851 |
private JTextArea getTxtMessage2() { |
|
852 |
if (txtMessage2 == null) { |
|
853 |
txtMessage2 = new JTextArea(); |
|
854 |
txtMessage2.setText(PluginServices.getText(this,"eval_expression_will_be_carried_out_right_now_with_current_values_in_table")); |
|
855 |
//txtMessage2.setSize(new java.awt.Dimension(550,100)); |
|
856 |
txtMessage2.setEditable(false); |
|
857 |
txtMessage2.setBackground(UIManager.getColor(this)); |
|
858 |
} |
|
859 |
return txtMessage2; |
|
860 |
} |
|
861 |
} // @jve:decl-index=0:visual-constraint="10,10" |
trunk/libraries/libExpressions/src/main/java/org/gvsig/gui/ListOperatorsModel.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 02-jun-2004 |
|
3 |
* |
|
4 |
*/ |
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
6 |
* |
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
8 |
* |
|
9 |
* This program is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU General Public License |
|
11 |
* as published by the Free Software Foundation; either version 2 |
|
12 |
* of the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
22 |
* |
|
23 |
* For more information, contact: |
|
24 |
* |
|
25 |
* Generalitat Valenciana |
|
26 |
* Conselleria d'Infraestructures i Transport |
|
27 |
* Av. Blasco Ib??ez, 50 |
|
28 |
* 46010 VALENCIA |
|
29 |
* SPAIN |
|
30 |
* |
|
31 |
* +34 963862235 |
|
32 |
* gvsig@gva.es |
|
33 |
* www.gvsig.gva.es |
|
34 |
* |
|
35 |
* or |
|
36 |
* |
|
37 |
* IVER T.I. S.A |
|
38 |
* Salamanca 50 |
|
39 |
* 46005 Valencia |
|
40 |
* Spain |
|
41 |
* |
|
42 |
* +34 963163400 |
|
43 |
* dac@iver.es |
|
44 |
*/ |
|
45 |
package org.gvsig.gui; |
|
46 |
|
|
47 |
import java.util.ArrayList; |
|
48 |
|
|
49 |
import javax.swing.AbstractListModel; |
|
50 |
|
|
51 |
|
|
52 |
/** |
|
53 |
* Modelo de la Lista de operadores a seleccionar. |
|
54 |
* |
|
55 |
* @author Vicente Caballero Navarro |
|
56 |
*/ |
|
57 |
public class ListOperatorsModel extends AbstractListModel { |
|
58 |
private ArrayList operators = new ArrayList(); |
|
59 |
|
|
60 |
/** |
|
61 |
* A?ade los comandos que tiene el proyecto a la lista. |
|
62 |
*/ |
|
63 |
public void addOperator(Object command) { |
|
64 |
operators.add(command); |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* @see javax.swing.ListModel#getSize() |
|
69 |
*/ |
|
70 |
public int getSize() { |
|
71 |
return operators.size(); |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* @see javax.swing.ListModel#getElementAt(int) |
|
76 |
*/ |
|
77 |
public Object getElementAt(int index) { |
|
78 |
return operators.get(index); |
|
79 |
} |
|
80 |
public void clear() { |
|
81 |
operators.clear(); |
|
82 |
} |
|
83 |
} |
trunk/libraries/libExpressions/src/main/java/org/gvsig/baseclasses/IOperator.java | ||
---|---|---|
1 |
package org.gvsig.baseclasses; |
|
2 |
|
|
3 |
import org.apache.bsf.BSFException; |
|
4 |
import org.apache.bsf.BSFManager; |
|
5 |
|
|
6 |
/** |
|
7 |
* @author Vicente Caballero Navarro |
|
8 |
*/ |
|
9 |
public interface IOperator { |
|
10 |
int NUMBER = 0; |
|
11 |
int STRING = 1; |
|
12 |
int DATE = 2; |
|
13 |
public String addText(String s); |
|
14 |
public String toString(); |
|
15 |
public void eval(BSFManager interpreter) throws BSFException ; |
|
16 |
public boolean isEnable(); |
|
17 |
public void setType(int fieldType); |
|
18 |
public String getTooltip(); |
|
19 |
} |
trunk/libraries/libExpressions/src/main/java/org/gvsig/baseclasses/Index.java | ||
---|---|---|
1 |
package org.gvsig.baseclasses; |
|
2 |
/** |
|
3 |
* @author Vicente Caballero Navarro |
|
4 |
*/ |
|
5 |
public class Index { |
|
6 |
private int index=0; |
|
7 |
|
|
8 |
public void next() { |
|
9 |
index++; |
|
10 |
} |
|
11 |
public void previous() { |
|
12 |
index--; |
|
13 |
} |
|
14 |
public int get() { |
|
15 |
return index; |
|
16 |
} |
|
17 |
public void set(int i) { |
|
18 |
index=i; |
|
19 |
} |
|
20 |
} |
trunk/libraries/libExpressions/src/main/java/org/gvsig/baseclasses/GraphicOperator.java | ||
---|---|---|
1 |
package org.gvsig.baseclasses; |
|
2 |
|
|
3 |
import java.awt.geom.PathIterator; |
|
4 |
import java.util.ArrayList; |
|
5 |
|
|
6 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
7 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
|
8 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
9 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
10 |
/** |
|
11 |
* @author Vicente Caballero Navarro |
|
12 |
*/ |
|
13 |
public abstract class GraphicOperator extends AbstractOperator{ |
|
14 |
private FLyrVect lv=null; |
|
15 |
public void setLayer(FLyrVect lv) { |
|
16 |
this.lv=lv; |
|
17 |
} |
|
18 |
public FLyrVect getLayer() { |
|
19 |
return lv; |
|
20 |
} |
|
21 |
public abstract double process(Index index) throws DriverIOException; |
|
22 |
protected ArrayList getXY(IGeometry geometry) { |
|
23 |
ArrayList xs = new ArrayList(); |
|
24 |
ArrayList ys = new ArrayList(); |
|
25 |
ArrayList parts=new ArrayList(); |
|
26 |
double[] theData = new double[6]; |
|
27 |
|
|
28 |
//double[] aux = new double[6]; |
|
29 |
PathIterator theIterator; |
|
30 |
int theType; |
|
31 |
int numParts = 0; |
|
32 |
boolean close=false; |
|
33 |
// boolean bFirst = true; |
|
34 |
// int xInt, yInt, antX = -1, antY = -1; |
|
35 |
theIterator = geometry.getPathIterator(null,FConverter.FLATNESS); //, flatness); |
|
36 |
|
|
37 |
// int numSegmentsAdded = 0; |
|
38 |
while (!theIterator.isDone()) { |
|
39 |
theType = theIterator.currentSegment(theData); |
|
40 |
|
|
41 |
switch (theType) { |
|
42 |
case PathIterator.SEG_MOVETO: |
|
43 |
if (numParts==0){ |
|
44 |
xs.add(new Double(theData[0])); |
|
45 |
ys.add(new Double(theData[1])); |
|
46 |
}else{ |
|
47 |
Double[] x = (Double[]) xs.toArray(new Double[0]); |
|
48 |
Double[] y = (Double[]) ys.toArray(new Double[0]); |
|
49 |
parts.add(new Double[][] { x, y }); |
|
50 |
xs.clear(); |
|
51 |
ys.clear(); |
|
52 |
xs.add(new Double(theData[0])); |
|
53 |
ys.add(new Double(theData[1])); |
|
54 |
} |
|
55 |
numParts++; |
|
56 |
|
|
57 |
break; |
|
58 |
|
|
59 |
case PathIterator.SEG_LINETO: |
|
60 |
xs.add(new Double(theData[0])); |
|
61 |
ys.add(new Double(theData[1])); |
|
62 |
|
|
63 |
|
|
64 |
break; |
|
65 |
|
|
66 |
|
|
67 |
case PathIterator.SEG_CLOSE: |
|
68 |
xs.add(new Double(theData[0])); |
|
69 |
ys.add(new Double(theData[1])); |
|
70 |
Double[] x = (Double[]) xs.toArray(new Double[0]); |
|
71 |
Double[] y = (Double[]) ys.toArray(new Double[0]); |
|
72 |
parts.add(new Double[][] { x, y }); |
|
73 |
xs.clear(); |
|
74 |
ys.clear(); |
|
75 |
close=true; |
|
76 |
break; |
|
77 |
} //end switch |
|
78 |
|
|
79 |
theIterator.next(); |
|
80 |
} //end while loop |
|
81 |
|
|
82 |
// Double[] x = (Double[]) xs.toArray(new Double[0]); |
|
83 |
// Double[] y = (Double[]) ys.toArray(new Double[0]); |
|
84 |
if (!close){ |
|
85 |
xs.add(new Double(theData[0])); |
|
86 |
ys.add(new Double(theData[1])); |
|
87 |
Double[] x = (Double[]) xs.toArray(new Double[0]); |
|
88 |
Double[] y = (Double[]) ys.toArray(new Double[0]); |
|
89 |
parts.add(new Double[][] { x, y }); |
|
90 |
xs.clear(); |
|
91 |
ys.clear(); |
|
92 |
} |
|
93 |
return parts; |
|
94 |
|
|
95 |
} |
|
96 |
|
|
97 |
} |
trunk/libraries/libExpressions/src/main/java/org/gvsig/baseclasses/AbstractOperator.java | ||
---|---|---|
1 |
package org.gvsig.baseclasses; |
|
2 |
|
|
3 |
|
|
4 |
/** |
|
5 |
* @author Vicente Caballero Navarro |
|
6 |
*/ |
|
7 |
public abstract class AbstractOperator implements IOperator{ |
|
8 |
private int type; |
|
9 |
|
|
10 |
public void setType(int type) { |
|
11 |
this.type=type; |
|
12 |
} |
|
13 |
public int getType() { |
|
14 |
return type; |
|
15 |
} |
|
16 |
public abstract String toString(); |
|
17 |
|
|
18 |
public String getTooltip(){ |
|
19 |
return "Operator : "+addText("parameter")+"\n"+getDescription(); |
|
20 |
} |
|
21 |
public abstract String getDescription(); |
|
22 |
} |
trunk/libraries/libExpressions/src/main/java/org/gvsig/operators/Equal.java | ||
---|---|---|
1 |
package org.gvsig.operators; |
|
2 |
|
|
3 |
import org.apache.bsf.BSFException; |
|
4 |
import org.apache.bsf.BSFManager; |
|
5 |
import org.gvsig.baseclasses.AbstractOperator; |
|
6 |
import org.gvsig.baseclasses.IOperator; |
|
7 |
|
|
8 |
/** |
|
9 |
* @author Vicente Caballero Navarro |
|
10 |
*/ |
|
11 |
public class Equal extends AbstractOperator{ |
|
12 |
|
|
13 |
public String addText(String s) { |
|
14 |
return s.concat(toString()); |
|
15 |
} |
|
16 |
|
|
17 |
public void eval(BSFManager interpreter) throws BSFException { |
|
18 |
|
|
19 |
} |
|
20 |
public String toString() { |
|
21 |
return " == "; |
|
22 |
} |
|
23 |
public boolean isEnable() { |
|
24 |
return (getType()==IOperator.DATE || getType()==IOperator.NUMBER || getType()==IOperator.STRING); |
|
25 |
} |
|
26 |
public String getTooltip(){ |
|
27 |
return "operator"+": "+addText("")+"\n"+getDescription(); |
|
28 |
} |
|
29 |
public String getDescription() { |
|
30 |
return "returns" + ": " + |
|
31 |
"boolean_value" + "\n" + |
|
32 |
"description" + ": " + |
|
33 |
"Returns true if the first object value is equals than the second value."; |
|
34 |
} |
|
35 |
} |
trunk/libraries/libExpressions/src/main/java/org/gvsig/operators/Pi.java | ||
---|---|---|
1 |
package org.gvsig.operators; |
|
2 |
|
|
3 |
import org.apache.bsf.BSFException; |
|
4 |
import org.apache.bsf.BSFManager; |
|
5 |
import org.gvsig.baseclasses.AbstractOperator; |
|
6 |
import org.gvsig.baseclasses.IOperator; |
|
7 |
import org.gvsig.expresions.EvalOperatorsTask; |
|
8 |
|
|
9 |
/** |
|
10 |
* @author Vicente Caballero Navarro |
|
11 |
*/ |
|
12 |
public class Pi extends AbstractOperator{ |
|
13 |
|
|
14 |
public String addText(String s) { |
|
15 |
return s.concat(toString()+"()"); |
|
16 |
} |
|
17 |
public String toString() { |
|
18 |
return "pi"; |
|
19 |
} |
|
20 |
public void eval(BSFManager interpreter) throws BSFException { |
|
21 |
// interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double pi(){return java.lang.Math.PI;};"); |
|
22 |
interpreter.exec(EvalOperatorsTask.JYTHON,null,-1,-1,"def pi():\n" + |
|
23 |
" import java.lang.Math\n" + |
|
24 |
" return java.lang.Math.PI"); |
|
25 |
} |
|
26 |
public boolean isEnable() { |
|
27 |
return (getType()==IOperator.NUMBER); |
|
28 |
} |
|
29 |
public String getTooltip(){ |
|
30 |
return "operator"+": "+addText("")+"\n"+getDescription(); |
|
31 |
} |
|
32 |
public String getDescription() { |
|
33 |
return "returns" + ": " + |
|
34 |
"numeric_value" + "\n" + |
|
35 |
"description" + ": " + |
|
36 |
"The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter."; |
|
37 |
} |
|
38 |
} |
trunk/libraries/libExpressions/src/main/java/org/gvsig/operators/Area.java | ||
---|---|---|
1 |
package org.gvsig.operators; |
|
2 |
|
|
3 |
import java.awt.geom.Point2D; |
|
4 |
import java.util.ArrayList; |
|
5 |
|
|
6 |
import org.apache.bsf.BSFException; |
|
7 |
import org.apache.bsf.BSFManager; |
|
8 |
import org.cresques.cts.IProjection; |
|
9 |
import org.gvsig.baseclasses.GraphicOperator; |
|
10 |
import org.gvsig.baseclasses.IOperator; |
|
11 |
import org.gvsig.baseclasses.Index; |
|
12 |
import org.gvsig.expresions.EvalOperatorsTask; |
|
13 |
|
|
14 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
15 |
import com.iver.andami.PluginServices; |
|
16 |
import com.iver.andami.messages.NotificationManager; |
|
17 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
|
18 |
import com.iver.cit.gvsig.fmap.MapContext; |
|
19 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
20 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
21 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
22 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
23 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
|
24 |
import com.iver.cit.gvsig.fmap.tools.geo.Geo; |
Also available in: Unified diff