root / trunk / libraries / libExpressions / src / main / java / org / gvsig / gui / EvalExpressionDialog.java @ 27304
History | View | Annotate | Download (28.2 KB)
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 |
public Object getWindowProfile() { |
862 |
// TODO Auto-generated method stub
|
863 |
return WindowInfo.TOOL_PROFILE;
|
864 |
} |
865 |
|
866 |
} // @jve:decl-index=0:visual-constraint="10,10"
|