root / trunk / extensions / extExpressionField / src / com / iver / cit / gvsig / project / documents / table / gui / EvalExpressionDialog.java @ 36458
History | View | Annotate | Download (23.4 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.util.prefs.Preferences; |
15 |
|
16 |
import javax.swing.BoxLayout; |
17 |
import javax.swing.ButtonGroup; |
18 |
import javax.swing.JFileChooser; |
19 |
import javax.swing.JLabel; |
20 |
import javax.swing.JList; |
21 |
import javax.swing.JOptionPane; |
22 |
import javax.swing.JPanel; |
23 |
import javax.swing.JRadioButton; |
24 |
import javax.swing.JScrollPane; |
25 |
import javax.swing.JTabbedPane; |
26 |
import javax.swing.JTextArea; |
27 |
import javax.swing.JTextField; |
28 |
import javax.swing.UIManager; |
29 |
import javax.swing.event.CaretEvent; |
30 |
import javax.swing.event.CaretListener; |
31 |
|
32 |
import org.apache.bsf.BSFException; |
33 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
34 |
import org.gvsig.gui.beans.swing.JButton; |
35 |
|
36 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
37 |
import com.iver.andami.PluginServices; |
38 |
import com.iver.andami.messages.NotificationManager; |
39 |
import com.iver.andami.ui.mdiManager.IWindow; |
40 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
41 |
import com.iver.cit.gvsig.ExpressionFieldExtension; |
42 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
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.operators.Field; |
46 |
import com.iver.utiles.GenericFileFilter; |
47 |
|
48 |
|
49 |
/**
|
50 |
* This dialog allows the user create expressions to fill a field of the table
|
51 |
*
|
52 |
* @author Vicente Caballero Navarro
|
53 |
*/
|
54 |
public class EvalExpressionDialog extends JPanel implements IWindow { |
55 |
private JPanel pNorth = null; |
56 |
private JPanel pCentral = null; |
57 |
private JScrollPane jScrollPane = null; |
58 |
private JTextArea txtExp = null; |
59 |
private AcceptCancelPanel acceptCancel;
|
60 |
private JPanel pNorthEast = null; |
61 |
private JPanel pNorthCenter = null; |
62 |
private JPanel pNorthWest = null; |
63 |
private JScrollPane jScrollPane1 = null; |
64 |
private JList listFields = null; |
65 |
private JRadioButton rbNumber = null; |
66 |
private JRadioButton rbString = null; |
67 |
private JRadioButton rbDate = null; |
68 |
private JScrollPane jScrollPane2 = null; |
69 |
private JList listCommand = null; |
70 |
private JPanel pMessage; |
71 |
private EvalExpression evalExpression;
|
72 |
|
73 |
|
74 |
public EvalExpressionDialog(EvalExpression ee) {
|
75 |
this.evalExpression = ee;
|
76 |
initialize(); |
77 |
} |
78 |
|
79 |
private void initialize() { |
80 |
ButtonGroup bg = new ButtonGroup(); |
81 |
bg.add(getRbNumber()); |
82 |
bg.add(getRbString()); |
83 |
bg.add(getRbDate()); |
84 |
this.setLayout(new GridBagLayout()); |
85 |
this.setSize(549, 480); |
86 |
GridBagConstraints constr = new GridBagConstraints(); |
87 |
constr.gridwidth = GridBagConstraints.REMAINDER;
|
88 |
constr.gridheight = 1;
|
89 |
constr.fill = GridBagConstraints.BOTH;
|
90 |
constr.ipadx=5;
|
91 |
constr.ipady=5;
|
92 |
constr.weightx=1;
|
93 |
constr.weighty=0.3;
|
94 |
|
95 |
this.add(getPMessage(), constr);
|
96 |
constr.gridheight = 5;
|
97 |
constr.weighty=1;
|
98 |
this.add(getTabPrincipal(), constr);
|
99 |
GridBagConstraints constr2 = new GridBagConstraints(); |
100 |
constr2.gridwidth = GridBagConstraints.REMAINDER;
|
101 |
constr2.gridheight = 1;
|
102 |
constr2.fill = GridBagConstraints.HORIZONTAL;
|
103 |
constr2.anchor = GridBagConstraints.LAST_LINE_END;
|
104 |
constr2.weightx=1;
|
105 |
constr2.weighty=0;
|
106 |
|
107 |
this.add(getAcceptCancel(), constr2);
|
108 |
|
109 |
} |
110 |
|
111 |
private JPanel getPNorth() { |
112 |
if (pNorth == null) { |
113 |
pNorth = new JPanel(); |
114 |
pNorth.setLayout(new GridBagLayout()); |
115 |
GridBagConstraints contr = new GridBagConstraints(); |
116 |
contr.ipadx = 5;
|
117 |
contr.ipady = 5;
|
118 |
contr.fill = GridBagConstraints.BOTH;
|
119 |
contr.weightx =1;
|
120 |
contr.weighty =1;
|
121 |
pNorth.add(getPNorthWest(), contr); |
122 |
|
123 |
contr.fill = GridBagConstraints.VERTICAL;
|
124 |
contr.weightx =0;
|
125 |
contr.weighty =1;
|
126 |
|
127 |
pNorth.add(getPNorthCenter(), contr); |
128 |
|
129 |
contr.fill = GridBagConstraints.BOTH;
|
130 |
contr.weightx =0.5;
|
131 |
contr.weighty =1;
|
132 |
|
133 |
pNorth.add(getPNorthEast(), contr); |
134 |
|
135 |
} |
136 |
|
137 |
return pNorth;
|
138 |
} |
139 |
|
140 |
private JPanel getPCentral() { |
141 |
if (pCentral == null) { |
142 |
StringBuilder tit = new StringBuilder(); |
143 |
tit.append(PluginServices.getText(this,"expression")); |
144 |
tit.append(" ");
|
145 |
tit.append(PluginServices.getText(this, "column")); |
146 |
tit.append(" : ");
|
147 |
tit.append(evalExpression.getFieldDescriptorSelected().getFieldAlias()); |
148 |
pCentral = new JPanel(); |
149 |
pCentral.setLayout(new GridBagLayout()); |
150 |
pCentral.setBorder(javax.swing.BorderFactory.createTitledBorder( |
151 |
null, tit.toString(),
|
152 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
153 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
154 |
|
155 |
GridBagConstraints contr = new GridBagConstraints(); |
156 |
contr.gridwidth = GridBagConstraints.REMAINDER;
|
157 |
contr.gridheight = 1;
|
158 |
contr.fill = GridBagConstraints.BOTH;
|
159 |
contr.ipadx = 5;
|
160 |
contr.ipady = 5;
|
161 |
contr.weightx=1;
|
162 |
contr.weighty=1;
|
163 |
pCentral.add(getJScrollPane(), contr); |
164 |
|
165 |
GridBagConstraints contr1 = new GridBagConstraints(); |
166 |
contr1.gridwidth = 1;
|
167 |
contr1.gridheight = 1;
|
168 |
contr1.fill = GridBagConstraints.NONE;
|
169 |
contr1.ipadx = 5;
|
170 |
contr1.ipady = 5;
|
171 |
contr1.anchor = GridBagConstraints.CENTER;
|
172 |
pCentral.add(getBClear(), contr1); |
173 |
} |
174 |
|
175 |
return pCentral;
|
176 |
} |
177 |
|
178 |
private AcceptCancelPanel getAcceptCancel() {
|
179 |
if (this.acceptCancel == null) { |
180 |
this.acceptCancel = new AcceptCancelPanel( |
181 |
new java.awt.event.ActionListener() {
|
182 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
183 |
boolean isAccepted=true; |
184 |
Preferences prefs = Preferences.userRoot().node( |
185 |
"fieldExpressionOptions");
|
186 |
int limit;
|
187 |
limit = prefs.getInt("limit_rows_in_memory", -1); |
188 |
if (limit != -1) { |
189 |
int option = JOptionPane.showConfirmDialog( |
190 |
(Component) PluginServices.getMainFrame(),
|
191 |
PluginServices.getText( |
192 |
this,
|
193 |
"it_has_established_a_limit_of_rows_will_lose_the_possibility_to_undo_wants_to_continue"));
|
194 |
if (option != JOptionPane.OK_OPTION) { |
195 |
return;
|
196 |
} |
197 |
} |
198 |
try {
|
199 |
isAccepted=evalExpression.evalExpression(getTxtExp().getText()); |
200 |
if (evalExpression.getTable() != null) { |
201 |
evalExpression.getTable().refresh(); |
202 |
} |
203 |
} catch (BSFException e1) {
|
204 |
NotificationManager.addError(e1); |
205 |
} catch (ReadDriverException e1) {
|
206 |
NotificationManager.addError(e1); |
207 |
} |
208 |
if (isAccepted)
|
209 |
PluginServices.getMDIManager().closeWindow( |
210 |
EvalExpressionDialog.this); |
211 |
} |
212 |
}, new java.awt.event.ActionListener() {
|
213 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
214 |
PluginServices.getMDIManager().closeWindow( |
215 |
EvalExpressionDialog.this); |
216 |
} |
217 |
}); |
218 |
acceptCancel.setOkButtonEnabled(false);
|
219 |
} |
220 |
|
221 |
return this.acceptCancel; |
222 |
} |
223 |
|
224 |
private JPanel getPMessage() { |
225 |
if (pMessage == null) { |
226 |
|
227 |
pMessage = new JPanel(); |
228 |
pMessage.setLayout(new GridLayout()); |
229 |
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)); |
230 |
pMessage.add(getJScrollPane3(), null);
|
231 |
} |
232 |
return pMessage;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* Evaluate the fields.
|
237 |
*
|
238 |
* @param interpreter
|
239 |
*
|
240 |
* @throws EvalError
|
241 |
*/
|
242 |
int lastType=-1; |
243 |
private JButton bClear = null; |
244 |
private JTabbedPane tabPrincipal = null; |
245 |
private JPanel pPrincipal = null; |
246 |
private JPanel pAdvanced = null; |
247 |
private JPanel pAdvancedNorth = null; |
248 |
private JTextField jTextField = null; |
249 |
private JButton bFile = null; |
250 |
private JPanel pAdvancedCenter = null; |
251 |
private JLabel lblLeng = null; |
252 |
private JButton bEval = null; |
253 |
private JScrollPane jScrollPane3 = null; |
254 |
private JTextArea txtMessage2 = null; |
255 |
|
256 |
private void refreshOperators(int type) { |
257 |
if (lastType!=-1 && lastType==type) |
258 |
return;
|
259 |
lastType=type; |
260 |
ListOperatorsModel lom=(ListOperatorsModel)getListCommand().getModel(); |
261 |
lom.clear(); |
262 |
|
263 |
for (IOperator operator : evalExpression.getOperators()) {
|
264 |
operator.setType(type); |
265 |
if ((evalExpression.getLayer() != null) && operator instanceof GraphicOperator) { |
266 |
GraphicOperator igo = (GraphicOperator) operator; |
267 |
igo.setLayer(evalExpression.getLayer()); |
268 |
} |
269 |
if (operator.isEnable()) {
|
270 |
lom.addOperator(operator); |
271 |
} |
272 |
|
273 |
} |
274 |
|
275 |
getListCommand().repaint(); |
276 |
getJScrollPane2().repaint(); |
277 |
getJScrollPane2().doLayout(); |
278 |
this.doLayout();
|
279 |
|
280 |
} |
281 |
|
282 |
private JScrollPane getJScrollPane() { |
283 |
if (jScrollPane == null) { |
284 |
jScrollPane = new JScrollPane(); |
285 |
jScrollPane.setPreferredSize(new java.awt.Dimension(480, 80)); |
286 |
jScrollPane.setViewportView(getTxtExp()); |
287 |
} |
288 |
|
289 |
return jScrollPane;
|
290 |
} |
291 |
|
292 |
|
293 |
private JTextArea getTxtExp() { |
294 |
if (txtExp == null) { |
295 |
txtExp = new JTextArea(); |
296 |
txtExp.addCaretListener(new CaretListener(){ |
297 |
public void caretUpdate(CaretEvent e) { |
298 |
if (txtExp.getText().length()>0) |
299 |
getAcceptCancel().setOkButtonEnabled(true);
|
300 |
else
|
301 |
getAcceptCancel().setOkButtonEnabled(false);
|
302 |
} |
303 |
}); |
304 |
} |
305 |
|
306 |
return txtExp;
|
307 |
} |
308 |
|
309 |
public WindowInfo getWindowInfo() {
|
310 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG+WindowInfo.RESIZABLE);
|
311 |
wi.setTitle(PluginServices.getText(this, "calculate_expression")); |
312 |
|
313 |
|
314 |
return wi;
|
315 |
} |
316 |
|
317 |
private JPanel getPNorthEast() { |
318 |
if (pNorthEast == null) { |
319 |
pNorthEast = new JPanel(new GridLayout()); |
320 |
pNorthEast.setBorder(javax.swing.BorderFactory.createTitledBorder( |
321 |
null, PluginServices.getText(this,"commands"), |
322 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
323 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
324 |
pNorthEast.add(getJScrollPane2(), null);
|
325 |
} |
326 |
|
327 |
return pNorthEast;
|
328 |
} |
329 |
|
330 |
private JPanel getPNorthCenter() { |
331 |
if (pNorthCenter == null) { |
332 |
pNorthCenter = new JPanel(); |
333 |
pNorthCenter.setLayout(new BoxLayout(getPNorthCenter(), |
334 |
BoxLayout.Y_AXIS));
|
335 |
pNorthCenter.setBorder(javax.swing.BorderFactory.createTitledBorder( |
336 |
null, PluginServices.getText(this,"type"), |
337 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
338 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
339 |
pNorthCenter.add(getRbNumber(), null);
|
340 |
pNorthCenter.add(getRbString(), null);
|
341 |
pNorthCenter.add(getRbDate(), null);
|
342 |
} |
343 |
|
344 |
return pNorthCenter;
|
345 |
} |
346 |
|
347 |
private JPanel getPNorthWest() { |
348 |
if (pNorthWest == null) { |
349 |
pNorthWest = new JPanel(new GridLayout()); |
350 |
pNorthWest.setBorder(javax.swing.BorderFactory.createTitledBorder( |
351 |
null, PluginServices.getText(this,"field"), |
352 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
353 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
354 |
pNorthWest.add(getJScrollPane1(), null);
|
355 |
} |
356 |
|
357 |
return pNorthWest;
|
358 |
} |
359 |
|
360 |
private JScrollPane getJScrollPane1() { |
361 |
if (jScrollPane1 == null) { |
362 |
jScrollPane1 = new JScrollPane(); |
363 |
jScrollPane1.setPreferredSize(new java.awt.Dimension(175, 100)); |
364 |
jScrollPane1.setViewportView(getListFields()); |
365 |
} |
366 |
|
367 |
return jScrollPane1;
|
368 |
} |
369 |
|
370 |
private JList getListFields() { |
371 |
if (listFields == null) { |
372 |
listFields = new JList(); |
373 |
listFields.setModel(new ListOperatorsModel());
|
374 |
|
375 |
ListOperatorsModel lm = (ListOperatorsModel) listFields.getModel(); |
376 |
FieldDescription[] fds=evalExpression.getFieldDescriptors();
|
377 |
for (int i = 0; i < fds.length; i++) { |
378 |
Field field=new Field(); |
379 |
field.setFieldDescription(fds[i]); |
380 |
try {
|
381 |
field.eval(evalExpression.getInterpreter()); |
382 |
} catch (BSFException e) {
|
383 |
e.printStackTrace(); |
384 |
} |
385 |
lm.addOperator(field); |
386 |
} |
387 |
|
388 |
listFields.addMouseListener(new MouseListener() { |
389 |
public void mouseClicked(MouseEvent e) { |
390 |
IOperator operator=((IOperator) listFields.getSelectedValue()); |
391 |
if (operator!=null){ |
392 |
getTxtMessage2().setText(operator.getTooltip()); |
393 |
if (e.getClickCount() == 2) { |
394 |
String text = getTxtExp().getText();
|
395 |
int caretPos = getTxtExp().getCaretPosition();
|
396 |
int selStart = getTxtExp().getSelectionStart();
|
397 |
int selEnd = getTxtExp().getSelectionEnd();
|
398 |
|
399 |
// if (caretPos == text.length()){
|
400 |
// getTxtExp().setText(operator.addText(text));
|
401 |
// } else {
|
402 |
// getTxtExp().setText(operator.addText(text.substring(0, caretPos))+
|
403 |
// text.substring(caretPos));
|
404 |
// }
|
405 |
getTxtExp().setText( |
406 |
operator.addText(text.substring(0, selStart))+
|
407 |
text.substring(selEnd) |
408 |
); |
409 |
|
410 |
} |
411 |
} |
412 |
} |
413 |
|
414 |
public void mouseEntered(MouseEvent e) { |
415 |
} |
416 |
|
417 |
public void mouseExited(MouseEvent e) { |
418 |
} |
419 |
|
420 |
public void mousePressed(MouseEvent e) { |
421 |
} |
422 |
|
423 |
public void mouseReleased(MouseEvent e) { |
424 |
} |
425 |
}); |
426 |
} |
427 |
|
428 |
return listFields;
|
429 |
} |
430 |
|
431 |
private JRadioButton getRbNumber() { |
432 |
if (rbNumber == null) { |
433 |
rbNumber = new JRadioButton(); |
434 |
rbNumber.setText(PluginServices.getText(this,"numeric")); |
435 |
rbNumber.setSelected(true);
|
436 |
rbNumber.addChangeListener(new javax.swing.event.ChangeListener() {
|
437 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
438 |
if (rbNumber.isSelected())
|
439 |
refreshCommands(); |
440 |
} |
441 |
}); |
442 |
} |
443 |
|
444 |
return rbNumber;
|
445 |
} |
446 |
|
447 |
private JRadioButton getRbString() { |
448 |
if (rbString == null) { |
449 |
rbString = new JRadioButton(); |
450 |
rbString.setText(PluginServices.getText(this,"string")); |
451 |
rbString.addChangeListener(new javax.swing.event.ChangeListener() {
|
452 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
453 |
if (rbString.isSelected())
|
454 |
refreshCommands(); |
455 |
} |
456 |
}); |
457 |
} |
458 |
|
459 |
return rbString;
|
460 |
} |
461 |
|
462 |
private JRadioButton getRbDate() { |
463 |
if (rbDate == null) { |
464 |
rbDate = new JRadioButton(); |
465 |
rbDate.setText(PluginServices.getText(this,"date")); |
466 |
rbDate.addChangeListener(new javax.swing.event.ChangeListener() {
|
467 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
468 |
if (rbDate.isSelected())
|
469 |
refreshCommands(); |
470 |
} |
471 |
}); |
472 |
} |
473 |
|
474 |
return rbDate;
|
475 |
} |
476 |
|
477 |
private JScrollPane getJScrollPane2() { |
478 |
if (jScrollPane2 == null) { |
479 |
jScrollPane2 = new JScrollPane(); |
480 |
jScrollPane2.setPreferredSize(new java.awt.Dimension(175, 100)); |
481 |
jScrollPane2.setViewportView(getListCommand()); |
482 |
} |
483 |
|
484 |
return jScrollPane2;
|
485 |
} |
486 |
|
487 |
private void refreshCommands() { |
488 |
int type=IOperator.NUMBER;
|
489 |
if (getRbNumber().isSelected()) {
|
490 |
type=IOperator.NUMBER; |
491 |
} else if (getRbString().isSelected()) { |
492 |
type=IOperator.STRING; |
493 |
} else if (getRbDate().isSelected()) { |
494 |
type=IOperator.DATE; |
495 |
} |
496 |
refreshOperators(type); |
497 |
|
498 |
} |
499 |
|
500 |
private JList getListCommand() { |
501 |
if (listCommand == null) { |
502 |
listCommand = new JList(); |
503 |
listCommand.setModel(new ListOperatorsModel());
|
504 |
listCommand.addMouseListener(new MouseListener() { |
505 |
public void mouseClicked(MouseEvent e) { |
506 |
IOperator operator=((IOperator) listCommand.getSelectedValue()); |
507 |
if (operator!=null){ |
508 |
getTxtMessage2().setText(operator.getTooltip()); |
509 |
if (e.getClickCount() == 2) { |
510 |
if (listCommand.getSelectedValue()==null) |
511 |
return;
|
512 |
|
513 |
String text = getTxtExp().getText();
|
514 |
int caretPos = getTxtExp().getCaretPosition();
|
515 |
int selStart = getTxtExp().getSelectionStart();
|
516 |
int selEnd = getTxtExp().getSelectionEnd();
|
517 |
if (caretPos == text.length()){
|
518 |
getTxtExp().setText(operator.addText(text)); |
519 |
} else {
|
520 |
getTxtExp().setText( |
521 |
text.substring(0, selStart)+
|
522 |
operator.addText(text.substring(selStart, selEnd))+ |
523 |
text.substring(selEnd) |
524 |
); |
525 |
} |
526 |
|
527 |
|
528 |
} |
529 |
|
530 |
} |
531 |
} |
532 |
|
533 |
public void mouseEntered(MouseEvent e) { |
534 |
} |
535 |
|
536 |
public void mouseExited(MouseEvent e) { |
537 |
} |
538 |
|
539 |
public void mousePressed(MouseEvent e) { |
540 |
} |
541 |
|
542 |
public void mouseReleased(MouseEvent e) { |
543 |
} |
544 |
}); |
545 |
refreshOperators(IOperator.NUMBER); |
546 |
} |
547 |
|
548 |
return listCommand;
|
549 |
} |
550 |
|
551 |
private JButton getBClear() { |
552 |
if (bClear == null) { |
553 |
bClear = new JButton(); |
554 |
bClear.setText(PluginServices.getText(this,"clear_expression")); |
555 |
bClear.addActionListener(new java.awt.event.ActionListener() {
|
556 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
557 |
getTxtExp().setText("");
|
558 |
} |
559 |
}); |
560 |
} |
561 |
return bClear;
|
562 |
} |
563 |
|
564 |
private JTabbedPane getTabPrincipal() { |
565 |
if (tabPrincipal == null) { |
566 |
tabPrincipal = new JTabbedPane(); |
567 |
tabPrincipal.addTab(PluginServices.getText(this,"general"), null, getPPrincipal(), null); |
568 |
tabPrincipal.addTab(PluginServices.getText(this,"advanced"), null, getPAdvanced(), null); |
569 |
} |
570 |
return tabPrincipal;
|
571 |
} |
572 |
|
573 |
private JPanel getPPrincipal() { |
574 |
if (pPrincipal == null) { |
575 |
pPrincipal = new JPanel(); |
576 |
pPrincipal.setLayout(new BorderLayout()); |
577 |
pPrincipal.add(getPNorth(), java.awt.BorderLayout.NORTH); |
578 |
pPrincipal.add(getPCentral(), java.awt.BorderLayout.CENTER); |
579 |
|
580 |
} |
581 |
return pPrincipal;
|
582 |
} |
583 |
|
584 |
private JPanel getPAdvanced() { |
585 |
if (pAdvanced == null) { |
586 |
pAdvanced = new JPanel(); |
587 |
pAdvanced.setLayout(new BorderLayout()); |
588 |
pAdvanced.add(getPAdvancedNorth(), java.awt.BorderLayout.NORTH); |
589 |
pAdvanced.add(getPAdvancedCenter(), java.awt.BorderLayout.CENTER); |
590 |
} |
591 |
return pAdvanced;
|
592 |
} |
593 |
|
594 |
private JPanel getPAdvancedNorth() { |
595 |
if (pAdvancedNorth == null) { |
596 |
pAdvancedNorth = new JPanel(new GridBagLayout()); |
597 |
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)); |
598 |
GridBagConstraints contr = new GridBagConstraints(); |
599 |
contr.anchor = GridBagConstraints.FIRST_LINE_START;
|
600 |
contr.fill = GridBagConstraints.HORIZONTAL;
|
601 |
contr.weighty =0;
|
602 |
contr.weightx =1;
|
603 |
contr.insets = new Insets(3,3,3,3); |
604 |
contr.ipadx=5;
|
605 |
contr.ipady=5;
|
606 |
|
607 |
pAdvancedNorth.add(getJTextField(), contr); |
608 |
contr.fill = GridBagConstraints.NONE;
|
609 |
contr.weighty =0;
|
610 |
contr.weightx =0;
|
611 |
pAdvancedNorth.add(getBFile(), null);
|
612 |
pAdvancedNorth.add(getBEval(), null);
|
613 |
} |
614 |
return pAdvancedNorth;
|
615 |
} |
616 |
|
617 |
private JTextField getJTextField() { |
618 |
if (jTextField == null) { |
619 |
jTextField = new JTextField(); |
620 |
jTextField.setPreferredSize(new java.awt.Dimension(250,20)); |
621 |
} |
622 |
return jTextField;
|
623 |
} |
624 |
|
625 |
private JButton getBFile() { |
626 |
if (bFile == null) { |
627 |
bFile = new JButton(); |
628 |
bFile.setText(PluginServices.getText(this,"explorer")); |
629 |
bFile.addActionListener(new java.awt.event.ActionListener() {
|
630 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
631 |
JFileChooser jfc = new JFileChooser(); |
632 |
jfc.addChoosableFileFilter(new GenericFileFilter("py", |
633 |
PluginServices.getText(this, "python"))); |
634 |
|
635 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
636 |
File fileExpression = jfc.getSelectedFile();
|
637 |
getJTextField().setText(fileExpression.getAbsolutePath()); |
638 |
|
639 |
} |
640 |
} |
641 |
}); |
642 |
} |
643 |
return bFile;
|
644 |
} |
645 |
private String readFile(File aFile) throws IOException { |
646 |
StringBuffer fileContents = new StringBuffer(); |
647 |
FileReader fileReader = new FileReader(aFile); |
648 |
int c;
|
649 |
while ((c = fileReader.read()) > -1) { |
650 |
fileContents.append((char)c);
|
651 |
} |
652 |
fileReader.close(); |
653 |
return fileContents.toString();
|
654 |
} |
655 |
|
656 |
private JPanel getPAdvancedCenter() { |
657 |
if (pAdvancedCenter == null) { |
658 |
lblLeng = new JLabel(); |
659 |
lblLeng.setText("");
|
660 |
pAdvancedCenter = new JPanel(); |
661 |
pAdvancedCenter.add(lblLeng, null);
|
662 |
} |
663 |
return pAdvancedCenter;
|
664 |
} |
665 |
|
666 |
private JButton getBEval() { |
667 |
if (bEval == null) { |
668 |
bEval = new JButton(); |
669 |
bEval.setText(PluginServices.getText(this,"evaluate")); |
670 |
bEval.addActionListener(new java.awt.event.ActionListener() {
|
671 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
672 |
File file=new File(getJTextField().getText()); |
673 |
if (!file.exists()) {
|
674 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"incorrect_file")); |
675 |
return;
|
676 |
} |
677 |
try {
|
678 |
evalExpression.getInterpreter().exec( |
679 |
ExpressionFieldExtension.JYTHON, |
680 |
null, -1, -1, readFile(file)); |
681 |
} catch (IOException e1) { |
682 |
e1.printStackTrace(); |
683 |
} catch (BSFException e1) {
|
684 |
e1.printStackTrace(); |
685 |
} |
686 |
} |
687 |
}); |
688 |
} |
689 |
return bEval;
|
690 |
} |
691 |
|
692 |
private JScrollPane getJScrollPane3() { |
693 |
if (jScrollPane3 == null) { |
694 |
jScrollPane3 = new JScrollPane(); |
695 |
jScrollPane3.setPreferredSize(new java.awt.Dimension(530,80)); |
696 |
jScrollPane3.setViewportView(getTxtMessage2()); |
697 |
} |
698 |
return jScrollPane3;
|
699 |
} |
700 |
|
701 |
private JTextArea getTxtMessage2() { |
702 |
if (txtMessage2 == null) { |
703 |
txtMessage2 = new JTextArea(); |
704 |
txtMessage2.setText(PluginServices.getText(this,"eval_expression_will_be_carried_out_right_now_with_current_values_in_table")); |
705 |
txtMessage2.setEditable(false);
|
706 |
txtMessage2.setBackground(UIManager.getColor(this)); |
707 |
} |
708 |
return txtMessage2;
|
709 |
} |
710 |
public Object getWindowProfile() { |
711 |
return WindowInfo.DIALOG_PROFILE;
|
712 |
} |
713 |
} |