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