Revision 1383 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/component/DefaultEvaluatorPanel.java
DefaultEvaluatorPanel.java | ||
---|---|---|
72 | 72 |
|
73 | 73 |
|
74 | 74 |
/** |
75 |
*
|
|
75 |
* |
|
76 | 76 |
* @author jldominguez |
77 | 77 |
* |
78 | 78 |
*/ |
... | ... | |
81 | 81 |
|
82 | 82 |
private DynClass dynclass = null; |
83 | 83 |
private EvaluatorWithDescriptions eval_wdesc = null; |
84 |
|
|
84 |
|
|
85 | 85 |
private JTextArea expressionArea = null; |
86 | 86 |
private JList fieldList = null; |
87 | 87 |
private JList opfuList = null; |
88 | 88 |
private JPanel categRadioPanel = null; |
89 |
|
|
89 |
|
|
90 | 90 |
private JTextArea fieldExplainLabel = null; |
91 | 91 |
private JTextArea opfuDescLabel = null; |
92 |
|
|
92 |
|
|
93 | 93 |
private JRadioButton num_CategRB = null; |
94 | 94 |
private JRadioButton str_CategRB = null; |
95 | 95 |
private JRadioButton dat_CategRB = null; |
96 | 96 |
private JRadioButton geo_CategRB = null; |
97 | 97 |
private JRadioButton boo_CategRB = null; |
98 | 98 |
private JRadioButton all_CategRB = null; |
99 |
|
|
99 |
|
|
100 | 100 |
private JPanel opfuDescPanel = null; |
101 | 101 |
private JScrollPane opfuDescScroll = null; |
102 | 102 |
private JPanel opfuPanel = null; |
103 | 103 |
private JPanel fieldsPanel = null; |
104 |
|
|
104 |
|
|
105 | 105 |
private JPanel topPanel = null; |
106 | 106 |
private JPanel expressionPanel = null; |
107 |
|
|
107 |
|
|
108 | 108 |
private JButton clearButton = null; |
109 | 109 |
private JButton validateButton = null; |
110 |
|
|
110 |
|
|
111 | 111 |
private static I18nManager im = ToolsLocator.getI18nManager(); |
112 |
|
|
112 |
|
|
113 | 113 |
public DefaultEvaluatorPanel( |
114 | 114 |
DynClass dcla, EvaluatorWithDescriptions evaluator) { |
115 | 115 |
initialize(dcla, evaluator); |
... | ... | |
118 | 118 |
public String getExpression() { |
119 | 119 |
return getExpressionArea().getText(); |
120 | 120 |
} |
121 |
|
|
121 |
|
|
122 | 122 |
public void initialize(DynClass dcla, EvaluatorWithDescriptions evaluator) { |
123 | 123 |
dynclass = dcla; |
124 | 124 |
eval_wdesc = evaluator; |
125 | 125 |
initComponents(); |
126 | 126 |
} |
127 |
|
|
127 |
|
|
128 | 128 |
/** |
129 |
*
|
|
129 |
* |
|
130 | 130 |
*/ |
131 | 131 |
private void initComponents() { |
132 |
|
|
132 |
|
|
133 | 133 |
this.setLayout(new GridBagLayout()); |
134 | 134 |
GridBagConstraints gbc = new GridBagConstraints(); |
135 | 135 |
gbc.fill = GridBagConstraints.BOTH; |
... | ... | |
145 | 145 |
gbc.gridy = 2; |
146 | 146 |
gbc.insets = new Insets(5, 0, 0, 0); |
147 | 147 |
this.add(getExpressionPanel(), gbc); |
148 |
|
|
148 |
|
|
149 | 149 |
} |
150 | 150 |
|
151 |
|
|
151 |
|
|
152 | 152 |
private JTextArea getExpressionArea() { |
153 | 153 |
if (expressionArea == null) { |
154 | 154 |
expressionArea = new JTextArea(); |
... | ... | |
160 | 160 |
} |
161 | 161 |
return expressionArea; |
162 | 162 |
} |
163 |
|
|
163 |
|
|
164 | 164 |
private JPanel getExpressionPanel() { |
165 |
|
|
165 |
|
|
166 | 166 |
if (expressionPanel == null) { |
167 | 167 |
expressionPanel = new JPanel(); |
168 | 168 |
expressionPanel.setLayout(new BorderLayout()); |
169 | 169 |
expressionPanel.setBorder(BorderFactory.createTitledBorder( |
170 | 170 |
im.getTranslation("_User_expression"))); |
171 |
|
|
171 |
|
|
172 | 172 |
JScrollPane scroll = new JScrollPane(getExpressionArea()); |
173 | 173 |
scroll.setHorizontalScrollBarPolicy( |
174 | 174 |
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
175 | 175 |
scroll.setVerticalScrollBarPolicy( |
176 | 176 |
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); |
177 | 177 |
expressionPanel.add(scroll, BorderLayout.CENTER); |
178 |
|
|
178 |
|
|
179 | 179 |
JPanel buttonsp = new JPanel(); |
180 | 180 |
buttonsp.setLayout(new GridLayout(1, 1)); |
181 | 181 |
// ======================== |
... | ... | |
190 | 190 |
expressionPanel.add(buttonsp, BorderLayout.EAST); |
191 | 191 |
} |
192 | 192 |
return expressionPanel; |
193 |
|
|
193 |
|
|
194 | 194 |
} |
195 | 195 |
|
196 |
|
|
196 |
|
|
197 | 197 |
/** |
198 | 198 |
* @return |
199 | 199 |
*/ |
200 | 200 |
private Component getClearButton() { |
201 | 201 |
if (clearButton == null) { |
202 |
clearButton = new JButton(im.getTranslation("_Clear"));
|
|
202 |
clearButton = new JButton(im.getTranslation("clear_expression"));
|
|
203 | 203 |
clearButton.addActionListener(this); |
204 | 204 |
} |
205 | 205 |
return clearButton; |
... | ... | |
220 | 220 |
if (fieldList == null) { |
221 | 221 |
fieldList = new JList(); |
222 | 222 |
if (dynclass != null) { |
223 |
|
|
223 |
|
|
224 | 224 |
fieldList.addListSelectionListener(this); |
225 | 225 |
DynField[] ff = dynclass.getDynFields(); |
226 | 226 |
DefaultListModel resultList = new DefaultListModel(); |
... | ... | |
235 | 235 |
return fieldList; |
236 | 236 |
} |
237 | 237 |
|
238 |
|
|
238 |
|
|
239 | 239 |
private JList getOpfuList() { |
240 | 240 |
if (opfuList == null) { |
241 | 241 |
opfuList = new JList(); |
... | ... | |
249 | 249 |
|
250 | 250 |
|
251 | 251 |
private void reloadOpfuList(JList list) { |
252 |
|
|
252 |
|
|
253 | 253 |
DefaultListModel dlm = new DefaultListModel(); |
254 | 254 |
if (this.eval_wdesc != null) { |
255 | 255 |
Description[] descs = getCurrentDescriptions(eval_wdesc); |
... | ... | |
263 | 263 |
|
264 | 264 |
private Description[] getCurrentDescriptions( |
265 | 265 |
EvaluatorWithDescriptions eval) { |
266 |
|
|
266 |
|
|
267 | 267 |
int goodbits = 0; |
268 | 268 |
if (getAllCategRB().isSelected()) { |
269 | 269 |
goodbits = |
... | ... | |
284 | 284 |
if (getBooCategRB().isSelected()) { |
285 | 285 |
goodbits = EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN; |
286 | 286 |
} else { |
287 |
|
|
287 |
|
|
288 | 288 |
} |
289 | 289 |
} |
290 | 290 |
} |
291 | 291 |
} |
292 | 292 |
} |
293 | 293 |
} |
294 |
|
|
294 |
|
|
295 | 295 |
ArrayList list = new ArrayList(); |
296 | 296 |
Description[] dd = eval.getAvailableOperators(); |
297 | 297 |
int andop = 0; |
... | ... | |
308 | 308 |
list.add(dd[i]); |
309 | 309 |
} |
310 | 310 |
} |
311 |
|
|
311 |
|
|
312 | 312 |
return (Description[]) list.toArray(new Description[0]); |
313 | 313 |
} |
314 | 314 |
|
... | ... | |
357 | 357 |
return geo_CategRB; |
358 | 358 |
} |
359 | 359 |
|
360 |
|
|
360 |
|
|
361 | 361 |
private JPanel getCategRadioPanel() { |
362 | 362 |
if (categRadioPanel == null) { |
363 | 363 |
categRadioPanel = new JPanel(); |
... | ... | |
394 | 394 |
return categRadioPanel; |
395 | 395 |
} |
396 | 396 |
|
397 |
|
|
397 |
|
|
398 | 398 |
/** |
399 | 399 |
* @return |
400 | 400 |
*/ |
... | ... | |
421 | 421 |
} |
422 | 422 |
return opfuDescLabel; |
423 | 423 |
} |
424 |
|
|
424 |
|
|
425 | 425 |
private JPanel getOpfuListCategPanel() { |
426 |
|
|
426 |
|
|
427 | 427 |
if (opfuDescPanel == null) { |
428 | 428 |
opfuDescPanel = new JPanel(); |
429 | 429 |
opfuDescPanel.setLayout(new GridBagLayout()); |
430 |
|
|
430 |
|
|
431 | 431 |
GridBagConstraints gbc = new GridBagConstraints(); |
432 | 432 |
gbc.fill = GridBagConstraints.BOTH; |
433 | 433 |
gbc.anchor = GridBagConstraints.NORTHWEST; |
... | ... | |
435 | 435 |
gbc.weighty = 1; |
436 | 436 |
gbc.gridx = 0; |
437 | 437 |
gbc.gridy = 0; |
438 |
|
|
438 |
|
|
439 | 439 |
JScrollPane scroll = new JScrollPane(getOpfuList()); |
440 | 440 |
scroll.setHorizontalScrollBarPolicy( |
441 | 441 |
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
... | ... | |
443 | 443 |
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); |
444 | 444 |
// scroll.setMinimumSize(new Dimension(100, 100)); |
445 | 445 |
opfuDescPanel.add(scroll, gbc); |
446 |
|
|
446 |
|
|
447 | 447 |
gbc.weightx = 0.5; |
448 | 448 |
gbc.weighty = 1; |
449 | 449 |
gbc.gridx = 1; |
... | ... | |
452 | 452 |
} |
453 | 453 |
return opfuDescPanel; |
454 | 454 |
} |
455 |
|
|
455 |
|
|
456 | 456 |
private JPanel getOpfuPanel() { |
457 | 457 |
if (opfuPanel == null) { |
458 | 458 |
opfuPanel = new JPanel(); |
459 | 459 |
opfuPanel.setLayout(new GridBagLayout()); |
460 |
|
|
460 |
|
|
461 | 461 |
GridBagConstraints gbc = new GridBagConstraints(); |
462 | 462 |
gbc.anchor = GridBagConstraints.NORTHWEST; |
463 | 463 |
gbc.fill = GridBagConstraints.BOTH; |
... | ... | |
466 | 466 |
gbc.gridheight = 2; |
467 | 467 |
gbc.weightx = 1; |
468 | 468 |
gbc.weighty = 0.5; |
469 |
|
|
469 |
|
|
470 | 470 |
opfuPanel.add(getOpfuListCategPanel(), gbc); |
471 |
|
|
471 |
|
|
472 | 472 |
gbc.gridx = 0; |
473 | 473 |
gbc.gridy = 2; |
474 | 474 |
gbc.weightx = 1; |
475 | 475 |
gbc.weighty = 0.5; |
476 | 476 |
gbc.gridheight = 1; |
477 | 477 |
gbc.insets = new Insets(5, 0, 0, 0); |
478 |
|
|
478 |
|
|
479 | 479 |
opfuPanel.add( |
480 | 480 |
getOpfuDescScroll(opfuPanel.getBackground()), gbc); |
481 | 481 |
// ================== |
... | ... | |
484 | 484 |
// ================== |
485 | 485 |
ActionEvent aev = new ActionEvent(getAllCategRB(), 0, ""); |
486 | 486 |
this.actionPerformed(aev); |
487 |
|
|
487 |
|
|
488 | 488 |
} |
489 | 489 |
return opfuPanel; |
490 | 490 |
} |
491 |
|
|
491 |
|
|
492 | 492 |
private JScrollPane getOpfuDescScroll(Color bg) { |
493 |
|
|
493 |
|
|
494 | 494 |
if (opfuDescScroll == null) { |
495 | 495 |
opfuDescScroll = new JScrollPane(getOpfuDescLabel(bg)); |
496 | 496 |
opfuDescScroll.setHorizontalScrollBarPolicy( |
... | ... | |
498 | 498 |
opfuDescScroll.setVerticalScrollBarPolicy( |
499 | 499 |
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); |
500 | 500 |
opfuDescScroll.setBorder(new EmptyBorder(0, 0, 0, 0)); |
501 |
|
|
501 |
|
|
502 | 502 |
} |
503 | 503 |
return opfuDescScroll; |
504 | 504 |
} |
505 |
|
|
505 |
|
|
506 | 506 |
private JTextArea getFieldExplainLabel(Color bgcolor) { |
507 | 507 |
if (fieldExplainLabel == null) { |
508 | 508 |
fieldExplainLabel = new JTextArea(); |
... | ... | |
517 | 517 |
} |
518 | 518 |
return fieldExplainLabel; |
519 | 519 |
} |
520 |
|
|
520 |
|
|
521 | 521 |
private JPanel getFieldsPanel() { |
522 | 522 |
if (fieldsPanel == null) { |
523 | 523 |
fieldsPanel = new JPanel(); |
524 | 524 |
fieldsPanel.setLayout(new GridLayout(1, 2, 12, 0)); |
525 |
|
|
525 |
|
|
526 | 526 |
/* |
527 | 527 |
GridBagConstraints gbc = new GridBagConstraints(); |
528 | 528 |
gbc.fill = GridBagConstraints.BOTH; |
... | ... | |
532 | 532 |
gbc.weightx = 1; |
533 | 533 |
gbc.weighty = 1; |
534 | 534 |
*/ |
535 |
|
|
535 |
|
|
536 | 536 |
JScrollPane scroll = new JScrollPane(getFieldList()); |
537 | 537 |
scroll.setHorizontalScrollBarPolicy( |
538 | 538 |
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
... | ... | |
540 | 540 |
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); |
541 | 541 |
scroll.setMinimumSize(new Dimension(100, 100)); |
542 | 542 |
fieldsPanel.add(scroll); // , gbc); |
543 |
|
|
543 |
|
|
544 | 544 |
/* |
545 | 545 |
gbc.gridx = 1; |
546 | 546 |
gbc.insets = new Insets(0, 5, 0, 0); |
... | ... | |
548 | 548 |
fieldsPanel.add( |
549 | 549 |
getFieldExplainLabel(fieldsPanel.getBackground())); |
550 | 550 |
// , gbc); |
551 |
|
|
551 |
|
|
552 | 552 |
// ================ |
553 | 553 |
fieldsPanel.setBorder(BorderFactory.createTitledBorder( |
554 | 554 |
im.getTranslation("_Available_fields"))); |
555 | 555 |
} |
556 | 556 |
return fieldsPanel; |
557 | 557 |
} |
558 |
|
|
558 |
|
|
559 | 559 |
private JPanel getTopPanel() { |
560 | 560 |
if (topPanel == null) { |
561 | 561 |
topPanel = new JPanel(); |
... | ... | |
563 | 563 |
topPanel.add(getFieldsPanel()); |
564 | 564 |
topPanel.add(getOpfuPanel()); |
565 | 565 |
} |
566 |
|
|
566 |
|
|
567 | 567 |
return topPanel; |
568 | 568 |
} |
569 |
|
|
570 | 569 |
|
570 |
|
|
571 | 571 |
public void valueChanged(ListSelectionEvent e) { |
572 |
|
|
572 |
|
|
573 | 573 |
if (e.getSource() == this.getOpfuList()) { |
574 | 574 |
Object sel = this.getOpfuList().getSelectedValue(); |
575 | 575 |
if (sel instanceof DescriptionListItem) { |
... | ... | |
579 | 579 |
this.getOpfuDescLabel(null).setText(txt); |
580 | 580 |
this.getOpfuDescLabel(null).scrollRectToVisible( |
581 | 581 |
new Rectangle(0, 0, 10, 10)); |
582 |
|
|
582 |
|
|
583 | 583 |
// ============= |
584 | 584 |
this.getOpfuDescLabel(null).setCaretPosition(0); |
585 |
|
|
585 |
|
|
586 | 586 |
} else { |
587 | 587 |
this.getOpfuDescLabel(null).setText(" \n \n \n "); |
588 | 588 |
} |
... | ... | |
592 | 592 |
|
593 | 593 |
|
594 | 594 |
public void mousePressed(MouseEvent e) { |
595 |
|
|
595 |
|
|
596 | 596 |
Object src = e.getSource(); |
597 |
|
|
597 |
|
|
598 | 598 |
if (src == this.getFieldList() && e.getClickCount() == 2) { |
599 | 599 |
// paste field in text area |
600 | 600 |
Object sel = this.getFieldList().getSelectedValue(); |
... | ... | |
622 | 622 |
public void mouseEntered(MouseEvent e) { } |
623 | 623 |
public void mouseExited(MouseEvent e) { } |
624 | 624 |
public void mouseClicked(MouseEvent e) { } |
625 |
|
|
625 |
|
|
626 | 626 |
private class DescriptionListItem { |
627 |
|
|
627 |
|
|
628 | 628 |
private Description desc = null; |
629 |
|
|
629 |
|
|
630 | 630 |
public DescriptionListItem(Description d) { |
631 | 631 |
desc = d; |
632 | 632 |
} |
633 |
|
|
633 |
|
|
634 | 634 |
public String toString() { |
635 | 635 |
return desc.getName(); |
636 | 636 |
} |
637 |
|
|
637 |
|
|
638 | 638 |
public Description getDescription() { |
639 | 639 |
return desc; |
640 | 640 |
} |
641 |
|
|
641 |
|
|
642 | 642 |
} |
643 | 643 |
|
644 | 644 |
public void actionPerformed(ActionEvent e) { |
645 |
|
|
645 |
|
|
646 | 646 |
if (e.getSource() instanceof JRadioButton) { |
647 | 647 |
this.reloadOpfuList(this.getOpfuList()); |
648 | 648 |
} |
649 |
|
|
649 |
|
|
650 | 650 |
if (e.getSource() == this.getClearButton()) { |
651 | 651 |
this.getExpressionArea().setText(""); |
652 | 652 |
} |
Also available in: Unified diff