Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / featurequery / DefaultFeatureQueryCalculatedColumnsPanelView.java @ 47426

History | View | Annotate | Download (12.2 KB)

1
package org.gvsig.fmap.dal.swing.impl.featurequery;
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.ComponentOrientation;
8
import java.awt.Container;
9
import java.awt.Dimension;
10
import javax.swing.Box;
11
import javax.swing.ImageIcon;
12
import javax.swing.JButton;
13
import javax.swing.JComboBox;
14
import javax.swing.JFrame;
15
import javax.swing.JLabel;
16
import javax.swing.JList;
17
import javax.swing.JPanel;
18
import javax.swing.JScrollPane;
19
import javax.swing.JTextArea;
20
import javax.swing.JTextField;
21
import javax.swing.border.EmptyBorder;
22

    
23

    
24
public class DefaultFeatureQueryCalculatedColumnsPanelView extends JPanel
25
{
26
   JList lstAttributes = new JList();
27
   JButton btnDown = new JButton();
28
   JButton btnUp = new JButton();
29
   JButton btnRemove = new JButton();
30
   JButton btnAdd = new JButton();
31
   JLabel lblName = new JLabel();
32
   JLabel lblType = new JLabel();
33
   JLabel lblExpression = new JLabel();
34
   JTextField txtColumnName = new JTextField();
35
   JButton btnColumnDataType = new JButton();
36
   JComboBox cboColumnDataType = new JComboBox();
37
   JButton btnApplyChanges = new JButton();
38
   JButton btnColumnMore = new JButton();
39
   JTextArea txtColumnExpression = new JTextArea();
40
   JTextField txtColumnSize = new JTextField();
41
   JLabel lblSize = new JLabel();
42
   JLabel lblPrecision = new JLabel();
43
   JTextField txtColumnPrecision = new JTextField();
44
   JLabel lblScale = new JLabel();
45
   JTextField txtColumnScale = new JTextField();
46
   JButton btnColumnExpression = new JButton();
47
   JButton btnColumnExpressionHistory = new JButton();
48
   JButton btnColumnExpressionBookmarks = new JButton();
49

    
50
   /**
51
    * Default constructor
52
    */
53
   public DefaultFeatureQueryCalculatedColumnsPanelView()
54
   {
55
      initializePanel();
56
   }
57

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

    
68
      boolean filled_cell_11 = false;
69
      CellConstraints cc = new CellConstraints();
70
      if ( cols.length > 0 && rows.length > 0 )
71
      {
72
         if ( cols[0] == 1 && rows[0] == 1 )
73
         {
74
            /** add a rigid area  */
75
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
76
            filled_cell_11 = true;
77
         }
78
      }
79

    
80
      for( int index = 0; index < cols.length; index++ )
81
      {
82
         if ( cols[index] == 1 && filled_cell_11 )
83
         {
84
            continue;
85
         }
86
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
87
      }
88

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

    
98
   }
99

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

    
125
   /**
126
    * Method for recalculating the component orientation for 
127
    * right-to-left Locales.
128
    * @param orientation the component orientation to be applied
129
    */
130
   public void applyComponentOrientation( ComponentOrientation orientation )
131
   {
132
      // Not yet implemented...
133
      // I18NUtils.applyComponentOrientation(this, orientation);
134
      super.applyComponentOrientation(orientation);
135
   }
136

    
137
   public JPanel createPanel()
138
   {
139
      JPanel jpanel1 = new JPanel();
140
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:GROW(0.4),FILL:4DLU:NONE,FILL:DEFAULT:GROW(0.6),FILL:4DLU:NONE","CENTER:2DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
141
      CellConstraints cc = new CellConstraints();
142
      jpanel1.setLayout(formlayout1);
143

    
144
      lstAttributes.setName("lstAttributes");
145
      JScrollPane jscrollpane1 = new JScrollPane();
146
      jscrollpane1.setViewportView(lstAttributes);
147
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
148
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
149
      jpanel1.add(jscrollpane1,cc.xy(2,2));
150

    
151
      jpanel1.add(createPanel1(),cc.xy(2,4));
152
      jpanel1.add(createPanel2(),cc.xy(4,2));
153
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5 });
154
      return jpanel1;
155
   }
156

    
157
   public JPanel createPanel1()
158
   {
159
      JPanel jpanel1 = new JPanel();
160
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
161
      CellConstraints cc = new CellConstraints();
162
      jpanel1.setLayout(formlayout1);
163

    
164
      btnDown.setActionCommand("...");
165
      btnDown.setIcon(loadImage("common-arrow-down.png"));
166
      btnDown.setName("btnDown");
167
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
168
      btnDown.setBorder(emptyborder1);
169
      jpanel1.add(btnDown,cc.xy(9,1));
170

    
171
      btnUp.setActionCommand("...");
172
      btnUp.setIcon(loadImage("common-arrow-up.png"));
173
      btnUp.setName("btnUp");
174
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
175
      btnUp.setBorder(emptyborder2);
176
      jpanel1.add(btnUp,cc.xy(7,1));
177

    
178
      btnRemove.setActionCommand("...");
179
      btnRemove.setIcon(loadImage("common-arrow-left.png"));
180
      btnRemove.setName("btnRemove");
181
      EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2);
182
      btnRemove.setBorder(emptyborder3);
183
      jpanel1.add(btnRemove,cc.xy(5,1));
184

    
185
      btnAdd.setActionCommand("...");
186
      btnAdd.setIcon(loadImage("common-arrow-right.png"));
187
      btnAdd.setName("btnAdd");
188
      EmptyBorder emptyborder4 = new EmptyBorder(2,2,2,2);
189
      btnAdd.setBorder(emptyborder4);
190
      jpanel1.add(btnAdd,cc.xy(3,1));
191

    
192
      addFillComponents(jpanel1,new int[]{ 1,2,4,6,8 },new int[]{ 1 });
193
      return jpanel1;
194
   }
195

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

    
203
      lblName.setName("lblName");
204
      lblName.setText("_Name");
205
      jpanel1.add(lblName,cc.xy(1,1));
206

    
207
      lblType.setName("lblType");
208
      lblType.setText("_Type");
209
      jpanel1.add(lblType,cc.xy(1,3));
210

    
211
      lblExpression.setName("lblExpression");
212
      lblExpression.setText("_Expression");
213
      jpanel1.add(lblExpression,new CellConstraints(1,11,1,1,CellConstraints.DEFAULT,CellConstraints.TOP));
214

    
215
      txtColumnName.setName("txtColumnName");
216
      jpanel1.add(txtColumnName,cc.xywh(3,1,3,1));
217

    
218
      btnColumnDataType.setActionCommand("...");
219
      btnColumnDataType.setIcon(loadImage("common-more.png"));
220
      btnColumnDataType.setName("btnColumnDataType");
221
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
222
      btnColumnDataType.setBorder(emptyborder1);
223
      jpanel1.add(btnColumnDataType,cc.xy(5,3));
224

    
225
      cboColumnDataType.setName("cboColumnDataType");
226
      jpanel1.add(cboColumnDataType,cc.xywh(3,3,2,1));
227

    
228
      jpanel1.add(createPanel3(),cc.xywh(1,13,5,1));
229
      txtColumnExpression.setName("txtColumnExpression");
230
      JScrollPane jscrollpane1 = new JScrollPane();
231
      jscrollpane1.setViewportView(txtColumnExpression);
232
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
233
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
234
      jpanel1.add(jscrollpane1,cc.xy(3,11));
235

    
236
      txtColumnSize.setName("txtColumnSize");
237
      jpanel1.add(txtColumnSize,cc.xywh(3,5,3,1));
238

    
239
      lblSize.setName("lblSize");
240
      lblSize.setText("_Size");
241
      jpanel1.add(lblSize,cc.xy(1,5));
242

    
243
      lblPrecision.setName("lblPrecision");
244
      lblPrecision.setText("_Precision");
245
      jpanel1.add(lblPrecision,cc.xy(1,7));
246

    
247
      txtColumnPrecision.setName("txtColumnPrecision");
248
      jpanel1.add(txtColumnPrecision,cc.xywh(3,7,3,1));
249

    
250
      lblScale.setName("lblScale");
251
      lblScale.setText("_Scale");
252
      jpanel1.add(lblScale,cc.xy(1,9));
253

    
254
      txtColumnScale.setName("txtColumnScale");
255
      jpanel1.add(txtColumnScale,cc.xywh(3,9,3,1));
256

    
257
      jpanel1.add(createPanel4(),cc.xy(5,11));
258
      addFillComponents(jpanel1,new int[]{ 2,4,5 },new int[]{ 2,4,6,8,10,12,13 });
259
      return jpanel1;
260
   }
261

    
262
   public JPanel createPanel3()
263
   {
264
      JPanel jpanel1 = new JPanel();
265
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
266
      CellConstraints cc = new CellConstraints();
267
      jpanel1.setLayout(formlayout1);
268

    
269
      btnApplyChanges.setActionCommand("...");
270
      btnApplyChanges.setIcon(loadImage("common-applychanges.png"));
271
      btnApplyChanges.setName("btnApplyChanges");
272
      btnApplyChanges.setText("_Apply_changes");
273
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
274
      btnApplyChanges.setBorder(emptyborder1);
275
      jpanel1.add(btnApplyChanges,cc.xy(5,1));
276

    
277
      btnColumnMore.setActionCommand("...");
278
      btnColumnMore.setIcon(loadImage("common-more.png"));
279
      btnColumnMore.setName("btnColumnMore");
280
      btnColumnMore.setText("_More");
281
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
282
      btnColumnMore.setBorder(emptyborder2);
283
      jpanel1.add(btnColumnMore,cc.xy(3,1));
284

    
285
      addFillComponents(jpanel1,new int[]{ 1,2,4 },new int[]{ 1 });
286
      return jpanel1;
287
   }
288

    
289
   public JPanel createPanel4()
290
   {
291
      JPanel jpanel1 = new JPanel();
292
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0)");
293
      CellConstraints cc = new CellConstraints();
294
      jpanel1.setLayout(formlayout1);
295

    
296
      btnColumnExpression.setActionCommand("...");
297
      btnColumnExpression.setName("btnColumnExpression");
298
      btnColumnExpression.setText("...");
299
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
300
      btnColumnExpression.setBorder(emptyborder1);
301
      jpanel1.add(btnColumnExpression,cc.xy(1,1));
302

    
303
      btnColumnExpressionHistory.setActionCommand("...");
304
      btnColumnExpressionHistory.setName("btnColumnExpressionHistory");
305
      btnColumnExpressionHistory.setText("...");
306
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
307
      btnColumnExpressionHistory.setBorder(emptyborder2);
308
      jpanel1.add(btnColumnExpressionHistory,cc.xy(1,3));
309

    
310
      btnColumnExpressionBookmarks.setActionCommand("...");
311
      btnColumnExpressionBookmarks.setName("btnColumnExpressionBookmarks");
312
      btnColumnExpressionBookmarks.setText("...");
313
      EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2);
314
      btnColumnExpressionBookmarks.setBorder(emptyborder3);
315
      jpanel1.add(btnColumnExpressionBookmarks,cc.xy(1,5));
316

    
317
      addFillComponents(jpanel1,new int[0],new int[]{ 2,4,6 });
318
      return jpanel1;
319
   }
320

    
321
   /**
322
    * Initializer
323
    */
324
   protected void initializePanel()
325
   {
326
      setLayout(new BorderLayout());
327
      add(createPanel(), BorderLayout.CENTER);
328
   }
329

    
330

    
331
}