svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extExpressionField / src / com / iver / cit / gvsig / project / documents / table / gui / EvalExpressionDialog.java @ 28291
History | View | Annotate | Download (34 KB)
1 |
package com.iver.cit.gvsig.project.documents.table.gui; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Component; |
5 |
import java.awt.GridBagConstraints; |
6 |
import java.awt.GridBagLayout; |
7 |
import java.awt.GridLayout; |
8 |
import java.awt.Insets; |
9 |
import java.awt.event.MouseEvent; |
10 |
import java.awt.event.MouseListener; |
11 |
import java.io.File; |
12 |
import java.io.FileReader; |
13 |
import java.io.IOException; |
14 |
import java.io.UnsupportedEncodingException; |
15 |
import java.util.ArrayList; |
16 |
import java.util.Iterator; |
17 |
import java.util.prefs.Preferences; |
18 |
|
19 |
import javax.swing.BoxLayout; |
20 |
import javax.swing.ButtonGroup; |
21 |
import javax.swing.JFileChooser; |
22 |
import javax.swing.JLabel; |
23 |
import javax.swing.JList; |
24 |
import javax.swing.JOptionPane; |
25 |
import javax.swing.JPanel; |
26 |
import javax.swing.JRadioButton; |
27 |
import javax.swing.JScrollPane; |
28 |
import javax.swing.JTabbedPane; |
29 |
import javax.swing.JTextArea; |
30 |
import javax.swing.JTextField; |
31 |
import javax.swing.UIManager; |
32 |
import javax.swing.event.CaretEvent; |
33 |
import javax.swing.event.CaretListener; |
34 |
|
35 |
import org.apache.bsf.BSFException; |
36 |
import org.apache.bsf.BSFManager; |
37 |
import org.gvsig.fmap.dal.exception.DataException; |
38 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
39 |
import org.gvsig.fmap.dal.feature.Feature; |
40 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
41 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
43 |
import org.gvsig.fmap.dal.feature.FeatureType; |
44 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
45 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
46 |
import org.gvsig.gui.beans.swing.JButton; |
47 |
import org.gvsig.project.document.table.gui.FeatureTableDocumentPanel; |
48 |
|
49 |
import bsh.EvalError; |
50 |
|
51 |
import com.iver.andami.PluginServices; |
52 |
import com.iver.andami.messages.NotificationManager; |
53 |
import com.iver.andami.ui.mdiManager.IWindow; |
54 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
55 |
import com.iver.cit.gvsig.ExpressionFieldExtension; |
56 |
import com.iver.cit.gvsig.project.documents.table.GraphicOperator; |
57 |
import com.iver.cit.gvsig.project.documents.table.IOperator; |
58 |
import com.iver.cit.gvsig.project.documents.table.operators.Field; |
59 |
import com.iver.utiles.GenericFileFilter; |
60 |
|
61 |
|
62 |
/**
|
63 |
* DOCUMENT ME!
|
64 |
*
|
65 |
* @author Vicente Caballero Navarro
|
66 |
*/
|
67 |
public class EvalExpressionDialog extends JPanel implements IWindow { |
68 |
private static Preferences prefs = Preferences.userRoot().node( "fieldExpressionOptions" ); |
69 |
private JPanel pNorth = null; |
70 |
private JPanel pCentral = null; |
71 |
private JScrollPane jScrollPane = null; |
72 |
private JTextArea txtExp = null; |
73 |
private AcceptCancelPanel acceptCancel;
|
74 |
private FeatureTableDocumentPanel table;
|
75 |
private FLyrVect lv;
|
76 |
private JPanel pNorthEast = null; |
77 |
private JPanel pNorthCenter = null; |
78 |
private JPanel pNorthWest = null; |
79 |
private JScrollPane jScrollPane1 = null; |
80 |
private JList listFields = null; |
81 |
private JRadioButton rbNumber = null; |
82 |
private JRadioButton rbString = null; |
83 |
private JRadioButton rbDate = null; |
84 |
private JScrollPane jScrollPane2 = null; |
85 |
private JList listCommand = null; |
86 |
private BSFManager interpreter = null; // Construct an interpreter |
87 |
private Feature feature;
|
88 |
private FeatureStore featureStore = null; |
89 |
private EvalExpression evalExpression=null; |
90 |
private JPanel pMessage; |
91 |
private FeatureContainer featureContainer;
|
92 |
private static ArrayList<IOperator> operators=new ArrayList<IOperator>(); |
93 |
public EvalExpressionDialog(FeatureTableDocumentPanel table, BSFManager interpreter, ArrayList<IOperator> operators) { |
94 |
super();
|
95 |
this.operators=operators;
|
96 |
this.interpreter=interpreter;
|
97 |
this.table = table;
|
98 |
initialize(); |
99 |
|
100 |
} |
101 |
/**
|
102 |
* This method initializes this
|
103 |
*/
|
104 |
private void initialize() { |
105 |
try {
|
106 |
evalExpressions(); |
107 |
} catch (BSFException e) {
|
108 |
NotificationManager.addError(e); |
109 |
} |
110 |
evalExpression=new EvalExpression();
|
111 |
evalExpression.setTable(table); |
112 |
lv = (FLyrVect) table.getModel().getAssociatedLayer(); |
113 |
ButtonGroup bg = new ButtonGroup(); |
114 |
bg.add(getRbNumber()); |
115 |
bg.add(getRbString()); |
116 |
bg.add(getRbDate()); |
117 |
this.setLayout(new GridBagLayout()); |
118 |
this.setSize(549, 480); |
119 |
GridBagConstraints constr = new GridBagConstraints(); |
120 |
constr.gridwidth = GridBagConstraints.REMAINDER;
|
121 |
constr.gridheight = 1;
|
122 |
constr.fill = GridBagConstraints.BOTH;
|
123 |
constr.ipadx=5;
|
124 |
constr.ipady=5;
|
125 |
constr.weightx=1;
|
126 |
constr.weighty=0.3;
|
127 |
this.add(getPMessage(), constr);
|
128 |
constr.gridheight = 5;
|
129 |
constr.weighty=1;
|
130 |
this.add(getTabPrincipal(), constr);
|
131 |
GridBagConstraints constr2 = new GridBagConstraints(); |
132 |
constr2.gridwidth = GridBagConstraints.REMAINDER;
|
133 |
constr2.gridheight = 1;
|
134 |
constr2.fill = GridBagConstraints.HORIZONTAL;
|
135 |
constr2.anchor = GridBagConstraints.LAST_LINE_END;
|
136 |
constr2.weightx=1;
|
137 |
constr2.weighty=0;
|
138 |
|
139 |
this.add(getAcceptCancel(), constr2);
|
140 |
|
141 |
} |
142 |
/**
|
143 |
* This method initializes pCentral
|
144 |
*
|
145 |
* @return javax.swing.JPanel
|
146 |
*/
|
147 |
private JPanel getPNorth() { |
148 |
if (pNorth == null) { |
149 |
pNorth = new JPanel(); |
150 |
pNorth.setLayout(new GridBagLayout()); |
151 |
GridBagConstraints contr = new GridBagConstraints(); |
152 |
contr.ipadx = 5;
|
153 |
contr.ipady = 5;
|
154 |
contr.fill = GridBagConstraints.BOTH;
|
155 |
contr.weightx =1;
|
156 |
contr.weighty =1;
|
157 |
pNorth.add(getPNorthWest(), contr); |
158 |
|
159 |
contr.fill = GridBagConstraints.VERTICAL;
|
160 |
contr.weightx =0;
|
161 |
contr.weighty =1;
|
162 |
|
163 |
pNorth.add(getPNorthCenter(), contr); |
164 |
|
165 |
contr.fill = GridBagConstraints.BOTH;
|
166 |
contr.weightx =0.5;
|
167 |
contr.weighty =1;
|
168 |
|
169 |
pNorth.add(getPNorthEast(), contr); |
170 |
} |
171 |
|
172 |
return pNorth;
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* This method initializes pNorth
|
177 |
*
|
178 |
* @return javax.swing.JPanel
|
179 |
*/
|
180 |
private JPanel getPCentral() { |
181 |
if (pCentral == null) { |
182 |
StringBuilder tit = new StringBuilder(); |
183 |
tit.append(PluginServices.getText(this,"expression")); |
184 |
tit.append(" ");
|
185 |
tit.append(PluginServices.getText(this, "column")); |
186 |
tit.append(" : ");
|
187 |
tit.append(evalExpression.getFieldDescriptorSelected().getName()); |
188 |
pCentral = new JPanel(); |
189 |
pCentral.setLayout(new GridBagLayout()); |
190 |
pCentral.setBorder(javax.swing.BorderFactory.createTitledBorder( |
191 |
null, tit.toString(),
|
192 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
193 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
194 |
GridBagConstraints contr = new GridBagConstraints(); |
195 |
contr.gridwidth = GridBagConstraints.REMAINDER;
|
196 |
contr.gridheight = 1;
|
197 |
contr.fill = GridBagConstraints.BOTH;
|
198 |
contr.ipadx = 5;
|
199 |
contr.ipady = 5;
|
200 |
contr.weightx=1;
|
201 |
contr.weighty=1;
|
202 |
pCentral.add(getJScrollPane(), contr); |
203 |
GridBagConstraints contr1 = new GridBagConstraints(); |
204 |
contr1.gridwidth = 1;
|
205 |
contr1.gridheight = 1;
|
206 |
contr1.fill = GridBagConstraints.NONE;
|
207 |
contr1.ipadx = 5;
|
208 |
contr1.ipady = 5;
|
209 |
contr1.anchor = GridBagConstraints.CENTER;
|
210 |
pCentral.add(getBClear(), contr1); |
211 |
} |
212 |
|
213 |
return pCentral;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* This method initializes pSouth
|
218 |
*
|
219 |
* @return javax.swing.JPanel
|
220 |
*/
|
221 |
private AcceptCancelPanel getAcceptCancel() {
|
222 |
if (this.acceptCancel == null) { |
223 |
this.acceptCancel = new AcceptCancelPanel( |
224 |
new java.awt.event.ActionListener() {
|
225 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
226 |
boolean isAccepted=true; |
227 |
Preferences prefs = Preferences.userRoot().node( |
228 |
"fieldExpressionOptions");
|
229 |
int limit;
|
230 |
limit = prefs.getInt("limit_rows_in_memory", -1); |
231 |
if (limit != -1) { |
232 |
int option = JOptionPane |
233 |
.showConfirmDialog( |
234 |
(Component) PluginServices
|
235 |
.getMainFrame(), |
236 |
PluginServices |
237 |
.getText( |
238 |
this,
|
239 |
"it_has_established_a_limit_of_rows_will_lose_the_possibility_to_undo_wants_to_continue"));
|
240 |
if (option != JOptionPane.OK_OPTION) { |
241 |
return;
|
242 |
} |
243 |
} |
244 |
try {
|
245 |
long t1 = System.currentTimeMillis(); |
246 |
isAccepted=evalExpression(); |
247 |
long t2 = System.currentTimeMillis(); |
248 |
System.out
|
249 |
.println("Tiempo evaluar expresiones = "
|
250 |
+ (t2 - t1)); |
251 |
} catch (BSFException e1) {
|
252 |
NotificationManager.addError(e1); |
253 |
} |
254 |
if (isAccepted)
|
255 |
PluginServices.getMDIManager().closeWindow( |
256 |
EvalExpressionDialog.this); |
257 |
} |
258 |
}, new java.awt.event.ActionListener() {
|
259 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
260 |
PluginServices.getMDIManager().closeWindow( |
261 |
EvalExpressionDialog.this); |
262 |
} |
263 |
}); |
264 |
acceptCancel.setOkButtonEnabled(false);
|
265 |
} |
266 |
|
267 |
return this.acceptCancel; |
268 |
} |
269 |
/**
|
270 |
* Evaluate the expression.
|
271 |
* @throws ReadDriverException
|
272 |
* @throws BSFException
|
273 |
*
|
274 |
* @throws EvalError
|
275 |
* @throws DriverException
|
276 |
* @throws DriverIOException
|
277 |
* @throws IOException
|
278 |
* @throws DriverIOException
|
279 |
* @throws IOException
|
280 |
* @throws BSFException
|
281 |
*/
|
282 |
private boolean evalExpression() throws BSFException{ |
283 |
|
284 |
|
285 |
String expression=getTxtExp().getText();
|
286 |
byte[] expressionBytes; |
287 |
String encoding = System.getProperty("file.encoding"); |
288 |
try {
|
289 |
expressionBytes = expression.getBytes(encoding); |
290 |
expression = new String(expressionBytes, "ISO-8859-1"); |
291 |
} catch (UnsupportedEncodingException e) { |
292 |
// TODO Auto-generated catch block
|
293 |
e.printStackTrace(); |
294 |
} |
295 |
expression=expression.replaceAll("\\[","field(\"").replaceAll("\\]","\")"); |
296 |
|
297 |
interpreter.declareBean("evalExpression",evalExpression,EvalExpression.class);
|
298 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def expression():\n" + |
299 |
" return " +expression+ ""); |
300 |
|
301 |
try {
|
302 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def isCorrect():\n" + |
303 |
" evalExpression.isCorrectValue(expression())\n");
|
304 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"isCorrect()"); |
305 |
} catch (BSFException ee) {
|
306 |
String message=ee.getMessage();
|
307 |
if (message.length()>200){ |
308 |
message=message.substring(0,200); |
309 |
} |
310 |
int option=JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), |
311 |
PluginServices.getText(this,
|
312 |
"error_expression")+"\n"+message+"\n"+PluginServices.getText(this,"continue?")); |
313 |
if (option!=JOptionPane.OK_OPTION) { |
314 |
return false; |
315 |
} |
316 |
} |
317 |
try {
|
318 |
boolean select = true; |
319 |
interpreter.declareBean("select", select, boolean.class); |
320 |
if (featureStore.isEditing()){
|
321 |
evalInEditing(); |
322 |
}else{
|
323 |
evalOutEditing(); |
324 |
} |
325 |
} catch (DataException e) {
|
326 |
NotificationManager.addError(e); |
327 |
} |
328 |
|
329 |
return true; |
330 |
} |
331 |
private void evalInEditing() throws BSFException, DataException { |
332 |
int limit=prefs.getInt("limit_rows_in_memory",-1); |
333 |
ArrayList exceptions=new ArrayList(); |
334 |
interpreter.declareBean("exceptions",exceptions,ArrayList.class); |
335 |
boolean emptySelection = ((FeatureSelection)featureStore.getSelection()).isEmpty();
|
336 |
|
337 |
|
338 |
FeatureSet set= featureStore.getFeatureSet(table.getModel().getQuery()); |
339 |
DisposableIterator iterator=set.iterator(); |
340 |
|
341 |
interpreter.declareBean("featureSet", set, FeatureSet.class);
|
342 |
interpreter.declareBean("iterator",iterator,Iterator.class); |
343 |
interpreter.declareBean("limit",limit,int.class); |
344 |
|
345 |
|
346 |
if (limit==-1){ |
347 |
featureStore.beginEditingGroup(PluginServices.getText(this, "expression")); |
348 |
if (!emptySelection){
|
349 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def p():\n" + |
350 |
" \n" +
|
351 |
" while iterator.hasNext():\n" +
|
352 |
" feature=iterator.next()\n" +
|
353 |
" select=featureStore.getSelection().isSelected(feature)\n" +
|
354 |
" if select:\n" +
|
355 |
" featureContainer.setFeature(feature)\n" +
|
356 |
" obj=expression()\n" +
|
357 |
" evalExpression.setValue(featureSet,feature,obj)\n" +
|
358 |
" iterator.dispose()\n" +
|
359 |
" featureSet.dispose\n"
|
360 |
); |
361 |
}else{
|
362 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def p():\n" + |
363 |
" \n" +
|
364 |
" while iterator.hasNext():\n" +
|
365 |
" feature=iterator.next()\n" +
|
366 |
" featureContainer.setFeature(feature)\n" +
|
367 |
" obj=expression()\n" +
|
368 |
" evalExpression.setValue(featureSet,feature,obj)\n" +
|
369 |
" iterator.dispose()\n" +
|
370 |
" featureSet.dispose\n"
|
371 |
); |
372 |
} |
373 |
try {
|
374 |
interpreter.eval(ExpressionFieldExtension.JYTHON,null,-1,-1,"p()"); |
375 |
} catch (BSFException ee) {
|
376 |
|
377 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
378 |
PluginServices.getText(this, "evaluate_expression_with_errors")+" "+exceptions.size() +ee.getMessage()); |
379 |
} |
380 |
featureStore.endEditingGroup(); |
381 |
}else{
|
382 |
long size=set.getSize();
|
383 |
for(int i=0;i<size;i=i+limit){ |
384 |
// featureStore.finishEditing();
|
385 |
// featureStore.edit();
|
386 |
featureStore.beginEditingGroup(PluginServices.getText(this, "expression")); |
387 |
set= featureStore.getFeatureSet(table.getModel().getQuery()); |
388 |
interpreter.declareBean("featureSet",set,FeatureSet.class);
|
389 |
iterator=set.iterator(i); |
390 |
interpreter.declareBean("iterator",iterator,Iterator.class); |
391 |
if (!emptySelection){
|
392 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def p():\n" + |
393 |
" \n" +
|
394 |
" pos=0\n" +
|
395 |
" while iterator.hasNext() and pos<limit:\n" +
|
396 |
" feature=iterator.next()\n" +
|
397 |
" select=featureStore.getSelection().isSelected(feature)\n" +
|
398 |
" if select:\n" +
|
399 |
" featureContainer.setFeature(feature)\n" +
|
400 |
" obj=expression()\n" +
|
401 |
" evalExpression.setValue(featureSet,feature,obj)\n" +
|
402 |
" pos=pos+1\n" +
|
403 |
" iterator.dispose()\n" +
|
404 |
" featureSet.dispose\n"
|
405 |
); |
406 |
}else{
|
407 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def p():\n" + |
408 |
" \n" +
|
409 |
" pos=0\n" +
|
410 |
" while iterator.hasNext() and pos<limit:\n" +
|
411 |
" feature=iterator.next()\n" +
|
412 |
" featureContainer.setFeature(feature)\n" +
|
413 |
" obj=expression()\n" +
|
414 |
" evalExpression.setValue(featureSet,feature,obj)\n" +
|
415 |
" pos=pos+1\n" +
|
416 |
" iterator.dispose()\n" +
|
417 |
" featureSet.dispose\n"
|
418 |
); |
419 |
} |
420 |
try {
|
421 |
interpreter.eval(ExpressionFieldExtension.JYTHON,null,-1,-1,"p()"); |
422 |
} catch (BSFException ee) {
|
423 |
|
424 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
425 |
PluginServices.getText(this, "evaluate_expression_with_errors")+" "+exceptions.size() +ee.getMessage()); |
426 |
} |
427 |
|
428 |
featureStore.endEditingGroup(); |
429 |
featureStore.finishEditing(); |
430 |
featureStore.edit(); |
431 |
} |
432 |
} |
433 |
|
434 |
} |
435 |
private void evalOutEditing() throws BSFException, DataException { |
436 |
|
437 |
} |
438 |
|
439 |
/**
|
440 |
* This method initializes pMessage
|
441 |
*
|
442 |
* @return javax.swing.JPanel
|
443 |
*/
|
444 |
private JPanel getPMessage() { |
445 |
if (pMessage == null) { |
446 |
|
447 |
pMessage = new JPanel(); |
448 |
pMessage.setLayout(new GridLayout()); |
449 |
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)); |
450 |
pMessage.add(getJScrollPane3(), null);
|
451 |
} |
452 |
return pMessage;
|
453 |
} |
454 |
private void evalExpressions() throws BSFException { |
455 |
featureStore = table.getModel().getStore(); |
456 |
interpreter.declareBean("featureStore", featureStore,FeatureStore.class);
|
457 |
featureContainer=new FeatureContainer();
|
458 |
DisposableIterator iterator=null;
|
459 |
FeatureSet set= null;
|
460 |
try {
|
461 |
set=featureStore.getFeatureSet(table.getModel().getQuery()); |
462 |
iterator = set.iterator(); |
463 |
|
464 |
} catch (DataException e) {
|
465 |
e.printStackTrace(); |
466 |
} |
467 |
if (iterator.hasNext())
|
468 |
feature=(Feature)iterator.next(); |
469 |
featureContainer.setFeature(feature); |
470 |
iterator.dispose(); |
471 |
set.dispose(); |
472 |
interpreter.declareBean("featureContainer", featureContainer,Feature.class);
|
473 |
} |
474 |
/**
|
475 |
* Evaluate the fields.
|
476 |
*
|
477 |
* @param interpreter
|
478 |
*
|
479 |
* @throws EvalError
|
480 |
*/
|
481 |
int lastType=-1; |
482 |
private JButton bClear = null; |
483 |
private JTabbedPane tabPrincipal = null; |
484 |
private JPanel pPrincipal = null; |
485 |
private JPanel pAdvanced = null; |
486 |
private JPanel pAdvancedNorth = null; |
487 |
private JTextField jTextField = null; |
488 |
private JButton bFile = null; |
489 |
private JPanel pAdvancedCenter = null; |
490 |
private JLabel lblLeng = null; |
491 |
private JButton bEval = null; |
492 |
private JScrollPane jScrollPane3 = null; |
493 |
private JTextArea txtMessage2 = null; |
494 |
private void refreshOperators(int type) { |
495 |
if (lastType!=-1 && lastType==type) |
496 |
return;
|
497 |
lastType=type; |
498 |
ListOperatorsModel lom=(ListOperatorsModel)getListCommand().getModel(); |
499 |
lom.clear(); |
500 |
for (int i=0;i<operators.size();i++) { |
501 |
IOperator operator = (IOperator)operators.get(i); |
502 |
operator.setType(type); |
503 |
//Comprobar si tiene una capa asociada y pasarsela al GraphicOperator.
|
504 |
if ((lv != null) && operator instanceof GraphicOperator) { |
505 |
GraphicOperator igo = (GraphicOperator) operator; |
506 |
igo.setLayer(lv); |
507 |
} |
508 |
if (operator.isEnable()) {
|
509 |
lom.addOperator(operator); |
510 |
//System.out.println("Operator = "+operator.toString());
|
511 |
} |
512 |
} |
513 |
getListCommand().repaint(); |
514 |
getJScrollPane2().repaint(); |
515 |
getJScrollPane2().doLayout(); |
516 |
this.doLayout();
|
517 |
|
518 |
} |
519 |
/**
|
520 |
* This method initializes jScrollPane
|
521 |
*
|
522 |
* @return javax.swing.JScrollPane
|
523 |
*/
|
524 |
private JScrollPane getJScrollPane() { |
525 |
if (jScrollPane == null) { |
526 |
jScrollPane = new JScrollPane(); |
527 |
jScrollPane.setPreferredSize(new java.awt.Dimension(480, 80)); |
528 |
jScrollPane.setViewportView(getTxtExp()); |
529 |
} |
530 |
|
531 |
return jScrollPane;
|
532 |
} |
533 |
|
534 |
/**
|
535 |
* This method initializes txtExp
|
536 |
*
|
537 |
* @return javax.swing.JTextArea
|
538 |
*/
|
539 |
private JTextArea getTxtExp() { |
540 |
if (txtExp == null) { |
541 |
txtExp = new JTextArea(); |
542 |
txtExp.addCaretListener(new CaretListener(){ |
543 |
public void caretUpdate(CaretEvent e) { |
544 |
if (txtExp.getText().length()>0) |
545 |
getAcceptCancel().setOkButtonEnabled(true);
|
546 |
else
|
547 |
getAcceptCancel().setOkButtonEnabled(false);
|
548 |
} |
549 |
|
550 |
|
551 |
|
552 |
|
553 |
}); |
554 |
} |
555 |
|
556 |
return txtExp;
|
557 |
} |
558 |
|
559 |
public WindowInfo getWindowInfo() {
|
560 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG+WindowInfo.RESIZABLE);
|
561 |
wi.setTitle(PluginServices.getText(this, "calculate_expression")); |
562 |
|
563 |
|
564 |
return wi;
|
565 |
} |
566 |
|
567 |
/**
|
568 |
* This method initializes pNorthEast
|
569 |
*
|
570 |
* @return javax.swing.JPanel
|
571 |
*/
|
572 |
private JPanel getPNorthEast() { |
573 |
if (pNorthEast == null) { |
574 |
pNorthEast = new JPanel(new GridLayout()); |
575 |
pNorthEast.setBorder(javax.swing.BorderFactory.createTitledBorder( |
576 |
null, PluginServices.getText(this,"commands"), |
577 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
578 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
579 |
pNorthEast.add(getJScrollPane2(), null);
|
580 |
} |
581 |
|
582 |
return pNorthEast;
|
583 |
} |
584 |
|
585 |
/**
|
586 |
* This method initializes pNorthCenter
|
587 |
*
|
588 |
* @return javax.swing.JPanel
|
589 |
*/
|
590 |
private JPanel getPNorthCenter() { |
591 |
if (pNorthCenter == null) { |
592 |
pNorthCenter = new JPanel(); |
593 |
pNorthCenter.setLayout(new BoxLayout(getPNorthCenter(), |
594 |
BoxLayout.Y_AXIS));
|
595 |
pNorthCenter.setBorder(javax.swing.BorderFactory.createTitledBorder( |
596 |
null, PluginServices.getText(this,"type"), |
597 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
598 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
599 |
pNorthCenter.add(getRbNumber(), null);
|
600 |
pNorthCenter.add(getRbString(), null);
|
601 |
pNorthCenter.add(getRbDate(), null);
|
602 |
} |
603 |
|
604 |
return pNorthCenter;
|
605 |
} |
606 |
|
607 |
/**
|
608 |
* This method initializes pNorthWest
|
609 |
*
|
610 |
* @return javax.swing.JPanel
|
611 |
*/
|
612 |
private JPanel getPNorthWest() { |
613 |
if (pNorthWest == null) { |
614 |
pNorthWest = new JPanel(new GridLayout()); |
615 |
pNorthWest.setBorder(javax.swing.BorderFactory.createTitledBorder( |
616 |
null, PluginServices.getText(this,"field"), |
617 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
618 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
619 |
pNorthWest.add(getJScrollPane1(), null);
|
620 |
} |
621 |
|
622 |
return pNorthWest;
|
623 |
} |
624 |
|
625 |
/**
|
626 |
* This method initializes jScrollPane1
|
627 |
*
|
628 |
* @return javax.swing.JScrollPane
|
629 |
*/
|
630 |
private JScrollPane getJScrollPane1() { |
631 |
if (jScrollPane1 == null) { |
632 |
jScrollPane1 = new JScrollPane(); |
633 |
jScrollPane1.setPreferredSize(new java.awt.Dimension(175, 100)); |
634 |
jScrollPane1.setViewportView(getListFields()); |
635 |
} |
636 |
|
637 |
return jScrollPane1;
|
638 |
} |
639 |
|
640 |
/**
|
641 |
* This method initializes listFields
|
642 |
*
|
643 |
* @return javax.swing.JList
|
644 |
*/
|
645 |
private JList getListFields() { |
646 |
if (listFields == null) { |
647 |
listFields = new JList(); |
648 |
listFields.setModel(new ListOperatorsModel());
|
649 |
|
650 |
ListOperatorsModel lm = (ListOperatorsModel) listFields.getModel(); |
651 |
FeatureType fds=evalExpression.getFieldDescriptors(); |
652 |
for (int i = 0; i < fds.size(); i++) { |
653 |
Field field=new Field(); |
654 |
field.setFieldDescription(fds.getAttributeDescriptor(i)); |
655 |
try {
|
656 |
field.eval(interpreter); |
657 |
} catch (BSFException e) {
|
658 |
e.printStackTrace(); |
659 |
} |
660 |
lm.addOperator(field); |
661 |
} |
662 |
|
663 |
listFields.addMouseListener(new MouseListener() { |
664 |
public void mouseClicked(MouseEvent e) { |
665 |
IOperator operator=((IOperator) listFields.getSelectedValue()); |
666 |
getTxtMessage2().setText(operator.getTooltip()); |
667 |
if (e.getClickCount() == 2) { |
668 |
getTxtExp().setText(operator.addText( |
669 |
getTxtExp().getText())); |
670 |
} |
671 |
} |
672 |
|
673 |
public void mouseEntered(MouseEvent e) { |
674 |
} |
675 |
|
676 |
public void mouseExited(MouseEvent e) { |
677 |
} |
678 |
|
679 |
public void mousePressed(MouseEvent e) { |
680 |
} |
681 |
|
682 |
public void mouseReleased(MouseEvent e) { |
683 |
} |
684 |
}); |
685 |
} |
686 |
|
687 |
return listFields;
|
688 |
} |
689 |
|
690 |
/**
|
691 |
* This method initializes rbNumber
|
692 |
*
|
693 |
* @return javax.swing.JRadioButton
|
694 |
*/
|
695 |
private JRadioButton getRbNumber() { |
696 |
if (rbNumber == null) { |
697 |
rbNumber = new JRadioButton(); |
698 |
rbNumber.setText(PluginServices.getText(this,"numeric")); |
699 |
rbNumber.setSelected(true);
|
700 |
rbNumber.addChangeListener(new javax.swing.event.ChangeListener() {
|
701 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
702 |
if (rbNumber.isSelected())
|
703 |
refreshCommands(); |
704 |
} |
705 |
}); |
706 |
} |
707 |
|
708 |
return rbNumber;
|
709 |
} |
710 |
|
711 |
/**
|
712 |
* This method initializes rbString
|
713 |
*
|
714 |
* @return javax.swing.JRadioButton
|
715 |
*/
|
716 |
private JRadioButton getRbString() { |
717 |
if (rbString == null) { |
718 |
rbString = new JRadioButton(); |
719 |
rbString.setText(PluginServices.getText(this,"string")); |
720 |
rbString.addChangeListener(new javax.swing.event.ChangeListener() {
|
721 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
722 |
if (rbString.isSelected())
|
723 |
refreshCommands(); |
724 |
} |
725 |
}); |
726 |
} |
727 |
|
728 |
return rbString;
|
729 |
} |
730 |
|
731 |
/**
|
732 |
* This method initializes rbData
|
733 |
*
|
734 |
* @return javax.swing.JRadioButton
|
735 |
*/
|
736 |
private JRadioButton getRbDate() { |
737 |
if (rbDate == null) { |
738 |
rbDate = new JRadioButton(); |
739 |
rbDate.setText(PluginServices.getText(this,"date")); |
740 |
rbDate.addChangeListener(new javax.swing.event.ChangeListener() {
|
741 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
742 |
if (rbDate.isSelected())
|
743 |
refreshCommands(); |
744 |
} |
745 |
}); |
746 |
} |
747 |
|
748 |
return rbDate;
|
749 |
} |
750 |
|
751 |
/**
|
752 |
* This method initializes jScrollPane2
|
753 |
*
|
754 |
* @return javax.swing.JScrollPane
|
755 |
*/
|
756 |
private JScrollPane getJScrollPane2() { |
757 |
if (jScrollPane2 == null) { |
758 |
jScrollPane2 = new JScrollPane(); |
759 |
jScrollPane2.setPreferredSize(new java.awt.Dimension(175, 100)); |
760 |
jScrollPane2.setViewportView(getListCommand()); |
761 |
} |
762 |
|
763 |
return jScrollPane2;
|
764 |
} |
765 |
|
766 |
/**
|
767 |
* Refresh the commands.
|
768 |
*/
|
769 |
private void refreshCommands() { |
770 |
int type=IOperator.NUMBER;
|
771 |
if (getRbNumber().isSelected()) {
|
772 |
type=IOperator.NUMBER; |
773 |
} else if (getRbString().isSelected()) { |
774 |
type=IOperator.STRING; |
775 |
} else if (getRbDate().isSelected()) { |
776 |
type=IOperator.DATE; |
777 |
} |
778 |
refreshOperators(type); |
779 |
|
780 |
} |
781 |
|
782 |
/**
|
783 |
* This method initializes ListCommand
|
784 |
*
|
785 |
* @return javax.swing.JList
|
786 |
*/
|
787 |
private JList getListCommand() { |
788 |
if (listCommand == null) { |
789 |
listCommand = new JList(); |
790 |
listCommand.setModel(new ListOperatorsModel());
|
791 |
listCommand.addMouseListener(new MouseListener() { |
792 |
public void mouseClicked(MouseEvent e) { |
793 |
IOperator operator=((IOperator) listCommand.getSelectedValue()); |
794 |
getTxtMessage2().setText(operator.getTooltip()); |
795 |
if (e.getClickCount() == 2) { |
796 |
if (listCommand.getSelectedValue()==null) |
797 |
return;
|
798 |
getTxtExp().setText(operator.addText( |
799 |
getTxtExp().getText())); |
800 |
} |
801 |
} |
802 |
|
803 |
public void mouseEntered(MouseEvent e) { |
804 |
} |
805 |
|
806 |
public void mouseExited(MouseEvent e) { |
807 |
} |
808 |
|
809 |
public void mousePressed(MouseEvent e) { |
810 |
} |
811 |
|
812 |
public void mouseReleased(MouseEvent e) { |
813 |
} |
814 |
}); |
815 |
refreshOperators(IOperator.NUMBER); |
816 |
} |
817 |
|
818 |
return listCommand;
|
819 |
} |
820 |
|
821 |
/**
|
822 |
* This method initializes bClear
|
823 |
*
|
824 |
* @return javax.swing.JButton
|
825 |
*/
|
826 |
private JButton getBClear() { |
827 |
if (bClear == null) { |
828 |
bClear = new JButton(); |
829 |
bClear.setText(PluginServices.getText(this,"clear_expression")); |
830 |
bClear.addActionListener(new java.awt.event.ActionListener() {
|
831 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
832 |
getTxtExp().setText("");
|
833 |
} |
834 |
}); |
835 |
} |
836 |
return bClear;
|
837 |
} |
838 |
/**
|
839 |
* This method initializes tabPrincipal
|
840 |
*
|
841 |
* @return javax.swing.JTabbedPane
|
842 |
*/
|
843 |
private JTabbedPane getTabPrincipal() { |
844 |
if (tabPrincipal == null) { |
845 |
tabPrincipal = new JTabbedPane(); |
846 |
tabPrincipal.addTab(PluginServices.getText(this,"general"), null, getPPrincipal(), null); |
847 |
tabPrincipal.addTab(PluginServices.getText(this,"advanced"), null, getPAdvanced(), null); |
848 |
} |
849 |
return tabPrincipal;
|
850 |
} |
851 |
/**
|
852 |
* This method initializes pPrincipal
|
853 |
*
|
854 |
* @return javax.swing.JPanel
|
855 |
*/
|
856 |
private JPanel getPPrincipal() { |
857 |
if (pPrincipal == null) { |
858 |
pPrincipal = new JPanel(); |
859 |
pPrincipal.setLayout(new BorderLayout()); |
860 |
// pPrincipal.setPreferredSize(new java.awt.Dimension(540,252));
|
861 |
pPrincipal.add(getPNorth(), java.awt.BorderLayout.NORTH); |
862 |
pPrincipal.add(getPCentral(), java.awt.BorderLayout.CENTER); |
863 |
|
864 |
} |
865 |
return pPrincipal;
|
866 |
} |
867 |
/**
|
868 |
* This method initializes pAdvanced
|
869 |
*
|
870 |
* @return javax.swing.JPanel
|
871 |
*/
|
872 |
private JPanel getPAdvanced() { |
873 |
if (pAdvanced == null) { |
874 |
pAdvanced = new JPanel(); |
875 |
pAdvanced.setLayout(new BorderLayout()); |
876 |
pAdvanced.add(getPAdvancedNorth(), java.awt.BorderLayout.NORTH); |
877 |
pAdvanced.add(getPAdvancedCenter(), java.awt.BorderLayout.CENTER); |
878 |
} |
879 |
return pAdvanced;
|
880 |
} |
881 |
/**
|
882 |
* This method initializes pAdvancedNorth
|
883 |
*
|
884 |
* @return javax.swing.JPanel
|
885 |
*/
|
886 |
private JPanel getPAdvancedNorth() { |
887 |
if (pAdvancedNorth == null) { |
888 |
pAdvancedNorth = new JPanel(new GridBagLayout()); |
889 |
// pAdvancedNorth.setPreferredSize(new java.awt.Dimension(873,100));
|
890 |
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)); |
891 |
GridBagConstraints contr = new GridBagConstraints(); |
892 |
contr.anchor = GridBagConstraints.FIRST_LINE_START;
|
893 |
contr.fill = GridBagConstraints.HORIZONTAL;
|
894 |
contr.weighty =0;
|
895 |
contr.weightx =1;
|
896 |
contr.insets = new Insets(3,3,3,3); |
897 |
contr.ipadx=5;
|
898 |
contr.ipady=5;
|
899 |
|
900 |
pAdvancedNorth.add(getJTextField(), contr); |
901 |
contr.fill = GridBagConstraints.NONE;
|
902 |
contr.weighty =0;
|
903 |
contr.weightx =0;
|
904 |
pAdvancedNorth.add(getBFile(), null);
|
905 |
pAdvancedNorth.add(getBEval(), null);
|
906 |
} |
907 |
return pAdvancedNorth;
|
908 |
} |
909 |
/**
|
910 |
* This method initializes jTextField
|
911 |
*
|
912 |
* @return javax.swing.JTextField
|
913 |
*/
|
914 |
private JTextField getJTextField() { |
915 |
if (jTextField == null) { |
916 |
jTextField = new JTextField(); |
917 |
jTextField.setPreferredSize(new java.awt.Dimension(250,20)); |
918 |
} |
919 |
return jTextField;
|
920 |
} |
921 |
/**
|
922 |
* This method initializes bFile
|
923 |
*
|
924 |
* @return javax.swing.JButton
|
925 |
*/
|
926 |
private JButton getBFile() { |
927 |
if (bFile == null) { |
928 |
bFile = new JButton(); |
929 |
bFile.setText(PluginServices.getText(this,"explorer")); |
930 |
bFile.addActionListener(new java.awt.event.ActionListener() {
|
931 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
932 |
JFileChooser jfc = new JFileChooser(); |
933 |
jfc.addChoosableFileFilter(new GenericFileFilter("py", |
934 |
PluginServices.getText(this, "python"))); |
935 |
|
936 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
937 |
File fileExpression = jfc.getSelectedFile();
|
938 |
getJTextField().setText(fileExpression.getAbsolutePath()); |
939 |
|
940 |
} |
941 |
} |
942 |
}); |
943 |
} |
944 |
return bFile;
|
945 |
} |
946 |
private String readFile(File aFile) throws IOException { |
947 |
StringBuffer fileContents = new StringBuffer(); |
948 |
FileReader fileReader = new FileReader(aFile); |
949 |
int c;
|
950 |
while ((c = fileReader.read()) > -1) { |
951 |
fileContents.append((char)c);
|
952 |
} |
953 |
fileReader.close(); |
954 |
return fileContents.toString();
|
955 |
} |
956 |
/**
|
957 |
* This method initializes pAdvancedCenter
|
958 |
*
|
959 |
* @return javax.swing.JPanel
|
960 |
*/
|
961 |
private JPanel getPAdvancedCenter() { |
962 |
if (pAdvancedCenter == null) { |
963 |
lblLeng = new JLabel(); |
964 |
lblLeng.setText("");
|
965 |
pAdvancedCenter = new JPanel(); |
966 |
pAdvancedCenter.add(lblLeng, null);
|
967 |
} |
968 |
return pAdvancedCenter;
|
969 |
} |
970 |
|
971 |
/**
|
972 |
* This method initializes bEval
|
973 |
*
|
974 |
* @return javax.swing.JButton
|
975 |
*/
|
976 |
private JButton getBEval() { |
977 |
if (bEval == null) { |
978 |
bEval = new JButton(); |
979 |
bEval.setText(PluginServices.getText(this,"evaluate")); |
980 |
bEval.addActionListener(new java.awt.event.ActionListener() {
|
981 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
982 |
File file=new File(getJTextField().getText()); |
983 |
if (!file.exists()) {
|
984 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"incorrect_file")); |
985 |
return;
|
986 |
} |
987 |
try {
|
988 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,readFile(file)); |
989 |
} catch (IOException e1) { |
990 |
e1.printStackTrace(); |
991 |
} catch (BSFException e1) {
|
992 |
e1.printStackTrace(); |
993 |
} |
994 |
} |
995 |
}); |
996 |
} |
997 |
return bEval;
|
998 |
} |
999 |
/**
|
1000 |
* This method initializes jScrollPane3
|
1001 |
*
|
1002 |
* @return javax.swing.JScrollPane
|
1003 |
*/
|
1004 |
private JScrollPane getJScrollPane3() { |
1005 |
if (jScrollPane3 == null) { |
1006 |
jScrollPane3 = new JScrollPane(); |
1007 |
jScrollPane3.setPreferredSize(new java.awt.Dimension(530,80)); |
1008 |
jScrollPane3.setViewportView(getTxtMessage2()); |
1009 |
} |
1010 |
return jScrollPane3;
|
1011 |
} |
1012 |
/**
|
1013 |
* This method initializes txtMessage2
|
1014 |
*
|
1015 |
* @return javax.swing.JTextArea
|
1016 |
*/
|
1017 |
private JTextArea getTxtMessage2() { |
1018 |
if (txtMessage2 == null) { |
1019 |
txtMessage2 = new JTextArea(); |
1020 |
txtMessage2.setText(PluginServices.getText(this,"eval_expression_will_be_carried_out_right_now_with_current_values_in_table")); |
1021 |
txtMessage2.setEditable(false);
|
1022 |
txtMessage2.setBackground(UIManager.getColor(this)); |
1023 |
} |
1024 |
return txtMessage2;
|
1025 |
} |
1026 |
public Object getWindowProfile() { |
1027 |
return WindowInfo.DIALOG_PROFILE;
|
1028 |
} |
1029 |
} // @jve:decl-index=0:visual-constraint="10,10"
|