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 / DefaultJExpressionBuilderView.java @ 43939
History | View | Annotate | Download (14.9 KB)
1 |
package org.gvsig.expressionevaluator.swing.impl; |
---|---|
2 |
|
3 |
import com.jeta.open.i18n.I18NUtils; |
4 |
import com.jgoodies.forms.layout.CellConstraints; |
5 |
import com.jgoodies.forms.layout.FormLayout; |
6 |
import java.awt.BorderLayout; |
7 |
import java.awt.Color; |
8 |
import java.awt.ComponentOrientation; |
9 |
import java.awt.Container; |
10 |
import java.awt.Dimension; |
11 |
import javax.swing.Box; |
12 |
import javax.swing.ImageIcon; |
13 |
import javax.swing.JButton; |
14 |
import javax.swing.JEditorPane; |
15 |
import javax.swing.JFrame; |
16 |
import javax.swing.JList; |
17 |
import javax.swing.JPanel; |
18 |
import javax.swing.JScrollPane; |
19 |
import javax.swing.JTabbedPane; |
20 |
import javax.swing.JTextArea; |
21 |
import javax.swing.JTextField; |
22 |
import javax.swing.JTree; |
23 |
import javax.swing.border.EmptyBorder; |
24 |
|
25 |
|
26 |
public class DefaultJExpressionBuilderView extends JPanel |
27 |
{ |
28 |
JTabbedPane tabExpressionBuilder = new JTabbedPane(); |
29 |
JList lstSimpleElement = new JList(); |
30 |
JTextArea txtExpression = new JTextArea(); |
31 |
JButton btnEq = new JButton(); |
32 |
JButton btnAdd = new JButton(); |
33 |
JButton btnSubst = new JButton(); |
34 |
JButton btnMult = new JButton(); |
35 |
JButton btnDiv = new JButton(); |
36 |
JButton btnParentOpen = new JButton(); |
37 |
JButton btnParentClose = new JButton(); |
38 |
JButton btnNeq = new JButton(); |
39 |
JTree treeElements = new JTree(); |
40 |
JEditorPane txtDescription = new JEditorPane(); |
41 |
JTextField txtGroupElement = new JTextField(); |
42 |
JButton btnGroupElementInsert = new JButton(); |
43 |
JButton btnSimpleElementInsert = new JButton(); |
44 |
JButton btnSimpleElementSortUp = new JButton(); |
45 |
JButton btnSimpleElementSortDown = new JButton(); |
46 |
JTextField txtSimpleElementFilter = new JTextField(); |
47 |
JButton btnSimpleElementFilter = new JButton(); |
48 |
|
49 |
/**
|
50 |
* Default constructor
|
51 |
*/
|
52 |
public DefaultJExpressionBuilderView()
|
53 |
{ |
54 |
initializePanel(); |
55 |
} |
56 |
|
57 |
/**
|
58 |
* Adds fill components to empty cells in the first row and first column of the grid.
|
59 |
* This ensures that the grid spacing will be the same as shown in the designer.
|
60 |
* @param cols an array of column indices in the first row where fill components should be added.
|
61 |
* @param rows an array of row indices in the first column where fill components should be added.
|
62 |
*/
|
63 |
void addFillComponents( Container panel, int[] cols, int[] rows ) |
64 |
{ |
65 |
Dimension filler = new Dimension(10,10); |
66 |
|
67 |
boolean filled_cell_11 = false; |
68 |
CellConstraints cc = new CellConstraints();
|
69 |
if ( cols.length > 0 && rows.length > 0 ) |
70 |
{ |
71 |
if ( cols[0] == 1 && rows[0] == 1 ) |
72 |
{ |
73 |
/** add a rigid area */
|
74 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); |
75 |
filled_cell_11 = true;
|
76 |
} |
77 |
} |
78 |
|
79 |
for( int index = 0; index < cols.length; index++ ) |
80 |
{ |
81 |
if ( cols[index] == 1 && filled_cell_11 ) |
82 |
{ |
83 |
continue;
|
84 |
} |
85 |
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); |
86 |
} |
87 |
|
88 |
for( int index = 0; index < rows.length; index++ ) |
89 |
{ |
90 |
if ( rows[index] == 1 && filled_cell_11 ) |
91 |
{ |
92 |
continue;
|
93 |
} |
94 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); |
95 |
} |
96 |
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Helper method to load an image file from the CLASSPATH
|
101 |
* @param imageName the package and name of the file to load relative to the CLASSPATH
|
102 |
* @return an ImageIcon instance with the specified image file
|
103 |
* @throws IllegalArgumentException if the image resource cannot be loaded.
|
104 |
*/
|
105 |
public ImageIcon loadImage( String imageName ) |
106 |
{ |
107 |
try
|
108 |
{ |
109 |
ClassLoader classloader = getClass().getClassLoader();
|
110 |
java.net.URL url = classloader.getResource( imageName ); |
111 |
if ( url != null ) |
112 |
{ |
113 |
ImageIcon icon = new ImageIcon( url ); |
114 |
return icon;
|
115 |
} |
116 |
} |
117 |
catch( Exception e ) |
118 |
{ |
119 |
e.printStackTrace(); |
120 |
} |
121 |
throw new IllegalArgumentException( "Unable to load image: " + imageName ); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Method for recalculating the component orientation for
|
126 |
* right-to-left Locales.
|
127 |
* @param orientation the component orientation to be applied
|
128 |
*/
|
129 |
public void applyComponentOrientation( ComponentOrientation orientation ) |
130 |
{ |
131 |
// Not yet implemented...
|
132 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
133 |
super.applyComponentOrientation(orientation);
|
134 |
} |
135 |
|
136 |
public JPanel createPanel() |
137 |
{ |
138 |
JPanel jpanel1 = new JPanel(); |
139 |
FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:2DLU:NONE"); |
140 |
CellConstraints cc = new CellConstraints();
|
141 |
jpanel1.setLayout(formlayout1); |
142 |
|
143 |
tabExpressionBuilder.setName("tabExpressionBuilder");
|
144 |
tabExpressionBuilder.addTab("_Expression",null,createPanel1()); |
145 |
tabExpressionBuilder.addTab("_Scripts",null,createPanel7()); |
146 |
jpanel1.add(tabExpressionBuilder,cc.xy(2,2)); |
147 |
|
148 |
addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3 }); |
149 |
return jpanel1;
|
150 |
} |
151 |
|
152 |
public JPanel createPanel1() |
153 |
{ |
154 |
JPanel jpanel1 = new JPanel(); |
155 |
FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,FILL:DEFAULT:NONE,CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE"); |
156 |
CellConstraints cc = new CellConstraints();
|
157 |
jpanel1.setLayout(formlayout1); |
158 |
|
159 |
lstSimpleElement.setName("lstSimpleElement");
|
160 |
JScrollPane jscrollpane1 = new JScrollPane(); |
161 |
jscrollpane1.setViewportView(lstSimpleElement); |
162 |
jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
163 |
jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
164 |
jpanel1.add(jscrollpane1,cc.xy(4,8)); |
165 |
|
166 |
jpanel1.add(createPanel2(),cc.xywh(2,2,5,1)); |
167 |
treeElements.setName("treeElements");
|
168 |
JScrollPane jscrollpane2 = new JScrollPane(); |
169 |
jscrollpane2.setViewportView(treeElements); |
170 |
jscrollpane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
171 |
jscrollpane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
172 |
jpanel1.add(jscrollpane2,cc.xywh(2,4,1,6)); |
173 |
|
174 |
txtDescription.setName("txtDescription");
|
175 |
JScrollPane jscrollpane3 = new JScrollPane(); |
176 |
jscrollpane3.setViewportView(txtDescription); |
177 |
jscrollpane3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
178 |
jscrollpane3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
179 |
jpanel1.add(jscrollpane3,cc.xywh(6,4,1,6)); |
180 |
|
181 |
jpanel1.add(createPanel4(),cc.xy(4,4)); |
182 |
jpanel1.add(createPanel5(),cc.xy(4,9)); |
183 |
jpanel1.add(createPanel6(),cc.xy(4,6)); |
184 |
addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7 },new int[]{ 1,2,3,4,5,6,7,8,9 }); |
185 |
return jpanel1;
|
186 |
} |
187 |
|
188 |
public JPanel createPanel2() |
189 |
{ |
190 |
JPanel jpanel1 = new JPanel(); |
191 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE","FILL:DEFAULT:GROW(1.0)"); |
192 |
CellConstraints cc = new CellConstraints();
|
193 |
jpanel1.setLayout(formlayout1); |
194 |
|
195 |
txtExpression.setName("txtExpression");
|
196 |
JScrollPane jscrollpane1 = new JScrollPane(); |
197 |
jscrollpane1.setViewportView(txtExpression); |
198 |
jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
199 |
jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
200 |
jpanel1.add(jscrollpane1,cc.xy(1,1)); |
201 |
|
202 |
jpanel1.add(createPanel3(),cc.xy(3,1)); |
203 |
addFillComponents(jpanel1,new int[]{ 2,3 },new int[0]); |
204 |
return jpanel1;
|
205 |
} |
206 |
|
207 |
public JPanel createPanel3() |
208 |
{ |
209 |
JPanel jpanel1 = new JPanel(); |
210 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE"); |
211 |
CellConstraints cc = new CellConstraints();
|
212 |
jpanel1.setLayout(formlayout1); |
213 |
|
214 |
btnEq.setActionCommand("+");
|
215 |
btnEq.setName("btnEq");
|
216 |
btnEq.setText("=");
|
217 |
EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2); |
218 |
btnEq.setBorder(emptyborder1); |
219 |
jpanel1.add(btnEq,cc.xy(1,1)); |
220 |
|
221 |
btnAdd.setActionCommand("+");
|
222 |
btnAdd.setName("btnAdd");
|
223 |
btnAdd.setText("+");
|
224 |
EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2); |
225 |
btnAdd.setBorder(emptyborder2); |
226 |
jpanel1.add(btnAdd,cc.xy(1,2)); |
227 |
|
228 |
btnSubst.setActionCommand("+");
|
229 |
btnSubst.setName("btnSubst");
|
230 |
btnSubst.setText("-");
|
231 |
EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2); |
232 |
btnSubst.setBorder(emptyborder3); |
233 |
jpanel1.add(btnSubst,cc.xy(2,2)); |
234 |
|
235 |
btnMult.setActionCommand("+");
|
236 |
btnMult.setName("btnMult");
|
237 |
btnMult.setText("*");
|
238 |
EmptyBorder emptyborder4 = new EmptyBorder(2,2,2,2); |
239 |
btnMult.setBorder(emptyborder4); |
240 |
jpanel1.add(btnMult,cc.xy(1,3)); |
241 |
|
242 |
btnDiv.setActionCommand("+");
|
243 |
btnDiv.setName("btnDiv");
|
244 |
btnDiv.setText("/");
|
245 |
EmptyBorder emptyborder5 = new EmptyBorder(2,2,2,2); |
246 |
btnDiv.setBorder(emptyborder5); |
247 |
jpanel1.add(btnDiv,cc.xy(2,3)); |
248 |
|
249 |
btnParentOpen.setActionCommand("+");
|
250 |
btnParentOpen.setName("btnParentOpen");
|
251 |
btnParentOpen.setText("(");
|
252 |
EmptyBorder emptyborder6 = new EmptyBorder(2,2,2,2); |
253 |
btnParentOpen.setBorder(emptyborder6); |
254 |
jpanel1.add(btnParentOpen,cc.xy(1,4)); |
255 |
|
256 |
btnParentClose.setActionCommand("+");
|
257 |
btnParentClose.setName("btnParentClose");
|
258 |
btnParentClose.setText(")");
|
259 |
EmptyBorder emptyborder7 = new EmptyBorder(2,2,2,2); |
260 |
btnParentClose.setBorder(emptyborder7); |
261 |
jpanel1.add(btnParentClose,cc.xy(2,4)); |
262 |
|
263 |
btnNeq.setActionCommand("+");
|
264 |
btnNeq.setName("btnNeq");
|
265 |
btnNeq.setText("<>");
|
266 |
EmptyBorder emptyborder8 = new EmptyBorder(2,2,2,2); |
267 |
btnNeq.setBorder(emptyborder8); |
268 |
jpanel1.add(btnNeq,cc.xy(2,1)); |
269 |
|
270 |
addFillComponents(jpanel1,new int[0],new int[0]); |
271 |
return jpanel1;
|
272 |
} |
273 |
|
274 |
public JPanel createPanel4() |
275 |
{ |
276 |
JPanel jpanel1 = new JPanel(); |
277 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE"); |
278 |
CellConstraints cc = new CellConstraints();
|
279 |
jpanel1.setLayout(formlayout1); |
280 |
|
281 |
txtGroupElement.setBackground(new Color(236,233,216)); |
282 |
txtGroupElement.setEditable(false);
|
283 |
txtGroupElement.setName("txtGroupElement");
|
284 |
jpanel1.add(txtGroupElement,cc.xy(1,1)); |
285 |
|
286 |
btnGroupElementInsert.setActionCommand("+");
|
287 |
btnGroupElementInsert.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/expresionbuilder-insert-text.png"));
|
288 |
btnGroupElementInsert.setName("btnGroupElementInsert");
|
289 |
EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2); |
290 |
btnGroupElementInsert.setBorder(emptyborder1); |
291 |
jpanel1.add(btnGroupElementInsert,cc.xy(3,1)); |
292 |
|
293 |
addFillComponents(jpanel1,new int[]{ 2 },new int[0]); |
294 |
return jpanel1;
|
295 |
} |
296 |
|
297 |
public JPanel createPanel5() |
298 |
{ |
299 |
JPanel jpanel1 = new JPanel(); |
300 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:PREF:NONE"); |
301 |
CellConstraints cc = new CellConstraints();
|
302 |
jpanel1.setLayout(formlayout1); |
303 |
|
304 |
btnSimpleElementInsert.setActionCommand("+");
|
305 |
btnSimpleElementInsert.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/expresionbuilder-insert-text.png"));
|
306 |
btnSimpleElementInsert.setName("btnSimpleElementInsert");
|
307 |
EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2); |
308 |
btnSimpleElementInsert.setBorder(emptyborder1); |
309 |
jpanel1.add(btnSimpleElementInsert,cc.xy(6,1)); |
310 |
|
311 |
btnSimpleElementSortUp.setActionCommand("+");
|
312 |
btnSimpleElementSortUp.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-sortup.png"));
|
313 |
btnSimpleElementSortUp.setName("btnSimpleElementSortUp");
|
314 |
EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2); |
315 |
btnSimpleElementSortUp.setBorder(emptyborder2); |
316 |
jpanel1.add(btnSimpleElementSortUp,cc.xy(4,1)); |
317 |
|
318 |
btnSimpleElementSortDown.setActionCommand("+");
|
319 |
btnSimpleElementSortDown.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-sortdown.png"));
|
320 |
btnSimpleElementSortDown.setName("btnSimpleElementSortDown");
|
321 |
EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2); |
322 |
btnSimpleElementSortDown.setBorder(emptyborder3); |
323 |
jpanel1.add(btnSimpleElementSortDown,cc.xy(2,1)); |
324 |
|
325 |
addFillComponents(jpanel1,new int[]{ 1,3,5 },new int[]{ 1 }); |
326 |
return jpanel1;
|
327 |
} |
328 |
|
329 |
public JPanel createPanel6() |
330 |
{ |
331 |
JPanel jpanel1 = new JPanel(); |
332 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE"); |
333 |
CellConstraints cc = new CellConstraints();
|
334 |
jpanel1.setLayout(formlayout1); |
335 |
|
336 |
txtSimpleElementFilter.setName("txtSimpleElementFilter");
|
337 |
jpanel1.add(txtSimpleElementFilter,cc.xy(1,1)); |
338 |
|
339 |
btnSimpleElementFilter.setActionCommand("+");
|
340 |
btnSimpleElementFilter.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-filter-values.png"));
|
341 |
btnSimpleElementFilter.setName("btnSimpleElementFilter");
|
342 |
EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2); |
343 |
btnSimpleElementFilter.setBorder(emptyborder1); |
344 |
jpanel1.add(btnSimpleElementFilter,cc.xy(3,1)); |
345 |
|
346 |
addFillComponents(jpanel1,new int[]{ 2 },new int[0]); |
347 |
return jpanel1;
|
348 |
} |
349 |
|
350 |
public JPanel createPanel7() |
351 |
{ |
352 |
JPanel jpanel1 = new JPanel(); |
353 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE"); |
354 |
CellConstraints cc = new CellConstraints();
|
355 |
jpanel1.setLayout(formlayout1); |
356 |
|
357 |
addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3 }); |
358 |
return jpanel1;
|
359 |
} |
360 |
|
361 |
/**
|
362 |
* Initializer
|
363 |
*/
|
364 |
protected void initializePanel() |
365 |
{ |
366 |
setLayout(new BorderLayout()); |
367 |
add(createPanel(), BorderLayout.CENTER);
|
368 |
} |
369 |
|
370 |
|
371 |
} |