root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / FilterRasterDialogPanel.java @ 1764
History | View | Annotate | Download (7.76 KB)
1 |
/*
|
---|---|
2 |
* Creado el 30-marzo-2005
|
3 |
*/
|
4 |
package org.cresques.ui.raster; |
5 |
|
6 |
import java.awt.event.ActionEvent; |
7 |
import java.awt.event.ActionListener; |
8 |
import java.awt.event.FocusEvent; |
9 |
import java.awt.event.FocusListener; |
10 |
import java.io.IOException; |
11 |
|
12 |
import javax.swing.event.ChangeEvent; |
13 |
import javax.swing.event.ChangeListener; |
14 |
|
15 |
import org.cresques.ui.DefaultTabPanel; |
16 |
|
17 |
/**
|
18 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
19 |
*
|
20 |
* Panel que contiene todos los paneles de los tabs del cuadro de dialogo
|
21 |
* de bandas y transparencias
|
22 |
*/
|
23 |
public class FilterRasterDialogPanel extends DefaultTabPanel implements ActionListener, ChangeListener, FocusListener{ |
24 |
|
25 |
//Tama?o de panel interior. El tab de dentro es proporcional
|
26 |
protected int sizePanelX = 350; |
27 |
protected int sizePanelY = 210; |
28 |
private RasterTransparencyPanel pTrans = null; |
29 |
private BandSetupPanel pSetup = null; |
30 |
private int[][] rangeTransparency; |
31 |
|
32 |
public FilterRasterDialogPanel() {
|
33 |
|
34 |
super();
|
35 |
contentPane.setPreferredSize(new java.awt.Dimension(sizePanelX, sizePanelY));
|
36 |
this.tabbedPane.setPreferredSize(new java.awt.Dimension(sizePanelX, sizePanelY-5)); |
37 |
initPanels(); |
38 |
|
39 |
} |
40 |
|
41 |
/**
|
42 |
* This method initializes this
|
43 |
*
|
44 |
* @return void
|
45 |
*/
|
46 |
protected void initPanels() { |
47 |
|
48 |
this.setBounds(0,0,355,230); |
49 |
pTrans = new RasterTransparencyPanel(this); |
50 |
pSetup = new BandSetupPanel();
|
51 |
this.addTab(pSetup.nom, pSetup);
|
52 |
this.addTab(pTrans.nom, pTrans);
|
53 |
|
54 |
pTrans.getCbOpacidad().addActionListener(this);
|
55 |
pTrans.getCbTransparencia().addActionListener(this);
|
56 |
pTrans.getTRojo().addActionListener(this);
|
57 |
pTrans.getTVerde().addActionListener(this);
|
58 |
pTrans.getTAzul().addActionListener(this);
|
59 |
pTrans.getSlOpacidad().addChangeListener(this);
|
60 |
pTrans.getTOpacidad().addActionListener(this);
|
61 |
pTrans.getTOpacidad().addFocusListener(this);
|
62 |
|
63 |
//Ocultamos el bot?n de aplicar
|
64 |
|
65 |
//this.getApplyButton().setVisible(false);
|
66 |
|
67 |
} |
68 |
|
69 |
/**
|
70 |
*
|
71 |
* @return
|
72 |
*/
|
73 |
public BandSetupPanel getBandSetup(){
|
74 |
return this.pSetup; |
75 |
} |
76 |
|
77 |
/**
|
78 |
*
|
79 |
* @return
|
80 |
*/
|
81 |
public RasterTransparencyPanel getTransparencyPanel(){
|
82 |
return this.pTrans; |
83 |
} |
84 |
|
85 |
public void actionPerformed(ActionEvent e){ |
86 |
|
87 |
//Evento sobre el checkbox de opacidad
|
88 |
|
89 |
if( e.getSource().equals(pTrans.getCbOpacidad())){
|
90 |
|
91 |
//Check de opacidad activado -> Activar controles de opacidad
|
92 |
if(pTrans.getCbOpacidad().isSelected()){
|
93 |
pTrans.getSlOpacidad().setEnabled(true);
|
94 |
pTrans.getTOpacidad().setEnabled(true);
|
95 |
}else{
|
96 |
pTrans.getSlOpacidad().setEnabled(false);
|
97 |
pTrans.getTOpacidad().setEnabled(false);
|
98 |
} |
99 |
|
100 |
} |
101 |
|
102 |
//Evento sobre el checkbox de transparencia
|
103 |
|
104 |
if( e.getSource().equals(pTrans.getCbTransparencia())){
|
105 |
|
106 |
//Check de opacidad activado -> Activar controles de opacidad
|
107 |
if(pTrans.getCbTransparencia().isSelected()){
|
108 |
pTrans.getTRojo().setEnabled(true);
|
109 |
pTrans.getTVerde().setEnabled(true);
|
110 |
pTrans.getTAzul().setEnabled(true);
|
111 |
}else{
|
112 |
pTrans.getTRojo().setEnabled(false);
|
113 |
pTrans.getTVerde().setEnabled(false);
|
114 |
pTrans.getTAzul().setEnabled(false);
|
115 |
} |
116 |
|
117 |
} |
118 |
|
119 |
//Evento sobre el textfield de opacidad
|
120 |
|
121 |
if( e.getSource().equals(pTrans.getTOpacidad())){
|
122 |
checkOpacity(); |
123 |
} |
124 |
|
125 |
//Evento sobre el textfield de valor para el Rojo
|
126 |
|
127 |
if( e.getSource().equals(pTrans.getTRojo())){
|
128 |
try{
|
129 |
getTransparencyValues(pTrans.getTRojo().getText()); |
130 |
}catch(IOException exc){ |
131 |
pTrans.getTRojo().setText("");
|
132 |
} |
133 |
} |
134 |
|
135 |
//Evento sobre el textfield de valor para el Verde
|
136 |
|
137 |
if( e.getSource().equals(pTrans.getTVerde())){
|
138 |
try{
|
139 |
getTransparencyValues(pTrans.getTVerde().getText()); |
140 |
}catch(IOException exc){ |
141 |
pTrans.getTVerde().setText("");
|
142 |
} |
143 |
} |
144 |
|
145 |
//Evento sobre el textfield de valor para el Azul
|
146 |
|
147 |
if( e.getSource().equals(pTrans.getTAzul())){
|
148 |
try{
|
149 |
getTransparencyValues(pTrans.getTAzul().getText()); |
150 |
}catch(IOException exc){ |
151 |
pTrans.getTAzul().setText("");
|
152 |
} |
153 |
} |
154 |
|
155 |
|
156 |
} |
157 |
|
158 |
/**
|
159 |
* Obtiene el rango de valores a partir de la cadena de
|
160 |
* texto introducida por el usuario.
|
161 |
* @param values
|
162 |
*/
|
163 |
private void getTransparencyValues(String values)throws IOException{ |
164 |
|
165 |
for(int i=0;i<values.length();i++){ |
166 |
char c = values.charAt(i);
|
167 |
|
168 |
//Control de caracter valido
|
169 |
if( c != '0' && c != '1' && c != '2' && c != '3' && c != '4' && |
170 |
c != '5' && c != '6' && c != '7' && c != '8' && c != '9' && |
171 |
c != ':' && c != ','){ |
172 |
System.err.println("Caracteres incorrectos en la cadena."); |
173 |
throw new IOException("Caracteres incorrectos en la cadena."); |
174 |
} |
175 |
|
176 |
//Control de comienzo por un simbolo
|
177 |
if( values.startsWith(",") || values.startsWith(":") || |
178 |
values.endsWith(",") || values.endsWith(":")){ |
179 |
System.err.println("La cadena empieza o acaba con simbolos incorrectos"); |
180 |
throw new IOException(); |
181 |
} |
182 |
|
183 |
//Control de signos consecutivos
|
184 |
if(i<values.length()-1){ |
185 |
|
186 |
char cmas = values.charAt(i+1); |
187 |
if((c == ',' || c == ':') && (cmas == ',' || cmas == ':')){ |
188 |
System.err.println("Signos consecutivos"); |
189 |
throw new IOException(); |
190 |
} |
191 |
|
192 |
} |
193 |
|
194 |
//Control de dos : seguidos con un n?mero en el medio
|
195 |
if(i<values.length()-3 && c==':'){ |
196 |
int n=i+1; |
197 |
while(n<values.length()-1 && values.charAt(n) != ',' && values.charAt(n) != ':') |
198 |
n++; |
199 |
|
200 |
char signoSgte = values.charAt(n);
|
201 |
if(signoSgte == ':'){ |
202 |
System.err.println("Dos separadores de rango consecutivos"); |
203 |
throw new IOException(); |
204 |
} |
205 |
} |
206 |
|
207 |
} |
208 |
|
209 |
//Obtenemos los valores de los intervalos
|
210 |
|
211 |
if(!values.equals("")){ |
212 |
String[] t1 = null; |
213 |
t1 = values.split("\\,");
|
214 |
rangeTransparency = new int[t1.length][2]; |
215 |
for(int i=0;i<t1.length;i++){ |
216 |
if(t1[i].indexOf(":")==-1){ |
217 |
rangeTransparency[i][0] = rangeTransparency[i][1] = Integer.parseInt(t1[i]); |
218 |
}else{
|
219 |
String[] t2 = null; |
220 |
t2 = t1[i].split("\\:");
|
221 |
if(Integer.parseInt(t2[1])>Integer.parseInt(t2[0])){ |
222 |
rangeTransparency[i][0] = Integer.parseInt(t2[0]); |
223 |
rangeTransparency[i][1] = Integer.parseInt(t2[1]); |
224 |
}else{
|
225 |
rangeTransparency[i][0] = Integer.parseInt(t2[1]); |
226 |
rangeTransparency[i][1] = Integer.parseInt(t2[0]); |
227 |
} |
228 |
} |
229 |
if( rangeTransparency[i][0]<0 || rangeTransparency[i][0]>255 || |
230 |
rangeTransparency[i][1]<0 || rangeTransparency[i][1]>255){ |
231 |
System.err.println("Valores fuera de rango (0-255)"); |
232 |
throw new IOException(); |
233 |
} |
234 |
} |
235 |
|
236 |
for(int i=0;i<rangeTransparency.length;i++) |
237 |
System.out.println("("+rangeTransparency[i][0]+":"+rangeTransparency[i][1]+")"); |
238 |
} |
239 |
} |
240 |
|
241 |
|
242 |
|
243 |
/**
|
244 |
* Controla que si el formato introducido en el textfield
|
245 |
* de opacidad es numerico se actualiza la posici?n del
|
246 |
* slider.
|
247 |
*/
|
248 |
private void checkOpacity(){ |
249 |
String op = pTrans.getTOpacidad().getText();
|
250 |
int value = 0; |
251 |
try{
|
252 |
if(!op.equals("")) |
253 |
value = Integer.parseInt(op);
|
254 |
pTrans.getSlOpacidad().setValue(value); |
255 |
}catch(NumberFormatException exc){ |
256 |
System.err.println("Formato no numerico"); |
257 |
pTrans.getTOpacidad().setText("100");
|
258 |
pTrans.getSlOpacidad().setValue(100);
|
259 |
} |
260 |
} |
261 |
|
262 |
/*
|
263 |
*
|
264 |
*/
|
265 |
public void stateChanged(ChangeEvent e){ |
266 |
|
267 |
//Ponemos el valor del texto de la opacidad de pendiendo de la posici?n del Slider
|
268 |
pTrans.getTOpacidad().setText(String.valueOf(pTrans.getSlOpacidad().getValue()));
|
269 |
} |
270 |
|
271 |
public void focusGained(FocusEvent e){} |
272 |
public void focusLost(FocusEvent e){ |
273 |
checkOpacity(); |
274 |
} |
275 |
|
276 |
/*public void mouseExited(MouseEvent e){}
|
277 |
public void mouseReleased(MouseEvent e){}
|
278 |
public void mouseEntered(MouseEvent e){}
|
279 |
|
280 |
public void mouseClicked(MouseEvent e){}
|
281 |
|
282 |
public void mousePressed(MouseEvent e){}
|
283 |
|
284 |
public void keyTyped(KeyEvent e){
|
285 |
}
|
286 |
public void keyPressed(KeyEvent e){
|
287 |
}
|
288 |
public void keyReleased(KeyEvent e){}
|
289 |
*/
|
290 |
} |
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|