svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / ui / raster / FilterRasterDialogPanel.java @ 4578
History | View | Annotate | Download (12.7 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.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
import java.awt.event.FocusEvent; |
29 |
import java.awt.event.FocusListener; |
30 |
import java.awt.event.KeyEvent; |
31 |
import java.awt.event.KeyListener; |
32 |
import java.awt.event.MouseEvent; |
33 |
import java.awt.event.MouseListener; |
34 |
import java.util.ArrayList; |
35 |
import java.util.TreeMap; |
36 |
|
37 |
import javax.swing.JPanel; |
38 |
import javax.swing.event.ChangeEvent; |
39 |
import javax.swing.event.ChangeListener; |
40 |
|
41 |
import org.cresques.io.GeoRasterFile; |
42 |
import org.cresques.io.raster.IRasterOperationsRegistrablePanels; |
43 |
import org.cresques.io.raster.TransparencyRange; |
44 |
import org.cresques.ui.DefaultTabPanel; |
45 |
|
46 |
|
47 |
/**
|
48 |
* Panel que contiene todos los paneles de los tabs del cuadro de dialogo
|
49 |
* de bandas y transparencias
|
50 |
*
|
51 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
52 |
*/
|
53 |
public class FilterRasterDialogPanel extends DefaultTabPanel |
54 |
implements ActionListener, ChangeListener, MouseListener, FocusListener, |
55 |
KeyListener {
|
56 |
final private static long serialVersionUID = -3370601314380922368L; |
57 |
|
58 |
/**
|
59 |
* Tama?o en X del panel interior.El tab de dentro es proporcional
|
60 |
*/
|
61 |
protected int sizePanelX = 450; |
62 |
|
63 |
/**
|
64 |
* Tama?o en Y del panel interior. El tab de dentro es proporcional
|
65 |
*/
|
66 |
protected int sizePanelY = 260; |
67 |
|
68 |
/**
|
69 |
* Propiedades guardadas en una matriz Nx2 con la forma propiedad/valor.
|
70 |
*/
|
71 |
public Object[][] props = null; |
72 |
|
73 |
/**
|
74 |
* N?mero de bandas.
|
75 |
*/
|
76 |
protected int nbands = 0; |
77 |
|
78 |
/**
|
79 |
* Lista de georrasterfiles correspondiente a los ficheros de bandas
|
80 |
*/
|
81 |
protected GeoRasterFile[] grf = null; |
82 |
private TreeMap shadePanel = new TreeMap(); |
83 |
|
84 |
//Paneles que se registran dentro de esta misma clase
|
85 |
private RasterTransparencyPanel pTrans = null; |
86 |
private BandSetupPanel pSetup = null; |
87 |
private EnhancedPanel pEnhan = null; |
88 |
private InfoPanel pInfo = null; |
89 |
|
90 |
|
91 |
/**
|
92 |
* Constructor. Inicializa los paneles y propiedades
|
93 |
* @param props Propiedades
|
94 |
*/
|
95 |
public FilterRasterDialogPanel(Object[][] props) { |
96 |
super();
|
97 |
init(props); |
98 |
} |
99 |
|
100 |
/**
|
101 |
* Constructor
|
102 |
*/
|
103 |
public FilterRasterDialogPanel() {
|
104 |
super();
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Inicializa las propiedades
|
109 |
* @param props Propiedades. Guardadas en una matriz Nx2 con la forma proiedad/valor
|
110 |
*/
|
111 |
public void init(Object[][] props) { |
112 |
contentPane.setPreferredSize(new java.awt.Dimension(sizePanelX,
|
113 |
sizePanelY)); |
114 |
this.tabbedPane.setPreferredSize(new java.awt.Dimension(sizePanelX, |
115 |
sizePanelY - 5));
|
116 |
this.props = props;
|
117 |
initPanels(); |
118 |
} |
119 |
|
120 |
/**
|
121 |
* This method initializes this
|
122 |
*
|
123 |
* @return void
|
124 |
*/
|
125 |
protected void initPanels() { |
126 |
this.setBounds(0, 0, 355, 230); |
127 |
pTrans = new RasterTransparencyPanel(this); |
128 |
pSetup = new BandSetupPanel();
|
129 |
pEnhan = new EnhancedPanel(this); |
130 |
pInfo = new InfoPanel(this); |
131 |
|
132 |
this.addTab(pInfo.getName(), pInfo);
|
133 |
this.addTab(pSetup.getName(), pSetup);
|
134 |
this.addTab(pTrans.getName(), pTrans);
|
135 |
this.addTab(pEnhan.getName(), pEnhan);
|
136 |
|
137 |
pTrans.getOpacityCheck().addActionListener(this);
|
138 |
pTrans.getTransparencyCheck().addActionListener(this);
|
139 |
pTrans.getOpacitySlider().addChangeListener(this);
|
140 |
pTrans.getOpacityText().addActionListener(this);
|
141 |
pTrans.getOpacityText().addFocusListener(this);
|
142 |
pTrans.addFocusListener(this);
|
143 |
this.getTab().addFocusListener(this); |
144 |
|
145 |
pEnhan.getTailCheck().addActionListener(this);
|
146 |
pEnhan.getTailSlider().addChangeListener(this);
|
147 |
pEnhan.getSinRealceRadioButton().addMouseListener(this);
|
148 |
pEnhan.getLinealDirectoRadioButton().addMouseListener(this);
|
149 |
pEnhan.getTailText().addActionListener(this);
|
150 |
pEnhan.getTailText().addFocusListener(this);
|
151 |
|
152 |
//Ocultamos el bot?n de aplicar
|
153 |
//this.getApplyButton().setVisible(false);
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* Asigna la visibilidad de un tab a verdadero o falso. La
|
158 |
* selecci?n del tab se hace por el identificador.
|
159 |
* @param tab Identificador del tab. Variable nom del mismo
|
160 |
* @param active True o false para visible o invisible.
|
161 |
*/
|
162 |
public void setTabVisible(String tab, boolean active){ |
163 |
if(active == false){ |
164 |
for(int i=0; i<this.getTab().getTabCount(); i++){ |
165 |
if(tab.equals( ((JPanel)this.getTab().getComponentAt(i)).getName() )){ |
166 |
shadePanel.put(tab, this.getTab().getComponentAt(i));
|
167 |
this.getTab().removeTabAt(i);
|
168 |
} |
169 |
} |
170 |
}else
|
171 |
this.addTab(tab, ((JPanel)shadePanel.get(tab)) ); |
172 |
} |
173 |
|
174 |
/**
|
175 |
* Selecciona el panel indicado por index
|
176 |
* @param index panel seleccionado
|
177 |
*/
|
178 |
public void setSelectedIndex(int index) { |
179 |
tabbedPane.setSelectedIndex(index); |
180 |
} |
181 |
|
182 |
/**
|
183 |
* Obtiene un panel a trav?s del nombre de su clase
|
184 |
* @param name Nombre de la clase del panel
|
185 |
*/
|
186 |
public JPanel getPanelByClassName(String name){ |
187 |
for(int i=0;i<super.getTab().getTabCount() ;i++){ |
188 |
JPanel p = (JPanel)super.getTab().getComponentAt(i); |
189 |
if(p.getClass().getName().endsWith(name))
|
190 |
return p;
|
191 |
} |
192 |
return null; |
193 |
} |
194 |
|
195 |
/**
|
196 |
* Eventos sobre TextField y CheckBox. Controla eventos de checkbox de opacidad, transparencia,
|
197 |
* recorte de colas y los textfield de opacidad, valores de transparencia por banda y
|
198 |
* porcentaje de recorte.
|
199 |
*/
|
200 |
public void actionPerformed(ActionEvent e) { |
201 |
//Evento sobre el checkbox de opacidad
|
202 |
if (e.getSource().equals(pTrans.getOpacityCheck())) {
|
203 |
//Check de opacidad activado -> Activar controles de opacidad
|
204 |
if (pTrans.getOpacityCheck().isSelected()) {
|
205 |
pTrans.getOpacitySlider().setEnabled(true);
|
206 |
pTrans.getOpacityText().setEnabled(true);
|
207 |
} else {
|
208 |
pTrans.getOpacitySlider().setEnabled(false);
|
209 |
pTrans.getOpacityText().setEnabled(false);
|
210 |
} |
211 |
} |
212 |
|
213 |
//Evento sobre el checkbox de transparencia
|
214 |
if (e.getSource().equals(pTrans.getTransparencyCheck())) {
|
215 |
//Check de opacidad activado -> Activar controles de opacidad
|
216 |
if (pTrans.getTransparencyCheck().isSelected()) {
|
217 |
pTrans.getPTranspByPixel().setControlEnabled(true);
|
218 |
pTrans.getPTranspByPixel().getPRGBInput().setActiveBands(nbands); |
219 |
}else
|
220 |
pTrans.getPTranspByPixel().setControlEnabled(false);
|
221 |
} |
222 |
|
223 |
//Evento sobre el textfield de opacidad
|
224 |
if (e.getSource().equals(pTrans.getOpacityText())) {
|
225 |
checkOpacityText(); |
226 |
} |
227 |
|
228 |
//Evento sobre el checkbox de Recorte de colas
|
229 |
if (e.getSource().equals(pEnhan.getTailCheck())) {
|
230 |
if (pEnhan.getTailCheck().isSelected()) {
|
231 |
pEnhan.setActiveTailControl(true);
|
232 |
} else {
|
233 |
pEnhan.setActiveTailControl(false);
|
234 |
} |
235 |
} |
236 |
|
237 |
//Evento sobre el textfield de porcentaje de recorte
|
238 |
if (e.getSource().equals(pEnhan.getTailText())) {
|
239 |
checkTailText(); |
240 |
} |
241 |
} |
242 |
|
243 |
/**
|
244 |
* Asigna valores para los rangos.
|
245 |
* @param ranges
|
246 |
*/
|
247 |
public void setRanges(ArrayList ranges) { |
248 |
if(ranges != null){ |
249 |
TransparencyByPixelPanel panel = (TransparencyByPixelPanel)pTrans.getPTranspByPixel(); |
250 |
pTrans.getTransparencyCheck().setSelected(true);
|
251 |
panel.setControlEnabled(true);
|
252 |
panel.setEntries(ranges); |
253 |
for(int i=0;i<ranges.size();i++) |
254 |
panel.getListModel().addElement( ((TransparencyRange)ranges.get(i)).getStrEntry() ); |
255 |
} |
256 |
} |
257 |
|
258 |
/**
|
259 |
* A?ade las bandas de los georrasterfile a los paneles
|
260 |
* que lo necesitan
|
261 |
* @param files
|
262 |
*/
|
263 |
public void addFiles(GeoRasterFile[] files){ |
264 |
for(int i=0;i<this.getTab().getTabCount();i++){ |
265 |
if(this.getTab().getComponentAt(i) instanceof IRasterOperationsRegistrablePanels) |
266 |
((IRasterOperationsRegistrablePanels)getTab().getComponentAt(i)).addFiles(files); |
267 |
} |
268 |
|
269 |
if(pSetup != null) |
270 |
pSetup.addFiles(files); |
271 |
} |
272 |
|
273 |
/**
|
274 |
* Elimina las bandas de los georrasterfile a los paneles
|
275 |
* @param file Banda a eliminar
|
276 |
*/
|
277 |
public void removeFile(String file) { |
278 |
for(int i=0;i<this.getTab().getTabCount();i++){ |
279 |
if(this.getTab().getComponentAt(i) instanceof IRasterOperationsRegistrablePanels); |
280 |
((IRasterOperationsRegistrablePanels)getTab().getComponentAt(i)).removeFile(file); |
281 |
} |
282 |
if(pSetup != null) |
283 |
pSetup.removeFile(file); |
284 |
} |
285 |
|
286 |
/**
|
287 |
* Controla que si el formato introducido en el textfield
|
288 |
* de opacidad es numerico se actualiza la posici?n del
|
289 |
* slider.
|
290 |
*/
|
291 |
private void checkOpacityText() { |
292 |
String op = pTrans.getOpacityText().getText();
|
293 |
int value = 0; |
294 |
|
295 |
try {
|
296 |
if (!op.equals("")) { |
297 |
value = Integer.parseInt(op);
|
298 |
} |
299 |
|
300 |
pTrans.getOpacitySlider().setValue(value); |
301 |
} catch (NumberFormatException exc) { |
302 |
System.err.println("Formato no numerico"); |
303 |
pTrans.getOpacityText().setText("100");
|
304 |
pTrans.getOpacitySlider().setValue(100);
|
305 |
} |
306 |
} |
307 |
|
308 |
/**
|
309 |
* Controla que si el formato introducido en el textfield
|
310 |
* de Recorte de colas es numerico se actualiza la posici?n del
|
311 |
* slider
|
312 |
*/
|
313 |
private void checkTailText() { |
314 |
String op = pEnhan.getTailText().getText();
|
315 |
double value = 0; |
316 |
|
317 |
try {
|
318 |
if (!op.equals("")) { |
319 |
value = (Double.parseDouble(op) * 100) / 50; |
320 |
} |
321 |
|
322 |
pEnhan.getTailSlider().setValue((int) Math.round(value)); |
323 |
pEnhan.getTailText().setText(op); |
324 |
} catch (NumberFormatException exc) { |
325 |
System.err.println("Formato no numerico"); |
326 |
pEnhan.getTailText().setText("0.0");
|
327 |
pEnhan.getTailSlider().setValue(0);
|
328 |
} |
329 |
} |
330 |
|
331 |
/*
|
332 |
*
|
333 |
*/
|
334 |
public void stateChanged(ChangeEvent e) { |
335 |
//Ponemos el valor del texto de la opacidad de pendiendo de la posici?n del Slider
|
336 |
if (e.getSource().equals(pTrans.getOpacitySlider())) {
|
337 |
pTrans.getOpacityText().setText( |
338 |
String.valueOf(pTrans.getOpacitySlider().getValue()));
|
339 |
} |
340 |
|
341 |
if (e.getSource().equals(pEnhan.getTailSlider())) {
|
342 |
pEnhan.getTailText().setText( |
343 |
String.valueOf((pEnhan.getTailSlider().getValue() >> 1)) + ".0"); |
344 |
} |
345 |
} |
346 |
|
347 |
public void focusGained(FocusEvent e) { |
348 |
//pTrans.updateTextBox();
|
349 |
} |
350 |
|
351 |
public void focusLost(FocusEvent e) { |
352 |
checkOpacityText(); |
353 |
checkTailText(); |
354 |
} |
355 |
|
356 |
public void mouseExited(MouseEvent e) { |
357 |
} |
358 |
|
359 |
public void mouseReleased(MouseEvent e) { |
360 |
} |
361 |
|
362 |
public void mouseEntered(MouseEvent e) { |
363 |
} |
364 |
|
365 |
public void mouseClicked(MouseEvent e) { |
366 |
} |
367 |
|
368 |
public void mousePressed(MouseEvent e) { |
369 |
//Evento sobre los radio button de Realce
|
370 |
if (e.getSource().equals(pEnhan.getSinRealceRadioButton())) {
|
371 |
if (pEnhan.getSinRealceRadioButton().isEnabled()) {
|
372 |
pEnhan.getTailCheck().setEnabled(false);
|
373 |
pEnhan.setActiveTailControl(false);
|
374 |
pEnhan.getSinRealceRadioButton().setSelected(true);
|
375 |
pEnhan.setActiveRemoveCheck(false);
|
376 |
} |
377 |
} |
378 |
|
379 |
if (e.getSource().equals(pEnhan.getLinealDirectoRadioButton())) {
|
380 |
pEnhan.getTailCheck().setEnabled(true);
|
381 |
pEnhan.setActiveRemoveCheck(true);
|
382 |
|
383 |
if (pEnhan.getTailCheck().isSelected()) {
|
384 |
pEnhan.setActiveTailControl(true);
|
385 |
} |
386 |
} |
387 |
} |
388 |
|
389 |
public void keyTyped(KeyEvent e) { |
390 |
} |
391 |
|
392 |
public void keyPressed(KeyEvent e) { |
393 |
} |
394 |
|
395 |
public void keyReleased(KeyEvent e) { |
396 |
} |
397 |
} |