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