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