Statistics
| Revision:

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 @ 43983

History | View | Annotate | Download (16.7 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.JComboBox;
15
import javax.swing.JEditorPane;
16
import javax.swing.JFrame;
17
import javax.swing.JLabel;
18
import javax.swing.JList;
19
import javax.swing.JPanel;
20
import javax.swing.JScrollPane;
21
import javax.swing.JTabbedPane;
22
import javax.swing.JTextArea;
23
import javax.swing.JTextField;
24
import javax.swing.JTree;
25
import javax.swing.border.EmptyBorder;
26

    
27

    
28
public class DefaultJExpressionBuilderView extends JPanel
29
{
30
   JTabbedPane tabExpressionBuilder = new JTabbedPane();
31
   JList lstSimpleElement = new JList();
32
   JTextArea txtExpression = new JTextArea();
33
   JButton btnEq = new JButton();
34
   JButton btnAdd = new JButton();
35
   JButton btnSubst = new JButton();
36
   JButton btnMult = new JButton();
37
   JButton btnDiv = new JButton();
38
   JButton btnParentOpen = new JButton();
39
   JButton btnParentClose = new JButton();
40
   JButton btnNeq = new JButton();
41
   JTree treeElements = new JTree();
42
   JEditorPane txtDescription = new JEditorPane();
43
   JTextField txtGroupElement = new JTextField();
44
   JButton btnGroupElementInsert = new JButton();
45
   JButton btnSimpleElementInsert = new JButton();
46
   JButton btnSimpleElementSortDown = new JButton();
47
   JButton btnSimpleElementSortUp = new JButton();
48
   JLabel lblSimpleElementsMsg = new JLabel();
49
   JTextField txtSimpleElementFilter = new JTextField();
50
   JButton btnSimpleElementFilter = new JButton();
51
   JPanel pnlScriptEditorContainer = new JPanel();
52
   JComboBox cboPickerScripts = new JComboBox();
53
   JButton btnPickerRemove = new JButton();
54
   JButton btnPickerSelectScript = new JButton();
55

    
56
   /**
57
    * Default constructor
58
    */
59
   public DefaultJExpressionBuilderView()
60
   {
61
      initializePanel();
62
   }
63

    
64
   /**
65
    * Adds fill components to empty cells in the first row and first column of the grid.
66
    * This ensures that the grid spacing will be the same as shown in the designer.
67
    * @param cols an array of column indices in the first row where fill components should be added.
68
    * @param rows an array of row indices in the first column where fill components should be added.
69
    */
70
   void addFillComponents( Container panel, int[] cols, int[] rows )
71
   {
72
      Dimension filler = new Dimension(10,10);
73

    
74
      boolean filled_cell_11 = false;
75
      CellConstraints cc = new CellConstraints();
76
      if ( cols.length > 0 && rows.length > 0 )
77
      {
78
         if ( cols[0] == 1 && rows[0] == 1 )
79
         {
80
            /** add a rigid area  */
81
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
82
            filled_cell_11 = true;
83
         }
84
      }
85

    
86
      for( int index = 0; index < cols.length; index++ )
87
      {
88
         if ( cols[index] == 1 && filled_cell_11 )
89
         {
90
            continue;
91
         }
92
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
93
      }
94

    
95
      for( int index = 0; index < rows.length; index++ )
96
      {
97
         if ( rows[index] == 1 && filled_cell_11 )
98
         {
99
            continue;
100
         }
101
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
102
      }
103

    
104
   }
105

    
106
   /**
107
    * Helper method to load an image file from the CLASSPATH
108
    * @param imageName the package and name of the file to load relative to the CLASSPATH
109
    * @return an ImageIcon instance with the specified image file
110
    * @throws IllegalArgumentException if the image resource cannot be loaded.
111
    */
112
   public ImageIcon loadImage( String imageName )
113
   {
114
      try
115
      {
116
         ClassLoader classloader = getClass().getClassLoader();
117
         java.net.URL url = classloader.getResource( imageName );
118
         if ( url != null )
119
         {
120
            ImageIcon icon = new ImageIcon( url );
121
            return icon;
122
         }
123
      }
124
      catch( Exception e )
125
      {
126
         e.printStackTrace();
127
      }
128
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
129
   }
130

    
131
   /**
132
    * Method for recalculating the component orientation for 
133
    * right-to-left Locales.
134
    * @param orientation the component orientation to be applied
135
    */
136
   public void applyComponentOrientation( ComponentOrientation orientation )
137
   {
138
      // Not yet implemented...
139
      // I18NUtils.applyComponentOrientation(this, orientation);
140
      super.applyComponentOrientation(orientation);
141
   }
142

    
143
   public JPanel createPanel()
144
   {
145
      JPanel jpanel1 = new JPanel();
146
      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");
147
      CellConstraints cc = new CellConstraints();
148
      jpanel1.setLayout(formlayout1);
149

    
150
      tabExpressionBuilder.setName("tabExpressionBuilder");
151
      tabExpressionBuilder.addTab("_Expression",null,createPanel1());
152
      tabExpressionBuilder.addTab("_Scripts",null,createPanel7());
153
      jpanel1.add(tabExpressionBuilder,cc.xy(2,2));
154

    
155
      addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3 });
156
      return jpanel1;
157
   }
158

    
159
   public JPanel createPanel1()
160
   {
161
      JPanel jpanel1 = new JPanel();
162
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:80DLU:NONE,FILL:4DLU:NONE,FILL:100DLU:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(0.3),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");
163
      CellConstraints cc = new CellConstraints();
164
      jpanel1.setLayout(formlayout1);
165

    
166
      lstSimpleElement.setName("lstSimpleElement");
167
      JScrollPane jscrollpane1 = new JScrollPane();
168
      jscrollpane1.setViewportView(lstSimpleElement);
169
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
170
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
171
      jpanel1.add(jscrollpane1,cc.xy(4,8));
172

    
173
      jpanel1.add(createPanel2(),cc.xywh(2,2,5,1));
174
      treeElements.setName("treeElements");
175
      JScrollPane jscrollpane2 = new JScrollPane();
176
      jscrollpane2.setViewportView(treeElements);
177
      jscrollpane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
178
      jscrollpane2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
179
      jpanel1.add(jscrollpane2,cc.xywh(2,4,1,6));
180

    
181
      txtDescription.setEditable(false);
182
      txtDescription.setName("txtDescription");
183
      JScrollPane jscrollpane3 = new JScrollPane();
184
      jscrollpane3.setViewportView(txtDescription);
185
      jscrollpane3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
186
      jscrollpane3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
187
      jpanel1.add(jscrollpane3,cc.xywh(6,4,1,6));
188

    
189
      jpanel1.add(createPanel4(),cc.xy(4,4));
190
      jpanel1.add(createPanel5(),cc.xy(4,9));
191
      jpanel1.add(createPanel6(),cc.xy(4,6));
192
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7 },new int[]{ 1,2,3,4,5,6,7,8,9 });
193
      return jpanel1;
194
   }
195

    
196
   public JPanel createPanel2()
197
   {
198
      JPanel jpanel1 = new JPanel();
199
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","FILL:DEFAULT:GROW(1.0)");
200
      CellConstraints cc = new CellConstraints();
201
      jpanel1.setLayout(formlayout1);
202

    
203
      txtExpression.setName("txtExpression");
204
      JScrollPane jscrollpane1 = new JScrollPane();
205
      jscrollpane1.setViewportView(txtExpression);
206
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
207
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
208
      jpanel1.add(jscrollpane1,cc.xy(1,1));
209

    
210
      jpanel1.add(createPanel3(),cc.xy(3,1));
211
      addFillComponents(jpanel1,new int[]{ 2,3 },new int[0]);
212
      return jpanel1;
213
   }
214

    
215
   public JPanel createPanel3()
216
   {
217
      JPanel jpanel1 = new JPanel();
218
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE");
219
      CellConstraints cc = new CellConstraints();
220
      jpanel1.setLayout(formlayout1);
221

    
222
      btnEq.setActionCommand("+");
223
      btnEq.setName("btnEq");
224
      btnEq.setText("=");
225
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
226
      btnEq.setBorder(emptyborder1);
227
      jpanel1.add(btnEq,cc.xy(1,1));
228

    
229
      btnAdd.setActionCommand("+");
230
      btnAdd.setName("btnAdd");
231
      btnAdd.setText("+");
232
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
233
      btnAdd.setBorder(emptyborder2);
234
      jpanel1.add(btnAdd,cc.xy(1,3));
235

    
236
      btnSubst.setActionCommand("+");
237
      btnSubst.setName("btnSubst");
238
      btnSubst.setText("-");
239
      EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2);
240
      btnSubst.setBorder(emptyborder3);
241
      jpanel1.add(btnSubst,cc.xy(3,3));
242

    
243
      btnMult.setActionCommand("+");
244
      btnMult.setName("btnMult");
245
      btnMult.setText("*");
246
      EmptyBorder emptyborder4 = new EmptyBorder(2,2,2,2);
247
      btnMult.setBorder(emptyborder4);
248
      jpanel1.add(btnMult,cc.xy(1,5));
249

    
250
      btnDiv.setActionCommand("+");
251
      btnDiv.setName("btnDiv");
252
      btnDiv.setText("/");
253
      EmptyBorder emptyborder5 = new EmptyBorder(2,2,2,2);
254
      btnDiv.setBorder(emptyborder5);
255
      jpanel1.add(btnDiv,cc.xy(3,5));
256

    
257
      btnParentOpen.setActionCommand("+");
258
      btnParentOpen.setName("btnParentOpen");
259
      btnParentOpen.setText("(");
260
      EmptyBorder emptyborder6 = new EmptyBorder(2,2,2,2);
261
      btnParentOpen.setBorder(emptyborder6);
262
      jpanel1.add(btnParentOpen,cc.xy(1,7));
263

    
264
      btnParentClose.setActionCommand("+");
265
      btnParentClose.setName("btnParentClose");
266
      btnParentClose.setText(")");
267
      EmptyBorder emptyborder7 = new EmptyBorder(2,2,2,2);
268
      btnParentClose.setBorder(emptyborder7);
269
      jpanel1.add(btnParentClose,cc.xy(3,7));
270

    
271
      btnNeq.setActionCommand("+");
272
      btnNeq.setName("btnNeq");
273
      btnNeq.setText("<>");
274
      EmptyBorder emptyborder8 = new EmptyBorder(2,2,2,2);
275
      btnNeq.setBorder(emptyborder8);
276
      jpanel1.add(btnNeq,cc.xy(3,1));
277

    
278
      addFillComponents(jpanel1,new int[]{ 2 },new int[]{ 2,4,6 });
279
      return jpanel1;
280
   }
281

    
282
   public JPanel createPanel4()
283
   {
284
      JPanel jpanel1 = new JPanel();
285
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
286
      CellConstraints cc = new CellConstraints();
287
      jpanel1.setLayout(formlayout1);
288

    
289
      txtGroupElement.setBackground(new Color(236,233,216));
290
      txtGroupElement.setEditable(false);
291
      txtGroupElement.setName("txtGroupElement");
292
      jpanel1.add(txtGroupElement,cc.xy(1,1));
293

    
294
      btnGroupElementInsert.setActionCommand("+");
295
      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/expressionbuilder-insert-text.png"));
296
      btnGroupElementInsert.setName("btnGroupElementInsert");
297
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
298
      btnGroupElementInsert.setBorder(emptyborder1);
299
      jpanel1.add(btnGroupElementInsert,cc.xy(3,1));
300

    
301
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
302
      return jpanel1;
303
   }
304

    
305
   public JPanel createPanel5()
306
   {
307
      JPanel jpanel1 = new JPanel();
308
      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");
309
      CellConstraints cc = new CellConstraints();
310
      jpanel1.setLayout(formlayout1);
311

    
312
      btnSimpleElementInsert.setActionCommand("+");
313
      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/expressionbuilder-insert-text.png"));
314
      btnSimpleElementInsert.setName("btnSimpleElementInsert");
315
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
316
      btnSimpleElementInsert.setBorder(emptyborder1);
317
      jpanel1.add(btnSimpleElementInsert,cc.xy(6,1));
318

    
319
      btnSimpleElementSortDown.setActionCommand("+");
320
      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"));
321
      btnSimpleElementSortDown.setName("btnSimpleElementSortDown");
322
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
323
      btnSimpleElementSortDown.setBorder(emptyborder2);
324
      jpanel1.add(btnSimpleElementSortDown,cc.xy(4,1));
325

    
326
      btnSimpleElementSortUp.setActionCommand("+");
327
      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"));
328
      btnSimpleElementSortUp.setName("btnSimpleElementSortUp");
329
      EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2);
330
      btnSimpleElementSortUp.setBorder(emptyborder3);
331
      jpanel1.add(btnSimpleElementSortUp,cc.xy(2,1));
332

    
333
      lblSimpleElementsMsg.setName("lblSimpleElementsMsg");
334
      jpanel1.add(lblSimpleElementsMsg,cc.xy(1,1));
335

    
336
      addFillComponents(jpanel1,new int[]{ 3,5 },new int[0]);
337
      return jpanel1;
338
   }
339

    
340
   public JPanel createPanel6()
341
   {
342
      JPanel jpanel1 = new JPanel();
343
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
344
      CellConstraints cc = new CellConstraints();
345
      jpanel1.setLayout(formlayout1);
346

    
347
      txtSimpleElementFilter.setName("txtSimpleElementFilter");
348
      jpanel1.add(txtSimpleElementFilter,cc.xy(1,1));
349

    
350
      btnSimpleElementFilter.setActionCommand("+");
351
      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"));
352
      btnSimpleElementFilter.setName("btnSimpleElementFilter");
353
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
354
      btnSimpleElementFilter.setBorder(emptyborder1);
355
      jpanel1.add(btnSimpleElementFilter,cc.xy(3,1));
356

    
357
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
358
      return jpanel1;
359
   }
360

    
361
   public JPanel createPanel7()
362
   {
363
      JPanel jpanel1 = new JPanel();
364
      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,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
365
      CellConstraints cc = new CellConstraints();
366
      jpanel1.setLayout(formlayout1);
367

    
368
      pnlScriptEditorContainer.setName("pnlScriptEditorContainer");
369
      jpanel1.add(pnlScriptEditorContainer,cc.xy(2,2));
370

    
371
      jpanel1.add(createPanel8(),cc.xy(2,4));
372
      addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5 });
373
      return jpanel1;
374
   }
375

    
376
   public JPanel createPanel8()
377
   {
378
      JPanel jpanel1 = new JPanel();
379
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
380
      CellConstraints cc = new CellConstraints();
381
      jpanel1.setLayout(formlayout1);
382

    
383
      cboPickerScripts.setName("cboPickerScripts");
384
      jpanel1.add(cboPickerScripts,cc.xy(1,1));
385

    
386
      btnPickerRemove.setActionCommand("+");
387
      btnPickerRemove.setName("btnPickerRemove");
388
      btnPickerRemove.setText("R");
389
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
390
      btnPickerRemove.setBorder(emptyborder1);
391
      jpanel1.add(btnPickerRemove,cc.xy(3,1));
392

    
393
      btnPickerSelectScript.setActionCommand("+");
394
      btnPickerSelectScript.setName("btnPickerSelectScript");
395
      btnPickerSelectScript.setText("S");
396
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
397
      btnPickerSelectScript.setBorder(emptyborder2);
398
      jpanel1.add(btnPickerSelectScript,cc.xy(5,1));
399

    
400
      addFillComponents(jpanel1,new int[]{ 2,4 },new int[0]);
401
      return jpanel1;
402
   }
403

    
404
   /**
405
    * Initializer
406
    */
407
   protected void initializePanel()
408
   {
409
      setLayout(new BorderLayout());
410
      add(createPanel(), BorderLayout.CENTER);
411
   }
412

    
413

    
414
}