root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / FilterRasterDialogPanel.java @ 2147
History | View | Annotate | Download (14.1 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.awt.event.KeyEvent; |
11 |
import java.awt.event.KeyListener; |
12 |
import java.awt.event.MouseEvent; |
13 |
import java.awt.event.MouseListener; |
14 |
import java.io.IOException; |
15 |
|
16 |
import javax.swing.event.ChangeEvent; |
17 |
import javax.swing.event.ChangeListener; |
18 |
import javax.swing.text.View; |
19 |
|
20 |
import org.cresques.ui.DefaultTabPanel; |
21 |
|
22 |
/**
|
23 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
24 |
*
|
25 |
* Panel que contiene todos los paneles de los tabs del cuadro de dialogo
|
26 |
* de bandas y transparencias
|
27 |
*/
|
28 |
public class FilterRasterDialogPanel extends DefaultTabPanel implements ActionListener, ChangeListener, MouseListener, FocusListener, KeyListener{ |
29 |
|
30 |
//Tama?o de panel interior. El tab de dentro es proporcional
|
31 |
protected int sizePanelX = 450; |
32 |
protected int sizePanelY = 260; |
33 |
private RasterTransparencyPanel pTrans = null; |
34 |
protected BandSetupPanel pSetup = null; |
35 |
private EnhancedPanel pEnhan = null; |
36 |
private InfoPanel pInfo = null; |
37 |
private int[][] rangeRed = null; |
38 |
private int[][] rangeGreen = null; |
39 |
private int[][] rangeBlue = null; |
40 |
public Object[][] props = null; |
41 |
|
42 |
|
43 |
public FilterRasterDialogPanel(Object[][] props) { |
44 |
super();
|
45 |
init(props); |
46 |
} |
47 |
|
48 |
public FilterRasterDialogPanel(){
|
49 |
super();
|
50 |
} |
51 |
|
52 |
public void init(Object[][] props){ |
53 |
contentPane.setPreferredSize(new java.awt.Dimension(sizePanelX, sizePanelY));
|
54 |
this.tabbedPane.setPreferredSize(new java.awt.Dimension(sizePanelX, sizePanelY-5)); |
55 |
this.props = props;
|
56 |
initPanels(); |
57 |
} |
58 |
|
59 |
/**
|
60 |
* This method initializes this
|
61 |
*
|
62 |
* @return void
|
63 |
*/
|
64 |
protected void initPanels() { |
65 |
|
66 |
this.setBounds(0, 0, 355, 230); |
67 |
pTrans = new RasterTransparencyPanel(this); |
68 |
pSetup = new BandSetupPanel();
|
69 |
pEnhan = new EnhancedPanel(this); |
70 |
pInfo = new InfoPanel(this); |
71 |
this.addTab(pInfo.nom,pInfo);
|
72 |
this.addTab(pSetup.nom, pSetup);
|
73 |
this.addTab(pTrans.nom, pTrans);
|
74 |
this.addTab(pEnhan.nom, pEnhan);
|
75 |
|
76 |
pTrans.getOpacityCheck().addActionListener(this);
|
77 |
pTrans.getTransparencyCheck().addActionListener(this);
|
78 |
pTrans.getTRojo().addActionListener(this);
|
79 |
pTrans.getTVerde().addActionListener(this);
|
80 |
pTrans.getTAzul().addActionListener(this);
|
81 |
pTrans.getOpacitySlider().addChangeListener(this);
|
82 |
pTrans.getOpacityText().addActionListener(this);
|
83 |
pTrans.getOpacityText().addFocusListener(this);
|
84 |
pTrans.getTRojo().addFocusListener(this);
|
85 |
pTrans.getTVerde().addFocusListener(this);
|
86 |
pTrans.getTAzul().addFocusListener(this);
|
87 |
pTrans.getTRojo().addMouseListener(this);
|
88 |
pTrans.getTVerde().addMouseListener(this);
|
89 |
pTrans.getTAzul().addMouseListener(this);
|
90 |
|
91 |
pEnhan.getTailCheck().addActionListener(this);
|
92 |
pEnhan.getTailSlider().addChangeListener(this);
|
93 |
pEnhan.getSinRealceRadioButton().addMouseListener(this);
|
94 |
pEnhan.getLinealDirectoRadioButton().addMouseListener(this);
|
95 |
pEnhan.getTailText().addActionListener(this);
|
96 |
pEnhan.getTailText().addFocusListener(this);
|
97 |
|
98 |
//Ocultamos el bot?n de aplicar
|
99 |
|
100 |
//this.getApplyButton().setVisible(false);
|
101 |
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* Selecciona el panel indicado por index
|
106 |
* @param index panel seleccionado
|
107 |
*/
|
108 |
public void setSelectedIndex(int index){ |
109 |
tabbedPane.setSelectedIndex(index); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* Obtiene el panel que corresponde a la selecci?n de bandas
|
114 |
* @return Panel de selecci?n de bandas
|
115 |
*/
|
116 |
public BandSetupPanel getBandSetup(){
|
117 |
return this.pSetup; |
118 |
} |
119 |
|
120 |
/**
|
121 |
* Obtiene el panel que corresponde a la selecci?n de transparencia y opacidad
|
122 |
* @return Panel de transparencia y opacidad
|
123 |
*/
|
124 |
public RasterTransparencyPanel getTransparencyPanel(){
|
125 |
return this.pTrans; |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Obtiene el panel que corresponde al filtro de realce
|
130 |
* @return Panel del filtro de realce
|
131 |
*/
|
132 |
public EnhancedPanel getEnhancedPanel(){
|
133 |
return this.pEnhan; |
134 |
} |
135 |
|
136 |
public InfoPanel getInfoPanel(){
|
137 |
return this.pInfo; |
138 |
} |
139 |
|
140 |
public void actionPerformed(ActionEvent e){ |
141 |
|
142 |
//Evento sobre el checkbox de opacidad
|
143 |
|
144 |
if( e.getSource().equals(pTrans.getOpacityCheck())){
|
145 |
|
146 |
//Check de opacidad activado -> Activar controles de opacidad
|
147 |
if(pTrans.getOpacityCheck().isSelected()){
|
148 |
pTrans.getOpacitySlider().setEnabled(true);
|
149 |
pTrans.getOpacityText().setEnabled(true);
|
150 |
}else{
|
151 |
pTrans.getOpacitySlider().setEnabled(false);
|
152 |
pTrans.getOpacityText().setEnabled(false);
|
153 |
} |
154 |
|
155 |
} |
156 |
|
157 |
//Evento sobre el checkbox de transparencia
|
158 |
|
159 |
if( e.getSource().equals(pTrans.getTransparencyCheck())){
|
160 |
|
161 |
//Check de opacidad activado -> Activar controles de opacidad
|
162 |
if(pTrans.getTransparencyCheck().isSelected()){
|
163 |
pTrans.getTRojo().setEnabled(true);
|
164 |
pTrans.getTVerde().setEnabled(true);
|
165 |
pTrans.getTAzul().setEnabled(true);
|
166 |
}else{
|
167 |
pTrans.getTRojo().setEnabled(false);
|
168 |
pTrans.getTVerde().setEnabled(false);
|
169 |
pTrans.getTAzul().setEnabled(false);
|
170 |
} |
171 |
|
172 |
} |
173 |
|
174 |
//Evento sobre el textfield de opacidad
|
175 |
|
176 |
if( e.getSource().equals(pTrans.getOpacityText())){
|
177 |
checkOpacityText(); |
178 |
} |
179 |
|
180 |
//Evento sobre el textfield de valor para el Rojo
|
181 |
|
182 |
if( e.getSource().equals(pTrans.getTRojo())){
|
183 |
try{
|
184 |
rangeRed = getTransparencyValues(pTrans.getTRojo().getText()); |
185 |
}catch(IOException exc){ |
186 |
pTrans.getTRojo().setText("");
|
187 |
} |
188 |
} |
189 |
|
190 |
//Evento sobre el textfield de valor para el Verde
|
191 |
|
192 |
if( e.getSource().equals(pTrans.getTVerde())){
|
193 |
try{
|
194 |
rangeGreen = getTransparencyValues(pTrans.getTVerde().getText()); |
195 |
}catch(IOException exc){ |
196 |
pTrans.getTVerde().setText("");
|
197 |
} |
198 |
} |
199 |
|
200 |
//Evento sobre el textfield de valor para el Azul
|
201 |
|
202 |
if( e.getSource().equals(pTrans.getTAzul())){
|
203 |
try{
|
204 |
rangeBlue = getTransparencyValues(pTrans.getTAzul().getText()); |
205 |
}catch(IOException exc){ |
206 |
pTrans.getTAzul().setText("");
|
207 |
} |
208 |
} |
209 |
|
210 |
//Evento sobre el checkbox de Recorte de colas
|
211 |
|
212 |
if( e.getSource().equals(pEnhan.getTailCheck())){
|
213 |
if(pEnhan.getTailCheck().isSelected())
|
214 |
pEnhan.setActiveTailControl(true);
|
215 |
else
|
216 |
pEnhan.setActiveTailControl(false);
|
217 |
|
218 |
} |
219 |
|
220 |
//Evento sobre el textfield de porcentaje de recorte
|
221 |
|
222 |
if( e.getSource().equals(pEnhan.getTailText())){
|
223 |
checkTailText(); |
224 |
} |
225 |
|
226 |
} |
227 |
|
228 |
/**
|
229 |
* Obtiene el rango de valores a partir de la cadena de
|
230 |
* texto introducida por el usuario.
|
231 |
* @param values
|
232 |
*/
|
233 |
private int[][] getTransparencyValues(String values)throws IOException{ |
234 |
|
235 |
int[][] rangeTransparency = null; |
236 |
|
237 |
for(int i=0;i<values.length();i++){ |
238 |
char c = values.charAt(i);
|
239 |
|
240 |
//Control de caracter valido
|
241 |
if(c != ':' && c != ','){ |
242 |
try{
|
243 |
Integer.parseInt(String.valueOf(c)); |
244 |
}catch(Exception exp){ |
245 |
System.err.println("Caracteres incorrectos en la cadena:"+c); |
246 |
throw new IOException("Caracteres incorrectos en la cadena."); |
247 |
} |
248 |
} |
249 |
|
250 |
//Control de comienzo por un simbolo
|
251 |
if( values.startsWith(",") || values.startsWith(":") || |
252 |
values.endsWith(",") || values.endsWith(":")){ |
253 |
System.err.println("La cadena empieza o acaba con simbolos incorrectos"); |
254 |
throw new IOException(); |
255 |
} |
256 |
|
257 |
//Control de signos consecutivos
|
258 |
if(i<values.length()-1){ |
259 |
|
260 |
char cmas = values.charAt(i+1); |
261 |
if((c == ',' || c == ':') && (cmas == ',' || cmas == ':')){ |
262 |
System.err.println("Signos consecutivos"); |
263 |
throw new IOException(); |
264 |
} |
265 |
|
266 |
} |
267 |
|
268 |
//Control de dos : seguidos con un n?mero en el medio
|
269 |
if(i<values.length()-3 && c==':'){ |
270 |
int n=i+1; |
271 |
while(n<values.length()-1 && values.charAt(n) != ',' && values.charAt(n) != ':') |
272 |
n++; |
273 |
|
274 |
char signoSgte = values.charAt(n);
|
275 |
if(signoSgte == ':'){ |
276 |
System.err.println("Dos separadores de rango consecutivos"); |
277 |
throw new IOException(); |
278 |
} |
279 |
} |
280 |
|
281 |
} |
282 |
|
283 |
//Obtenemos los valores de los intervalos
|
284 |
|
285 |
if(!values.equals("")){ |
286 |
String[] t1 = null; |
287 |
t1 = values.split("\\,");
|
288 |
rangeTransparency = new int[t1.length][2]; |
289 |
for(int i=0;i<t1.length;i++){ |
290 |
if(t1[i].indexOf(":")==-1){ |
291 |
rangeTransparency[i][0] = rangeTransparency[i][1] = Integer.parseInt(t1[i]); |
292 |
}else{
|
293 |
String[] t2 = null; |
294 |
t2 = t1[i].split("\\:");
|
295 |
if(Integer.parseInt(t2[1])>Integer.parseInt(t2[0])){ |
296 |
rangeTransparency[i][0] = Integer.parseInt(t2[0]); |
297 |
rangeTransparency[i][1] = Integer.parseInt(t2[1]); |
298 |
}else{
|
299 |
rangeTransparency[i][0] = Integer.parseInt(t2[1]); |
300 |
rangeTransparency[i][1] = Integer.parseInt(t2[0]); |
301 |
} |
302 |
} |
303 |
if( rangeTransparency[i][0]<0 || rangeTransparency[i][0]>255 || |
304 |
rangeTransparency[i][1]<0 || rangeTransparency[i][1]>255){ |
305 |
System.err.println("Valores fuera de rango (0-255)"); |
306 |
throw new IOException(); |
307 |
} |
308 |
} |
309 |
return rangeTransparency;
|
310 |
//for(int i=0;i<rangeTransparency.length;i++)
|
311 |
// System.out.println("("+rangeTransparency[i][0]+":"+rangeTransparency[i][1]+")");
|
312 |
} |
313 |
|
314 |
return null; |
315 |
} |
316 |
|
317 |
/**
|
318 |
* Devuelve el rango de valores para poner transparencia en el Rojo
|
319 |
* @return
|
320 |
*/
|
321 |
public int[][] getRangeRed(){ |
322 |
return rangeRed;
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* Devuelve el rango de valores para poner transparencia en el Verde
|
327 |
* @return
|
328 |
*/
|
329 |
public int[][] getRangeGreen(){ |
330 |
return rangeGreen;
|
331 |
} |
332 |
|
333 |
/**
|
334 |
* Devuelve el rango de valores para poner transparencia en el Azul
|
335 |
* @return
|
336 |
*/
|
337 |
public int[][] getRangeBlue(){ |
338 |
return rangeBlue;
|
339 |
} |
340 |
|
341 |
/**
|
342 |
* Asigna valore para los rangos
|
343 |
* @param red
|
344 |
* @param green
|
345 |
* @param blue
|
346 |
*/
|
347 |
public void setRanges(int[][] red, int[][] green, int[][] blue){ |
348 |
rangeRed = red; |
349 |
rangeGreen = green; |
350 |
rangeBlue = blue; |
351 |
if(pTrans!=null){ |
352 |
StringBuffer rango = new StringBuffer(); |
353 |
if(red!=null){ |
354 |
for(int i=0;i<red.length;i++){ |
355 |
if(red[i][0] == red[i][1]) |
356 |
rango.append(String.valueOf(red[i][0])+","); |
357 |
else
|
358 |
rango.append(String.valueOf(red[i][0])+":"+String.valueOf(red[i][1])+","); |
359 |
} |
360 |
String t = rango.toString();
|
361 |
if(t.endsWith(",")) |
362 |
t = t.substring(0, t.length()-1); |
363 |
pTrans.getTRojo().setText(t); |
364 |
pTrans.setActiveTransparencyControl(true);
|
365 |
} |
366 |
|
367 |
if(green!=null){ |
368 |
rango = new StringBuffer(); |
369 |
for(int i=0;i<green.length;i++){ |
370 |
if(green[i][0] == green[i][1]) |
371 |
rango.append(String.valueOf(green[i][0])+","); |
372 |
else
|
373 |
rango.append(String.valueOf(green[i][0])+":"+String.valueOf(green[i][1])+","); |
374 |
} |
375 |
String t = rango.toString();
|
376 |
if(t.endsWith(",")) |
377 |
t = t.substring(0, t.length()-1); |
378 |
pTrans.getTVerde().setText(t); |
379 |
pTrans.setActiveTransparencyControl(true);
|
380 |
} |
381 |
|
382 |
if(blue!=null){ |
383 |
rango = new StringBuffer(); |
384 |
for(int i=0;i<blue.length;i++){ |
385 |
if(blue[i][0] == blue[i][1]) |
386 |
rango.append(String.valueOf(blue[i][0])+","); |
387 |
else
|
388 |
rango.append(String.valueOf(blue[i][0])+":"+String.valueOf(blue[i][1])+","); |
389 |
} |
390 |
String t = rango.toString();
|
391 |
if(t.endsWith(",")) |
392 |
t = t.substring(0, t.length()-1); |
393 |
pTrans.setActiveTransparencyControl(true);
|
394 |
pTrans.getTAzul().setText(t); |
395 |
} |
396 |
|
397 |
} |
398 |
|
399 |
} |
400 |
|
401 |
/**
|
402 |
* Controla que si el formato introducido en el textfield
|
403 |
* de opacidad es numerico se actualiza la posici?n del
|
404 |
* slider.
|
405 |
*/
|
406 |
private void checkOpacityText(){ |
407 |
String op = pTrans.getOpacityText().getText();
|
408 |
int value = 0; |
409 |
try{
|
410 |
if(!op.equals("")) |
411 |
value = Integer.parseInt(op);
|
412 |
pTrans.getOpacitySlider().setValue(value); |
413 |
}catch(NumberFormatException exc){ |
414 |
System.err.println("Formato no numerico"); |
415 |
pTrans.getOpacityText().setText("100");
|
416 |
pTrans.getOpacitySlider().setValue(100);
|
417 |
} |
418 |
} |
419 |
|
420 |
/**
|
421 |
* Controla que si el formato introducido en el textfield
|
422 |
* de Recorte de colas es numerico se actualiza la posici?n del
|
423 |
* slider
|
424 |
*/
|
425 |
private void checkTailText(){ |
426 |
String op = pEnhan.getTailText().getText();
|
427 |
double value = 0; |
428 |
try{
|
429 |
if(!op.equals("")) |
430 |
value = (Double.parseDouble(op)*100)/50; |
431 |
pEnhan.getTailSlider().setValue((int)Math.round(value)); |
432 |
pEnhan.getTailText().setText(op); |
433 |
}catch(NumberFormatException exc){ |
434 |
System.err.println("Formato no numerico"); |
435 |
pEnhan.getTailText().setText("0.0");
|
436 |
pEnhan.getTailSlider().setValue(0);
|
437 |
} |
438 |
} |
439 |
|
440 |
/**
|
441 |
* Llama a las funciones que obtienen los valores de los pixels a los que se
|
442 |
* quiere aplicar transparencia desde las cajas de texto.
|
443 |
*/
|
444 |
public void checkTransparencyValues(){ |
445 |
|
446 |
if(!pTrans.getTRojo().getText().equals("")){ |
447 |
try{
|
448 |
rangeRed = getTransparencyValues(pTrans.getTRojo().getText()); |
449 |
}catch(IOException exc){ |
450 |
pTrans.getTRojo().setText("");
|
451 |
} |
452 |
} |
453 |
if(!pTrans.getTVerde().getText().equals("")){ |
454 |
try{
|
455 |
rangeGreen = getTransparencyValues(pTrans.getTVerde().getText()); |
456 |
}catch(IOException exc){ |
457 |
pTrans.getTVerde().setText("");
|
458 |
} |
459 |
} |
460 |
if(!pTrans.getTAzul().getText().equals("")){ |
461 |
try{
|
462 |
rangeBlue = getTransparencyValues(pTrans.getTAzul().getText()); |
463 |
}catch(IOException exc){ |
464 |
pTrans.getTAzul().setText("");
|
465 |
} |
466 |
} |
467 |
} |
468 |
|
469 |
/*
|
470 |
*
|
471 |
*/
|
472 |
public void stateChanged(ChangeEvent e){ |
473 |
|
474 |
//Ponemos el valor del texto de la opacidad de pendiendo de la posici?n del Slider
|
475 |
if(e.getSource().equals(pTrans.getOpacitySlider()))
|
476 |
pTrans.getOpacityText().setText(String.valueOf(pTrans.getOpacitySlider().getValue()));
|
477 |
|
478 |
if(e.getSource().equals(pEnhan.getTailSlider()))
|
479 |
pEnhan.getTailText().setText(String.valueOf((pEnhan.getTailSlider().getValue()>>1))+".0"); |
480 |
} |
481 |
|
482 |
public void focusGained(FocusEvent e) { |
483 |
} |
484 |
|
485 |
public void focusLost(FocusEvent e) { |
486 |
checkOpacityText(); |
487 |
checkTailText(); |
488 |
checkTransparencyValues(); |
489 |
} |
490 |
|
491 |
public void mouseExited(MouseEvent e){} |
492 |
public void mouseReleased(MouseEvent e){} |
493 |
public void mouseEntered(MouseEvent e){} |
494 |
|
495 |
public void mouseClicked(MouseEvent e){} |
496 |
|
497 |
public void mousePressed(MouseEvent e){ |
498 |
checkTransparencyValues(); |
499 |
|
500 |
//Evento sobre los radio button de Realce
|
501 |
|
502 |
if(e.getSource().equals(pEnhan.getSinRealceRadioButton())){
|
503 |
if(pEnhan.getSinRealceRadioButton().isEnabled()){
|
504 |
pEnhan.getTailCheck().setEnabled(false);
|
505 |
pEnhan.setActiveTailControl(false);
|
506 |
pEnhan.getSinRealceRadioButton().setSelected(true);
|
507 |
pEnhan.getRemoveCheck().setEnabled(false);
|
508 |
} |
509 |
} |
510 |
|
511 |
if(e.getSource().equals(pEnhan.getLinealDirectoRadioButton())){
|
512 |
pEnhan.getTailCheck().setEnabled(true);
|
513 |
pEnhan.getRemoveCheck().setEnabled(true);
|
514 |
if(pEnhan.getTailCheck().isSelected()){
|
515 |
pEnhan.setActiveTailControl(true);
|
516 |
} |
517 |
} |
518 |
} |
519 |
|
520 |
public void keyTyped(KeyEvent e){ |
521 |
} |
522 |
public void keyPressed(KeyEvent e){ |
523 |
} |
524 |
public void keyReleased(KeyEvent e){} |
525 |
|
526 |
} |
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|