svn-gvsig-desktop / tags / Root_v061 / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / RasterTransparencyPanel.java @ 4812
History | View | Annotate | Download (15.1 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 |
/**
|
39 |
* Dialogo para asignar la transparencia por pixel y global al raster.
|
40 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
41 |
*/
|
42 |
public class RasterTransparencyPanel extends JPanel { |
43 |
final private static long serialVersionUID = -3370601314380922368L; |
44 |
|
45 |
/**
|
46 |
* Nombre del panel
|
47 |
*/
|
48 |
private String nom = "Transparencia"; |
49 |
FilterRasterDialogPanel parent = null;
|
50 |
|
51 |
/**
|
52 |
* N?mero de bandas del raster
|
53 |
*/
|
54 |
public int nBands = 3; |
55 |
private String[] nameBands = { "Rojo", "Verde", "Azul" }; |
56 |
private JPanel jPanel = null; |
57 |
private JPanel jPanel1 = null; |
58 |
private JPanel jPanel2 = null; |
59 |
private JPanel jPanel3 = null; |
60 |
private JCheckBox cbTransparencia = null; |
61 |
|
62 |
/**
|
63 |
* Variable p?blica para la traducci?n
|
64 |
*/
|
65 |
public JLabel lRedValue = null; |
66 |
private JTextFieldExt tRojo = null; |
67 |
|
68 |
/**
|
69 |
* Variable p?blica para la traducci?n
|
70 |
*/
|
71 |
public JLabel lGreenValue = null; |
72 |
|
73 |
/**
|
74 |
* Variable p?blica para la traducci?n
|
75 |
*/
|
76 |
public JLabel lBlueValue = null; |
77 |
|
78 |
/**
|
79 |
* Variable p?blica para la traducci?n
|
80 |
*/
|
81 |
public JPanel pGeneralTrans = null; |
82 |
|
83 |
/**
|
84 |
* Variable p?blica para la traducci?n
|
85 |
*/
|
86 |
public JLabel lRange = null; |
87 |
|
88 |
/**
|
89 |
* Variable p?blica para la traducci?n
|
90 |
*/
|
91 |
public JLabel lPixelValue = null; |
92 |
private JTextFieldExt tVerde = null; |
93 |
private JTextFieldExt tAzul = null; |
94 |
private JCheckBox cbOpacidad = null; |
95 |
private JSlider slOpacidad = null; |
96 |
private JTextField tOpacidad = null; |
97 |
private JPanel jPanel5 = null; |
98 |
private JPanel jPanel6 = null; |
99 |
|
100 |
/**
|
101 |
* Constructor. Asigna la variable panel que contiene este
|
102 |
* @param parent FilterRasterDialogPanel
|
103 |
*/
|
104 |
public RasterTransparencyPanel(FilterRasterDialogPanel parent) {
|
105 |
this.parent = parent;
|
106 |
initialize(); |
107 |
} |
108 |
|
109 |
/**
|
110 |
* This method initializes this
|
111 |
*
|
112 |
* @return void
|
113 |
*/
|
114 |
private void initialize() { |
115 |
this.setLayout(new BorderLayout()); |
116 |
this.setBounds(0, 0, 445, 239); |
117 |
this.setPreferredSize(new java.awt.Dimension(445, 239)); |
118 |
this.add(getJPanel(), java.awt.BorderLayout.CENTER);
|
119 |
initControls(); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Obtiene el nombre del panel
|
124 |
* @return Cadena con el nombre del panel
|
125 |
*/
|
126 |
public String getName(){ |
127 |
return this.nom; |
128 |
} |
129 |
|
130 |
/**
|
131 |
* Asigna el n?mero de bandas de la imagen
|
132 |
* @param nBands
|
133 |
*/
|
134 |
public void setBands(int nBands) { |
135 |
this.nBands = nBands;
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* Asigna el n?mero de bandas de la imagen
|
140 |
* @param nBands
|
141 |
*/
|
142 |
public void setNameBands(String[] nameBands) { |
143 |
this.nameBands = nameBands;
|
144 |
} |
145 |
|
146 |
/**
|
147 |
* Inicializa controles a sus valores por defecto
|
148 |
*/
|
149 |
public void initControls() { |
150 |
this.getOpacityText().setText("100"); |
151 |
this.setActiveOpacityControl(false); |
152 |
this.setActiveTransparencyControl(false); |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Esta funci?n no est? en uso.
|
157 |
* Oculta los controles de transparencia por bandas en caso de que haya menos de 3 bandas.
|
158 |
*
|
159 |
*/
|
160 |
public void updateTextBox() { |
161 |
if (parent.nbands == 1) { |
162 |
this.getTRojo().setVisible(true); |
163 |
this.getTVerde().setVisible(false); |
164 |
this.getTAzul().setVisible(false); |
165 |
lRedValue.setVisible(true);
|
166 |
lGreenValue.setVisible(false);
|
167 |
lBlueValue.setVisible(false);
|
168 |
} |
169 |
|
170 |
if (parent.nbands == 2) { |
171 |
this.getTRojo().setVisible(true); |
172 |
this.getTVerde().setVisible(true); |
173 |
this.getTAzul().setVisible(false); |
174 |
lRedValue.setVisible(true);
|
175 |
lGreenValue.setVisible(true);
|
176 |
lBlueValue.setVisible(false);
|
177 |
} |
178 |
|
179 |
if (parent.nbands >= 3) { |
180 |
this.getTRojo().setVisible(true); |
181 |
this.getTVerde().setVisible(true); |
182 |
this.getTAzul().setVisible(true); |
183 |
lRedValue.setVisible(true);
|
184 |
lGreenValue.setVisible(true);
|
185 |
lBlueValue.setVisible(true);
|
186 |
} |
187 |
} |
188 |
|
189 |
/**
|
190 |
* This method initializes jPanel
|
191 |
*
|
192 |
* @return javax.swing.JPanel
|
193 |
*/
|
194 |
private JPanel getJPanel() { |
195 |
if (jPanel == null) { |
196 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
197 |
GridBagConstraints gridBagConstraints9 = new GridBagConstraints(); |
198 |
GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); |
199 |
GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); |
200 |
GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); |
201 |
GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
202 |
jPanel = new JPanel(); |
203 |
jPanel.setLayout(new GridBagLayout()); |
204 |
gridBagConstraints5.fill = java.awt.GridBagConstraints.NONE; |
205 |
gridBagConstraints5.ipady = 0;
|
206 |
gridBagConstraints5.gridheight = 1;
|
207 |
gridBagConstraints5.gridwidth = 0;
|
208 |
gridBagConstraints5.anchor = java.awt.GridBagConstraints.WEST; |
209 |
gridBagConstraints5.insets = new java.awt.Insets(0, 0, 0, 0); |
210 |
gridBagConstraints6.gridwidth = 0;
|
211 |
gridBagConstraints6.anchor = java.awt.GridBagConstraints.WEST; |
212 |
gridBagConstraints7.gridwidth = 1;
|
213 |
gridBagConstraints7.insets = new java.awt.Insets(20, 0, 0, 0); |
214 |
gridBagConstraints8.gridwidth = 0;
|
215 |
gridBagConstraints8.anchor = java.awt.GridBagConstraints.WEST; |
216 |
jPanel.setPreferredSize(new java.awt.Dimension(333, 113)); |
217 |
gridBagConstraints9.gridx = 0;
|
218 |
gridBagConstraints9.gridy = 1;
|
219 |
gridBagConstraints9.insets = new java.awt.Insets(0, 180, 0, 0); |
220 |
gridBagConstraints1.gridx = 0;
|
221 |
gridBagConstraints1.gridy = 2;
|
222 |
gridBagConstraints1.insets = new java.awt.Insets(0, 180, 0, 0); |
223 |
jPanel.add(getJPanel1(), gridBagConstraints5); |
224 |
jPanel.add(getJPanel2(), gridBagConstraints6); |
225 |
jPanel.add(getJPanel3(), gridBagConstraints8); |
226 |
jPanel.add(getJPanel4(), gridBagConstraints7); |
227 |
jPanel.add(getJPanel5(), gridBagConstraints9); |
228 |
jPanel.add(getJPanel6(), gridBagConstraints1); |
229 |
} |
230 |
|
231 |
return jPanel;
|
232 |
} |
233 |
|
234 |
/**
|
235 |
* This method initializes jPanel1
|
236 |
*
|
237 |
* @return javax.swing.JPanel
|
238 |
*/
|
239 |
private JPanel getJPanel1() { |
240 |
if (jPanel1 == null) { |
241 |
lRedValue = new JLabel(); |
242 |
jPanel1 = new JPanel(); |
243 |
jPanel1.setLayout(new BorderLayout()); |
244 |
lRedValue.setText("Valor Rojo: ");
|
245 |
jPanel1.setPreferredSize(new java.awt.Dimension(170, 42)); |
246 |
jPanel1.add(getTransparencyCheck(), java.awt.BorderLayout.NORTH); |
247 |
jPanel1.add(lRedValue, java.awt.BorderLayout.WEST); |
248 |
jPanel1.add(getTRojo(), java.awt.BorderLayout.EAST); |
249 |
} |
250 |
|
251 |
return jPanel1;
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* This method initializes jPanel2
|
256 |
*
|
257 |
* @return javax.swing.JPanel
|
258 |
*/
|
259 |
private JPanel getJPanel2() { |
260 |
if (jPanel2 == null) { |
261 |
lGreenValue = new JLabel(); |
262 |
jPanel2 = new JPanel(); |
263 |
jPanel2.setLayout(new BorderLayout()); |
264 |
lGreenValue.setText("Valor Verde: ");
|
265 |
jPanel2.setPreferredSize(new java.awt.Dimension(170, 19)); |
266 |
jPanel2.add(lGreenValue, java.awt.BorderLayout.WEST); |
267 |
jPanel2.add(getTVerde(), java.awt.BorderLayout.EAST); |
268 |
} |
269 |
|
270 |
return jPanel2;
|
271 |
} |
272 |
|
273 |
/**
|
274 |
* This method initializes jPanel3
|
275 |
*
|
276 |
* @return javax.swing.JPanel
|
277 |
*/
|
278 |
private JPanel getJPanel3() { |
279 |
if (jPanel3 == null) { |
280 |
lBlueValue = new JLabel(); |
281 |
jPanel3 = new JPanel(); |
282 |
jPanel3.setLayout(new BorderLayout()); |
283 |
lBlueValue.setText("Valor Azul: ");
|
284 |
jPanel3.setPreferredSize(new java.awt.Dimension(170, 19)); |
285 |
jPanel3.add(lBlueValue, java.awt.BorderLayout.WEST); |
286 |
jPanel3.add(getTAzul(), java.awt.BorderLayout.EAST); |
287 |
} |
288 |
|
289 |
return jPanel3;
|
290 |
} |
291 |
|
292 |
/**
|
293 |
* This method initializes jCheckBox
|
294 |
*
|
295 |
* @return javax.swing.JCheckBox
|
296 |
*/
|
297 |
public JCheckBox getTransparencyCheck() { |
298 |
if (cbTransparencia == null) { |
299 |
cbTransparencia = new JCheckBox(); |
300 |
cbTransparencia.setText("Transparencia");
|
301 |
} |
302 |
|
303 |
return cbTransparencia;
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* This method initializes jTextField
|
308 |
*
|
309 |
* @return javax.swing.JTextField
|
310 |
*/
|
311 |
public JTextFieldExt getTRojo() {
|
312 |
if (tRojo == null) { |
313 |
tRojo = new JTextFieldExt(this.getBackground()); |
314 |
tRojo.setPreferredSize(new java.awt.Dimension(80, 19)); |
315 |
} |
316 |
|
317 |
return tRojo;
|
318 |
} |
319 |
|
320 |
/**
|
321 |
* This method initializes jTextField1
|
322 |
*
|
323 |
* @return javax.swing.JTextField
|
324 |
*/
|
325 |
public JTextFieldExt getTVerde() {
|
326 |
if (tVerde == null) { |
327 |
tVerde = new JTextFieldExt(this.getBackground()); |
328 |
tVerde.setPreferredSize(new java.awt.Dimension(80, 19)); |
329 |
} |
330 |
|
331 |
return tVerde;
|
332 |
} |
333 |
|
334 |
/**
|
335 |
* This method initializes jTextField2
|
336 |
*
|
337 |
* @return javax.swing.JTextField
|
338 |
*/
|
339 |
public JTextFieldExt getTAzul() {
|
340 |
if (tAzul == null) { |
341 |
tAzul = new JTextFieldExt(this.getBackground()); |
342 |
tAzul.setPreferredSize(new java.awt.Dimension(80, 19)); |
343 |
} |
344 |
|
345 |
return tAzul;
|
346 |
} |
347 |
|
348 |
/**
|
349 |
* This method initializes jPanel4
|
350 |
*
|
351 |
* @return javax.swing.JPanel
|
352 |
*/
|
353 |
private JPanel getJPanel4() { |
354 |
if (pGeneralTrans == null) { |
355 |
pGeneralTrans = new JPanel(); |
356 |
pGeneralTrans.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, |
357 |
1));
|
358 |
pGeneralTrans.setPreferredSize(new java.awt.Dimension(415, 35)); |
359 |
pGeneralTrans.add(getOpacityCheck(), null);
|
360 |
pGeneralTrans.add(getOpacitySlider(), null);
|
361 |
pGeneralTrans.add(getOpacityText(), null);
|
362 |
} |
363 |
|
364 |
return pGeneralTrans;
|
365 |
} |
366 |
|
367 |
/**
|
368 |
* This method initializes jCheckBox1
|
369 |
*
|
370 |
* @return javax.swing.JCheckBox
|
371 |
*/
|
372 |
public JCheckBox getOpacityCheck() { |
373 |
if (cbOpacidad == null) { |
374 |
cbOpacidad = new JCheckBox(); |
375 |
cbOpacidad.setText("Opacidad");
|
376 |
} |
377 |
|
378 |
return cbOpacidad;
|
379 |
} |
380 |
|
381 |
/**
|
382 |
* This method initializes jSlider
|
383 |
*
|
384 |
* @return javax.swing.JSlider
|
385 |
*/
|
386 |
public JSlider getOpacitySlider() { |
387 |
if (slOpacidad == null) { |
388 |
slOpacidad = new JSlider(); |
389 |
slOpacidad.setPreferredSize(new java.awt.Dimension(280, 16)); |
390 |
} |
391 |
|
392 |
return slOpacidad;
|
393 |
} |
394 |
|
395 |
/**
|
396 |
* This method initializes jTextField3
|
397 |
*
|
398 |
* @return javax.swing.JTextField
|
399 |
*/
|
400 |
public JTextField getOpacityText() { |
401 |
if (tOpacidad == null) { |
402 |
tOpacidad = new JTextField(); |
403 |
tOpacidad.setPreferredSize(new java.awt.Dimension(30, 19)); |
404 |
} |
405 |
|
406 |
return tOpacidad;
|
407 |
} |
408 |
|
409 |
/**
|
410 |
* This method initializes jPanel5
|
411 |
*
|
412 |
* @return javax.swing.JPanel
|
413 |
*/
|
414 |
private JPanel getJPanel5() { |
415 |
if (jPanel5 == null) { |
416 |
lRange = new JLabel(); |
417 |
jPanel5 = new JPanel(); |
418 |
lRange.setText("Usa un rango: 1,3,5:8");
|
419 |
jPanel5.setPreferredSize(new java.awt.Dimension(161, 21)); |
420 |
jPanel5.add(lRange, null);
|
421 |
} |
422 |
|
423 |
return jPanel5;
|
424 |
} |
425 |
|
426 |
/**
|
427 |
* Activa/Desactiva los controles de opacidad
|
428 |
* @param active
|
429 |
*/
|
430 |
public void setActiveOpacityControl(boolean active) { |
431 |
this.getOpacityCheck().setSelected(active);
|
432 |
this.getOpacitySlider().setEnabled(active);
|
433 |
this.getOpacityText().setEnabled(active);
|
434 |
} |
435 |
|
436 |
/**
|
437 |
* Activa/Desactiva los controles de transparencia
|
438 |
* @param active
|
439 |
*/
|
440 |
public void setActiveTransparencyControl(boolean active) { |
441 |
this.getTransparencyCheck().setSelected(active);
|
442 |
this.getTRojo().setEnabled(active);
|
443 |
|
444 |
if ((active && (parent.nbands >= 2)) || !active) { |
445 |
this.getTVerde().setEnabled(active);
|
446 |
} else {
|
447 |
this.getTVerde().setEnabled(false); |
448 |
} |
449 |
|
450 |
if ((active && (parent.nbands >= 3)) || !active) { |
451 |
this.getTAzul().setEnabled(active);
|
452 |
} else {
|
453 |
this.getTAzul().setEnabled(false); |
454 |
} |
455 |
} |
456 |
|
457 |
/**
|
458 |
* Asigna el valor de opacidad a los controles de la ventana
|
459 |
* para que cuando esta se abra tenga los valores seleccionados en la
|
460 |
* imagen.
|
461 |
* @param alpha
|
462 |
*/
|
463 |
public void setOpacity(int alpha) { |
464 |
int opacityPercent = (int) ((alpha * 100) / 255); |
465 |
this.getOpacityText().setText(String.valueOf(opacityPercent)); |
466 |
this.getOpacitySlider().setValue(opacityPercent);
|
467 |
this.setActiveOpacityControl(true); |
468 |
|
469 |
if (opacityPercent == 100) { |
470 |
this.setActiveOpacityControl(false); |
471 |
} |
472 |
} |
473 |
|
474 |
/**
|
475 |
* This method initializes jPanel6
|
476 |
*
|
477 |
* @return javax.swing.JPanel
|
478 |
*/
|
479 |
private JPanel getJPanel6() { |
480 |
if (jPanel6 == null) { |
481 |
lPixelValue = new JLabel(); |
482 |
jPanel6 = new JPanel(); |
483 |
jPanel6.setPreferredSize(new java.awt.Dimension(161, 20)); |
484 |
lPixelValue.setText("Valor de pixel: 0 a 255");
|
485 |
jPanel6.add(lPixelValue, null);
|
486 |
} |
487 |
|
488 |
return jPanel6;
|
489 |
} |
490 |
|
491 |
public class JTextFieldExt extends JTextField { |
492 |
final private static long serialVersionUID = -3370601314380922368L; |
493 |
private Color color = null; |
494 |
|
495 |
public JTextFieldExt(Color color) { |
496 |
this.color = color;
|
497 |
} |
498 |
|
499 |
public JTextFieldExt() {
|
500 |
super();
|
501 |
} |
502 |
|
503 |
public void setEnabled(boolean enabled) { |
504 |
super.setEnabled(enabled);
|
505 |
|
506 |
if (!enabled) {
|
507 |
if (color == null) { |
508 |
this.setBackground(new Color(210, 210, 210)); |
509 |
} else {
|
510 |
this.setBackground(color);
|
511 |
} |
512 |
} else {
|
513 |
this.setBackground(new Color(255, 255, 255)); |
514 |
} |
515 |
} |
516 |
} |
517 |
} // @jve:decl-index=0:visual-constraint="36,15"
|