svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / FilterRasterDialogPanel.java @ 1757
History | View | Annotate | Download (6.32 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 |
|
31 |
public FilterRasterDialogPanel() {
|
32 |
|
33 |
super();
|
34 |
contentPane.setPreferredSize(new java.awt.Dimension(sizePanelX, sizePanelY));
|
35 |
this.tabbedPane.setPreferredSize(new java.awt.Dimension(sizePanelX, sizePanelY-5)); |
36 |
initPanels(); |
37 |
|
38 |
} |
39 |
|
40 |
/**
|
41 |
* This method initializes this
|
42 |
*
|
43 |
* @return void
|
44 |
*/
|
45 |
protected void initPanels() { |
46 |
|
47 |
this.setBounds(0,0,355,230); |
48 |
pTrans = new RasterTransparencyPanel(this); |
49 |
pSetup = new BandSetupPanel();
|
50 |
this.addTab(pSetup.nom, pSetup);
|
51 |
this.addTab(pTrans.nom, pTrans);
|
52 |
|
53 |
pTrans.getCbOpacidad().addActionListener(this);
|
54 |
pTrans.getCbTransparencia().addActionListener(this);
|
55 |
pTrans.getTRojo().addActionListener(this);
|
56 |
pTrans.getTVerde().addActionListener(this);
|
57 |
pTrans.getTAzul().addActionListener(this);
|
58 |
pTrans.getSlOpacidad().addChangeListener(this);
|
59 |
pTrans.getTOpacidad().addActionListener(this);
|
60 |
pTrans.getTOpacidad().addFocusListener(this);
|
61 |
|
62 |
//Ocultamos el bot?n de aplicar
|
63 |
|
64 |
//this.getApplyButton().setVisible(false);
|
65 |
|
66 |
} |
67 |
|
68 |
/**
|
69 |
*
|
70 |
* @return
|
71 |
*/
|
72 |
public BandSetupPanel getBandSetup(){
|
73 |
return this.pSetup; |
74 |
} |
75 |
|
76 |
/**
|
77 |
*
|
78 |
* @return
|
79 |
*/
|
80 |
public RasterTransparencyPanel getTransparencyPanel(){
|
81 |
return this.pTrans; |
82 |
} |
83 |
|
84 |
public void actionPerformed(ActionEvent e){ |
85 |
|
86 |
//Evento sobre el checkbox de opacidad
|
87 |
|
88 |
if( e.getSource().equals(pTrans.getCbOpacidad())){
|
89 |
|
90 |
//Check de opacidad activado -> Activar controles de opacidad
|
91 |
if(pTrans.getCbOpacidad().isSelected()){
|
92 |
pTrans.getSlOpacidad().setEnabled(true);
|
93 |
pTrans.getTOpacidad().setEnabled(true);
|
94 |
}else{
|
95 |
pTrans.getSlOpacidad().setEnabled(false);
|
96 |
pTrans.getTOpacidad().setEnabled(false);
|
97 |
} |
98 |
|
99 |
} |
100 |
|
101 |
//Evento sobre el checkbox de transparencia
|
102 |
|
103 |
if( e.getSource().equals(pTrans.getCbTransparencia())){
|
104 |
|
105 |
//Check de opacidad activado -> Activar controles de opacidad
|
106 |
if(pTrans.getCbTransparencia().isSelected()){
|
107 |
pTrans.getTRojo().setEnabled(true);
|
108 |
pTrans.getTVerde().setEnabled(true);
|
109 |
pTrans.getTAzul().setEnabled(true);
|
110 |
}else{
|
111 |
pTrans.getTRojo().setEnabled(false);
|
112 |
pTrans.getTVerde().setEnabled(false);
|
113 |
pTrans.getTAzul().setEnabled(false);
|
114 |
} |
115 |
|
116 |
} |
117 |
|
118 |
//Evento sobre el textfield de opacidad
|
119 |
|
120 |
if( e.getSource().equals(pTrans.getTOpacidad())){
|
121 |
checkOpacity(); |
122 |
} |
123 |
|
124 |
//Evento sobre el textfield de valor para el Rojo
|
125 |
|
126 |
if( e.getSource().equals(pTrans.getTRojo())){
|
127 |
try{
|
128 |
getTransparencyValues(pTrans.getTRojo().getText()); |
129 |
}catch(IOException exc){ |
130 |
pTrans.getTRojo().setText("");
|
131 |
} |
132 |
} |
133 |
|
134 |
//Evento sobre el textfield de valor para el Verde
|
135 |
|
136 |
if( e.getSource().equals(pTrans.getTVerde())){
|
137 |
try{
|
138 |
getTransparencyValues(pTrans.getTVerde().getText()); |
139 |
}catch(IOException exc){ |
140 |
pTrans.getTVerde().setText("");
|
141 |
} |
142 |
} |
143 |
|
144 |
//Evento sobre el textfield de valor para el Azul
|
145 |
|
146 |
if( e.getSource().equals(pTrans.getTAzul())){
|
147 |
try{
|
148 |
getTransparencyValues(pTrans.getTAzul().getText()); |
149 |
}catch(IOException exc){ |
150 |
pTrans.getTAzul().setText("");
|
151 |
} |
152 |
} |
153 |
|
154 |
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* Obtiene el rango de valores a partir de la cadena de
|
159 |
* texto introducida por el usuario.
|
160 |
* @param values
|
161 |
*/
|
162 |
private void getTransparencyValues(String values)throws IOException{ |
163 |
|
164 |
for(int i=0;i<values.length();i++){ |
165 |
char c = values.charAt(i);
|
166 |
if( c!='0' && c!='1' && c!='2' && c!='3' && c!='4' && |
167 |
c!='5' && c!='6' && c!='7' && c!='8' && c!='9' && |
168 |
c!='.' && c!=':' && c!=','){ |
169 |
System.err.println("Caracteres incorrectos en la cadena."); |
170 |
throw new IOException("Caracteres incorrectos en la cadena."); |
171 |
} |
172 |
|
173 |
if( values.startsWith(".") || values.startsWith(",") || values.startsWith(":") || |
174 |
values.endsWith(".") || values.endsWith(",") || values.endsWith(":")){ |
175 |
System.err.println("La cadena empieza o acaba con simbolos incorrectos"); |
176 |
throw new IOException(); |
177 |
} |
178 |
if(i<values.length()-1){ |
179 |
char cmas = values.charAt(i+1); |
180 |
if((c==',' || c=='.' || c==':') && (cmas==',' || cmas=='.' || cmas==':')){ |
181 |
System.err.println("Signos de puntuaci?n consecutivos"); |
182 |
throw new IOException(); |
183 |
} |
184 |
|
185 |
} |
186 |
|
187 |
} |
188 |
|
189 |
/*String [] temp = null;
|
190 |
temp = values.split("\\,");
|
191 |
for(int i=0;i<temp.length;i++){
|
192 |
if(temp[i].indexOf(":")==-1){
|
193 |
|
194 |
}
|
195 |
}*/
|
196 |
} |
197 |
/**
|
198 |
* Controla que si el formato introducido en el textfield
|
199 |
* de opacidad es numerico se actualiza la posici?n del
|
200 |
* slider.
|
201 |
*/
|
202 |
private void checkOpacity(){ |
203 |
String op = pTrans.getTOpacidad().getText();
|
204 |
int value = 0; |
205 |
try{
|
206 |
if(!op.equals("")) |
207 |
value = Integer.parseInt(op);
|
208 |
pTrans.getSlOpacidad().setValue(value); |
209 |
}catch(NumberFormatException exc){ |
210 |
System.err.println("Formato no numerico"); |
211 |
pTrans.getTOpacidad().setText("100");
|
212 |
pTrans.getSlOpacidad().setValue(100);
|
213 |
} |
214 |
} |
215 |
|
216 |
/*
|
217 |
*
|
218 |
*/
|
219 |
public void stateChanged(ChangeEvent e){ |
220 |
|
221 |
//Ponemos el valor del texto de la opacidad de pendiendo de la posici?n del Slider
|
222 |
pTrans.getTOpacidad().setText(String.valueOf(pTrans.getSlOpacidad().getValue()));
|
223 |
} |
224 |
|
225 |
public void focusGained(FocusEvent e){} |
226 |
public void focusLost(FocusEvent e){ |
227 |
checkOpacity(); |
228 |
} |
229 |
|
230 |
/*public void mouseExited(MouseEvent e){}
|
231 |
public void mouseReleased(MouseEvent e){}
|
232 |
public void mouseEntered(MouseEvent e){}
|
233 |
|
234 |
public void mouseClicked(MouseEvent e){}
|
235 |
|
236 |
public void mousePressed(MouseEvent e){}
|
237 |
|
238 |
public void keyTyped(KeyEvent e){
|
239 |
}
|
240 |
public void keyPressed(KeyEvent e){
|
241 |
}
|
242 |
public void keyReleased(KeyEvent e){}
|
243 |
*/
|
244 |
} |
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|