svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / RasterTransparencyPanel.java @ 2312
History | View | Annotate | Download (12.6 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.ui.raster; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Color; |
28 |
import java.awt.GridBagConstraints; |
29 |
import java.awt.GridBagLayout; |
30 |
|
31 |
import javax.swing.JCheckBox; |
32 |
import javax.swing.JLabel; |
33 |
import javax.swing.JPanel; |
34 |
import javax.swing.JSlider; |
35 |
import javax.swing.JTextField; |
36 |
|
37 |
/**
|
38 |
* Dialogo para asignar la transparencia por pixel y global al raster
|
39 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
40 |
*/
|
41 |
public class RasterTransparencyPanel extends JPanel{ |
42 |
|
43 |
/**
|
44 |
* Nombre del panel
|
45 |
*/
|
46 |
public String nom = "Transparencia"; |
47 |
FilterRasterDialogPanel parent = null;
|
48 |
|
49 |
/**
|
50 |
* N?mero de bandas del raster
|
51 |
*/
|
52 |
public int nBands = 3; |
53 |
private String[] nameBands = {"Rojo","Verde","Azul"}; |
54 |
private JPanel jPanel = null; |
55 |
private JPanel jPanel1 = null; |
56 |
private JPanel jPanel2 = null; |
57 |
private JPanel jPanel3 = null; |
58 |
private JCheckBox cbTransparencia = null; |
59 |
|
60 |
/**
|
61 |
* Label p?blico para traducci?n
|
62 |
*/
|
63 |
public JLabel redValue = null; |
64 |
private JTextFieldExt tRojo = null; |
65 |
|
66 |
/**
|
67 |
* Label p?blico para traducci?n
|
68 |
*/
|
69 |
public JLabel greenValue = null; |
70 |
|
71 |
/**
|
72 |
* Label p?blico para traducci?n
|
73 |
*/
|
74 |
public JLabel blueValue = null; |
75 |
|
76 |
/**
|
77 |
* Label p?blico para traducci?n
|
78 |
*/
|
79 |
public JPanel jPanel4 = null; |
80 |
|
81 |
/**
|
82 |
* Label p?blico para traducci?n
|
83 |
*/
|
84 |
public JLabel range = null; |
85 |
|
86 |
/**
|
87 |
* Label p?blico para traducci?n
|
88 |
*/
|
89 |
public JLabel jLabel4 = null; |
90 |
private JTextFieldExt tVerde = null; |
91 |
private JTextFieldExt tAzul = null; |
92 |
private JCheckBox cbOpacidad = null; |
93 |
private JSlider slOpacidad = null; |
94 |
private JTextField tOpacidad = null; |
95 |
private JPanel jPanel5 = null; |
96 |
private JPanel jPanel6 = null; |
97 |
|
98 |
|
99 |
public class JTextFieldExt extends JTextField{ |
100 |
|
101 |
private Color color = null; |
102 |
|
103 |
public JTextFieldExt(Color color){ |
104 |
this.color=color;
|
105 |
} |
106 |
|
107 |
public JTextFieldExt(){
|
108 |
super();
|
109 |
} |
110 |
|
111 |
public void setEnabled(boolean enabled){ |
112 |
super.setEnabled(enabled);
|
113 |
if(!enabled){
|
114 |
if(color == null) |
115 |
this.setBackground(new Color(210, 210, 210)); |
116 |
else
|
117 |
this.setBackground(color);
|
118 |
}else
|
119 |
this.setBackground(new Color(255, 255, 255)); |
120 |
} |
121 |
} |
122 |
|
123 |
/**
|
124 |
* Constructor. Asigna la variable panel que contiene este
|
125 |
* @param parent FilterRasterDialogPanel
|
126 |
*/
|
127 |
public RasterTransparencyPanel(FilterRasterDialogPanel parent){
|
128 |
this.parent = parent;
|
129 |
initialize(); |
130 |
} |
131 |
|
132 |
/**
|
133 |
* This method initializes this
|
134 |
*
|
135 |
* @return void
|
136 |
*/
|
137 |
private void initialize() { |
138 |
this.setLayout(new BorderLayout()); |
139 |
this.setBounds(0, 0, 445, 239); |
140 |
this.setPreferredSize(new java.awt.Dimension(445,239)); |
141 |
this.add(getJPanel(), java.awt.BorderLayout.CENTER);
|
142 |
initControls(); |
143 |
} |
144 |
|
145 |
/**
|
146 |
* Asigna el n?mero de bandas de la imagen
|
147 |
* @param nBands
|
148 |
*/
|
149 |
public void setBands(int nBands){ |
150 |
this.nBands = nBands;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* Asigna el n?mero de bandas de la imagen
|
155 |
* @param nBands
|
156 |
*/
|
157 |
public void setNameBands(String[] nameBands){ |
158 |
this.nameBands = nameBands;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* Inicializa controles a sus valores por defecto
|
163 |
*/
|
164 |
public void initControls(){ |
165 |
this.getOpacityText().setText("100"); |
166 |
this.setActiveOpacityControl(false); |
167 |
this.setActiveTransparencyControl(false); |
168 |
} |
169 |
|
170 |
/**
|
171 |
* Esta funci?n no est? en uso.
|
172 |
* Oculta los controles de transparencia por bandas en caso de que haya menos de 3 bandas.
|
173 |
*
|
174 |
*/
|
175 |
public void updateTextBox(){ |
176 |
if(parent.nbands==1){ |
177 |
this.getTRojo().setVisible(true); |
178 |
this.getTVerde().setVisible(false); |
179 |
this.getTAzul().setVisible(false); |
180 |
redValue.setVisible(true);
|
181 |
greenValue.setVisible(false);
|
182 |
blueValue.setVisible(false);
|
183 |
} |
184 |
|
185 |
if(parent.nbands==2){ |
186 |
this.getTRojo().setVisible(true); |
187 |
this.getTVerde().setVisible(true); |
188 |
this.getTAzul().setVisible(false); |
189 |
redValue.setVisible(true);
|
190 |
greenValue.setVisible(true);
|
191 |
blueValue.setVisible(false);
|
192 |
} |
193 |
|
194 |
if(parent.nbands>=3){ |
195 |
this.getTRojo().setVisible(true); |
196 |
this.getTVerde().setVisible(true); |
197 |
this.getTAzul().setVisible(true); |
198 |
redValue.setVisible(true);
|
199 |
greenValue.setVisible(true);
|
200 |
blueValue.setVisible(true);
|
201 |
} |
202 |
} |
203 |
|
204 |
/**
|
205 |
* This method initializes jPanel
|
206 |
*
|
207 |
* @return javax.swing.JPanel
|
208 |
*/
|
209 |
private JPanel getJPanel() { |
210 |
if (jPanel == null) { |
211 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
212 |
GridBagConstraints gridBagConstraints9 = new GridBagConstraints(); |
213 |
GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); |
214 |
GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); |
215 |
GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); |
216 |
GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
217 |
jPanel = new JPanel(); |
218 |
jPanel.setLayout(new GridBagLayout()); |
219 |
gridBagConstraints5.fill = java.awt.GridBagConstraints.NONE; |
220 |
gridBagConstraints5.ipady = 0;
|
221 |
gridBagConstraints5.gridheight = 1;
|
222 |
gridBagConstraints5.gridwidth = 0;
|
223 |
gridBagConstraints5.anchor = java.awt.GridBagConstraints.WEST; |
224 |
gridBagConstraints5.insets = new java.awt.Insets(0,0,0,0); |
225 |
gridBagConstraints6.gridwidth = 0;
|
226 |
gridBagConstraints6.anchor = java.awt.GridBagConstraints.WEST; |
227 |
gridBagConstraints7.gridwidth = 1;
|
228 |
gridBagConstraints7.insets = new java.awt.Insets(20,0,0,0); |
229 |
gridBagConstraints8.gridwidth = 0;
|
230 |
gridBagConstraints8.anchor = java.awt.GridBagConstraints.WEST; |
231 |
jPanel.setPreferredSize(new java.awt.Dimension(333,113)); |
232 |
gridBagConstraints9.gridx = 0;
|
233 |
gridBagConstraints9.gridy = 1;
|
234 |
gridBagConstraints9.insets = new java.awt.Insets(0,180,0,0); |
235 |
gridBagConstraints1.gridx = 0;
|
236 |
gridBagConstraints1.gridy = 2;
|
237 |
gridBagConstraints1.insets = new java.awt.Insets(0,180,0,0); |
238 |
jPanel.add(getJPanel1(), gridBagConstraints5); |
239 |
jPanel.add(getJPanel2(), gridBagConstraints6); |
240 |
jPanel.add(getJPanel3(), gridBagConstraints8); |
241 |
jPanel.add(getJPanel4(), gridBagConstraints7); |
242 |
jPanel.add(getJPanel5(), gridBagConstraints9); |
243 |
jPanel.add(getJPanel6(), gridBagConstraints1); |
244 |
} |
245 |
return jPanel;
|
246 |
} |
247 |
/**
|
248 |
* This method initializes jPanel1
|
249 |
*
|
250 |
* @return javax.swing.JPanel
|
251 |
*/
|
252 |
private JPanel getJPanel1() { |
253 |
if (jPanel1 == null) { |
254 |
redValue = new JLabel(); |
255 |
jPanel1 = new JPanel(); |
256 |
jPanel1.setLayout(new BorderLayout()); |
257 |
redValue.setText("Valor Rojo: ");
|
258 |
jPanel1.setPreferredSize(new java.awt.Dimension(170,42)); |
259 |
jPanel1.add(getTransparencyCheck(), java.awt.BorderLayout.NORTH); |
260 |
jPanel1.add(redValue, java.awt.BorderLayout.WEST); |
261 |
jPanel1.add(getTRojo(), java.awt.BorderLayout.EAST); |
262 |
} |
263 |
return jPanel1;
|
264 |
} |
265 |
/**
|
266 |
* This method initializes jPanel2
|
267 |
*
|
268 |
* @return javax.swing.JPanel
|
269 |
*/
|
270 |
private JPanel getJPanel2() { |
271 |
if (jPanel2 == null) { |
272 |
greenValue = new JLabel(); |
273 |
jPanel2 = new JPanel(); |
274 |
jPanel2.setLayout(new BorderLayout()); |
275 |
greenValue.setText("Valor Verde: ");
|
276 |
jPanel2.setPreferredSize(new java.awt.Dimension(170,19)); |
277 |
jPanel2.add(greenValue, java.awt.BorderLayout.WEST); |
278 |
jPanel2.add(getTVerde(), java.awt.BorderLayout.EAST); |
279 |
} |
280 |
return jPanel2;
|
281 |
} |
282 |
/**
|
283 |
* This method initializes jPanel3
|
284 |
*
|
285 |
* @return javax.swing.JPanel
|
286 |
*/
|
287 |
private JPanel getJPanel3() { |
288 |
if (jPanel3 == null) { |
289 |
blueValue = new JLabel(); |
290 |
jPanel3 = new JPanel(); |
291 |
jPanel3.setLayout(new BorderLayout()); |
292 |
blueValue.setText("Valor Azul: ");
|
293 |
jPanel3.setPreferredSize(new java.awt.Dimension(170,19)); |
294 |
jPanel3.add(blueValue, java.awt.BorderLayout.WEST); |
295 |
jPanel3.add(getTAzul(), java.awt.BorderLayout.EAST); |
296 |
} |
297 |
return jPanel3;
|
298 |
} |
299 |
/**
|
300 |
* This method initializes jCheckBox
|
301 |
*
|
302 |
* @return javax.swing.JCheckBox
|
303 |
*/
|
304 |
public JCheckBox getTransparencyCheck() { |
305 |
if (cbTransparencia == null) { |
306 |
cbTransparencia = new JCheckBox(); |
307 |
cbTransparencia.setText("Transparencia");
|
308 |
} |
309 |
return cbTransparencia;
|
310 |
} |
311 |
/**
|
312 |
* This method initializes jTextField
|
313 |
*
|
314 |
* @return javax.swing.JTextField
|
315 |
*/
|
316 |
public JTextFieldExt getTRojo() {
|
317 |
if (tRojo == null) { |
318 |
tRojo = new JTextFieldExt(this.getBackground()); |
319 |
tRojo.setPreferredSize(new java.awt.Dimension(80,19)); |
320 |
} |
321 |
return tRojo;
|
322 |
} |
323 |
/**
|
324 |
* This method initializes jTextField1
|
325 |
*
|
326 |
* @return javax.swing.JTextField
|
327 |
*/
|
328 |
public JTextFieldExt getTVerde() {
|
329 |
if (tVerde == null) { |
330 |
tVerde = new JTextFieldExt(this.getBackground()); |
331 |
tVerde.setPreferredSize(new java.awt.Dimension(80,19)); |
332 |
} |
333 |
return tVerde;
|
334 |
} |
335 |
/**
|
336 |
* This method initializes jTextField2
|
337 |
*
|
338 |
* @return javax.swing.JTextField
|
339 |
*/
|
340 |
public JTextFieldExt getTAzul() {
|
341 |
if (tAzul == null) { |
342 |
tAzul = new JTextFieldExt(this.getBackground()); |
343 |
tAzul.setPreferredSize(new java.awt.Dimension(80,19)); |
344 |
} |
345 |
return tAzul;
|
346 |
} |
347 |
/**
|
348 |
* This method initializes jPanel4
|
349 |
*
|
350 |
* @return javax.swing.JPanel
|
351 |
*/
|
352 |
private JPanel getJPanel4() { |
353 |
if (jPanel4 == null) { |
354 |
jPanel4 = new JPanel(); |
355 |
jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
356 |
jPanel4.setPreferredSize(new java.awt.Dimension(415,35)); |
357 |
jPanel4.add(getOpacityCheck(), null);
|
358 |
jPanel4.add(getOpacitySlider(), null);
|
359 |
jPanel4.add(getOpacityText(), null);
|
360 |
} |
361 |
return jPanel4;
|
362 |
} |
363 |
/**
|
364 |
* This method initializes jCheckBox1
|
365 |
*
|
366 |
* @return javax.swing.JCheckBox
|
367 |
*/
|
368 |
public JCheckBox getOpacityCheck() { |
369 |
if (cbOpacidad == null) { |
370 |
cbOpacidad = new JCheckBox(); |
371 |
cbOpacidad.setText("Opacidad");
|
372 |
} |
373 |
return cbOpacidad;
|
374 |
} |
375 |
/**
|
376 |
* This method initializes jSlider
|
377 |
*
|
378 |
* @return javax.swing.JSlider
|
379 |
*/
|
380 |
public JSlider getOpacitySlider() { |
381 |
if (slOpacidad == null) { |
382 |
slOpacidad = new JSlider(); |
383 |
slOpacidad.setPreferredSize(new java.awt.Dimension(280,16)); |
384 |
} |
385 |
return slOpacidad;
|
386 |
} |
387 |
/**
|
388 |
* This method initializes jTextField3
|
389 |
*
|
390 |
* @return javax.swing.JTextField
|
391 |
*/
|
392 |
public JTextField getOpacityText() { |
393 |
if (tOpacidad == null) { |
394 |
tOpacidad = new JTextField(); |
395 |
tOpacidad.setPreferredSize(new java.awt.Dimension(30,19)); |
396 |
} |
397 |
return tOpacidad;
|
398 |
} |
399 |
/**
|
400 |
* This method initializes jPanel5
|
401 |
*
|
402 |
* @return javax.swing.JPanel
|
403 |
*/
|
404 |
private JPanel getJPanel5() { |
405 |
if (jPanel5 == null) { |
406 |
range = new JLabel(); |
407 |
jPanel5 = new JPanel(); |
408 |
range.setText("Usa un rango: 1,3,5:8");
|
409 |
jPanel5.setPreferredSize(new java.awt.Dimension(161,21)); |
410 |
jPanel5.add(range, null);
|
411 |
} |
412 |
return jPanel5;
|
413 |
} |
414 |
|
415 |
/**
|
416 |
* Activa/Desactiva los controles de opacidad
|
417 |
* @param active
|
418 |
*/
|
419 |
public void setActiveOpacityControl(boolean active){ |
420 |
this.getOpacityCheck().setSelected(active);
|
421 |
this.getOpacitySlider().setEnabled(active);
|
422 |
this.getOpacityText().setEnabled(active);
|
423 |
} |
424 |
|
425 |
/**
|
426 |
* Activa/Desactiva los controles de transparencia
|
427 |
* @param active
|
428 |
*/
|
429 |
public void setActiveTransparencyControl(boolean active){ |
430 |
this.getTransparencyCheck().setSelected(active);
|
431 |
this.getTRojo().setEnabled(active);
|
432 |
if((active && parent.nbands>=2) || !active) |
433 |
this.getTVerde().setEnabled(active);
|
434 |
else
|
435 |
this.getTVerde().setEnabled(false); |
436 |
|
437 |
if((active && parent.nbands>=3) || !active) |
438 |
this.getTAzul().setEnabled(active);
|
439 |
else
|
440 |
this.getTAzul().setEnabled(false); |
441 |
|
442 |
|
443 |
} |
444 |
/**
|
445 |
* Asigna el valor de opacidad a los controles de la ventana
|
446 |
* para que cuando esta se abra tenga los valores seleccionados en la
|
447 |
* imagen.
|
448 |
* @param alpha
|
449 |
*/
|
450 |
public void setOpacity(int alpha){ |
451 |
int opacityPercent = (int)((alpha*100)/255); |
452 |
this.getOpacityText().setText(String.valueOf(opacityPercent)); |
453 |
this.getOpacitySlider().setValue(opacityPercent);
|
454 |
this.setActiveOpacityControl(true); |
455 |
if(opacityPercent==100) |
456 |
this.setActiveOpacityControl(false); |
457 |
} |
458 |
|
459 |
/**
|
460 |
* This method initializes jPanel6
|
461 |
*
|
462 |
* @return javax.swing.JPanel
|
463 |
*/
|
464 |
private JPanel getJPanel6() { |
465 |
if (jPanel6 == null) { |
466 |
jLabel4 = new JLabel(); |
467 |
jPanel6 = new JPanel(); |
468 |
jPanel6.setPreferredSize(new java.awt.Dimension(161,20)); |
469 |
jLabel4.setText("Valor de pixel: 0 a 255");
|
470 |
jPanel6.add(jLabel4, null);
|
471 |
} |
472 |
return jPanel6;
|
473 |
} |
474 |
} // @jve:decl-index=0:visual-constraint="36,15"
|