Statistics
| Revision:

root / org.gvsig.legend.heatmap / trunk / org.gvsig.legend.heatmap / org.gvsig.legend.heatmap.swing / org.gvsig.legend.heatmap.swing.impl / src / main / java / org / gvsig / legend / heatmap / swing / impl / DefaultHeatmapLegendEditorView.java @ 1766

History | View | Annotate | Download (13.3 KB)

1
package org.gvsig.legend.heatmap.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.ButtonGroup;
13
import javax.swing.ImageIcon;
14
import javax.swing.JButton;
15
import javax.swing.JCheckBox;
16
import javax.swing.JComboBox;
17
import javax.swing.JFrame;
18
import javax.swing.JLabel;
19
import javax.swing.JPanel;
20
import javax.swing.JRadioButton;
21
import javax.swing.JSlider;
22
import javax.swing.JSpinner;
23
import javax.swing.JTextField;
24

    
25

    
26
public class DefaultHeatmapLegendEditorView extends JPanel
27
{
28
   JLabel lblPixels = new JLabel();
29
   JSpinner spnDistance = new JSpinner();
30
   JRadioButton rdbUseColorRamp = new JRadioButton();
31
   ButtonGroup buttongroup1 = new ButtonGroup();
32
   JLabel lblDistance = new JLabel();
33
   JLabel lblHotColor = new JLabel();
34
   JLabel lblColdColor = new JLabel();
35
   JTextField txtHotColorLabel = new JTextField();
36
   JButton btnHotColor = new JButton();
37
   JLabel lblHotColorAlpha = new JLabel();
38
   JSlider sldHotColorAlpha = new JSlider();
39
   JButton btnColdColor = new JButton();
40
   JLabel lblColdColorAlpha = new JLabel();
41
   JSlider sldColdColorAlpha = new JSlider();
42
   JTextField txtColdColorLabel = new JTextField();
43
   JLabel lblNumberOfColors = new JLabel();
44
   JSpinner spnNumberOfColors = new JSpinner();
45
   JRadioButton rdbUseColorTable = new JRadioButton();
46
   JComboBox cboColorTable = new JComboBox();
47
   JCheckBox chkColorTableUseAlpha = new JCheckBox();
48
   JLabel lblHotColorTransparency = new JLabel();
49
   JLabel lblColdColorTransparency = new JLabel();
50
   JSlider sldColorTableHotAlpha = new JSlider();
51
   JSlider sldColorTableColdAlpha = new JSlider();
52
   JCheckBox chkUseField = new JCheckBox();
53
   JComboBox cboFields = new JComboBox();
54

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

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

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

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

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

    
103
   }
104

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

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

    
142
   public JPanel createPanel()
143
   {
144
      JPanel jpanel1 = new JPanel();
145
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:4DLU:NONE,CENTER:DEFAULT:NONE,CENTER:4DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU: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");
146
      CellConstraints cc = new CellConstraints();
147
      jpanel1.setLayout(formlayout1);
148

    
149
      jpanel1.add(createPanel1(),cc.xy(4,2));
150
      rdbUseColorRamp.setActionCommand("Use color ramp");
151
      rdbUseColorRamp.setName("rdbUseColorRamp");
152
      rdbUseColorRamp.setText("Use color ramp");
153
      buttongroup1.add(rdbUseColorRamp);
154
      jpanel1.add(rdbUseColorRamp,cc.xy(2,4));
155

    
156
      lblDistance.setName("lblDistance");
157
      lblDistance.setText("Distance");
158
      jpanel1.add(lblDistance,cc.xy(2,2));
159

    
160
      jpanel1.add(createPanel2(),cc.xywh(2,6,3,1));
161
      rdbUseColorTable.setActionCommand("Use color table");
162
      rdbUseColorTable.setName("rdbUseColorTable");
163
      rdbUseColorTable.setText("Use color table");
164
      buttongroup1.add(rdbUseColorTable);
165
      jpanel1.add(rdbUseColorTable,cc.xywh(2,8,3,1));
166

    
167
      jpanel1.add(createPanel5(),cc.xywh(2,10,3,1));
168
      chkUseField.setActionCommand("Use a field to calculate the heat map.");
169
      chkUseField.setName("chkUseField");
170
      chkUseField.setText("Use a field to weight the heat map");
171
      jpanel1.add(chkUseField,cc.xywh(2,12,3,1));
172

    
173
      jpanel1.add(createPanel7(),cc.xywh(2,14,3,1));
174
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 });
175
      return jpanel1;
176
   }
177

    
178
   public JPanel createPanel1()
179
   {
180
      JPanel jpanel1 = new JPanel();
181
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
182
      CellConstraints cc = new CellConstraints();
183
      jpanel1.setLayout(formlayout1);
184

    
185
      lblPixels.setName("lblPixels");
186
      lblPixels.setText("pixels");
187
      jpanel1.add(lblPixels,cc.xy(3,1));
188

    
189
      spnDistance.setName("spnDistance");
190
      jpanel1.add(spnDistance,cc.xy(1,1));
191

    
192
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
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:NONE,FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:NONE,CENTER:4DLU:NONE,CENTER:DEFAULT:NONE,CENTER:4DLU:NONE,CENTER:DEFAULT:NONE");
200
      CellConstraints cc = new CellConstraints();
201
      jpanel1.setLayout(formlayout1);
202

    
203
      lblHotColor.setName("lblHotColor");
204
      lblHotColor.setText("Hot color");
205
      jpanel1.add(lblHotColor,cc.xy(2,3));
206

    
207
      lblColdColor.setName("lblColdColor");
208
      lblColdColor.setText("Cold color");
209
      jpanel1.add(lblColdColor,cc.xy(2,5));
210

    
211
      jpanel1.add(createPanel3(),cc.xy(4,3));
212
      jpanel1.add(createPanel4(),cc.xy(4,5));
213
      lblNumberOfColors.setName("lblNumberOfColors");
214
      lblNumberOfColors.setText("Number of colors");
215
      jpanel1.add(lblNumberOfColors,cc.xy(2,1));
216

    
217
      spnNumberOfColors.setName("spnNumberOfColors");
218
      jpanel1.add(spnNumberOfColors,cc.xy(4,1));
219

    
220
      addFillComponents(jpanel1,new int[]{ 1,3 },new int[]{ 1,2,3,4,5 });
221
      return jpanel1;
222
   }
223

    
224
   public JPanel createPanel3()
225
   {
226
      JPanel jpanel1 = new JPanel();
227
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,LEFT:DEFAULT:NONE","CENTER:DEFAULT:NONE");
228
      CellConstraints cc = new CellConstraints();
229
      jpanel1.setLayout(formlayout1);
230

    
231
      txtHotColorLabel.setBackground(new Color(236,233,216));
232
      txtHotColorLabel.setEditable(false);
233
      txtHotColorLabel.setName("txtHotColorLabel");
234
      txtHotColorLabel.setHorizontalAlignment(JTextField.RIGHT);
235
      jpanel1.add(txtHotColorLabel,cc.xy(1,1));
236

    
237
      btnHotColor.setActionCommand("...");
238
      btnHotColor.setName("btnHotColor");
239
      btnHotColor.setText("...");
240
      jpanel1.add(btnHotColor,cc.xy(3,1));
241

    
242
      lblHotColorAlpha.setName("lblHotColorAlpha");
243
      lblHotColorAlpha.setText("Alpha");
244
      jpanel1.add(lblHotColorAlpha,cc.xy(5,1));
245

    
246
      sldHotColorAlpha.setMajorTickSpacing(20);
247
      sldHotColorAlpha.setMaximum(255);
248
      sldHotColorAlpha.setName("sldHotColorAlpha");
249
      sldHotColorAlpha.setValue(255);
250
      jpanel1.add(sldHotColorAlpha,cc.xy(7,1));
251

    
252
      addFillComponents(jpanel1,new int[]{ 2,4,6 },new int[0]);
253
      return jpanel1;
254
   }
255

    
256
   public JPanel createPanel4()
257
   {
258
      JPanel jpanel1 = new JPanel();
259
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,LEFT:DEFAULT:NONE","CENTER:DEFAULT:NONE");
260
      CellConstraints cc = new CellConstraints();
261
      jpanel1.setLayout(formlayout1);
262

    
263
      btnColdColor.setActionCommand("...");
264
      btnColdColor.setName("btnColdColor");
265
      btnColdColor.setText("...");
266
      jpanel1.add(btnColdColor,cc.xy(3,1));
267

    
268
      lblColdColorAlpha.setName("lblColdColorAlpha");
269
      lblColdColorAlpha.setText("Alpha");
270
      jpanel1.add(lblColdColorAlpha,cc.xy(5,1));
271

    
272
      sldColdColorAlpha.setMajorTickSpacing(20);
273
      sldColdColorAlpha.setMaximum(255);
274
      sldColdColorAlpha.setName("sldColdColorAlpha");
275
      sldColdColorAlpha.setValue(0);
276
      jpanel1.add(sldColdColorAlpha,cc.xy(7,1));
277

    
278
      txtColdColorLabel.setBackground(new Color(236,233,216));
279
      txtColdColorLabel.setEditable(false);
280
      txtColdColorLabel.setName("txtColdColorLabel");
281
      txtColdColorLabel.setHorizontalAlignment(JTextField.RIGHT);
282
      jpanel1.add(txtColdColorLabel,cc.xy(1,1));
283

    
284
      addFillComponents(jpanel1,new int[]{ 2,4,6 },new int[0]);
285
      return jpanel1;
286
   }
287

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

    
295
      cboColorTable.setName("cboColorTable");
296
      jpanel1.add(cboColorTable,cc.xy(4,1));
297

    
298
      JLabel jlabel1 = new JLabel();
299
      jlabel1.setText("Color table");
300
      jpanel1.add(jlabel1,cc.xy(2,1));
301

    
302
      chkColorTableUseAlpha.setActionCommand("Use transparency");
303
      chkColorTableUseAlpha.setName("chkColorTableUseAlpha");
304
      chkColorTableUseAlpha.setSelected(true);
305
      chkColorTableUseAlpha.setText("Use transparency");
306
      jpanel1.add(chkColorTableUseAlpha,cc.xy(2,3));
307

    
308
      jpanel1.add(createPanel6(),cc.xywh(2,5,3,1));
309
      addFillComponents(jpanel1,new int[]{ 1,3,5 },new int[]{ 1,2,3,4,5,6 });
310
      return jpanel1;
311
   }
312

    
313
   public JPanel createPanel6()
314
   {
315
      JPanel jpanel1 = new JPanel();
316
      FormLayout formlayout1 = new FormLayout("FILL:8DLU:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:NONE,CENTER:4DLU:NONE,CENTER:DEFAULT:NONE");
317
      CellConstraints cc = new CellConstraints();
318
      jpanel1.setLayout(formlayout1);
319

    
320
      lblHotColorTransparency.setName("lblHotColorTransparency");
321
      lblHotColorTransparency.setText("Hot color transparency");
322
      jpanel1.add(lblHotColorTransparency,cc.xy(2,1));
323

    
324
      lblColdColorTransparency.setName("lblColdColorTransparency");
325
      lblColdColorTransparency.setText("Cold color transparency");
326
      jpanel1.add(lblColdColorTransparency,cc.xy(2,3));
327

    
328
      sldColorTableHotAlpha.setMajorTickSpacing(20);
329
      sldColorTableHotAlpha.setMaximum(255);
330
      sldColorTableHotAlpha.setName("sldColorTableHotAlpha");
331
      sldColorTableHotAlpha.setValue(126);
332
      jpanel1.add(sldColorTableHotAlpha,cc.xy(4,1));
333

    
334
      sldColorTableColdAlpha.setMajorTickSpacing(20);
335
      sldColorTableColdAlpha.setMaximum(255);
336
      sldColorTableColdAlpha.setName("sldColorTableColdAlpha");
337
      sldColorTableColdAlpha.setValue(126);
338
      jpanel1.add(sldColorTableColdAlpha,cc.xy(4,3));
339

    
340
      addFillComponents(jpanel1,new int[]{ 1,3 },new int[]{ 1,2,3 });
341
      return jpanel1;
342
   }
343

    
344
   public JPanel createPanel7()
345
   {
346
      JPanel jpanel1 = new JPanel();
347
      FormLayout formlayout1 = new FormLayout("FILL:8DLU:NONE,FILL:DEFAULT:GROW(1.0)","CENTER:DEFAULT:NONE");
348
      CellConstraints cc = new CellConstraints();
349
      jpanel1.setLayout(formlayout1);
350

    
351
      cboFields.setName("cboFields");
352
      jpanel1.add(cboFields,cc.xy(2,1));
353

    
354
      addFillComponents(jpanel1,new int[]{ 1 },new int[]{ 1 });
355
      return jpanel1;
356
   }
357

    
358
   /**
359
    * Initializer
360
    */
361
   protected void initializePanel()
362
   {
363
      setLayout(new BorderLayout());
364
      add(createPanel(), BorderLayout.CENTER);
365
   }
366

    
367

    
368
}