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