svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.swing / org.gvsig.expressionevaluator.swing.impl / src / main / java / org / gvsig / expressionevaluator / swing / impl / DefaultJExpressionBuilderView2.java @ 47426
History | View | Annotate | Download (15.8 KB)
1 |
package org.gvsig.expressionevaluator.swing.impl; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Color; |
5 |
import java.awt.GridBagConstraints; |
6 |
import java.awt.GridBagLayout; |
7 |
import java.awt.Insets; |
8 |
import javax.swing.ImageIcon; |
9 |
import javax.swing.JButton; |
10 |
import javax.swing.JLabel; |
11 |
import javax.swing.JList; |
12 |
import javax.swing.JPanel; |
13 |
import javax.swing.JScrollPane; |
14 |
import javax.swing.JSplitPane; |
15 |
import javax.swing.JTextArea; |
16 |
import javax.swing.JTextField; |
17 |
import javax.swing.JTree; |
18 |
import javax.swing.border.EmptyBorder; |
19 |
import javax.swing.text.JTextComponent; |
20 |
import org.gvsig.expressionevaluator.swing.JTextComponentProxy; |
21 |
|
22 |
public class DefaultJExpressionBuilderView2 extends JPanel { |
23 |
|
24 |
protected static class GridBagConstraintsBuilder { |
25 |
|
26 |
private GridBagConstraints gbc; |
27 |
|
28 |
public GridBagConstraintsBuilder() {
|
29 |
this.gbc = new GridBagConstraints(); |
30 |
this.gbc.insets = new Insets(1, 1, 1, 1); |
31 |
} |
32 |
|
33 |
public GridBagConstraintsBuilder clear() {
|
34 |
this.gbc = new GridBagConstraints(); |
35 |
this.gbc.insets = new Insets(1, 1, 1, 1); |
36 |
return this; |
37 |
} |
38 |
|
39 |
public GridBagConstraints get() { |
40 |
return this.gbc; |
41 |
} |
42 |
|
43 |
public GridBagConstraintsBuilder insets(int top, int left, int bottom, int right) { |
44 |
this.gbc.insets = new Insets(top, left, bottom, right); |
45 |
return this; |
46 |
} |
47 |
|
48 |
public GridBagConstraintsBuilder anchor(int anchor) { |
49 |
this.gbc.anchor = anchor;
|
50 |
return this; |
51 |
} |
52 |
|
53 |
public GridBagConstraintsBuilder fill(int fill) { |
54 |
this.gbc.fill = fill;
|
55 |
return this; |
56 |
} |
57 |
|
58 |
public GridBagConstraintsBuilder growx(float growx) { |
59 |
this.gbc.weightx = growx;
|
60 |
return this; |
61 |
} |
62 |
|
63 |
public GridBagConstraintsBuilder growy(float growy) { |
64 |
this.gbc.weighty = growy;
|
65 |
return this; |
66 |
} |
67 |
|
68 |
public GridBagConstraintsBuilder grow(float growx, float growy) { |
69 |
this.gbc.weightx = growx;
|
70 |
this.gbc.weighty = growy;
|
71 |
return this; |
72 |
} |
73 |
|
74 |
public GridBagConstraintsBuilder nogrow() {
|
75 |
this.gbc.weightx = 0; |
76 |
this.gbc.weighty = 0; |
77 |
return this; |
78 |
} |
79 |
|
80 |
public GridBagConstraintsBuilder xy(int x, int y) { |
81 |
this.gbc.gridx = x;
|
82 |
this.gbc.gridy = y;
|
83 |
return this; |
84 |
} |
85 |
|
86 |
public GridBagConstraintsBuilder colspan(int n) { |
87 |
this.gbc.gridwidth = n;
|
88 |
return this; |
89 |
} |
90 |
|
91 |
public GridBagConstraintsBuilder rowspan(int n) { |
92 |
this.gbc.gridheight = n;
|
93 |
return this; |
94 |
} |
95 |
|
96 |
public GridBagConstraintsBuilder span(int cols, int rows) { |
97 |
this.gbc.gridwidth = cols;
|
98 |
this.gbc.gridheight = rows;
|
99 |
return this; |
100 |
} |
101 |
|
102 |
public GridBagConstraintsBuilder nospan() {
|
103 |
this.gbc.gridwidth = 1; |
104 |
this.gbc.gridheight = 1; |
105 |
return this; |
106 |
} |
107 |
|
108 |
} |
109 |
|
110 |
JPanel pnlCfgActions = new JPanel(); |
111 |
// JTabbedPane tabExpressionBuilder = new JTabbedPane();
|
112 |
|
113 |
JList lstSimpleElement = new JList(); |
114 |
JScrollPane scrSimpleElement = new JScrollPane(); |
115 |
|
116 |
JTree treeElements = new JTree(); |
117 |
JScrollPane scrElements = new JScrollPane(); |
118 |
|
119 |
protected JTextComponentProxy txtExpression = new JTextComponentProxy() { |
120 |
JTextComponent text = new JTextArea(); |
121 |
@Override
|
122 |
public JTextComponent getJTextComponent() { |
123 |
return text;
|
124 |
} |
125 |
}; |
126 |
|
127 |
JScrollPane scrExpression = new JScrollPane(); |
128 |
|
129 |
JButton btnHistory = new JButton(); |
130 |
JButton btnBookmarks = new JButton(); |
131 |
JButton btnEq = new JButton(); |
132 |
JButton btnNeq = new JButton(); |
133 |
JButton btnAdd = new JButton(); |
134 |
JButton btnSubst = new JButton(); |
135 |
JButton btnMult = new JButton(); |
136 |
JButton btnDiv = new JButton(); |
137 |
JButton btnParentOpen = new JButton(); |
138 |
JButton btnParentClose = new JButton(); |
139 |
JLabel lblMsg = new JLabel(); |
140 |
JButton btnTip = new JButton(); |
141 |
JLabel lblColumn = new JLabel(); |
142 |
JTextField txtGroupElement = new JTextField(); |
143 |
JButton btnGroupElementInsert = new JButton(); |
144 |
JButton btnSimpleElementInsert = new JButton(); |
145 |
JButton btnSimpleElementSortDown = new JButton(); |
146 |
JButton btnSimpleElementSortUp = new JButton(); |
147 |
JLabel lblSimpleElementsMsg = new JLabel(); |
148 |
JButton btnSimpleElementTimeLimit = new JButton(); |
149 |
JTextField txtSimpleElementFilter = new JTextField(); |
150 |
JButton btnSimpleElementFilter = new JButton(); |
151 |
JPanel pnlDescription = new JPanel(); |
152 |
// JPanel pnlScriptEditorContainer = new JPanel();
|
153 |
// JComboBox cboPickerScripts = new JComboBox();
|
154 |
// JButton btnPickerRemove = new JButton();
|
155 |
// JButton btnPickerSelectScript = new JButton();
|
156 |
|
157 |
JSplitPane spnlExpression = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
158 |
JSplitPane spnlBottom = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
159 |
JSplitPane spnlItem = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
160 |
|
161 |
JPanel pnlTop;
|
162 |
JPanel pnlElement;
|
163 |
|
164 |
EmptyBorder emptyborder2x2 = new EmptyBorder(2, 2, 2, 2); |
165 |
/**
|
166 |
* Default constructor
|
167 |
*/
|
168 |
public DefaultJExpressionBuilderView2() {
|
169 |
initComponents(); |
170 |
} |
171 |
|
172 |
protected void initComponents0() { |
173 |
|
174 |
lstSimpleElement.setName("lstSimpleElement");
|
175 |
|
176 |
treeElements.setName("treeElements");
|
177 |
pnlDescription.setName("pnlDescription");
|
178 |
getExpressionComponent().setName("txtExpression");
|
179 |
if( this.getExpressionComponent() instanceof JTextArea ) { |
180 |
((JTextArea)getExpressionComponent()).setLineWrap(true); |
181 |
((JTextArea)getExpressionComponent()).setRows(2); |
182 |
} |
183 |
|
184 |
|
185 |
btnHistory.setActionCommand("+");
|
186 |
btnHistory.setIcon(loadImage("picker-history.png"));
|
187 |
btnHistory.setName("btnHistory");
|
188 |
btnHistory.setText("");
|
189 |
btnHistory.setBorder(emptyborder2x2); |
190 |
|
191 |
btnBookmarks.setActionCommand("+");
|
192 |
btnBookmarks.setIcon(loadImage("picker-bookmarks.png"));
|
193 |
btnBookmarks.setName("btnBookmarks");
|
194 |
btnBookmarks.setText("");
|
195 |
btnBookmarks.setBorder(emptyborder2x2); |
196 |
|
197 |
btnEq.setActionCommand("+");
|
198 |
btnEq.setName("btnEq");
|
199 |
btnEq.setText("=");
|
200 |
btnEq.setBorder(emptyborder2x2); |
201 |
|
202 |
btnNeq.setActionCommand("+");
|
203 |
btnNeq.setName("btnNeq");
|
204 |
btnNeq.setText("<>");
|
205 |
btnNeq.setBorder(emptyborder2x2); |
206 |
|
207 |
btnAdd.setActionCommand("+");
|
208 |
btnAdd.setName("btnAdd");
|
209 |
btnAdd.setText("+");
|
210 |
btnAdd.setBorder(emptyborder2x2); |
211 |
|
212 |
btnSubst.setActionCommand("+");
|
213 |
btnSubst.setName("btnSubst");
|
214 |
btnSubst.setText("-");
|
215 |
btnSubst.setBorder(emptyborder2x2); |
216 |
|
217 |
btnMult.setActionCommand("+");
|
218 |
btnMult.setName("btnMult");
|
219 |
btnMult.setText("*");
|
220 |
btnMult.setBorder(emptyborder2x2); |
221 |
|
222 |
btnDiv.setActionCommand("+");
|
223 |
btnDiv.setName("btnDiv");
|
224 |
btnDiv.setText("/");
|
225 |
btnDiv.setBorder(emptyborder2x2); |
226 |
|
227 |
btnParentOpen.setActionCommand("+");
|
228 |
btnParentOpen.setName("btnParentOpen");
|
229 |
btnParentOpen.setText("(");
|
230 |
btnParentOpen.setBorder(emptyborder2x2); |
231 |
|
232 |
btnParentClose.setActionCommand("+");
|
233 |
btnParentClose.setName("btnParentClose");
|
234 |
btnParentClose.setText(")");
|
235 |
btnParentClose.setBorder(emptyborder2x2); |
236 |
|
237 |
lblMsg.setName("lblMsg");
|
238 |
|
239 |
btnTip.setActionCommand("+");
|
240 |
btnTip.setIcon(loadImage("datos/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/resources/org/gvsig/expressionevaluator/swing/impl/expressionbuilder-tip.png"));
|
241 |
btnTip.setName("btnTip");
|
242 |
btnTip.setBorder(emptyborder2x2); |
243 |
|
244 |
lblColumn.setName("lblColumn");
|
245 |
lblColumn.setText("0");
|
246 |
|
247 |
txtGroupElement.setBackground(new Color(236, 233, 216)); |
248 |
txtGroupElement.setEditable(false);
|
249 |
txtGroupElement.setName("txtGroupElement");
|
250 |
|
251 |
btnGroupElementInsert.setActionCommand("+");
|
252 |
btnGroupElementInsert.setIcon(loadImage("common-add.png"));
|
253 |
btnGroupElementInsert.setName("btnGroupElementInsert");
|
254 |
btnGroupElementInsert.setBorder(emptyborder2x2); |
255 |
|
256 |
btnSimpleElementInsert.setActionCommand("+");
|
257 |
btnSimpleElementInsert.setIcon(loadImage("common-add.png"));
|
258 |
btnSimpleElementInsert.setName("btnSimpleElementInsert");
|
259 |
btnSimpleElementInsert.setBorder(emptyborder2x2); |
260 |
|
261 |
btnSimpleElementSortDown.setActionCommand("+");
|
262 |
btnSimpleElementSortDown.setIcon(loadImage("common-sortdown.png"));
|
263 |
btnSimpleElementSortDown.setName("btnSimpleElementSortDown");
|
264 |
btnSimpleElementSortDown.setBorder(emptyborder2x2); |
265 |
|
266 |
btnSimpleElementSortUp.setActionCommand("+");
|
267 |
btnSimpleElementSortUp.setIcon(loadImage("common-sortup.png"));
|
268 |
btnSimpleElementSortUp.setName("btnSimpleElementSortUp");
|
269 |
btnSimpleElementSortUp.setBorder(emptyborder2x2); |
270 |
|
271 |
lblSimpleElementsMsg.setName("lblSimpleElementsMsg");
|
272 |
|
273 |
btnSimpleElementTimeLimit.setActionCommand("+");
|
274 |
btnSimpleElementTimeLimit.setIcon(loadImage("datos/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/resources/org/gvsig/expressionevaluator/swing/impl/expressionbuilder-time-limit.png"));
|
275 |
btnSimpleElementTimeLimit.setName("btnSimpleElementTimeLimit");
|
276 |
btnSimpleElementTimeLimit.setBorder(emptyborder2x2); |
277 |
|
278 |
txtSimpleElementFilter.setName("txtSimpleElementFilter");
|
279 |
|
280 |
btnSimpleElementFilter.setActionCommand("+");
|
281 |
btnSimpleElementFilter.setIcon(loadImage("common-filter.png"));
|
282 |
btnSimpleElementFilter.setName("btnSimpleElementFilter");
|
283 |
btnSimpleElementFilter.setBorder(emptyborder2x2); |
284 |
} |
285 |
|
286 |
public JTextComponent getExpressionComponent() { |
287 |
return this.txtExpression.getJTextComponent(); |
288 |
} |
289 |
|
290 |
protected void initComponents1() { |
291 |
this.scrExpression = new JScrollPane(); |
292 |
this.scrExpression.setViewportView(getExpressionComponent());
|
293 |
this.scrExpression.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
294 |
this.scrExpression.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
295 |
|
296 |
this.scrElements = new JScrollPane(); |
297 |
this.scrElements.setViewportView(treeElements);
|
298 |
this.scrElements.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
299 |
this.scrElements.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
300 |
|
301 |
this.scrSimpleElement = new JScrollPane(); |
302 |
this.scrSimpleElement.setViewportView(lstSimpleElement);
|
303 |
this.scrSimpleElement.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); |
304 |
this.scrSimpleElement.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
305 |
|
306 |
this.spnlExpression.setTopComponent(this.getPanelTop()); |
307 |
this.spnlExpression.setBottomComponent(this.spnlBottom); |
308 |
this.spnlExpression.setBorder(emptyborder2x2);
|
309 |
this.spnlExpression.setOneTouchExpandable(true); |
310 |
|
311 |
this.spnlBottom.setLeftComponent(this.scrElements); |
312 |
this.spnlBottom.setRightComponent(this.spnlItem); |
313 |
this.spnlBottom.setBorder(emptyborder2x2);
|
314 |
this.spnlBottom.setOneTouchExpandable(true); |
315 |
|
316 |
this.spnlItem.setLeftComponent(this.getPanelElement()); |
317 |
this.spnlItem.setRightComponent(this.pnlDescription); |
318 |
this.spnlItem.setBorder(emptyborder2x2);
|
319 |
this.spnlItem.setOneTouchExpandable(true); |
320 |
|
321 |
this.setLayout(new BorderLayout()); |
322 |
this.add(this.spnlExpression, BorderLayout.CENTER); |
323 |
this.add(pnlCfgActions, BorderLayout.PAGE_START); |
324 |
} |
325 |
|
326 |
protected void initComponents() { |
327 |
this.initComponents0();
|
328 |
this.initComponents1();
|
329 |
} |
330 |
|
331 |
protected JPanel getPanelTop() { |
332 |
if (this.pnlTop == null) { |
333 |
GridBagConstraintsBuilder cs = new GridBagConstraintsBuilder();
|
334 |
cs.anchor(GridBagConstraints.CENTER);
|
335 |
cs.fill(GridBagConstraints.BOTH);
|
336 |
|
337 |
JPanel pnlRight = createPanelOperators();
|
338 |
JPanel pnlLeft = createPanelExpressionWithMessages();
|
339 |
|
340 |
JPanel panel = new JPanel(); |
341 |
panel.setLayout(new GridBagLayout()); |
342 |
panel.add(pnlLeft, cs.xy(0, 0).nospan().grow(1, 1).get()); |
343 |
panel.add(pnlRight, cs.xy(1, 0).nospan().nogrow().anchor(GridBagConstraints.NORTH).get()); |
344 |
|
345 |
this.pnlTop = panel;
|
346 |
} |
347 |
return this.pnlTop; |
348 |
} |
349 |
|
350 |
protected JPanel createPanelExpressionWithMessages() { |
351 |
GridBagConstraintsBuilder cs = new GridBagConstraintsBuilder();
|
352 |
cs.anchor(GridBagConstraints.CENTER);
|
353 |
cs.fill(GridBagConstraints.BOTH);
|
354 |
|
355 |
JPanel panel = new JPanel(); |
356 |
panel.setLayout(new GridBagLayout()); |
357 |
panel.add(this.scrExpression, cs.xy(0, 0).span(3, 1).grow(1, 1).get()); |
358 |
panel.add(this.lblMsg, cs.xy(0, 1).nospan().grow(1, 0).get()); |
359 |
panel.add(this.btnTip, cs.xy(1, 1).nospan().nogrow().get()); |
360 |
panel.add(this.lblColumn, cs.xy(2, 1).nospan().nogrow().get()); |
361 |
return panel;
|
362 |
} |
363 |
|
364 |
protected JPanel createPanelOperators() { |
365 |
GridBagConstraintsBuilder cs = new GridBagConstraintsBuilder();
|
366 |
cs.anchor(GridBagConstraints.CENTER);
|
367 |
cs.fill(GridBagConstraints.BOTH);
|
368 |
|
369 |
JPanel panel = new JPanel(); |
370 |
panel.setLayout(new GridBagLayout()); |
371 |
panel.add(this.btnHistory, cs.xy(0, 0).get()); |
372 |
panel.add(this.btnBookmarks, cs.xy(1, 0).get()); |
373 |
panel.add(this.btnEq, cs.xy(0, 1).get()); |
374 |
panel.add(this.btnNeq, cs.xy(1, 1).get()); |
375 |
panel.add(this.btnAdd, cs.xy(2, 1).get()); |
376 |
panel.add(this.btnSubst, cs.xy(3, 1).get()); |
377 |
panel.add(this.btnMult, cs.xy(0, 2).get()); |
378 |
panel.add(this.btnDiv, cs.xy(1, 2).get()); |
379 |
panel.add(this.btnParentOpen, cs.xy(2, 2).get()); |
380 |
panel.add(this.btnParentClose, cs.xy(3, 2).get()); |
381 |
panel.add(new JLabel(), cs.xy(0, 3).span(4,0).grow(1, 1).get()); |
382 |
return panel;
|
383 |
} |
384 |
|
385 |
protected JPanel getPanelElement() { |
386 |
if (this.pnlElement == null) { |
387 |
GridBagConstraintsBuilder cs = new GridBagConstraintsBuilder();
|
388 |
cs.anchor(GridBagConstraints.CENTER);
|
389 |
cs.fill(GridBagConstraints.BOTH);
|
390 |
|
391 |
JPanel panel = new JPanel(); |
392 |
panel.setLayout(new GridBagLayout()); |
393 |
panel.add(this.txtGroupElement, cs.xy(0, 0).span(4, 1).grow(1,0).get()); |
394 |
panel.add(this.btnGroupElementInsert, cs.xy(4, 0).nospan().nogrow().get()); |
395 |
panel.add(this.txtSimpleElementFilter, cs.xy(0, 1).span(4, 1).grow(1,0).get()); |
396 |
panel.add(this.btnSimpleElementFilter, cs.xy(4, 1).nospan().nogrow().get()); |
397 |
panel.add(this.scrSimpleElement, cs.xy(0, 2).span(5, 1).grow(1, 1).get()); |
398 |
panel.add(new JLabel(), cs.xy(0, 3).nospan().grow(1,0).get()); |
399 |
panel.add(this.btnSimpleElementTimeLimit, cs.xy(1, 3).nospan().nogrow().get()); |
400 |
panel.add(this.btnSimpleElementSortUp, cs.xy(2, 3).nospan().nogrow().get()); |
401 |
panel.add(this.btnSimpleElementSortDown, cs.xy(3, 3).nospan().nogrow().get()); |
402 |
panel.add(this.btnSimpleElementInsert, cs.xy(4, 3).nospan().nogrow().get()); |
403 |
|
404 |
this.pnlElement = panel;
|
405 |
} |
406 |
return this.pnlElement; |
407 |
} |
408 |
|
409 |
public ImageIcon loadImage(String imageName) { |
410 |
try {
|
411 |
ClassLoader classloader = getClass().getClassLoader();
|
412 |
java.net.URL url = classloader.getResource(imageName); |
413 |
if (url != null) { |
414 |
ImageIcon icon = new ImageIcon(url); |
415 |
return icon;
|
416 |
} |
417 |
} catch (Exception e) { |
418 |
e.printStackTrace(); |
419 |
} |
420 |
throw new IllegalArgumentException("Unable to load image: " + imageName); |
421 |
} |
422 |
} |