Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / org.gvsig.fmap.mapcontext.swing / org.gvsig.fmap.mapcontext.swing.impl / src / main / java / org / gvsig / fmap / mapcontext / raster / swing / impl / transparency / TransparencyPanelView.java @ 43803

History | View | Annotate | Download (12.4 KB)

1
package org.gvsig.fmap.mapcontext.raster.swing.impl.transparency;
2

    
3
import com.jeta.forms.components.separator.TitledSeparator;
4
import com.jeta.open.i18n.I18NUtils;
5
import com.jgoodies.forms.layout.CellConstraints;
6
import com.jgoodies.forms.layout.FormLayout;
7
import java.awt.BorderLayout;
8
import java.awt.Color;
9
import java.awt.ComponentOrientation;
10
import java.awt.Container;
11
import java.awt.Dimension;
12
import javax.swing.Box;
13
import javax.swing.ButtonGroup;
14
import javax.swing.ImageIcon;
15
import javax.swing.JButton;
16
import javax.swing.JCheckBox;
17
import javax.swing.JColorChooser;
18
import javax.swing.JFrame;
19
import javax.swing.JList;
20
import javax.swing.JPanel;
21
import javax.swing.JRadioButton;
22
import javax.swing.JScrollPane;
23
import javax.swing.JSlider;
24
import javax.swing.JSpinner;
25
import javax.swing.border.LineBorder;
26

    
27

    
28
public class TransparencyPanelView extends JPanel
29
{
30
   JButton btnAdd = new JButton();
31
   JButton btnRemove = new JButton();
32
   JButton btnExternalTool0 = new JButton();
33
   JCheckBox chkNoDataTransparency = new JCheckBox();
34
   JColorChooser colorChooser = new JColorChooser();
35
   JCheckBox chkActivateOpacity = new JCheckBox();
36
   JSlider sldOpacity = new JSlider();
37
   JSpinner spOpacity = new JSpinner();
38
   TitledSeparator lblOpacity = new TitledSeparator();
39
   TitledSeparator lblPixelTransparency = new TitledSeparator();
40
   JCheckBox chkActivatePixelTransparency = new JCheckBox();
41
   JButton btnExternalTool1 = new JButton();
42
   JButton btnExternalTool2 = new JButton();
43
   JRadioButton rbtnAnd = new JRadioButton();
44
   ButtonGroup buttongroup1 = new ButtonGroup();
45
   JRadioButton rbtnOr = new JRadioButton();
46
   JCheckBox chkRed = new JCheckBox();
47
   JCheckBox chkGreen = new JCheckBox();
48
   JCheckBox chkBlue = new JCheckBox();
49
   JCheckBox chkAlpha = new JCheckBox();
50
   JList lstTransparencyRanges = new JList();
51

    
52
   /**
53
    * Default constructor
54
    */
55
   public TransparencyPanelView()
56
   {
57
      initializePanel();
58
   }
59

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

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

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

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

    
100
   }
101

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

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

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

    
146
      btnAdd.setActionCommand("_add");
147
      btnAdd.setEnabled(false);
148
      btnAdd.setName("btnAdd");
149
      btnAdd.setText("_add");
150
      btnAdd.setToolTipText("_add_color");
151
      jpanel1.add(btnAdd,cc.xy(5,13));
152

    
153
      btnRemove.setActionCommand("_remove");
154
      btnRemove.setEnabled(false);
155
      btnRemove.setName("btnRemove");
156
      btnRemove.setText("_remove");
157
      btnRemove.setToolTipText("_remove_color");
158
      jpanel1.add(btnRemove,cc.xy(5,15));
159

    
160
      btnExternalTool0.setActionCommand("JButton");
161
      btnExternalTool0.setEnabled(false);
162
      btnExternalTool0.setName("btnExternalTool0");
163
      btnExternalTool0.setText("_external_tool");
164
      btnExternalTool0.setToolTipText("_external_tool");
165
      jpanel1.add(btnExternalTool0,cc.xy(5,17));
166

    
167
      chkNoDataTransparency.setActionCommand("JCheckBox");
168
      chkNoDataTransparency.setName("chkNoDataTransparency");
169
      chkNoDataTransparency.setText("_treats_nodata_values_as_transparent");
170
      chkNoDataTransparency.setToolTipText("_treats_nodata_values_as_transparent");
171
      jpanel1.add(chkNoDataTransparency,cc.xywh(3,3,5,1));
172

    
173
      colorChooser.setEnabled(false);
174
      colorChooser.setName("colorChooser");
175
      colorChooser.setToolTipText("_color_chooser");
176
      jpanel1.add(colorChooser,cc.xywh(3,13,1,13));
177

    
178
      chkActivateOpacity.setActionCommand("JCheckBox");
179
      chkActivateOpacity.setName("chkActivateOpacity");
180
      chkActivateOpacity.setText("_activate");
181
      chkActivateOpacity.setToolTipText("_activate_opacity");
182
      jpanel1.add(chkActivateOpacity,cc.xywh(3,7,5,1));
183

    
184
      sldOpacity.setEnabled(false);
185
      sldOpacity.setMajorTickSpacing(20);
186
      sldOpacity.setMaximum(255);
187
      sldOpacity.setName("sldOpacity");
188
      sldOpacity.setPaintLabels(true);
189
      sldOpacity.setPaintTicks(true);
190
      sldOpacity.setValue(255);
191
      jpanel1.add(sldOpacity,cc.xy(3,8));
192

    
193
      spOpacity.setEnabled(false);
194
      spOpacity.setName("spOpacity");
195
      spOpacity.setToolTipText("_red");
196
      jpanel1.add(spOpacity,cc.xy(5,8));
197

    
198
      TitledSeparator titledseparator1 = new TitledSeparator();
199
      titledseparator1.setText("NoData");
200
      titledseparator1.setToolTipText("NoData");
201
      jpanel1.add(titledseparator1,cc.xywh(2,2,7,1));
202

    
203
      lblOpacity.setName("lblOpacity");
204
      lblOpacity.setText("_opacity");
205
      lblOpacity.setToolTipText("_opacity");
206
      jpanel1.add(lblOpacity,cc.xywh(2,5,7,1));
207

    
208
      lblPixelTransparency.setName("lblPixelTransparency");
209
      lblPixelTransparency.setText("_pixel_transparency");
210
      jpanel1.add(lblPixelTransparency,cc.xywh(2,10,7,1));
211

    
212
      chkActivatePixelTransparency.setActionCommand("JCheckBox");
213
      chkActivatePixelTransparency.setName("chkActivatePixelTransparency");
214
      chkActivatePixelTransparency.setText("_activate");
215
      chkActivatePixelTransparency.setToolTipText("_activate_pixel_transparency");
216
      jpanel1.add(chkActivatePixelTransparency,cc.xy(3,12));
217

    
218
      btnExternalTool1.setActionCommand("JButton");
219
      btnExternalTool1.setEnabled(false);
220
      btnExternalTool1.setName("btnExternalTool1");
221
      btnExternalTool1.setText("_external_tool");
222
      btnExternalTool1.setToolTipText("_external_tool");
223
      jpanel1.add(btnExternalTool1,cc.xy(5,19));
224

    
225
      btnExternalTool2.setActionCommand("JButton");
226
      btnExternalTool2.setEnabled(false);
227
      btnExternalTool2.setName("btnExternalTool2");
228
      btnExternalTool2.setText("_external_tool");
229
      btnExternalTool2.setToolTipText("_external_tool");
230
      jpanel1.add(btnExternalTool2,cc.xy(5,21));
231

    
232
      jpanel1.add(createPanel1(),cc.xy(5,23));
233
      jpanel1.add(createPanel2(),cc.xy(5,25));
234
      lstTransparencyRanges.setName("lstTransparencyRanges");
235
      lstTransparencyRanges.setSelectionMode(0);
236
      JScrollPane jscrollpane1 = new JScrollPane();
237
      jscrollpane1.setViewportView(lstTransparencyRanges);
238
      jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
239
      jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
240
      jpanel1.add(jscrollpane1,cc.xywh(7,13,1,13));
241

    
242
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8,9 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26 });
243
      return jpanel1;
244
   }
245

    
246
   public JPanel createPanel1()
247
   {
248
      JPanel jpanel1 = new JPanel();
249
      LineBorder lineborder1 = new LineBorder(new Color(0,0,0),1,false);
250
      jpanel1.setBorder(lineborder1);
251
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
252
      CellConstraints cc = new CellConstraints();
253
      jpanel1.setLayout(formlayout1);
254

    
255
      rbtnAnd.setActionCommand("AND");
256
      rbtnAnd.setEnabled(false);
257
      rbtnAnd.setName("rbtnAnd");
258
      rbtnAnd.setSelected(true);
259
      rbtnAnd.setText("_and");
260
      rbtnAnd.setToolTipText("_it_makes_transparent_the_pixels_whose_color_matches_all_the_channels_of_the_selected_color");
261
      buttongroup1.add(rbtnAnd);
262
      jpanel1.add(rbtnAnd,new CellConstraints(2,2,1,1,CellConstraints.DEFAULT,CellConstraints.TOP));
263

    
264
      rbtnOr.setActionCommand("OR");
265
      rbtnOr.setEnabled(false);
266
      rbtnOr.setName("rbtnOr");
267
      rbtnOr.setText("_or");
268
      rbtnOr.setToolTipText("_it_makes_transparent_the_pixels_whose_color_has_some_channel_that_matches_some_channel_of_the_selected_color");
269
      buttongroup1.add(rbtnOr);
270
      jpanel1.add(rbtnOr,cc.xy(2,4));
271

    
272
      addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5 });
273
      return jpanel1;
274
   }
275

    
276
   public JPanel createPanel2()
277
   {
278
      JPanel jpanel1 = new JPanel();
279
      LineBorder lineborder1 = new LineBorder(new Color(0,0,0),1,false);
280
      jpanel1.setBorder(lineborder1);
281
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
282
      CellConstraints cc = new CellConstraints();
283
      jpanel1.setLayout(formlayout1);
284

    
285
      chkRed.setActionCommand("_red");
286
      chkRed.setEnabled(false);
287
      chkRed.setName("chkRed");
288
      chkRed.setSelected(true);
289
      chkRed.setText("_red");
290
      jpanel1.add(chkRed,cc.xy(2,2));
291

    
292
      chkGreen.setActionCommand("_green");
293
      chkGreen.setEnabled(false);
294
      chkGreen.setName("chkGreen");
295
      chkGreen.setSelected(true);
296
      chkGreen.setText("_green");
297
      jpanel1.add(chkGreen,cc.xy(2,4));
298

    
299
      chkBlue.setActionCommand("_blue");
300
      chkBlue.setEnabled(false);
301
      chkBlue.setName("chkBlue");
302
      chkBlue.setSelected(true);
303
      chkBlue.setText("_blue");
304
      jpanel1.add(chkBlue,new CellConstraints(2,6,1,1,CellConstraints.DEFAULT,CellConstraints.TOP));
305

    
306
      chkAlpha.setActionCommand("_alpha");
307
      chkAlpha.setEnabled(false);
308
      chkAlpha.setName("chkAlpha");
309
      chkAlpha.setText("_alpha");
310
      jpanel1.add(chkAlpha,cc.xy(2,8));
311

    
312
      addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,2,3,4,5,6,7,8,9 });
313
      return jpanel1;
314
   }
315

    
316
   /**
317
    * Initializer
318
    */
319
   protected void initializePanel()
320
   {
321
      setLayout(new BorderLayout());
322
      add(createPanel(), BorderLayout.CENTER);
323
   }
324

    
325

    
326
}