svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / RasterTransparencyPanel.java @ 4377
History | View | Annotate | Download (9.73 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 JCheckBox cbTransparencia = null; |
59 |
|
60 |
/**
|
61 |
* Variable p?blica para la traducci?n
|
62 |
*/
|
63 |
public JPanel pGeneralTrans = null; |
64 |
|
65 |
private JCheckBox cbOpacidad = null; |
66 |
private JSlider slOpacidad = null; |
67 |
private JTextField tOpacidad = null; |
68 |
|
69 |
private TransparencyByPixelPanel pTranspByPixel = null; |
70 |
|
71 |
/**
|
72 |
* Constructor. Asigna la variable panel que contiene este
|
73 |
* @param parent FilterRasterDialogPanel
|
74 |
*/
|
75 |
public RasterTransparencyPanel(FilterRasterDialogPanel parent) {
|
76 |
this.parent = parent;
|
77 |
initialize(); |
78 |
} |
79 |
|
80 |
/**
|
81 |
* This method initializes this
|
82 |
*
|
83 |
* @return void
|
84 |
*/
|
85 |
private void initialize() { |
86 |
this.setLayout(new BorderLayout()); |
87 |
this.setBounds(0, 0, 445, 239); |
88 |
this.setPreferredSize(new java.awt.Dimension(445, 239)); |
89 |
this.add(getJPanel(), java.awt.BorderLayout.CENTER);
|
90 |
initControls(); |
91 |
} |
92 |
|
93 |
/**
|
94 |
* Obtiene el nombre del panel
|
95 |
* @return Cadena con el nombre del panel
|
96 |
*/
|
97 |
public String getName(){ |
98 |
return this.nom; |
99 |
} |
100 |
|
101 |
/**
|
102 |
* Asigna el n?mero de bandas de la imagen
|
103 |
* @param nBands
|
104 |
*/
|
105 |
public void setBands(int nBands) { |
106 |
this.nBands = nBands;
|
107 |
} |
108 |
|
109 |
/**
|
110 |
* Asigna el n?mero de bandas de la imagen
|
111 |
* @param nBands
|
112 |
*/
|
113 |
public void setNameBands(String[] nameBands) { |
114 |
this.nameBands = nameBands;
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Inicializa controles a sus valores por defecto
|
119 |
*/
|
120 |
public void initControls() { |
121 |
this.getOpacityText().setText("100"); |
122 |
this.setActiveOpacityControl(false); |
123 |
this.setActiveTransparencyControl(false); |
124 |
} |
125 |
|
126 |
/**
|
127 |
* This method initializes jPanel
|
128 |
*
|
129 |
* @return javax.swing.JPanel
|
130 |
*/
|
131 |
private JPanel getJPanel() { |
132 |
if (jPanel == null) { |
133 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
134 |
gridBagConstraints.gridx = 0;
|
135 |
gridBagConstraints.gridy = 1;
|
136 |
GridBagConstraints gridBagConstraints7 = 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.gridy = 0;
|
142 |
gridBagConstraints5.gridx = 0;
|
143 |
gridBagConstraints5.ipady = 0;
|
144 |
gridBagConstraints5.gridheight = 1;
|
145 |
gridBagConstraints5.gridwidth = 0;
|
146 |
gridBagConstraints5.anchor = java.awt.GridBagConstraints.WEST; |
147 |
gridBagConstraints5.insets = new java.awt.Insets(0,0,5,0); |
148 |
gridBagConstraints7.gridwidth = 1;
|
149 |
gridBagConstraints7.gridy = 2;
|
150 |
gridBagConstraints7.gridx = 0;
|
151 |
gridBagConstraints7.insets = new java.awt.Insets(5,0,0,0); |
152 |
jPanel.setPreferredSize(new java.awt.Dimension(333, 113)); |
153 |
jPanel.add(getJPanel1(), gridBagConstraints5); |
154 |
jPanel.add(getPTranspByPixel(), gridBagConstraints); |
155 |
jPanel.add(getJPanel4(), gridBagConstraints7); |
156 |
} |
157 |
|
158 |
return jPanel;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* This method initializes jPanel1
|
163 |
*
|
164 |
* @return javax.swing.JPanel
|
165 |
*/
|
166 |
private JPanel getJPanel1() { |
167 |
if (jPanel1 == null) { |
168 |
jPanel1 = new JPanel(); |
169 |
jPanel1.setLayout(new BorderLayout()); |
170 |
jPanel1.setPreferredSize(new java.awt.Dimension(415,25)); |
171 |
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
172 |
jPanel1.add(getTransparencyCheck(), java.awt.BorderLayout.NORTH); |
173 |
} |
174 |
|
175 |
return jPanel1;
|
176 |
} |
177 |
|
178 |
/**
|
179 |
* This method initializes jCheckBox
|
180 |
*
|
181 |
* @return javax.swing.JCheckBox
|
182 |
*/
|
183 |
public JCheckBox getTransparencyCheck() { |
184 |
if (cbTransparencia == null) { |
185 |
cbTransparencia = new JCheckBox(); |
186 |
cbTransparencia.setText("Transparencia por pixel");
|
187 |
} |
188 |
|
189 |
return cbTransparencia;
|
190 |
} |
191 |
|
192 |
/**
|
193 |
* This method initializes jPanel4
|
194 |
*
|
195 |
* @return javax.swing.JPanel
|
196 |
*/
|
197 |
private JPanel getJPanel4() { |
198 |
if (pGeneralTrans == null) { |
199 |
pGeneralTrans = new JPanel(); |
200 |
pGeneralTrans.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray, 1));
|
201 |
pGeneralTrans.setPreferredSize(new java.awt.Dimension(415, 35)); |
202 |
pGeneralTrans.add(getOpacityCheck(), null);
|
203 |
pGeneralTrans.add(getOpacitySlider(), null);
|
204 |
pGeneralTrans.add(getOpacityText(), null);
|
205 |
} |
206 |
|
207 |
return pGeneralTrans;
|
208 |
} |
209 |
|
210 |
/**
|
211 |
* This method initializes jCheckBox1
|
212 |
*
|
213 |
* @return javax.swing.JCheckBox
|
214 |
*/
|
215 |
public JCheckBox getOpacityCheck() { |
216 |
if (cbOpacidad == null) { |
217 |
cbOpacidad = new JCheckBox(); |
218 |
cbOpacidad.setText("Opacidad");
|
219 |
} |
220 |
|
221 |
return cbOpacidad;
|
222 |
} |
223 |
|
224 |
/**
|
225 |
* This method initializes jSlider
|
226 |
*
|
227 |
* @return javax.swing.JSlider
|
228 |
*/
|
229 |
public JSlider getOpacitySlider() { |
230 |
if (slOpacidad == null) { |
231 |
slOpacidad = new JSlider(); |
232 |
slOpacidad.setPreferredSize(new java.awt.Dimension(280, 16)); |
233 |
} |
234 |
|
235 |
return slOpacidad;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* This method initializes jTextField3
|
240 |
*
|
241 |
* @return javax.swing.JTextField
|
242 |
*/
|
243 |
public JTextField getOpacityText() { |
244 |
if (tOpacidad == null) { |
245 |
tOpacidad = new JTextField(); |
246 |
tOpacidad.setPreferredSize(new java.awt.Dimension(30, 19)); |
247 |
} |
248 |
|
249 |
return tOpacidad;
|
250 |
} |
251 |
|
252 |
/**
|
253 |
* Activa/Desactiva los controles de opacidad
|
254 |
* @param active
|
255 |
*/
|
256 |
public void setActiveOpacityControl(boolean active) { |
257 |
this.getOpacityCheck().setSelected(active);
|
258 |
this.getOpacitySlider().setEnabled(active);
|
259 |
this.getOpacityText().setEnabled(active);
|
260 |
} |
261 |
|
262 |
/**
|
263 |
* Activa/Desactiva los controles de transparencia
|
264 |
* @param active
|
265 |
*/
|
266 |
public void setActiveTransparencyControl(boolean active) { |
267 |
this.getTransparencyCheck().setSelected(active);
|
268 |
if ((active && (parent.nbands == 1))) { |
269 |
|
270 |
} |
271 |
|
272 |
if ((active && (parent.nbands == 2))) { |
273 |
|
274 |
} |
275 |
|
276 |
if ((active && (parent.nbands == 3))) { |
277 |
|
278 |
} |
279 |
} |
280 |
|
281 |
/**
|
282 |
* Asigna el valor de opacidad a los controles de la ventana
|
283 |
* para que cuando esta se abra tenga los valores seleccionados en la
|
284 |
* imagen.
|
285 |
* @param alpha
|
286 |
*/
|
287 |
public void setOpacity(int alpha) { |
288 |
int opacityPercent = (int) ((alpha * 100) / 255); |
289 |
this.getOpacityText().setText(String.valueOf(opacityPercent)); |
290 |
this.getOpacitySlider().setValue(opacityPercent);
|
291 |
this.setActiveOpacityControl(true); |
292 |
|
293 |
if (opacityPercent == 100) { |
294 |
this.setActiveOpacityControl(false); |
295 |
} |
296 |
} |
297 |
|
298 |
public class JTextFieldExt extends JTextField { |
299 |
final private static long serialVersionUID = -3370601314380922368L; |
300 |
private Color color = null; |
301 |
|
302 |
public JTextFieldExt(Color color) { |
303 |
this.color = color;
|
304 |
} |
305 |
|
306 |
public JTextFieldExt() {
|
307 |
super();
|
308 |
} |
309 |
|
310 |
public void setEnabled(boolean enabled) { |
311 |
super.setEnabled(enabled);
|
312 |
|
313 |
if (!enabled) {
|
314 |
if (color == null) { |
315 |
this.setBackground(new Color(210, 210, 210)); |
316 |
} else {
|
317 |
this.setBackground(color);
|
318 |
} |
319 |
} else {
|
320 |
this.setBackground(new Color(255, 255, 255)); |
321 |
} |
322 |
} |
323 |
} |
324 |
|
325 |
/**
|
326 |
* This method initializes jPanel2
|
327 |
*
|
328 |
* @return javax.swing.JPanel
|
329 |
*/
|
330 |
public TransparencyByPixelPanel getPTranspByPixel() {
|
331 |
if (pTranspByPixel == null) { |
332 |
pTranspByPixel = new TransparencyByPixelPanel();
|
333 |
pTranspByPixel.setPreferredSize(new java.awt.Dimension(415,128)); |
334 |
pTranspByPixel.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
|
335 |
pTranspByPixel.setControlEnabled(false);
|
336 |
} |
337 |
return pTranspByPixel;
|
338 |
} |
339 |
} // @jve:decl-index=0:visual-constraint="36,15"
|