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

History | View | Annotate | Download (17.4 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 btnNeq = new JButton();
35
   JButton btnAdd = new JButton();
36
   JButton btnSubst = new JButton();
37
   JButton btnMult = new JButton();
38
   JButton btnDiv = new JButton();
39
   JButton btnParentOpen = new JButton();
40
   JButton btnParentClose = 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
   JButton btnSimpleElementTimeLimit = new JButton();
50
   JTextField txtSimpleElementFilter = new JTextField();
51
   JButton btnSimpleElementFilter = new JButton();
52
   JPanel pnlScriptEditorContainer = new JPanel();
53
   JComboBox cboPickerScripts = new JComboBox();
54
   JButton btnPickerRemove = new JButton();
55
   JButton btnPickerSelectScript = new JButton();
56

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

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

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

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

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

    
105
   }
106

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
231
      btnNeq.setActionCommand("+");
232
      btnNeq.setName("btnNeq");
233
      btnNeq.setText("<>");
234
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
235
      btnNeq.setBorder(emptyborder2);
236
      jpanel1.add(btnNeq,cc.xy(3,1));
237

    
238
      btnAdd.setActionCommand("+");
239
      btnAdd.setName("btnAdd");
240
      btnAdd.setText("+");
241
      EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2);
242
      btnAdd.setBorder(emptyborder3);
243
      jpanel1.add(btnAdd,cc.xy(5,1));
244

    
245
      btnSubst.setActionCommand("+");
246
      btnSubst.setName("btnSubst");
247
      btnSubst.setText("-");
248
      EmptyBorder emptyborder4 = new EmptyBorder(2,2,2,2);
249
      btnSubst.setBorder(emptyborder4);
250
      jpanel1.add(btnSubst,cc.xy(7,1));
251

    
252
      btnMult.setActionCommand("+");
253
      btnMult.setName("btnMult");
254
      btnMult.setText("*");
255
      EmptyBorder emptyborder5 = new EmptyBorder(2,2,2,2);
256
      btnMult.setBorder(emptyborder5);
257
      jpanel1.add(btnMult,cc.xy(1,3));
258

    
259
      btnDiv.setActionCommand("+");
260
      btnDiv.setName("btnDiv");
261
      btnDiv.setText("/");
262
      EmptyBorder emptyborder6 = new EmptyBorder(2,2,2,2);
263
      btnDiv.setBorder(emptyborder6);
264
      jpanel1.add(btnDiv,cc.xy(3,3));
265

    
266
      btnParentOpen.setActionCommand("+");
267
      btnParentOpen.setName("btnParentOpen");
268
      btnParentOpen.setText("(");
269
      EmptyBorder emptyborder7 = new EmptyBorder(2,2,2,2);
270
      btnParentOpen.setBorder(emptyborder7);
271
      jpanel1.add(btnParentOpen,cc.xy(5,3));
272

    
273
      btnParentClose.setActionCommand("+");
274
      btnParentClose.setName("btnParentClose");
275
      btnParentClose.setText(")");
276
      EmptyBorder emptyborder8 = new EmptyBorder(2,2,2,2);
277
      btnParentClose.setBorder(emptyborder8);
278
      jpanel1.add(btnParentClose,cc.xy(7,3));
279

    
280
      addFillComponents(jpanel1,new int[]{ 2,4,6,8 },new int[]{ 2,4 });
281
      return jpanel1;
282
   }
283

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

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

    
296
      btnGroupElementInsert.setActionCommand("+");
297
      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"));
298
      btnGroupElementInsert.setName("btnGroupElementInsert");
299
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
300
      btnGroupElementInsert.setBorder(emptyborder1);
301
      jpanel1.add(btnGroupElementInsert,cc.xy(3,1));
302

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

    
307
   public JPanel createPanel5()
308
   {
309
      JPanel jpanel1 = new JPanel();
310
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:PREF:NONE");
311
      CellConstraints cc = new CellConstraints();
312
      jpanel1.setLayout(formlayout1);
313

    
314
      btnSimpleElementInsert.setActionCommand("+");
315
      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"));
316
      btnSimpleElementInsert.setName("btnSimpleElementInsert");
317
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
318
      btnSimpleElementInsert.setBorder(emptyborder1);
319
      jpanel1.add(btnSimpleElementInsert,cc.xy(8,1));
320

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

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

    
335
      lblSimpleElementsMsg.setName("lblSimpleElementsMsg");
336
      jpanel1.add(lblSimpleElementsMsg,cc.xy(1,1));
337

    
338
      btnSimpleElementTimeLimit.setActionCommand("+");
339
      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"));
340
      btnSimpleElementTimeLimit.setName("btnSimpleElementTimeLimit");
341
      EmptyBorder emptyborder4 = new EmptyBorder(2,2,2,2);
342
      btnSimpleElementTimeLimit.setBorder(emptyborder4);
343
      jpanel1.add(btnSimpleElementTimeLimit,cc.xy(2,1));
344

    
345
      addFillComponents(jpanel1,new int[]{ 3,5,7 },new int[0]);
346
      return jpanel1;
347
   }
348

    
349
   public JPanel createPanel6()
350
   {
351
      JPanel jpanel1 = new JPanel();
352
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
353
      CellConstraints cc = new CellConstraints();
354
      jpanel1.setLayout(formlayout1);
355

    
356
      txtSimpleElementFilter.setName("txtSimpleElementFilter");
357
      jpanel1.add(txtSimpleElementFilter,cc.xy(1,1));
358

    
359
      btnSimpleElementFilter.setActionCommand("+");
360
      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"));
361
      btnSimpleElementFilter.setName("btnSimpleElementFilter");
362
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
363
      btnSimpleElementFilter.setBorder(emptyborder1);
364
      jpanel1.add(btnSimpleElementFilter,cc.xy(3,1));
365

    
366
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
367
      return jpanel1;
368
   }
369

    
370
   public JPanel createPanel7()
371
   {
372
      JPanel jpanel1 = new JPanel();
373
      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");
374
      CellConstraints cc = new CellConstraints();
375
      jpanel1.setLayout(formlayout1);
376

    
377
      pnlScriptEditorContainer.setName("pnlScriptEditorContainer");
378
      jpanel1.add(pnlScriptEditorContainer,cc.xy(2,2));
379

    
380
      jpanel1.add(createPanel8(),cc.xy(2,4));
381
      addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5 });
382
      return jpanel1;
383
   }
384

    
385
   public JPanel createPanel8()
386
   {
387
      JPanel jpanel1 = new JPanel();
388
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
389
      CellConstraints cc = new CellConstraints();
390
      jpanel1.setLayout(formlayout1);
391

    
392
      cboPickerScripts.setName("cboPickerScripts");
393
      jpanel1.add(cboPickerScripts,cc.xy(1,1));
394

    
395
      btnPickerRemove.setActionCommand("+");
396
      btnPickerRemove.setName("btnPickerRemove");
397
      btnPickerRemove.setText("R");
398
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
399
      btnPickerRemove.setBorder(emptyborder1);
400
      jpanel1.add(btnPickerRemove,cc.xy(3,1));
401

    
402
      btnPickerSelectScript.setActionCommand("+");
403
      btnPickerSelectScript.setName("btnPickerSelectScript");
404
      btnPickerSelectScript.setText("S");
405
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
406
      btnPickerSelectScript.setBorder(emptyborder2);
407
      jpanel1.add(btnPickerSelectScript,cc.xy(5,1));
408

    
409
      addFillComponents(jpanel1,new int[]{ 2,4 },new int[0]);
410
      return jpanel1;
411
   }
412

    
413
   /**
414
    * Initializer
415
    */
416
   protected void initializePanel()
417
   {
418
      setLayout(new BorderLayout());
419
      add(createPanel(), BorderLayout.CENTER);
420
   }
421

    
422

    
423
}