root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / RasterTransparencyPanel.java @ 2185
History | View | Annotate | Download (10.7 KB)
1 |
package org.cresques.ui.raster; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.GridBagConstraints; |
5 |
import java.awt.GridBagLayout; |
6 |
|
7 |
import javax.swing.JCheckBox; |
8 |
import javax.swing.JLabel; |
9 |
import javax.swing.JPanel; |
10 |
import javax.swing.JSlider; |
11 |
import javax.swing.JTextField; |
12 |
|
13 |
/**
|
14 |
*
|
15 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
16 |
*
|
17 |
*/
|
18 |
public class RasterTransparencyPanel extends JPanel{ |
19 |
|
20 |
public String nom = "Transparencia"; |
21 |
FilterRasterDialogPanel parent = null;
|
22 |
public int nBands = 3; |
23 |
private String[] nameBands = {"Rojo","Verde","Azul"}; |
24 |
|
25 |
private JPanel jPanel = null; |
26 |
private JPanel jPanel1 = null; |
27 |
private JPanel jPanel2 = null; |
28 |
private JPanel jPanel3 = null; |
29 |
private JCheckBox cbTransparencia = null; |
30 |
public JLabel jLabel = null; |
31 |
private JTextField tRojo = null; |
32 |
public JLabel jLabel1 = null; |
33 |
private JTextField tVerde = null; |
34 |
public JLabel jLabel2 = null; |
35 |
private JTextField tAzul = null; |
36 |
public JPanel jPanel4 = null; |
37 |
private JCheckBox cbOpacidad = null; |
38 |
private JSlider slOpacidad = null; |
39 |
private JTextField tOpacidad = null; |
40 |
private JPanel jPanel5 = null; |
41 |
public JLabel jLabel3 = null; |
42 |
|
43 |
private JPanel jPanel6 = null; |
44 |
public JLabel jLabel4 = null; |
45 |
public RasterTransparencyPanel(FilterRasterDialogPanel parent){
|
46 |
this.parent = parent;
|
47 |
initialize(); |
48 |
} |
49 |
|
50 |
/**
|
51 |
* This method initializes this
|
52 |
*
|
53 |
* @return void
|
54 |
*/
|
55 |
private void initialize() { |
56 |
this.setLayout(new BorderLayout()); |
57 |
this.setBounds(0, 0, 445, 239); |
58 |
this.setPreferredSize(new java.awt.Dimension(445,239)); |
59 |
this.add(getJPanel(), java.awt.BorderLayout.CENTER);
|
60 |
initControls(); |
61 |
} |
62 |
|
63 |
/**
|
64 |
* Asigna el n?mero de bandas de la imagen
|
65 |
* @param nBands
|
66 |
*/
|
67 |
public void setBands(int nBands){ |
68 |
this.nBands = nBands;
|
69 |
} |
70 |
|
71 |
/**
|
72 |
* Asigna el n?mero de bandas de la imagen
|
73 |
* @param nBands
|
74 |
*/
|
75 |
public void setNameBands(String[] nameBands){ |
76 |
this.nameBands = nameBands;
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* Inicializa controles a sus valores por defecto
|
81 |
*/
|
82 |
public void initControls(){ |
83 |
this.getOpacityText().setText("100"); |
84 |
this.setActiveOpacityControl(false); |
85 |
this.setActiveTransparencyControl(false); |
86 |
|
87 |
|
88 |
|
89 |
} |
90 |
|
91 |
/**
|
92 |
* Esta funci?n no est? en uso.
|
93 |
* Oculta los controles de transparencia por bandas en caso de que haya menos de 3 bandas.
|
94 |
*
|
95 |
*/
|
96 |
public void updateTextBox(){ |
97 |
if(parent.nbands==1){ |
98 |
this.getTRojo().setVisible(true); |
99 |
this.getTVerde().setVisible(false); |
100 |
this.getTAzul().setVisible(false); |
101 |
jLabel.setVisible(true);
|
102 |
jLabel1.setVisible(false);
|
103 |
jLabel2.setVisible(false);
|
104 |
} |
105 |
|
106 |
if(parent.nbands==2){ |
107 |
this.getTRojo().setVisible(true); |
108 |
this.getTVerde().setVisible(true); |
109 |
this.getTAzul().setVisible(false); |
110 |
jLabel.setVisible(true);
|
111 |
jLabel1.setVisible(true);
|
112 |
jLabel2.setVisible(false);
|
113 |
} |
114 |
|
115 |
if(parent.nbands>=3){ |
116 |
this.getTRojo().setVisible(true); |
117 |
this.getTVerde().setVisible(true); |
118 |
this.getTAzul().setVisible(true); |
119 |
jLabel.setVisible(true);
|
120 |
jLabel1.setVisible(true);
|
121 |
jLabel2.setVisible(true);
|
122 |
} |
123 |
} |
124 |
|
125 |
/**
|
126 |
* This method initializes jPanel
|
127 |
*
|
128 |
* @return javax.swing.JPanel
|
129 |
*/
|
130 |
private JPanel getJPanel() { |
131 |
if (jPanel == null) { |
132 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
133 |
GridBagConstraints gridBagConstraints9 = new GridBagConstraints(); |
134 |
GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); |
135 |
GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); |
136 |
GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); |
137 |
GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
138 |
jPanel = new JPanel(); |
139 |
jPanel.setLayout(new GridBagLayout()); |
140 |
gridBagConstraints5.fill = java.awt.GridBagConstraints.NONE; |
141 |
gridBagConstraints5.ipady = 0;
|
142 |
gridBagConstraints5.gridheight = 1;
|
143 |
gridBagConstraints5.gridwidth = 0;
|
144 |
gridBagConstraints5.anchor = java.awt.GridBagConstraints.WEST; |
145 |
gridBagConstraints5.insets = new java.awt.Insets(0,0,0,0); |
146 |
gridBagConstraints6.gridwidth = 0;
|
147 |
gridBagConstraints6.anchor = java.awt.GridBagConstraints.WEST; |
148 |
gridBagConstraints7.gridwidth = 1;
|
149 |
gridBagConstraints7.insets = new java.awt.Insets(20,0,0,0); |
150 |
gridBagConstraints8.gridwidth = 0;
|
151 |
gridBagConstraints8.anchor = java.awt.GridBagConstraints.WEST; |
152 |
jPanel.setPreferredSize(new java.awt.Dimension(333,113)); |
153 |
gridBagConstraints9.gridx = 0;
|
154 |
gridBagConstraints9.gridy = 1;
|
155 |
gridBagConstraints9.insets = new java.awt.Insets(0,180,0,0); |
156 |
gridBagConstraints1.gridx = 0;
|
157 |
gridBagConstraints1.gridy = 2;
|
158 |
gridBagConstraints1.insets = new java.awt.Insets(0,180,0,0); |
159 |
jPanel.add(getJPanel1(), gridBagConstraints5); |
160 |
jPanel.add(getJPanel2(), gridBagConstraints6); |
161 |
jPanel.add(getJPanel3(), gridBagConstraints8); |
162 |
jPanel.add(getJPanel4(), gridBagConstraints7); |
163 |
jPanel.add(getJPanel5(), gridBagConstraints9); |
164 |
jPanel.add(getJPanel6(), gridBagConstraints1); |
165 |
} |
166 |
return jPanel;
|
167 |
} |
168 |
/**
|
169 |
* This method initializes jPanel1
|
170 |
*
|
171 |
* @return javax.swing.JPanel
|
172 |
*/
|
173 |
private JPanel getJPanel1() { |
174 |
if (jPanel1 == null) { |
175 |
jLabel = new JLabel(); |
176 |
jPanel1 = new JPanel(); |
177 |
jPanel1.setLayout(new BorderLayout()); |
178 |
jLabel.setText("Valor Rojo: ");
|
179 |
jPanel1.setPreferredSize(new java.awt.Dimension(170,42)); |
180 |
jPanel1.add(getTransparencyCheck(), java.awt.BorderLayout.NORTH); |
181 |
jPanel1.add(jLabel, java.awt.BorderLayout.WEST); |
182 |
jPanel1.add(getTRojo(), java.awt.BorderLayout.EAST); |
183 |
} |
184 |
return jPanel1;
|
185 |
} |
186 |
/**
|
187 |
* This method initializes jPanel2
|
188 |
*
|
189 |
* @return javax.swing.JPanel
|
190 |
*/
|
191 |
private JPanel getJPanel2() { |
192 |
if (jPanel2 == null) { |
193 |
jLabel1 = new JLabel(); |
194 |
jPanel2 = new JPanel(); |
195 |
jPanel2.setLayout(new BorderLayout()); |
196 |
jLabel1.setText("Valor Verde: ");
|
197 |
jPanel2.setPreferredSize(new java.awt.Dimension(170,19)); |
198 |
jPanel2.add(jLabel1, java.awt.BorderLayout.WEST); |
199 |
jPanel2.add(getTVerde(), java.awt.BorderLayout.EAST); |
200 |
} |
201 |
return jPanel2;
|
202 |
} |
203 |
/**
|
204 |
* This method initializes jPanel3
|
205 |
*
|
206 |
* @return javax.swing.JPanel
|
207 |
*/
|
208 |
private JPanel getJPanel3() { |
209 |
if (jPanel3 == null) { |
210 |
jLabel2 = new JLabel(); |
211 |
jPanel3 = new JPanel(); |
212 |
jPanel3.setLayout(new BorderLayout()); |
213 |
jLabel2.setText("Valor Azul: ");
|
214 |
jPanel3.setPreferredSize(new java.awt.Dimension(170,19)); |
215 |
jPanel3.add(jLabel2, java.awt.BorderLayout.WEST); |
216 |
jPanel3.add(getTAzul(), java.awt.BorderLayout.EAST); |
217 |
} |
218 |
return jPanel3;
|
219 |
} |
220 |
/**
|
221 |
* This method initializes jCheckBox
|
222 |
*
|
223 |
* @return javax.swing.JCheckBox
|
224 |
*/
|
225 |
public JCheckBox getTransparencyCheck() { |
226 |
if (cbTransparencia == null) { |
227 |
cbTransparencia = new JCheckBox(); |
228 |
cbTransparencia.setText("Transparencia");
|
229 |
} |
230 |
return cbTransparencia;
|
231 |
} |
232 |
/**
|
233 |
* This method initializes jTextField
|
234 |
*
|
235 |
* @return javax.swing.JTextField
|
236 |
*/
|
237 |
public JTextField getTRojo() { |
238 |
if (tRojo == null) { |
239 |
tRojo = new JTextField(); |
240 |
tRojo.setPreferredSize(new java.awt.Dimension(80,19)); |
241 |
} |
242 |
return tRojo;
|
243 |
} |
244 |
/**
|
245 |
* This method initializes jTextField1
|
246 |
*
|
247 |
* @return javax.swing.JTextField
|
248 |
*/
|
249 |
public JTextField getTVerde() { |
250 |
if (tVerde == null) { |
251 |
tVerde = new JTextField(); |
252 |
tVerde.setPreferredSize(new java.awt.Dimension(80,19)); |
253 |
} |
254 |
return tVerde;
|
255 |
} |
256 |
/**
|
257 |
* This method initializes jTextField2
|
258 |
*
|
259 |
* @return javax.swing.JTextField
|
260 |
*/
|
261 |
public JTextField getTAzul() { |
262 |
if (tAzul == null) { |
263 |
tAzul = new JTextField(); |
264 |
tAzul.setPreferredSize(new java.awt.Dimension(80,19)); |
265 |
} |
266 |
return tAzul;
|
267 |
} |
268 |
/**
|
269 |
* This method initializes jPanel4
|
270 |
*
|
271 |
* @return javax.swing.JPanel
|
272 |
*/
|
273 |
private JPanel getJPanel4() { |
274 |
if (jPanel4 == null) { |
275 |
jPanel4 = new JPanel(); |
276 |
jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
277 |
jPanel4.setPreferredSize(new java.awt.Dimension(415,35)); |
278 |
jPanel4.add(getOpacityCheck(), null);
|
279 |
jPanel4.add(getOpacitySlider(), null);
|
280 |
jPanel4.add(getOpacityText(), null);
|
281 |
} |
282 |
return jPanel4;
|
283 |
} |
284 |
/**
|
285 |
* This method initializes jCheckBox1
|
286 |
*
|
287 |
* @return javax.swing.JCheckBox
|
288 |
*/
|
289 |
public JCheckBox getOpacityCheck() { |
290 |
if (cbOpacidad == null) { |
291 |
cbOpacidad = new JCheckBox(); |
292 |
cbOpacidad.setText("Opacidad");
|
293 |
} |
294 |
return cbOpacidad;
|
295 |
} |
296 |
/**
|
297 |
* This method initializes jSlider
|
298 |
*
|
299 |
* @return javax.swing.JSlider
|
300 |
*/
|
301 |
public JSlider getOpacitySlider() { |
302 |
if (slOpacidad == null) { |
303 |
slOpacidad = new JSlider(); |
304 |
slOpacidad.setPreferredSize(new java.awt.Dimension(280,16)); |
305 |
} |
306 |
return slOpacidad;
|
307 |
} |
308 |
/**
|
309 |
* This method initializes jTextField3
|
310 |
*
|
311 |
* @return javax.swing.JTextField
|
312 |
*/
|
313 |
public JTextField getOpacityText() { |
314 |
if (tOpacidad == null) { |
315 |
tOpacidad = new JTextField(); |
316 |
tOpacidad.setPreferredSize(new java.awt.Dimension(30,19)); |
317 |
} |
318 |
return tOpacidad;
|
319 |
} |
320 |
/**
|
321 |
* This method initializes jPanel5
|
322 |
*
|
323 |
* @return javax.swing.JPanel
|
324 |
*/
|
325 |
private JPanel getJPanel5() { |
326 |
if (jPanel5 == null) { |
327 |
jLabel3 = new JLabel(); |
328 |
jPanel5 = new JPanel(); |
329 |
jLabel3.setText("Usa un rango: 1,3,5:8");
|
330 |
jPanel5.setPreferredSize(new java.awt.Dimension(161,21)); |
331 |
jPanel5.add(jLabel3, null);
|
332 |
} |
333 |
return jPanel5;
|
334 |
} |
335 |
|
336 |
/**
|
337 |
* Activa/Desactiva los controles de opacidad
|
338 |
* @param active
|
339 |
*/
|
340 |
public void setActiveOpacityControl(boolean active){ |
341 |
this.getOpacityCheck().setSelected(active);
|
342 |
this.getOpacitySlider().setEnabled(active);
|
343 |
this.getOpacityText().setEnabled(active);
|
344 |
} |
345 |
|
346 |
/**
|
347 |
* Activa/Desactiva los controles de transparencia
|
348 |
* @param active
|
349 |
*/
|
350 |
public void setActiveTransparencyControl(boolean active){ |
351 |
this.getTransparencyCheck().setSelected(active);
|
352 |
this.getTRojo().setEnabled(active);
|
353 |
if((active && parent.nbands>=2) || !active) |
354 |
this.getTVerde().setEnabled(active);
|
355 |
else
|
356 |
this.getTVerde().setEnabled(false); |
357 |
|
358 |
if((active && parent.nbands>=3) || !active) |
359 |
this.getTAzul().setEnabled(active);
|
360 |
else
|
361 |
this.getTAzul().setEnabled(false); |
362 |
} |
363 |
/**
|
364 |
* Asigna el valor de opacidad a los controles de la ventana
|
365 |
* para que cuando esta se abra tenga los valores seleccionados en la
|
366 |
* imagen.
|
367 |
* @param alpha
|
368 |
*/
|
369 |
public void setOpacity(int alpha){ |
370 |
int opacityPercent = (int)((alpha*100)/255); |
371 |
this.getOpacityText().setText(String.valueOf(opacityPercent)); |
372 |
this.getOpacitySlider().setValue(opacityPercent);
|
373 |
this.setActiveOpacityControl(true); |
374 |
if(opacityPercent==100) |
375 |
this.setActiveOpacityControl(false); |
376 |
} |
377 |
|
378 |
/**
|
379 |
* This method initializes jPanel6
|
380 |
*
|
381 |
* @return javax.swing.JPanel
|
382 |
*/
|
383 |
private JPanel getJPanel6() { |
384 |
if (jPanel6 == null) { |
385 |
jLabel4 = new JLabel(); |
386 |
jPanel6 = new JPanel(); |
387 |
jPanel6.setPreferredSize(new java.awt.Dimension(161,20)); |
388 |
jLabel4.setText("Valor de pixel: 0 a 255");
|
389 |
jPanel6.add(jLabel4, null);
|
390 |
} |
391 |
return jPanel6;
|
392 |
} |
393 |
} // @jve:decl-index=0:visual-constraint="36,15"
|