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