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