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

History | View | Annotate | Download (12.4 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
   JButton btnColumnExpression = new JButton();
35
   JButton btnColumnExpressionHistory = new JButton();
36
   JButton btnColumnExpressionBookmarks = new JButton();
37
   JTextField txtColumnName = new JTextField();
38
   JButton btnColumnDataType = new JButton();
39
   JComboBox cboColumnDataType = new JComboBox();
40
   JButton btnApplyChanges = new JButton();
41
   JButton btnColumnMore = new JButton();
42
   JTextArea txtColumnExpression = new JTextArea();
43
   JTextField txtColumnSize = new JTextField();
44
   JLabel lblSize = new JLabel();
45
   JLabel lblPrecision = new JLabel();
46
   JTextField txtColumnPrecision = new JTextField();
47
   JLabel lblScale = new JLabel();
48
   JTextField txtColumnScale = new JTextField();
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("src/main/resources/org/gvsig/fmap/dal/swing/impl/featurequery/featurequery-column-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("src/main/resources/org/gvsig/fmap/dal/swing/impl/featurequery/featurequery-column-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("src/main/resources/org/gvsig/fmap/dal/swing/impl/featurequery/featurequery-column-remove.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("src/main/resources/org/gvsig/fmap/dal/swing/impl/featurequery/featurequery-column-add.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,FILL:4DLU:NONE,FILL:DEFAULT:NONE,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
      btnColumnExpression.setActionCommand("...");
216
      btnColumnExpression.setName("btnColumnExpression");
217
      btnColumnExpression.setText("...");
218
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
219
      btnColumnExpression.setBorder(emptyborder1);
220
      jpanel1.add(btnColumnExpression,new CellConstraints(5,11,1,1,CellConstraints.DEFAULT,CellConstraints.TOP));
221

    
222
      btnColumnExpressionHistory.setActionCommand("...");
223
      btnColumnExpressionHistory.setName("btnColumnExpressionHistory");
224
      btnColumnExpressionHistory.setText("...");
225
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
226
      btnColumnExpressionHistory.setBorder(emptyborder2);
227
      jpanel1.add(btnColumnExpressionHistory,new CellConstraints(7,11,1,1,CellConstraints.DEFAULT,CellConstraints.TOP));
228

    
229
      btnColumnExpressionBookmarks.setActionCommand("...");
230
      btnColumnExpressionBookmarks.setName("btnColumnExpressionBookmarks");
231
      btnColumnExpressionBookmarks.setText("...");
232
      EmptyBorder emptyborder3 = new EmptyBorder(2,2,2,2);
233
      btnColumnExpressionBookmarks.setBorder(emptyborder3);
234
      jpanel1.add(btnColumnExpressionBookmarks,new CellConstraints(9,11,1,1,CellConstraints.DEFAULT,CellConstraints.TOP));
235

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

    
239
      btnColumnDataType.setActionCommand("...");
240
      btnColumnDataType.setIcon(loadImage("src/main/resources/org/gvsig/fmap/dal/swing/impl/featurequery/common-more.png"));
241
      btnColumnDataType.setName("btnColumnDataType");
242
      EmptyBorder emptyborder4 = new EmptyBorder(2,2,2,2);
243
      btnColumnDataType.setBorder(emptyborder4);
244
      jpanel1.add(btnColumnDataType,cc.xy(9,3));
245

    
246
      cboColumnDataType.setName("cboColumnDataType");
247
      jpanel1.add(cboColumnDataType,cc.xywh(3,3,5,1));
248

    
249
      jpanel1.add(createPanel3(),cc.xywh(1,13,9,1));
250
      txtColumnExpression.setName("txtColumnExpression");
251
      JScrollPane jscrollpane1 = new JScrollPane();
252
      jscrollpane1.setViewportView(txtColumnExpression);
253
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
254
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
255
      jpanel1.add(jscrollpane1,cc.xy(3,11));
256

    
257
      txtColumnSize.setName("txtColumnSize");
258
      jpanel1.add(txtColumnSize,cc.xywh(3,5,7,1));
259

    
260
      lblSize.setName("lblSize");
261
      lblSize.setText("_Size");
262
      jpanel1.add(lblSize,cc.xy(1,5));
263

    
264
      lblPrecision.setName("lblPrecision");
265
      lblPrecision.setText("_Precision");
266
      jpanel1.add(lblPrecision,cc.xy(1,7));
267

    
268
      txtColumnPrecision.setName("txtColumnPrecision");
269
      jpanel1.add(txtColumnPrecision,cc.xywh(3,7,7,1));
270

    
271
      lblScale.setName("lblScale");
272
      lblScale.setText("_Scale");
273
      jpanel1.add(lblScale,cc.xy(1,9));
274

    
275
      txtColumnScale.setName("txtColumnScale");
276
      jpanel1.add(txtColumnScale,cc.xywh(3,9,7,1));
277

    
278
      addFillComponents(jpanel1,new int[]{ 2,4,5,6,7,8,9 },new int[]{ 2,4,6,8,10,12,13 });
279
      return jpanel1;
280
   }
281

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

    
289
      btnApplyChanges.setActionCommand("...");
290
      btnApplyChanges.setIcon(loadImage("src/main/resources/org/gvsig/fmap/dal/swing/impl/featurequery/common-applychanges.png"));
291
      btnApplyChanges.setName("btnApplyChanges");
292
      btnApplyChanges.setText("_Apply_changes");
293
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
294
      btnApplyChanges.setBorder(emptyborder1);
295
      jpanel1.add(btnApplyChanges,cc.xy(5,1));
296

    
297
      btnColumnMore.setActionCommand("...");
298
      btnColumnMore.setIcon(loadImage("src/main/resources/org/gvsig/fmap/dal/swing/impl/featurequery/common-more.png"));
299
      btnColumnMore.setName("btnColumnMore");
300
      btnColumnMore.setText("_More");
301
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
302
      btnColumnMore.setBorder(emptyborder2);
303
      jpanel1.add(btnColumnMore,cc.xy(3,1));
304

    
305
      addFillComponents(jpanel1,new int[]{ 1,2,4 },new int[]{ 1 });
306
      return jpanel1;
307
   }
308

    
309
   /**
310
    * Initializer
311
    */
312
   protected void initializePanel()
313
   {
314
      setLayout(new BorderLayout());
315
      add(createPanel(), BorderLayout.CENTER);
316
   }
317

    
318

    
319
}