gvsig-tools / 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 @ 1274
History | View | Annotate | Download (22.6 KB)
1 | 806 | jldominguez | /* gvSIG. Desktop Geographic Information System.
|
---|---|---|---|
2 | *
|
||
3 | * Copyright ? 2007-2013 gvSIG Association
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
18 | * MA 02110-1301, USA.
|
||
19 | *
|
||
20 | * For any additional information, do not hesitate to contact us
|
||
21 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
22 | */
|
||
23 | package org.gvsig.tools.swing.impl.component; |
||
24 | |||
25 | import java.awt.BorderLayout; |
||
26 | import java.awt.Color; |
||
27 | import java.awt.Component; |
||
28 | import java.awt.Dimension; |
||
29 | import java.awt.Font; |
||
30 | import java.awt.GridBagConstraints; |
||
31 | import java.awt.GridBagLayout; |
||
32 | import java.awt.GridLayout; |
||
33 | import java.awt.Insets; |
||
34 | import java.awt.Rectangle; |
||
35 | import java.awt.event.ActionEvent; |
||
36 | import java.awt.event.ActionListener; |
||
37 | import java.awt.event.MouseEvent; |
||
38 | import java.awt.event.MouseListener; |
||
39 | import java.util.ArrayList; |
||
40 | |||
41 | import javax.swing.AbstractButton; |
||
42 | import javax.swing.BorderFactory; |
||
43 | import javax.swing.ButtonGroup; |
||
44 | import javax.swing.DefaultListModel; |
||
45 | import javax.swing.JButton; |
||
46 | import javax.swing.JLabel; |
||
47 | import javax.swing.JList; |
||
48 | import javax.swing.JPanel; |
||
49 | import javax.swing.JRadioButton; |
||
50 | import javax.swing.JScrollBar; |
||
51 | import javax.swing.JScrollPane; |
||
52 | import javax.swing.JTextArea; |
||
53 | import javax.swing.JTextPane; |
||
54 | import javax.swing.ListSelectionModel; |
||
55 | import javax.swing.ScrollPaneConstants; |
||
56 | import javax.swing.border.EmptyBorder; |
||
57 | import javax.swing.event.ListSelectionEvent; |
||
58 | import javax.swing.event.ListSelectionListener; |
||
59 | import javax.swing.text.SimpleAttributeSet; |
||
60 | import javax.swing.text.StyleConstants; |
||
61 | import javax.swing.text.StyledDocument; |
||
62 | |||
63 | import org.gvsig.tools.ToolsLocator; |
||
64 | import org.gvsig.tools.dynobject.DynClass; |
||
65 | import org.gvsig.tools.dynobject.DynField; |
||
66 | import org.gvsig.tools.dynobject.DynStruct; |
||
67 | import org.gvsig.tools.evaluator.EvaluatorWithDescriptions; |
||
68 | import org.gvsig.tools.evaluator.EvaluatorWithDescriptions.Description; |
||
69 | import org.gvsig.tools.i18n.I18nManager; |
||
70 | import org.gvsig.tools.swing.api.evaluator.EvaluatorPanel; |
||
71 | 1124 | jjdelcerro | //import org.gvsig.tools.swing.impl.dynobject.dynfield.DynFieldListItem;
|
72 | 806 | jldominguez | |
73 | |||
74 | /**
|
||
75 | *
|
||
76 | * @author jldominguez
|
||
77 | *
|
||
78 | */
|
||
79 | public class DefaultEvaluatorPanel extends EvaluatorPanel |
||
80 | implements ListSelectionListener, MouseListener, ActionListener { |
||
81 | |||
82 | private DynClass dynclass = null; |
||
83 | private EvaluatorWithDescriptions eval_wdesc = null; |
||
84 | |||
85 | private JTextArea expressionArea = null; |
||
86 | private JList fieldList = null; |
||
87 | private JList opfuList = null; |
||
88 | private JPanel categRadioPanel = null; |
||
89 | |||
90 | private JTextArea fieldExplainLabel = null; |
||
91 | private JTextArea opfuDescLabel = null; |
||
92 | |||
93 | private JRadioButton num_CategRB = null; |
||
94 | private JRadioButton str_CategRB = null; |
||
95 | private JRadioButton dat_CategRB = null; |
||
96 | private JRadioButton geo_CategRB = null; |
||
97 | private JRadioButton boo_CategRB = null; |
||
98 | private JRadioButton all_CategRB = null; |
||
99 | |||
100 | private JPanel opfuDescPanel = null; |
||
101 | private JScrollPane opfuDescScroll = null; |
||
102 | private JPanel opfuPanel = null; |
||
103 | private JPanel fieldsPanel = null; |
||
104 | |||
105 | private JPanel topPanel = null; |
||
106 | private JPanel expressionPanel = null; |
||
107 | |||
108 | private JButton clearButton = null; |
||
109 | private JButton validateButton = null; |
||
110 | |||
111 | private static I18nManager im = ToolsLocator.getI18nManager(); |
||
112 | |||
113 | public DefaultEvaluatorPanel(
|
||
114 | DynClass dcla, EvaluatorWithDescriptions evaluator) { |
||
115 | initialize(dcla, evaluator); |
||
116 | } |
||
117 | |||
118 | public String getExpression() { |
||
119 | return getExpressionArea().getText();
|
||
120 | } |
||
121 | |||
122 | public void initialize(DynClass dcla, EvaluatorWithDescriptions evaluator) { |
||
123 | dynclass = dcla; |
||
124 | eval_wdesc = evaluator; |
||
125 | initComponents(); |
||
126 | } |
||
127 | |||
128 | /**
|
||
129 | *
|
||
130 | */
|
||
131 | private void initComponents() { |
||
132 | |||
133 | this.setLayout(new GridBagLayout()); |
||
134 | GridBagConstraints gbc = new GridBagConstraints(); |
||
135 | gbc.fill = GridBagConstraints.BOTH;
|
||
136 | gbc.weightx = 1;
|
||
137 | gbc.weighty = 0.8;
|
||
138 | gbc.gridheight = 2;
|
||
139 | gbc.gridx = 0;
|
||
140 | gbc.gridy = 0;
|
||
141 | this.add(getTopPanel(), gbc);
|
||
142 | gbc.weightx = 1;
|
||
143 | gbc.weighty = 0.2;
|
||
144 | gbc.gridheight = 1;
|
||
145 | gbc.gridy = 2;
|
||
146 | gbc.insets = new Insets(5, 0, 0, 0); |
||
147 | this.add(getExpressionPanel(), gbc);
|
||
148 | |||
149 | } |
||
150 | |||
151 | |||
152 | private JTextArea getExpressionArea() { |
||
153 | if (expressionArea == null) { |
||
154 | expressionArea = new JTextArea(); |
||
155 | expressionArea.setLineWrap(true);
|
||
156 | expressionArea.setWrapStyleWord(true);
|
||
157 | if (eval_wdesc != null) { |
||
158 | expressionArea.setText(eval_wdesc.getSQL()); |
||
159 | } |
||
160 | } |
||
161 | return expressionArea;
|
||
162 | } |
||
163 | |||
164 | private JPanel getExpressionPanel() { |
||
165 | |||
166 | if (expressionPanel == null) { |
||
167 | expressionPanel = new JPanel(); |
||
168 | expressionPanel.setLayout(new BorderLayout()); |
||
169 | expressionPanel.setBorder(BorderFactory.createTitledBorder(
|
||
170 | im.getTranslation("_User_expression")));
|
||
171 | |||
172 | JScrollPane scroll = new JScrollPane(getExpressionArea()); |
||
173 | scroll.setHorizontalScrollBarPolicy( |
||
174 | ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||
175 | scroll.setVerticalScrollBarPolicy( |
||
176 | ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||
177 | expressionPanel.add(scroll, BorderLayout.CENTER);
|
||
178 | |||
179 | JPanel buttonsp = new JPanel(); |
||
180 | buttonsp.setLayout(new GridLayout(1, 1)); |
||
181 | // ========================
|
||
182 | // JPanel aux = new JPanel();
|
||
183 | // aux.add(getValidateButton());
|
||
184 | // buttonsp.add(aux);
|
||
185 | // =====================
|
||
186 | JPanel aux = new JPanel(); |
||
187 | aux.add(getClearButton()); |
||
188 | buttonsp.add(aux); |
||
189 | // ===========================
|
||
190 | expressionPanel.add(buttonsp, BorderLayout.EAST);
|
||
191 | } |
||
192 | return expressionPanel;
|
||
193 | |||
194 | } |
||
195 | |||
196 | |||
197 | /**
|
||
198 | * @return
|
||
199 | */
|
||
200 | private Component getClearButton() { |
||
201 | if (clearButton == null) { |
||
202 | clearButton = new JButton(im.getTranslation("_Clear")); |
||
203 | clearButton.addActionListener(this);
|
||
204 | } |
||
205 | return clearButton;
|
||
206 | } |
||
207 | |||
208 | /**
|
||
209 | * @return
|
||
210 | */
|
||
211 | private JButton getValidateButton() { |
||
212 | if (validateButton == null) { |
||
213 | validateButton = new JButton(im.getTranslation("_Validate")); |
||
214 | validateButton.addActionListener(this);
|
||
215 | } |
||
216 | return validateButton;
|
||
217 | } |
||
218 | |||
219 | private JList getFieldList() { |
||
220 | if (fieldList == null) { |
||
221 | fieldList = new JList(); |
||
222 | if (dynclass != null) { |
||
223 | |||
224 | fieldList.addListSelectionListener(this);
|
||
225 | DynField[] ff = dynclass.getDynFields();
|
||
226 | DefaultListModel resultList = new DefaultListModel(); |
||
227 | for (int i=0; i<ff.length; i++) { |
||
228 | 1124 | jjdelcerro | resultList.addElement(ff[i].getName()); |
229 | 806 | jldominguez | } |
230 | fieldList.setModel(resultList); |
||
231 | fieldList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||
232 | fieldList.addMouseListener(this);
|
||
233 | } |
||
234 | } |
||
235 | return fieldList;
|
||
236 | } |
||
237 | |||
238 | |||
239 | private JList getOpfuList() { |
||
240 | if (opfuList == null) { |
||
241 | opfuList = new JList(); |
||
242 | reloadOpfuList(opfuList); |
||
243 | opfuList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||
244 | opfuList.addListSelectionListener(this);
|
||
245 | opfuList.addMouseListener(this);
|
||
246 | } |
||
247 | return opfuList;
|
||
248 | } |
||
249 | |||
250 | |||
251 | private void reloadOpfuList(JList list) { |
||
252 | |||
253 | DefaultListModel dlm = new DefaultListModel(); |
||
254 | if (this.eval_wdesc != null) { |
||
255 | Description[] descs = getCurrentDescriptions(eval_wdesc);
|
||
256 | for (int i=0; i<descs.length; i++) { |
||
257 | dlm.addElement(new DescriptionListItem(descs[i]));
|
||
258 | } |
||
259 | } |
||
260 | list.setModel(dlm); |
||
261 | |||
262 | } |
||
263 | |||
264 | private Description[] getCurrentDescriptions( |
||
265 | EvaluatorWithDescriptions eval) { |
||
266 | |||
267 | int goodbits = 0; |
||
268 | if (getAllCategRB().isSelected()) {
|
||
269 | goodbits = |
||
270 | EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_ALL; |
||
271 | } else {
|
||
272 | if (getNumCategRB().isSelected()) {
|
||
273 | goodbits = EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER; |
||
274 | } else {
|
||
275 | if (getStrCategRB().isSelected()) {
|
||
276 | goodbits = EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING; |
||
277 | } else {
|
||
278 | if (getDatCategRB().isSelected()) {
|
||
279 | goodbits = EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME; |
||
280 | } else {
|
||
281 | if (getGeoCategRB().isSelected()) {
|
||
282 | goodbits = EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_GEOMETRY; |
||
283 | } else {
|
||
284 | if (getBooCategRB().isSelected()) {
|
||
285 | goodbits = EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN; |
||
286 | } else {
|
||
287 | |||
288 | } |
||
289 | } |
||
290 | } |
||
291 | } |
||
292 | } |
||
293 | } |
||
294 | |||
295 | ArrayList list = new ArrayList(); |
||
296 | Description[] dd = eval.getAvailableOperators();
|
||
297 | int andop = 0; |
||
298 | for (int i=0; i<dd.length; i++) { |
||
299 | andop = (dd[i].getDataTypeCategories() & goodbits); |
||
300 | if (goodbits == 0 /* all */ || andop != 0) { |
||
301 | list.add(dd[i]); |
||
302 | } |
||
303 | } |
||
304 | dd = eval.getAvailableFunctions(); |
||
305 | for (int i=0; i<dd.length; i++) { |
||
306 | andop = (dd[i].getDataTypeCategories() & goodbits); |
||
307 | if (goodbits == 0 /* all */ || andop != 0) { |
||
308 | list.add(dd[i]); |
||
309 | } |
||
310 | } |
||
311 | |||
312 | return (Description[]) list.toArray(new Description[0]); |
||
313 | } |
||
314 | |||
315 | private JRadioButton getAllCategRB() { |
||
316 | if (all_CategRB == null) { |
||
317 | this.all_CategRB = new JRadioButton(im.getTranslation("_All")); |
||
318 | this.all_CategRB.addActionListener(this); |
||
319 | } |
||
320 | return all_CategRB;
|
||
321 | } |
||
322 | |||
323 | |||
324 | private JRadioButton getNumCategRB() { |
||
325 | if (num_CategRB == null) { |
||
326 | this.num_CategRB = new JRadioButton(im.getTranslation("_Numeric")); |
||
327 | this.num_CategRB.addActionListener(this); |
||
328 | } |
||
329 | return num_CategRB;
|
||
330 | } |
||
331 | |||
332 | |||
333 | private JRadioButton getStrCategRB() { |
||
334 | if (str_CategRB == null) { |
||
335 | this.str_CategRB = new JRadioButton(im.getTranslation("_String")); |
||
336 | this.str_CategRB.addActionListener(this); |
||
337 | } |
||
338 | return str_CategRB;
|
||
339 | } |
||
340 | |||
341 | |||
342 | private JRadioButton getDatCategRB() { |
||
343 | if (dat_CategRB == null) { |
||
344 | this.dat_CategRB = new JRadioButton( |
||
345 | im.getTranslation("_Date_or_time"));
|
||
346 | this.dat_CategRB.addActionListener(this); |
||
347 | } |
||
348 | return dat_CategRB;
|
||
349 | } |
||
350 | |||
351 | |||
352 | private JRadioButton getGeoCategRB() { |
||
353 | if (geo_CategRB == null) { |
||
354 | this.geo_CategRB = new JRadioButton(im.getTranslation("_Geometry")); |
||
355 | this.geo_CategRB.addActionListener(this); |
||
356 | } |
||
357 | return geo_CategRB;
|
||
358 | } |
||
359 | |||
360 | |||
361 | private JPanel getCategRadioPanel() { |
||
362 | if (categRadioPanel == null) { |
||
363 | categRadioPanel = new JPanel(); |
||
364 | ButtonGroup bg = new ButtonGroup(); |
||
365 | bg.add(getAllCategRB()); |
||
366 | bg.add(getNumCategRB()); |
||
367 | bg.add(getStrCategRB()); |
||
368 | bg.add(getDatCategRB()); |
||
369 | bg.add(getBooCategRB()); |
||
370 | bg.add(getGeoCategRB()); |
||
371 | getAllCategRB().setSelected(true);
|
||
372 | categRadioPanel.setLayout(new GridBagLayout()); |
||
373 | GridBagConstraints gbc = new GridBagConstraints(); |
||
374 | gbc.anchor = GridBagConstraints.NORTHWEST;
|
||
375 | gbc.fill = GridBagConstraints.BOTH;
|
||
376 | gbc.weightx = 0.5;
|
||
377 | gbc.gridx = 0;
|
||
378 | gbc.gridy = 0;
|
||
379 | categRadioPanel.add(getAllCategRB(), gbc); |
||
380 | gbc.gridy = 1;
|
||
381 | categRadioPanel.add(getNumCategRB(), gbc); |
||
382 | gbc.gridy = 2;
|
||
383 | categRadioPanel.add(getStrCategRB(), gbc); |
||
384 | gbc.gridy = 3;
|
||
385 | categRadioPanel.add(getDatCategRB(), gbc); |
||
386 | gbc.gridy = 4;
|
||
387 | categRadioPanel.add(getBooCategRB(), gbc); |
||
388 | gbc.gridy = 5;
|
||
389 | categRadioPanel.add(getGeoCategRB(), gbc); |
||
390 | gbc.gridy = 6;
|
||
391 | gbc.weighty = 1;
|
||
392 | categRadioPanel.add(new JPanel(), gbc); |
||
393 | } |
||
394 | return categRadioPanel;
|
||
395 | } |
||
396 | |||
397 | |||
398 | /**
|
||
399 | * @return
|
||
400 | */
|
||
401 | private JRadioButton getBooCategRB() { |
||
402 | if (boo_CategRB == null) { |
||
403 | this.boo_CategRB = new JRadioButton(im.getTranslation("_Boolean")); |
||
404 | this.boo_CategRB.addActionListener(this); |
||
405 | } |
||
406 | return boo_CategRB;
|
||
407 | } |
||
408 | |||
409 | private JTextArea getOpfuDescLabel(Color bgcolor) { |
||
410 | if (opfuDescLabel == null) { |
||
411 | opfuDescLabel = new JTextArea(); |
||
412 | opfuDescLabel.setEditable(false);
|
||
413 | opfuDescLabel.setBorder(new EmptyBorder(2,2,2,2)); |
||
414 | if (bgcolor != null) { |
||
415 | opfuDescLabel.setBackground(bgcolor); |
||
416 | } |
||
417 | opfuDescLabel.setWrapStyleWord(true);
|
||
418 | opfuDescLabel.setLineWrap(true);
|
||
419 | opfuDescLabel.setFont(new JLabel().getFont()); |
||
420 | opfuDescLabel.setText(" \n \n \n ");
|
||
421 | } |
||
422 | return opfuDescLabel;
|
||
423 | } |
||
424 | |||
425 | private JPanel getOpfuListCategPanel() { |
||
426 | |||
427 | if (opfuDescPanel == null) { |
||
428 | opfuDescPanel = new JPanel(); |
||
429 | opfuDescPanel.setLayout(new GridBagLayout()); |
||
430 | |||
431 | GridBagConstraints gbc = new GridBagConstraints(); |
||
432 | gbc.fill = GridBagConstraints.BOTH;
|
||
433 | gbc.anchor = GridBagConstraints.NORTHWEST;
|
||
434 | gbc.weightx = 0.5;
|
||
435 | gbc.weighty = 1;
|
||
436 | gbc.gridx = 0;
|
||
437 | gbc.gridy = 0;
|
||
438 | |||
439 | JScrollPane scroll = new JScrollPane(getOpfuList()); |
||
440 | scroll.setHorizontalScrollBarPolicy( |
||
441 | ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||
442 | scroll.setVerticalScrollBarPolicy( |
||
443 | ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||
444 | // scroll.setMinimumSize(new Dimension(100, 100));
|
||
445 | opfuDescPanel.add(scroll, gbc); |
||
446 | |||
447 | gbc.weightx = 0.5;
|
||
448 | gbc.weighty = 1;
|
||
449 | gbc.gridx = 1;
|
||
450 | gbc.insets = new Insets(0, 5, 0, 0); |
||
451 | opfuDescPanel.add(getCategRadioPanel(), gbc); |
||
452 | } |
||
453 | return opfuDescPanel;
|
||
454 | } |
||
455 | |||
456 | private JPanel getOpfuPanel() { |
||
457 | if (opfuPanel == null) { |
||
458 | opfuPanel = new JPanel(); |
||
459 | opfuPanel.setLayout(new GridBagLayout()); |
||
460 | |||
461 | GridBagConstraints gbc = new GridBagConstraints(); |
||
462 | gbc.anchor = GridBagConstraints.NORTHWEST;
|
||
463 | gbc.fill = GridBagConstraints.BOTH;
|
||
464 | gbc.gridx = 0;
|
||
465 | gbc.gridy = 0;
|
||
466 | gbc.gridheight = 2;
|
||
467 | gbc.weightx = 1;
|
||
468 | gbc.weighty = 0.5;
|
||
469 | |||
470 | opfuPanel.add(getOpfuListCategPanel(), gbc); |
||
471 | |||
472 | gbc.gridx = 0;
|
||
473 | gbc.gridy = 2;
|
||
474 | gbc.weightx = 1;
|
||
475 | gbc.weighty = 0.5;
|
||
476 | gbc.gridheight = 1;
|
||
477 | gbc.insets = new Insets(5, 0, 0, 0); |
||
478 | |||
479 | opfuPanel.add( |
||
480 | getOpfuDescScroll(opfuPanel.getBackground()), gbc); |
||
481 | // ==================
|
||
482 | opfuPanel.setBorder(BorderFactory.createTitledBorder(
|
||
483 | im.getTranslation("_Available_functions_and_operators")));
|
||
484 | // ==================
|
||
485 | ActionEvent aev = new ActionEvent(getAllCategRB(), 0, ""); |
||
486 | this.actionPerformed(aev);
|
||
487 | |||
488 | } |
||
489 | return opfuPanel;
|
||
490 | } |
||
491 | |||
492 | private JScrollPane getOpfuDescScroll(Color bg) { |
||
493 | |||
494 | if (opfuDescScroll == null) { |
||
495 | opfuDescScroll = new JScrollPane(getOpfuDescLabel(bg)); |
||
496 | opfuDescScroll.setHorizontalScrollBarPolicy( |
||
497 | ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||
498 | opfuDescScroll.setVerticalScrollBarPolicy( |
||
499 | ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||
500 | opfuDescScroll.setBorder(new EmptyBorder(0, 0, 0, 0)); |
||
501 | |||
502 | } |
||
503 | return opfuDescScroll;
|
||
504 | } |
||
505 | |||
506 | private JTextArea getFieldExplainLabel(Color bgcolor) { |
||
507 | if (fieldExplainLabel == null) { |
||
508 | fieldExplainLabel = new JTextArea(); |
||
509 | fieldExplainLabel.setEditable(false);
|
||
510 | fieldExplainLabel.setBorder(new EmptyBorder(2,2,2,2)); |
||
511 | fieldExplainLabel.setBackground(bgcolor); |
||
512 | fieldExplainLabel.setLineWrap(true);
|
||
513 | fieldExplainLabel.setWrapStyleWord(true);
|
||
514 | fieldExplainLabel.setFont(new JLabel().getFont()); |
||
515 | fieldExplainLabel.setText( |
||
516 | im.getTranslation("_Double-click_to_paste_into_expression_box"));
|
||
517 | } |
||
518 | return fieldExplainLabel;
|
||
519 | } |
||
520 | |||
521 | private JPanel getFieldsPanel() { |
||
522 | if (fieldsPanel == null) { |
||
523 | fieldsPanel = new JPanel(); |
||
524 | fieldsPanel.setLayout(new GridLayout(1, 2, 12, 0)); |
||
525 | |||
526 | /*
|
||
527 | GridBagConstraints gbc = new GridBagConstraints();
|
||
528 | gbc.fill = GridBagConstraints.BOTH;
|
||
529 | gbc.anchor = GridBagConstraints.NORTHWEST;
|
||
530 | gbc.gridx = 0;
|
||
531 | gbc.gridy = 0;
|
||
532 | gbc.weightx = 1;
|
||
533 | gbc.weighty = 1;
|
||
534 | */
|
||
535 | |||
536 | JScrollPane scroll = new JScrollPane(getFieldList()); |
||
537 | scroll.setHorizontalScrollBarPolicy( |
||
538 | ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
||
539 | scroll.setVerticalScrollBarPolicy( |
||
540 | ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
||
541 | scroll.setMinimumSize(new Dimension(100, 100)); |
||
542 | fieldsPanel.add(scroll); // , gbc);
|
||
543 | |||
544 | /*
|
||
545 | gbc.gridx = 1;
|
||
546 | gbc.insets = new Insets(0, 5, 0, 0);
|
||
547 | */
|
||
548 | fieldsPanel.add( |
||
549 | getFieldExplainLabel(fieldsPanel.getBackground())); |
||
550 | // , gbc);
|
||
551 | |||
552 | // ================
|
||
553 | fieldsPanel.setBorder(BorderFactory.createTitledBorder(
|
||
554 | im.getTranslation("_Available_fields")));
|
||
555 | } |
||
556 | return fieldsPanel;
|
||
557 | } |
||
558 | |||
559 | private JPanel getTopPanel() { |
||
560 | if (topPanel == null) { |
||
561 | topPanel = new JPanel(); |
||
562 | topPanel.setLayout(new GridLayout(1, 2, 12, 0)); |
||
563 | topPanel.add(getFieldsPanel()); |
||
564 | topPanel.add(getOpfuPanel()); |
||
565 | } |
||
566 | |||
567 | return topPanel;
|
||
568 | } |
||
569 | |||
570 | |||
571 | public void valueChanged(ListSelectionEvent e) { |
||
572 | |||
573 | if (e.getSource() == this.getOpfuList()) { |
||
574 | Object sel = this.getOpfuList().getSelectedValue(); |
||
575 | if (sel instanceof DescriptionListItem) { |
||
576 | DescriptionListItem item = (DescriptionListItem) sel; |
||
577 | String txt = item.getDescription().getTemplate() + " : " |
||
578 | + item.getDescription().getDescription(); |
||
579 | this.getOpfuDescLabel(null).setText(txt); |
||
580 | this.getOpfuDescLabel(null).scrollRectToVisible( |
||
581 | new Rectangle(0, 0, 10, 10)); |
||
582 | |||
583 | // =============
|
||
584 | this.getOpfuDescLabel(null).setCaretPosition(0); |
||
585 | |||
586 | } else {
|
||
587 | this.getOpfuDescLabel(null).setText(" \n \n \n "); |
||
588 | } |
||
589 | return;
|
||
590 | } |
||
591 | } |
||
592 | |||
593 | |||
594 | public void mousePressed(MouseEvent e) { |
||
595 | |||
596 | Object src = e.getSource();
|
||
597 | |||
598 | if (src == this.getFieldList() && e.getClickCount() == 2) { |
||
599 | // paste field in text area
|
||
600 | Object sel = this.getFieldList().getSelectedValue(); |
||
601 | 1124 | jjdelcerro | if (sel instanceof String) { |
602 | 806 | jldominguez | int pos = this.getExpressionArea().getCaretPosition(); |
603 | 1124 | jjdelcerro | this.getExpressionArea().insert((String) sel, pos); |
604 | 806 | jldominguez | } |
605 | return;
|
||
606 | } |
||
607 | |||
608 | if (src == this.getOpfuList() && e.getClickCount() == 2) { |
||
609 | // paste function/operator in text area
|
||
610 | Object sel = this.getOpfuList().getSelectedValue(); |
||
611 | if (sel instanceof DescriptionListItem) { |
||
612 | DescriptionListItem item = (DescriptionListItem) sel; |
||
613 | int pos = this.getExpressionArea().getCaretPosition(); |
||
614 | this.getExpressionArea().insert(
|
||
615 | 1274 | jbadia | item.getDescription().getName(), pos); |
616 | 806 | jldominguez | } |
617 | return;
|
||
618 | } |
||
619 | |||
620 | } |
||
621 | public void mouseReleased(MouseEvent e) { } |
||
622 | public void mouseEntered(MouseEvent e) { } |
||
623 | public void mouseExited(MouseEvent e) { } |
||
624 | public void mouseClicked(MouseEvent e) { } |
||
625 | |||
626 | private class DescriptionListItem { |
||
627 | |||
628 | private Description desc = null; |
||
629 | |||
630 | public DescriptionListItem(Description d) {
|
||
631 | desc = d; |
||
632 | } |
||
633 | |||
634 | public String toString() { |
||
635 | return desc.getName();
|
||
636 | } |
||
637 | |||
638 | public Description getDescription() {
|
||
639 | return desc;
|
||
640 | } |
||
641 | |||
642 | } |
||
643 | |||
644 | public void actionPerformed(ActionEvent e) { |
||
645 | |||
646 | if (e.getSource() instanceof JRadioButton) { |
||
647 | this.reloadOpfuList(this.getOpfuList()); |
||
648 | } |
||
649 | |||
650 | if (e.getSource() == this.getClearButton()) { |
||
651 | this.getExpressionArea().setText(""); |
||
652 | } |
||
653 | |||
654 | if (e.getSource() == this.getValidateButton()) { |
||
655 | // this.getExpressionArea().setText("");
|
||
656 | } |
||
657 | |||
658 | } |
||
659 | |||
660 | |||
661 | } |