svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / project / documents / table / gui / EvalExpresionDialog.java @ 10254
History | View | Annotate | Download (25.6 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.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.Iterator; |
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 |
|
26 |
import org.apache.bsf.BSFException; |
27 |
import org.apache.bsf.BSFManager; |
28 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
29 |
import org.gvsig.gui.beans.swing.JButton; |
30 |
|
31 |
import bsh.EvalError; |
32 |
|
33 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
34 |
import com.iver.andami.PluginServices; |
35 |
import com.iver.andami.ui.mdiManager.IWindow; |
36 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
37 |
import com.iver.cit.gvsig.ExpresionFieldExtension; |
38 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
39 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
40 |
import com.iver.cit.gvsig.fmap.edition.IEditableSource; |
41 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
42 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
43 |
import com.iver.cit.gvsig.project.documents.table.GraphicOperator; |
44 |
import com.iver.cit.gvsig.project.documents.table.IOperator; |
45 |
import com.iver.cit.gvsig.project.documents.table.Index; |
46 |
import com.iver.cit.gvsig.project.documents.table.operators.Field; |
47 |
import com.iver.utiles.GenericFileFilter; |
48 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
49 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
50 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
51 |
|
52 |
|
53 |
/**
|
54 |
* DOCUMENT ME!
|
55 |
*
|
56 |
* @author Vicente Caballero Navarro
|
57 |
*/
|
58 |
public class EvalExpresionDialog extends JPanel implements IWindow { |
59 |
private JPanel pNorth = null; |
60 |
private JPanel pCentral = null; |
61 |
private JScrollPane jScrollPane = null; |
62 |
private JTextArea txtExp = null; |
63 |
private AcceptCancelPanel acceptCancel;
|
64 |
private Table table;
|
65 |
private FLyrVect lv;
|
66 |
private JLabel lblColumn = null; |
67 |
private JPanel pNorthEast = null; |
68 |
private JPanel pNorthCenter = null; |
69 |
private JPanel pNorthWest = null; |
70 |
private JScrollPane jScrollPane1 = null; |
71 |
private JList listFields = null; |
72 |
private JRadioButton rbNumber = null; |
73 |
private JRadioButton rbString = null; |
74 |
private JRadioButton rbDate = null; |
75 |
private JScrollPane jScrollPane2 = null; |
76 |
private JList listCommand = null; |
77 |
//private FieldDescription fieldDescriptor = null;
|
78 |
//private FieldDescription[] fieldDescriptors = null;
|
79 |
//private int selectedIndex = -1;
|
80 |
private BSFManager interpreter = null; // Construct an interpreter |
81 |
private Index indexRow = null; |
82 |
private SelectableDataSource sds = null; |
83 |
private EvalExpresion evalExpresion=null; |
84 |
private IEditableSource ies=null; |
85 |
private static ArrayList operators=new ArrayList(); |
86 |
public EvalExpresionDialog(Table table,BSFManager interpreter) {
|
87 |
super();
|
88 |
this.interpreter=interpreter;
|
89 |
this.table = table;
|
90 |
initialize(); |
91 |
|
92 |
} |
93 |
/**
|
94 |
* Evaluate operators.
|
95 |
*
|
96 |
* @param interpreter
|
97 |
* @throws BSFException
|
98 |
*
|
99 |
* @throws EvalError
|
100 |
*/
|
101 |
private void evalOperators(BSFManager interpreter) throws BSFException { |
102 |
// Evaluar las expresiones que aporta cada Operator.
|
103 |
long t1=System.currentTimeMillis(); |
104 |
//int type=getType();
|
105 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
106 |
ExtensionPoint extensionPoint =(ExtensionPoint)extensionPoints.get("ColumnOperators");
|
107 |
Iterator iterator = extensionPoint.keySet().iterator();
|
108 |
while (iterator.hasNext()) {
|
109 |
try {
|
110 |
IOperator operator = (IOperator)extensionPoint.create((String)iterator.next());
|
111 |
operator.eval(interpreter); |
112 |
operators.add(operator); |
113 |
} catch (InstantiationException e) { |
114 |
e.printStackTrace(); |
115 |
} catch (IllegalAccessException e) { |
116 |
e.printStackTrace(); |
117 |
} catch (ClassCastException e) { |
118 |
e.printStackTrace(); |
119 |
} |
120 |
} |
121 |
// Operators operatos=new Operators();
|
122 |
// operatos.eval(interpreter);
|
123 |
long t2=System.currentTimeMillis(); |
124 |
System.out.println("Tiempo en evaluar y crear del extension point = "+(t2-t1) ); |
125 |
//refreshOperators(IOperator.NUMBER);
|
126 |
long t3=System.currentTimeMillis(); |
127 |
System.out.println("Tiempo en a?adir los operadores correctos = "+(t3-t2) ); |
128 |
|
129 |
} |
130 |
/**
|
131 |
* This method initializes this
|
132 |
*/
|
133 |
private void initialize() { |
134 |
try {
|
135 |
if (operators.isEmpty()) {
|
136 |
evalOperators(interpreter); |
137 |
} |
138 |
evalExpresions(); |
139 |
} catch (BSFException e) {
|
140 |
e.printStackTrace(); |
141 |
} |
142 |
evalExpresion=new EvalExpresion();
|
143 |
evalExpresion.setTable(table); |
144 |
lv = (FLyrVect) table.getModel().getAssociatedTable(); |
145 |
ButtonGroup bg = new ButtonGroup(); |
146 |
bg.add(getRbNumber()); |
147 |
bg.add(getRbString()); |
148 |
bg.add(getRbDate()); |
149 |
this.setLayout(new BorderLayout()); |
150 |
this.setSize(549, 372); |
151 |
this.add(getTabPrincipal(), java.awt.BorderLayout.CENTER);
|
152 |
this.add(getAcceptCancel(), java.awt.BorderLayout.SOUTH);
|
153 |
} |
154 |
|
155 |
/**
|
156 |
* This method initializes pCentral
|
157 |
*
|
158 |
* @return javax.swing.JPanel
|
159 |
*/
|
160 |
private JPanel getPNorth() { |
161 |
if (pNorth == null) { |
162 |
pNorth = new JPanel(); |
163 |
pNorth.setLayout(new BorderLayout()); |
164 |
pNorth.add(getPNorthEast(), java.awt.BorderLayout.EAST); |
165 |
pNorth.add(getPNorthCenter(), java.awt.BorderLayout.CENTER); |
166 |
pNorth.add(getPNorthWest(), java.awt.BorderLayout.WEST); |
167 |
} |
168 |
|
169 |
return pNorth;
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* This method initializes pNorth
|
174 |
*
|
175 |
* @return javax.swing.JPanel
|
176 |
*/
|
177 |
private JPanel getPCentral() { |
178 |
if (pCentral == null) { |
179 |
pCentral = new JPanel(); |
180 |
pCentral.setBorder(javax.swing.BorderFactory.createTitledBorder( |
181 |
null, PluginServices.getText(this,"expresion"), |
182 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
183 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
184 |
lblColumn = new JLabel(); |
185 |
pCentral.add(lblColumn, null);
|
186 |
|
187 |
pCentral.add(getJScrollPane(), null);
|
188 |
lblColumn.setText(PluginServices.getText(this, "column") + " : " + |
189 |
evalExpresion.getFieldDescriptorSelected().getFieldAlias()); |
190 |
pCentral.add(getBClear(), null);
|
191 |
} |
192 |
|
193 |
return pCentral;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* This method initializes pSouth
|
198 |
*
|
199 |
* @return javax.swing.JPanel
|
200 |
*/
|
201 |
private AcceptCancelPanel getAcceptCancel() {
|
202 |
if (this.acceptCancel == null) { |
203 |
this.acceptCancel = new AcceptCancelPanel(new java.awt.event.ActionListener() { |
204 |
public void actionPerformed( |
205 |
java.awt.event.ActionEvent e) { |
206 |
try {
|
207 |
long t1=System.currentTimeMillis(); |
208 |
evalExpresion(); |
209 |
long t2=System.currentTimeMillis(); |
210 |
System.out.println("Tiempo evaluar expresiones = "+(t2-t1)); |
211 |
} catch (DriverException e1) {
|
212 |
e1.printStackTrace(); |
213 |
} catch (IOException e1) { |
214 |
e1.printStackTrace(); |
215 |
} catch (DriverIOException e1) {
|
216 |
e1.printStackTrace(); |
217 |
} catch (BSFException e1) {
|
218 |
e1.printStackTrace(); |
219 |
} |
220 |
|
221 |
PluginServices.getMDIManager().closeWindow(EvalExpresionDialog.this); |
222 |
} |
223 |
}, |
224 |
new java.awt.event.ActionListener() {
|
225 |
public void actionPerformed( |
226 |
java.awt.event.ActionEvent e) { |
227 |
PluginServices.getMDIManager().closeWindow(EvalExpresionDialog.this); |
228 |
} |
229 |
}); |
230 |
|
231 |
//this.acceptCancel.setBounds(5,150,this.getWidth()-10,30);
|
232 |
} |
233 |
|
234 |
return this.acceptCancel; |
235 |
} |
236 |
/**
|
237 |
* Evaluate the expresion.
|
238 |
*
|
239 |
* @throws EvalError
|
240 |
* @throws DriverException
|
241 |
* @throws DriverIOException
|
242 |
* @throws IOException
|
243 |
* @throws DriverIOException
|
244 |
* @throws IOException
|
245 |
* @throws BSFException
|
246 |
*/
|
247 |
private void evalExpresion() |
248 |
throws DriverException, IOException, DriverIOException, BSFException { |
249 |
long rowCount = sds.getRowCount();
|
250 |
interpreter.eval(ExpresionFieldExtension.BEANSHELL,null,-1,-1,"java.lang.Object myF () {" +getTxtExp().getText()+ ";};"); |
251 |
if (rowCount > 0) { |
252 |
try {
|
253 |
interpreter.eval(ExpresionFieldExtension.BEANSHELL,null,-1,-1,"myF()"); |
254 |
} catch (BSFException ee) {
|
255 |
int option=JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(), |
256 |
PluginServices.getText(this,
|
257 |
"error_expresion")+ee+PluginServices.getText(this,"continue?")); |
258 |
if (option!=JOptionPane.OK_OPTION) { |
259 |
return;
|
260 |
} |
261 |
} |
262 |
} |
263 |
ArrayList errors = new ArrayList(); |
264 |
ies.startComplexRow(); |
265 |
interpreter.declareBean("ee",evalExpresion,EvalExpresion.class);
|
266 |
String p= "for (int i=0; i < " +rowCount + "; i++){" + |
267 |
"indexRow.set(i);" +
|
268 |
"java.lang.Object obj = myF();" +
|
269 |
//"long t1 = System.currentTimeMillis();" +
|
270 |
"ee.setValue(obj,i);" +
|
271 |
"ee.saveEdits(i);" +
|
272 |
//"t2 = System.currentTimeMillis();" +
|
273 |
//"print(\"Obj = \" + obj.toString());" +
|
274 |
"}" +
|
275 |
"ee.saveEdits(-1);" +
|
276 |
"";
|
277 |
interpreter.eval(ExpresionFieldExtension.BEANSHELL,null,-1,-1,p); |
278 |
ies.endComplexRow(PluginServices.getText(this, "expresion")); |
279 |
// try {
|
280 |
// saveEdits();
|
281 |
// } catch (DriverLoadException e) {
|
282 |
// e.printStackTrace();
|
283 |
// } catch (EditionException e) {
|
284 |
// e.printStackTrace();
|
285 |
// } catch (DriverException e) {
|
286 |
// e.printStackTrace();
|
287 |
// } catch (com.iver.cit.gvsig.fmap.DriverException e) {
|
288 |
// e.printStackTrace();
|
289 |
// }
|
290 |
if (!errors.isEmpty()) {
|
291 |
JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(), |
292 |
PluginServices.getText(this, "evaluate_expresion_with_errors") + " = " + |
293 |
errors.size()); |
294 |
} |
295 |
table.refresh(); |
296 |
} |
297 |
|
298 |
private void evalExpresions() throws BSFException { |
299 |
ies = table.getModel().getModelo(); |
300 |
sds = ies.getRecordset(); |
301 |
interpreter.declareBean("sds", sds,SelectableDataSource.class);
|
302 |
indexRow=new Index();
|
303 |
interpreter.declareBean("indexRow", indexRow,Index.class);
|
304 |
} |
305 |
/**
|
306 |
* Evaluate the fields.
|
307 |
*
|
308 |
* @param interpreter
|
309 |
*
|
310 |
* @throws EvalError
|
311 |
*/
|
312 |
int lastType=-1; |
313 |
private JButton bClear = null; |
314 |
private JTabbedPane tabPrincipal = null; |
315 |
private JPanel pPrincipal = null; |
316 |
private JPanel pAdvanced = null; |
317 |
private JPanel pAdvancedNorth = null; |
318 |
private JTextField jTextField = null; |
319 |
private JButton bFile = null; |
320 |
private JPanel pAdvancedCenter = null; |
321 |
private JLabel lblLeng = null; |
322 |
private JButton bEval = null; |
323 |
private void refreshOperators(int type) { |
324 |
if (lastType!=-1 && lastType==type) |
325 |
return;
|
326 |
lastType=type; |
327 |
ListOperatorsModel lom=(ListOperatorsModel)getListCommand().getModel(); |
328 |
lom.clear(); |
329 |
for (int i=0;i<operators.size();i++) { |
330 |
IOperator operator = (IOperator)operators.get(i); |
331 |
operator.setType(type); |
332 |
//Comprobar si tiene una capa asociada y pasarsela al GraphicOperator.
|
333 |
if ((lv != null) && operator instanceof GraphicOperator) { |
334 |
GraphicOperator igo = (GraphicOperator) operator; |
335 |
igo.setLayer(lv); |
336 |
} |
337 |
if (operator.isEnable()) {
|
338 |
lom.addOperator(operator); |
339 |
//System.out.println("Operator = "+operator.toString());
|
340 |
} |
341 |
} |
342 |
getListCommand().repaint(); |
343 |
|
344 |
} |
345 |
/**
|
346 |
* This method initializes jScrollPane
|
347 |
*
|
348 |
* @return javax.swing.JScrollPane
|
349 |
*/
|
350 |
private JScrollPane getJScrollPane() { |
351 |
if (jScrollPane == null) { |
352 |
jScrollPane = new JScrollPane(); |
353 |
jScrollPane.setPreferredSize(new java.awt.Dimension(480, 80)); |
354 |
jScrollPane.setViewportView(getTxtExp()); |
355 |
} |
356 |
|
357 |
return jScrollPane;
|
358 |
} |
359 |
|
360 |
/**
|
361 |
* This method initializes txtExp
|
362 |
*
|
363 |
* @return javax.swing.JTextArea
|
364 |
*/
|
365 |
private JTextArea getTxtExp() { |
366 |
if (txtExp == null) { |
367 |
txtExp = new JTextArea(); |
368 |
} |
369 |
|
370 |
return txtExp;
|
371 |
} |
372 |
|
373 |
public WindowInfo getWindowInfo() {
|
374 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG);
|
375 |
wi.setTitle(PluginServices.getText(this, "calculate_expresion")); |
376 |
|
377 |
return wi;
|
378 |
} |
379 |
|
380 |
/**
|
381 |
* This method initializes pNorthEast
|
382 |
*
|
383 |
* @return javax.swing.JPanel
|
384 |
*/
|
385 |
private JPanel getPNorthEast() { |
386 |
if (pNorthEast == null) { |
387 |
pNorthEast = new JPanel(); |
388 |
pNorthEast.setBorder(javax.swing.BorderFactory.createTitledBorder( |
389 |
null, PluginServices.getText(this,"commands"), |
390 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
391 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
392 |
pNorthEast.add(getJScrollPane2(), null);
|
393 |
} |
394 |
|
395 |
return pNorthEast;
|
396 |
} |
397 |
|
398 |
/**
|
399 |
* This method initializes pNorthCenter
|
400 |
*
|
401 |
* @return javax.swing.JPanel
|
402 |
*/
|
403 |
private JPanel getPNorthCenter() { |
404 |
if (pNorthCenter == null) { |
405 |
pNorthCenter = new JPanel(); |
406 |
pNorthCenter.setLayout(new BoxLayout(getPNorthCenter(), |
407 |
BoxLayout.Y_AXIS));
|
408 |
pNorthCenter.setBorder(javax.swing.BorderFactory.createTitledBorder( |
409 |
null, PluginServices.getText(this,"type"), |
410 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
411 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
412 |
pNorthCenter.add(getRbNumber(), null);
|
413 |
pNorthCenter.add(getRbString(), null);
|
414 |
pNorthCenter.add(getRbDate(), null);
|
415 |
} |
416 |
|
417 |
return pNorthCenter;
|
418 |
} |
419 |
|
420 |
/**
|
421 |
* This method initializes pNorthWest
|
422 |
*
|
423 |
* @return javax.swing.JPanel
|
424 |
*/
|
425 |
private JPanel getPNorthWest() { |
426 |
if (pNorthWest == null) { |
427 |
pNorthWest = new JPanel(); |
428 |
pNorthWest.setBorder(javax.swing.BorderFactory.createTitledBorder( |
429 |
null, PluginServices.getText(this,"field"), |
430 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
431 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
432 |
pNorthWest.add(getJScrollPane1(), null);
|
433 |
} |
434 |
|
435 |
return pNorthWest;
|
436 |
} |
437 |
|
438 |
/**
|
439 |
* This method initializes jScrollPane1
|
440 |
*
|
441 |
* @return javax.swing.JScrollPane
|
442 |
*/
|
443 |
private JScrollPane getJScrollPane1() { |
444 |
if (jScrollPane1 == null) { |
445 |
jScrollPane1 = new JScrollPane(); |
446 |
jScrollPane1.setPreferredSize(new java.awt.Dimension(175, 100)); |
447 |
jScrollPane1.setViewportView(getListFields()); |
448 |
} |
449 |
|
450 |
return jScrollPane1;
|
451 |
} |
452 |
|
453 |
/**
|
454 |
* This method initializes listFields
|
455 |
*
|
456 |
* @return javax.swing.JList
|
457 |
*/
|
458 |
private JList getListFields() { |
459 |
if (listFields == null) { |
460 |
listFields = new JList(); |
461 |
listFields.setModel(new ListOperatorsModel());
|
462 |
|
463 |
ListOperatorsModel lm = (ListOperatorsModel) listFields.getModel(); |
464 |
FieldDescription[] fds=evalExpresion.getFieldDescriptors();
|
465 |
for (int i = 0; i < fds.length; i++) { |
466 |
Field field=new Field(); |
467 |
field.setFieldDescription(fds[i]); |
468 |
try {
|
469 |
field.eval(interpreter); |
470 |
} catch (BSFException e) {
|
471 |
// TODO Auto-generated catch block
|
472 |
e.printStackTrace(); |
473 |
} |
474 |
lm.addOperator(field); |
475 |
} |
476 |
|
477 |
listFields.addMouseListener(new MouseListener() { |
478 |
public void mouseClicked(MouseEvent e) { |
479 |
if (e.getClickCount() == 2) { |
480 |
getTxtExp().setText(((IOperator) listFields.getSelectedValue()).addText( |
481 |
getTxtExp().getText())); |
482 |
} |
483 |
} |
484 |
|
485 |
public void mouseEntered(MouseEvent e) { |
486 |
} |
487 |
|
488 |
public void mouseExited(MouseEvent e) { |
489 |
} |
490 |
|
491 |
public void mousePressed(MouseEvent e) { |
492 |
} |
493 |
|
494 |
public void mouseReleased(MouseEvent e) { |
495 |
} |
496 |
}); |
497 |
} |
498 |
|
499 |
return listFields;
|
500 |
} |
501 |
|
502 |
/**
|
503 |
* This method initializes rbNumber
|
504 |
*
|
505 |
* @return javax.swing.JRadioButton
|
506 |
*/
|
507 |
private JRadioButton getRbNumber() { |
508 |
if (rbNumber == null) { |
509 |
rbNumber = new JRadioButton(); |
510 |
rbNumber.setText(PluginServices.getText(this,"numeric")); |
511 |
rbNumber.setSelected(true);
|
512 |
rbNumber.addChangeListener(new javax.swing.event.ChangeListener() {
|
513 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
514 |
if (rbNumber.isSelected())
|
515 |
refreshCommands(); |
516 |
} |
517 |
}); |
518 |
} |
519 |
|
520 |
return rbNumber;
|
521 |
} |
522 |
|
523 |
/**
|
524 |
* This method initializes rbString
|
525 |
*
|
526 |
* @return javax.swing.JRadioButton
|
527 |
*/
|
528 |
private JRadioButton getRbString() { |
529 |
if (rbString == null) { |
530 |
rbString = new JRadioButton(); |
531 |
rbString.setText(PluginServices.getText(this,"string")); |
532 |
rbString.addChangeListener(new javax.swing.event.ChangeListener() {
|
533 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
534 |
if (rbString.isSelected())
|
535 |
refreshCommands(); |
536 |
} |
537 |
}); |
538 |
} |
539 |
|
540 |
return rbString;
|
541 |
} |
542 |
|
543 |
/**
|
544 |
* This method initializes rbData
|
545 |
*
|
546 |
* @return javax.swing.JRadioButton
|
547 |
*/
|
548 |
private JRadioButton getRbDate() { |
549 |
if (rbDate == null) { |
550 |
rbDate = new JRadioButton(); |
551 |
rbDate.setText(PluginServices.getText(this,"date")); |
552 |
rbDate.addChangeListener(new javax.swing.event.ChangeListener() {
|
553 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
554 |
if (rbDate.isSelected())
|
555 |
refreshCommands(); |
556 |
} |
557 |
}); |
558 |
} |
559 |
|
560 |
return rbDate;
|
561 |
} |
562 |
|
563 |
/**
|
564 |
* This method initializes jScrollPane2
|
565 |
*
|
566 |
* @return javax.swing.JScrollPane
|
567 |
*/
|
568 |
private JScrollPane getJScrollPane2() { |
569 |
if (jScrollPane2 == null) { |
570 |
jScrollPane2 = new JScrollPane(); |
571 |
jScrollPane2.setPreferredSize(new java.awt.Dimension(175, 100)); |
572 |
jScrollPane2.setViewportView(getListCommand()); |
573 |
} |
574 |
|
575 |
return jScrollPane2;
|
576 |
} |
577 |
|
578 |
/**
|
579 |
* Refresh the commands.
|
580 |
*/
|
581 |
private void refreshCommands() { |
582 |
int type=IOperator.NUMBER;
|
583 |
if (getRbNumber().isSelected()) {
|
584 |
type=IOperator.NUMBER; |
585 |
} else if (getRbString().isSelected()) { |
586 |
type=IOperator.STRING; |
587 |
} else if (getRbDate().isSelected()) { |
588 |
type=IOperator.DATE; |
589 |
} |
590 |
refreshOperators(type); |
591 |
|
592 |
} |
593 |
|
594 |
/**
|
595 |
* This method initializes ListCommand
|
596 |
*
|
597 |
* @return javax.swing.JList
|
598 |
*/
|
599 |
private JList getListCommand() { |
600 |
if (listCommand == null) { |
601 |
listCommand = new JList(); |
602 |
listCommand.setModel(new ListOperatorsModel());
|
603 |
listCommand.addMouseListener(new MouseListener() { |
604 |
public void mouseClicked(MouseEvent e) { |
605 |
if (e.getClickCount() == 2) { |
606 |
if (listCommand.getSelectedValue()==null) |
607 |
return;
|
608 |
getTxtExp().setText(((IOperator) listCommand.getSelectedValue()).addText( |
609 |
getTxtExp().getText())); |
610 |
} |
611 |
} |
612 |
|
613 |
public void mouseEntered(MouseEvent e) { |
614 |
} |
615 |
|
616 |
public void mouseExited(MouseEvent e) { |
617 |
} |
618 |
|
619 |
public void mousePressed(MouseEvent e) { |
620 |
} |
621 |
|
622 |
public void mouseReleased(MouseEvent e) { |
623 |
} |
624 |
}); |
625 |
refreshOperators(IOperator.NUMBER); |
626 |
} |
627 |
|
628 |
return listCommand;
|
629 |
} |
630 |
|
631 |
/**
|
632 |
* This method initializes bClear
|
633 |
*
|
634 |
* @return javax.swing.JButton
|
635 |
*/
|
636 |
private JButton getBClear() { |
637 |
if (bClear == null) { |
638 |
bClear = new JButton(); |
639 |
bClear.setText(PluginServices.getText(this,"clear_expresion")); |
640 |
bClear.addActionListener(new java.awt.event.ActionListener() {
|
641 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
642 |
getTxtExp().setText("");
|
643 |
} |
644 |
}); |
645 |
} |
646 |
return bClear;
|
647 |
} |
648 |
/**
|
649 |
* This method initializes tabPrincipal
|
650 |
*
|
651 |
* @return javax.swing.JTabbedPane
|
652 |
*/
|
653 |
private JTabbedPane getTabPrincipal() { |
654 |
if (tabPrincipal == null) { |
655 |
tabPrincipal = new JTabbedPane(); |
656 |
tabPrincipal.addTab(PluginServices.getText(this,"general"), null, getPPrincipal(), null); |
657 |
tabPrincipal.addTab(PluginServices.getText(this,"advanced"), null, getPAdvanced(), null); |
658 |
} |
659 |
return tabPrincipal;
|
660 |
} |
661 |
/**
|
662 |
* This method initializes pPrincipal
|
663 |
*
|
664 |
* @return javax.swing.JPanel
|
665 |
*/
|
666 |
private JPanel getPPrincipal() { |
667 |
if (pPrincipal == null) { |
668 |
pPrincipal = new JPanel(); |
669 |
pPrincipal.setLayout(new BorderLayout()); |
670 |
pPrincipal.setPreferredSize(new java.awt.Dimension(540,252)); |
671 |
pPrincipal.add(getPNorth(), java.awt.BorderLayout.NORTH); |
672 |
pPrincipal.add(getPCentral(), java.awt.BorderLayout.CENTER); |
673 |
|
674 |
} |
675 |
return pPrincipal;
|
676 |
} |
677 |
/**
|
678 |
* This method initializes pAdvanced
|
679 |
*
|
680 |
* @return javax.swing.JPanel
|
681 |
*/
|
682 |
private JPanel getPAdvanced() { |
683 |
if (pAdvanced == null) { |
684 |
pAdvanced = new JPanel(); |
685 |
pAdvanced.setLayout(new BorderLayout()); |
686 |
pAdvanced.add(getPAdvancedNorth(), java.awt.BorderLayout.NORTH); |
687 |
pAdvanced.add(getPAdvancedCenter(), java.awt.BorderLayout.CENTER); |
688 |
} |
689 |
return pAdvanced;
|
690 |
} |
691 |
/**
|
692 |
* This method initializes pAdvancedNorth
|
693 |
*
|
694 |
* @return javax.swing.JPanel
|
695 |
*/
|
696 |
private JPanel getPAdvancedNorth() { |
697 |
if (pAdvancedNorth == null) { |
698 |
pAdvancedNorth = new JPanel(); |
699 |
pAdvancedNorth.setPreferredSize(new java.awt.Dimension(873,100)); |
700 |
pAdvancedNorth.setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this,"expresions_from_file"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
701 |
pAdvancedNorth.add(getJTextField(), null);
|
702 |
pAdvancedNorth.add(getBFile(), null);
|
703 |
pAdvancedNorth.add(getBEval(), null);
|
704 |
} |
705 |
return pAdvancedNorth;
|
706 |
} |
707 |
/**
|
708 |
* This method initializes jTextField
|
709 |
*
|
710 |
* @return javax.swing.JTextField
|
711 |
*/
|
712 |
private JTextField getJTextField() { |
713 |
if (jTextField == null) { |
714 |
jTextField = new JTextField(); |
715 |
jTextField.setPreferredSize(new java.awt.Dimension(250,20)); |
716 |
} |
717 |
return jTextField;
|
718 |
} |
719 |
/**
|
720 |
* This method initializes bFile
|
721 |
*
|
722 |
* @return javax.swing.JButton
|
723 |
*/
|
724 |
private JButton getBFile() { |
725 |
if (bFile == null) { |
726 |
bFile = new JButton(); |
727 |
bFile.setText(PluginServices.getText(this,"explorer")); |
728 |
bFile.addActionListener(new java.awt.event.ActionListener() {
|
729 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
730 |
JFileChooser jfc = new JFileChooser(); |
731 |
jfc.addChoosableFileFilter(new GenericFileFilter("bs", |
732 |
PluginServices.getText(this, "expresions"))); |
733 |
|
734 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
735 |
File fileExpresion = jfc.getSelectedFile();
|
736 |
getJTextField().setText(fileExpresion.getAbsolutePath()); |
737 |
|
738 |
} |
739 |
} |
740 |
}); |
741 |
} |
742 |
return bFile;
|
743 |
} |
744 |
private String readFile(File aFile) throws IOException { |
745 |
StringBuffer fileContents = new StringBuffer(); |
746 |
FileReader fileReader = new FileReader(aFile); |
747 |
int c;
|
748 |
while ((c = fileReader.read()) > -1) { |
749 |
fileContents.append((char)c);
|
750 |
} |
751 |
fileReader.close(); |
752 |
return fileContents.toString();
|
753 |
} |
754 |
/**
|
755 |
* This method initializes pAdvancedCenter
|
756 |
*
|
757 |
* @return javax.swing.JPanel
|
758 |
*/
|
759 |
private JPanel getPAdvancedCenter() { |
760 |
if (pAdvancedCenter == null) { |
761 |
lblLeng = new JLabel(); |
762 |
lblLeng.setText("");
|
763 |
pAdvancedCenter = new JPanel(); |
764 |
pAdvancedCenter.add(lblLeng, null);
|
765 |
} |
766 |
return pAdvancedCenter;
|
767 |
} |
768 |
|
769 |
/**
|
770 |
* This method initializes bEval
|
771 |
*
|
772 |
* @return javax.swing.JButton
|
773 |
*/
|
774 |
private JButton getBEval() { |
775 |
if (bEval == null) { |
776 |
bEval = new JButton(); |
777 |
bEval.setText(PluginServices.getText(this,"evaluate")); |
778 |
bEval.addActionListener(new java.awt.event.ActionListener() {
|
779 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
780 |
File file=new File(getJTextField().getText()); |
781 |
if (!file.exists()) {
|
782 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"incorrect_file")); |
783 |
return;
|
784 |
} |
785 |
try {
|
786 |
interpreter.eval(ExpresionFieldExtension.BEANSHELL,null,-1,-1,readFile(file)); |
787 |
} catch (IOException e1) { |
788 |
e1.printStackTrace(); |
789 |
} catch (BSFException e1) {
|
790 |
e1.printStackTrace(); |
791 |
} |
792 |
} |
793 |
}); |
794 |
} |
795 |
return bEval;
|
796 |
} |
797 |
} // @jve:decl-index=0:visual-constraint="10,10"
|