root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / saveraster / ui / panels / listener / DataInputListener.java @ 16554
History | View | Annotate | Download (21.7 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.rastertools.saveraster.ui.panels.listener; |
20 |
|
21 |
import java.awt.event.ActionEvent; |
22 |
import java.awt.event.ActionListener; |
23 |
import java.awt.event.FocusEvent; |
24 |
import java.awt.event.FocusListener; |
25 |
import java.awt.event.KeyEvent; |
26 |
import java.awt.event.KeyListener; |
27 |
import java.awt.event.MouseEvent; |
28 |
import java.awt.event.MouseListener; |
29 |
import java.io.File; |
30 |
import java.util.EventObject; |
31 |
|
32 |
import javax.swing.JFileChooser; |
33 |
|
34 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
35 |
import org.gvsig.gui.beans.datainput.DataInputContainer; |
36 |
import org.gvsig.gui.beans.datainput.DataInputContainerListener; |
37 |
import org.gvsig.raster.dataset.GeoRasterWriter; |
38 |
import org.gvsig.raster.util.ExtendedFileFilter; |
39 |
import org.gvsig.raster.util.MathUtils; |
40 |
import org.gvsig.raster.util.RasterUtilities; |
41 |
import org.gvsig.rastertools.saveraster.ui.SaveRasterDialog; |
42 |
import org.gvsig.rastertools.saveraster.ui.SaveRasterPanel; |
43 |
|
44 |
import com.iver.andami.PluginServices; |
45 |
import com.iver.cit.gvsig.addlayer.fileopen.FileOpenWizard; |
46 |
/**
|
47 |
* Panel encargado de manejar los eventos del los controles de Salvar a Raster
|
48 |
*
|
49 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
50 |
*/
|
51 |
public class DataInputListener implements ActionListener, MouseListener, FocusListener, KeyListener, DataInputContainerListener { |
52 |
final private static long serialVersionUID = -3370601314380922368L; |
53 |
private SaveRasterPanel controlPanel = null; |
54 |
private SaveRasterDialog dialog = null; |
55 |
private String fName = null; |
56 |
private double widthInPixels = 0; |
57 |
private double heightInPixels = 0; |
58 |
private double mtsPerPixel = 0D; |
59 |
private Object obj = null; |
60 |
private double widthMts = 0D, heightMts = 0D; |
61 |
private boolean enableEventValueChanged = true; |
62 |
|
63 |
/**
|
64 |
* This method initializes
|
65 |
*
|
66 |
*/
|
67 |
public DataInputListener(SaveRasterPanel controlPanel) {
|
68 |
super();
|
69 |
this.controlPanel = controlPanel;
|
70 |
initialize(); |
71 |
} |
72 |
|
73 |
/**
|
74 |
* This method initializes this
|
75 |
*
|
76 |
* @return void
|
77 |
*/
|
78 |
void initialize() {
|
79 |
|
80 |
//A?adimos gesti?n de eventos
|
81 |
controlPanel.getTScale().addValueChangedListener(this);
|
82 |
controlPanel.getTMtsPixel().addValueChangedListener(this);
|
83 |
controlPanel.getTWidth().addValueChangedListener(this);
|
84 |
controlPanel.getTHeight().addValueChangedListener(this);
|
85 |
|
86 |
controlPanel.getCbMeasureType().addActionListener(this);
|
87 |
|
88 |
controlPanel.getTInfDerX().addValueChangedListener(this);
|
89 |
controlPanel.getTInfDerY().addValueChangedListener(this);
|
90 |
controlPanel.getTSupIzqX().addValueChangedListener(this);
|
91 |
controlPanel.getTSupIzqY().addValueChangedListener(this);
|
92 |
|
93 |
controlPanel.getBSelect().addActionListener(this);
|
94 |
controlPanel.getBProperties().addActionListener(this);
|
95 |
|
96 |
controlPanel.getCbResolution().addActionListener(this);
|
97 |
controlPanel.getCbResolution().addKeyListener(this);
|
98 |
} |
99 |
|
100 |
/**
|
101 |
* Asigna un valor al panel padre
|
102 |
* @param dialogPanel
|
103 |
*/
|
104 |
public void setDialogPanel(SaveRasterDialog dialog) { |
105 |
this.dialog = dialog;
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* Obtiene el Panel de Controles interior
|
110 |
* @return
|
111 |
*/
|
112 |
public SaveRasterPanel getSaveParameters() {
|
113 |
if (controlPanel == null) { |
114 |
controlPanel = new SaveRasterPanel();
|
115 |
} |
116 |
return controlPanel;
|
117 |
} |
118 |
|
119 |
/**
|
120 |
* A partir del valor de tama?o de imagen de salida, comprueba el tipo de
|
121 |
* dato seleccionado por el usuario (Pixels, mms, cms, mts, pulgadas) y devuelve
|
122 |
* el valor en pixeles.
|
123 |
* @param value Cadena introducida por el usuario
|
124 |
*/
|
125 |
private int getCorrectMeasure(String value){ |
126 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Pixels")) |
127 |
return (int)Double.parseDouble(value); |
128 |
|
129 |
int ppp = Integer.parseInt((String)controlPanel.getCbResolution().getSelectedItem()); |
130 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Mts")) |
131 |
return MathUtils.convertMtsToPixels(Double.parseDouble(value), ppp); |
132 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Cms")) |
133 |
return MathUtils.convertCmsToPixels(Double.parseDouble(value), ppp); |
134 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Mms")) |
135 |
return MathUtils.convertMmsToPixels(Double.parseDouble(value), ppp); |
136 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Inches")) |
137 |
return MathUtils.convertInchesToPixels(Double.parseDouble(value), ppp); |
138 |
|
139 |
return 0; |
140 |
} |
141 |
|
142 |
/**
|
143 |
* Asigna al JTextField pasado como par?metro el valor en pixels, cms, mms ,mtrs, pulgadas dependiendo
|
144 |
* de la selecci?n del combo
|
145 |
* @param pixel Valor en pixels
|
146 |
* @param field Campo donde se escribe el valor
|
147 |
*/
|
148 |
private void setCorrectMeasure(double pixel, DataInputContainer field){ |
149 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Pixels")) { |
150 |
field.setValue(String.valueOf(pixel));
|
151 |
return;
|
152 |
} |
153 |
|
154 |
enableEventValueChanged = false;
|
155 |
int ppp = Integer.parseInt((String)controlPanel.getCbResolution().getSelectedItem()); |
156 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Mts")) |
157 |
field.setValue(String.valueOf(MathUtils.tailDecimals(MathUtils.convertPixelsToMts(pixel, ppp),5))); |
158 |
|
159 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Cms")) |
160 |
field.setValue(String.valueOf(MathUtils.tailDecimals(MathUtils.convertPixelsToCms(pixel, ppp),5))); |
161 |
|
162 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Mms")) |
163 |
field.setValue(String.valueOf(MathUtils.tailDecimals(MathUtils.convertPixelsToMms(pixel, ppp),5))); |
164 |
|
165 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Inches")) |
166 |
field.setValue(String.valueOf(MathUtils.tailDecimals(MathUtils.convertPixelsToInches(pixel, ppp),5))); |
167 |
enableEventValueChanged = true;
|
168 |
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* Calculo del tama?o en pixels de la imagen a partir de las coordenadas del
|
173 |
* mundo real, la escala y los puntos por pulgada
|
174 |
*/
|
175 |
private void recalcParams() { |
176 |
validateFields(); |
177 |
double[] size = null; |
178 |
try{
|
179 |
size = calcSizeInMts(); |
180 |
} catch (NumberFormatException e) { |
181 |
return;
|
182 |
} |
183 |
widthMts = size[0];
|
184 |
heightMts = size[1];
|
185 |
|
186 |
int resolution = Integer.parseInt((String)controlPanel.getCbResolution().getSelectedItem()); |
187 |
|
188 |
//Al variar la resoluci?n independientemente del m?todo seleccionado recalculamos el ancho y el alto
|
189 |
if (obj.equals(controlPanel.getCbResolution())) {
|
190 |
String escala = controlPanel.getTScale().getValue();
|
191 |
try{
|
192 |
if(controlPanel.getProjection().isProjected())
|
193 |
calcSizeMtsPixel(Double.parseDouble(escala), resolution);
|
194 |
} |
195 |
catch(NumberFormatException exc){ |
196 |
calcSizeMtsPixel(0, resolution);
|
197 |
} |
198 |
return;
|
199 |
} |
200 |
|
201 |
//M?todo por escala seleccionado
|
202 |
if( controlPanel.getRbScale().isSelected() &&
|
203 |
!controlPanel.getTScale().getValue().equals("")) {
|
204 |
double scale = Double.parseDouble(controlPanel.getTScale().getValue()); |
205 |
if(controlPanel.getProjection().isProjected())
|
206 |
calcSizeMtsPixel(scale, resolution); |
207 |
else
|
208 |
calcSizeMtsPixelGeodesicas(scale, resolution); |
209 |
} |
210 |
|
211 |
//M?todo por tama?o seleccionado
|
212 |
if(controlPanel.getRbSize().isSelected()) {
|
213 |
double rel = (widthMts / heightMts);
|
214 |
|
215 |
if( obj != null && obj.equals(controlPanel.getTWidth().getDataInputField()) && |
216 |
!controlPanel.getTWidth().getValue().equals("")) {
|
217 |
this.widthInPixels = this.getCorrectMeasure(controlPanel.getTWidth().getValue()); |
218 |
this.heightInPixels = (int)Math.floor(this.widthInPixels / rel); |
219 |
if(controlPanel.getProjection().isProjected())
|
220 |
calcScaleMtsPixel(this.widthInPixels, this.heightInPixels, resolution); |
221 |
} |
222 |
if( obj != null && obj.equals(controlPanel.getTHeight().getDataInputField()) && |
223 |
!controlPanel.getTHeight().getValue().equals("")) {
|
224 |
this.heightInPixels = this.getCorrectMeasure(controlPanel.getTHeight().getValue()); |
225 |
this.widthInPixels = (int)Math.ceil(this.heightInPixels * rel); |
226 |
if(controlPanel.getProjection().isProjected())
|
227 |
calcScaleMtsPixel(this.widthInPixels, this.heightInPixels, resolution); |
228 |
} |
229 |
if( obj != null && |
230 |
obj.equals(controlPanel.getCbMeasureType())) { |
231 |
if(controlPanel.getProjection().isProjected())
|
232 |
calcScaleMtsPixel(this.widthInPixels, this.heightInPixels, resolution); |
233 |
} |
234 |
} |
235 |
|
236 |
//M?todo metros por pixel seleccionado
|
237 |
if( controlPanel.getRbMtsPixel().isSelected() &&
|
238 |
!controlPanel.getTMtsPixel().getValue().equals("")) {
|
239 |
double mtsPixel = Double.parseDouble(controlPanel.getTMtsPixel().getValue()); |
240 |
if(controlPanel.getProjection().isProjected())
|
241 |
calcSizeScale(mtsPixel, resolution); |
242 |
} |
243 |
} |
244 |
|
245 |
/**
|
246 |
* Comprueba si un campo de texto tiene el tipo de dato entero o double y si no lo
|
247 |
* tiene lo borra ya que su contenido es invalido para operar con el
|
248 |
* @param field Campo de texto a validar
|
249 |
* @param isInt true si el valor a validar es entero y false si es double
|
250 |
*/
|
251 |
private void validateTextField(DataInputContainer field){ |
252 |
try {
|
253 |
Double.parseDouble(field.getValue());
|
254 |
} catch (NumberFormatException e) { |
255 |
field.setValue("0");
|
256 |
} |
257 |
} |
258 |
|
259 |
/**
|
260 |
* Valida los campos de texto
|
261 |
*/
|
262 |
private void validateFields(){ |
263 |
|
264 |
//Validamos la escala si se ha introducido algo
|
265 |
if(!controlPanel.getTScale().getValue().equals("")) |
266 |
validateTextField(controlPanel.getTScale()); |
267 |
|
268 |
//Validamos los mts por pixel si se ha introducido algo
|
269 |
if(!controlPanel.getTMtsPixel().getValue().equals("")) |
270 |
validateTextField(controlPanel.getTMtsPixel()); |
271 |
|
272 |
//Validamos el ancho si se ha introducido algo
|
273 |
if(!controlPanel.getTWidth().getValue().equals("")) |
274 |
validateTextField(controlPanel.getTWidth()); |
275 |
|
276 |
//Validamos el alto si se ha introducido algo
|
277 |
if(!controlPanel.getTHeight().getValue().equals("")) |
278 |
validateTextField(controlPanel.getTHeight()); |
279 |
} |
280 |
|
281 |
/**
|
282 |
* Calcula el tama?o en mtrs a partir de las coordenadas.
|
283 |
* TODO: Esto solo es valido para UTM. El ancho y alto debe obtenerse desde la vista
|
284 |
* @return
|
285 |
* @throws NumberFormatException
|
286 |
*/
|
287 |
private double[] calcSizeInMts()throws NumberFormatException{ |
288 |
double[] size = new double[2]; |
289 |
|
290 |
double lrX = Double.parseDouble(controlPanel.getTInfDerX().getValue()); |
291 |
double lrY = Double.parseDouble(controlPanel.getTInfDerY().getValue()); |
292 |
double ulX = Double.parseDouble(controlPanel.getTSupIzqX().getValue()); |
293 |
double ulY = Double.parseDouble(controlPanel.getTSupIzqY().getValue()); |
294 |
|
295 |
if (ulX > lrX)
|
296 |
size[0] = ulX - lrX;
|
297 |
else
|
298 |
size[0] = lrX - ulX;
|
299 |
|
300 |
if (ulY > lrY)
|
301 |
size[1] = ulY - lrY;
|
302 |
else
|
303 |
size[1] = lrY - ulY;
|
304 |
|
305 |
return size;
|
306 |
} |
307 |
|
308 |
/**
|
309 |
* A partir de la escala y la resoluci?n calcula el tama?o en pixels y los metros por pixel
|
310 |
* si la imagen est? en coordenadas geograficas.
|
311 |
* @param scale Escala
|
312 |
* @param resolution Resoluci?n
|
313 |
*/
|
314 |
private void calcSizeMtsPixelGeodesicas(double scaleIntro, int resolution){ |
315 |
//TODO: Calculos para imagenes en coordenadas geograficas
|
316 |
|
317 |
/*double lrX = Double.parseDouble(controlPanel.getTInfDerX().getText());
|
318 |
double ulX = Double.parseDouble(controlPanel.getTSupIzqX().getText());
|
319 |
|
320 |
//Nos aseguramos de que la escala sea un entero. Si no lo es ponemos un 0
|
321 |
try {
|
322 |
Integer.parseInt(controlPanel.getTScale().getText());
|
323 |
} catch (NumberFormatException e) {
|
324 |
controlPanel.getTScale().setText("0");
|
325 |
}
|
326 |
|
327 |
double scale = controlPanel.getProjection().getScale(ulX, lrX,
|
328 |
controlPanel.getWidthInPixelsGeodesicas(),
|
329 |
Integer.parseInt((String)controlPanel.getCbResolution().getSelectedItem()));
|
330 |
|
331 |
this.widthInPixels = (int)((scaleIntro * controlPanel.getWidthInPixelsGeodesicas()) / scale);
|
332 |
this.heightInPixels = (int)((scaleIntro * controlPanel.getHeightInPixelsGeodesicas()) / scale);
|
333 |
|
334 |
mtsPerPixel = MathUtils.tailDecimals(((double)(widthMts / this.widthInPixels)), 5);
|
335 |
|
336 |
controlPanel.getTMtsPixel().setText(String.valueOf(mtsPerPixel));
|
337 |
this.setCorrectMeasure(this.widthInPixels, controlPanel.getTWidth());
|
338 |
this.setCorrectMeasure(this.heightInPixels, controlPanel.getTHeight());*/
|
339 |
} |
340 |
|
341 |
/**
|
342 |
* A partir de la escala y la resoluci?n calcula el tama?o en pixels y los metros por pixel
|
343 |
* @param scale Escala
|
344 |
* @param resolution Resoluci?n
|
345 |
*/
|
346 |
private void calcSizeMtsPixel(double scale, int resolution){ |
347 |
if ((widthMts <= 0) || (heightMts <= 0) || (scale == 0)){ |
348 |
controlPanel.getTWidth().setValue("0");
|
349 |
controlPanel.getTHeight().setValue("0");
|
350 |
return;
|
351 |
} |
352 |
|
353 |
//Calculo del tama?o de la imagen definitiva en pulgadas
|
354 |
double widthInches = (widthMts / scale) * MathUtils.INCHESMTR;
|
355 |
double heightInches = (heightMts / scale) * MathUtils.INCHESMTR;
|
356 |
|
357 |
//Ancho en pixeles = ppp * widthpulgadas
|
358 |
this.widthInPixels = (int) (resolution * widthInches); |
359 |
this.heightInPixels = (int) (resolution * heightInches); |
360 |
|
361 |
mtsPerPixel = (double)(widthMts / this.widthInPixels); |
362 |
//double mtsPixelH = wc_altomts/altoPixels;
|
363 |
|
364 |
//recortamos a 5 decimales
|
365 |
mtsPerPixel = MathUtils.tailDecimals(mtsPerPixel, 5);
|
366 |
|
367 |
enableEventValueChanged = false;
|
368 |
controlPanel.getTMtsPixel().setValue(String.valueOf(mtsPerPixel));
|
369 |
enableEventValueChanged = true;
|
370 |
setCorrectMeasure(this.widthInPixels, controlPanel.getTWidth());
|
371 |
setCorrectMeasure(this.heightInPixels, controlPanel.getTHeight());
|
372 |
|
373 |
//int anchopixels =(int) (Toolkit.getDefaultToolkit().getScreenResolution() * anchopulgadas);
|
374 |
//int altopixels = (int) (Toolkit.getDefaultToolkit().getScreenResolution() * altopulgadas);
|
375 |
} |
376 |
|
377 |
/**
|
378 |
* A partir de los metros por pixel y la resoluci?n calcula el tama?o en pixels y la escala
|
379 |
* @param mtsPixel Metros por pixel
|
380 |
* @param resolution Resoluci?n
|
381 |
*/
|
382 |
private void calcSizeScale(double mtsPixel, int resolution){ |
383 |
//N?mero de p?xeles de ancho y alto
|
384 |
this.widthInPixels = (int)(widthMts / mtsPixel); |
385 |
this.heightInPixels = (int)(heightMts / mtsPixel); |
386 |
|
387 |
//Obtenemos los mts/pixel reales ya que el n?mero de pixeles es entero deben redondearse
|
388 |
mtsPerPixel = (double)(widthMts / widthInPixels);
|
389 |
|
390 |
//recortamos a 5 decimales
|
391 |
mtsPerPixel = MathUtils.tailDecimals(mtsPerPixel, 5);
|
392 |
|
393 |
//Obtenemos el ancho y alto en pulgadas
|
394 |
double widthInches = (double)(widthInPixels / Integer.parseInt(controlPanel.getCbResolution().getSelectedItem().toString())); |
395 |
// double heightInches = (double)(heightInPixels / Integer.parseInt(controlPanel.getCbResolution().getSelectedItem().toString()));
|
396 |
|
397 |
//Calculo de la escala
|
398 |
int scale = (int)((widthMts * MathUtils.INCHESMTR) / widthInches); |
399 |
|
400 |
controlPanel.getTScale().setValue(String.valueOf(scale));
|
401 |
controlPanel.getTMtsPixel().setValue(String.valueOf(mtsPerPixel));
|
402 |
setCorrectMeasure(widthInPixels, controlPanel.getTWidth()); |
403 |
setCorrectMeasure(heightInPixels, controlPanel.getTHeight()); |
404 |
} |
405 |
|
406 |
/**
|
407 |
* A partir del tama?o en pixels de la imagen y la resoluci?n calcula los metros por pixel y la escala
|
408 |
* @param widthPixels Ancho de la imagen en pixels
|
409 |
* @param heightPixels Alto de la imagen en pixels
|
410 |
* @param resolution Resoluci?n
|
411 |
*/
|
412 |
private void calcScaleMtsPixel(double widthPixels, double heightPixels, int resolution){ |
413 |
this.widthInPixels = widthPixels;
|
414 |
this.heightInPixels = heightPixels;
|
415 |
|
416 |
//Obtenemos los mts/pixel reales ya que el n?mero de pixeles es entero deben redondearse
|
417 |
mtsPerPixel = (double)(widthMts / widthPixels);
|
418 |
|
419 |
//recortamos a 5 decimales
|
420 |
mtsPerPixel = MathUtils.tailDecimals(mtsPerPixel, 5);
|
421 |
|
422 |
//Obtenemos el ancho y alto en pulgadas
|
423 |
double widthInches = (double)(widthPixels / Integer.parseInt(controlPanel.getCbResolution().getSelectedItem().toString())); |
424 |
// double heightInches = (double)(heightPixels / Integer.parseInt(controlPanel.getCbResolution().getSelectedItem().toString()));
|
425 |
|
426 |
//Calculo de la escala
|
427 |
int scale = (int)((widthMts * MathUtils.INCHESMTR) / widthInches); |
428 |
|
429 |
controlPanel.getTScale().setValue(String.valueOf(scale));
|
430 |
controlPanel.getTMtsPixel().setValue(String.valueOf(mtsPerPixel));
|
431 |
setCorrectMeasure(widthPixels, controlPanel.getTWidth()); |
432 |
setCorrectMeasure(heightPixels, controlPanel.getTHeight()); |
433 |
} |
434 |
|
435 |
/**
|
436 |
* Controla cuando se cumplen todos los requisitos en el formulario para
|
437 |
* poder activar el bot?n de aceptar.
|
438 |
*/
|
439 |
public void enableButtons() { |
440 |
try {
|
441 |
if (Double.parseDouble(controlPanel.getTWidth().getValue()) == 0 || |
442 |
Double.parseDouble(controlPanel.getTHeight().getValue()) == 0 || |
443 |
controlPanel.getTWidth().getValue().equals("") ||
|
444 |
controlPanel.getTHeight().getValue().equals("") ||
|
445 |
this.fName == null || this.fName.equals("")) { |
446 |
if (dialog != null) |
447 |
dialog.getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(false);
|
448 |
return;
|
449 |
} |
450 |
} catch (NumberFormatException e) { |
451 |
dialog.getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(false);
|
452 |
return;
|
453 |
} |
454 |
|
455 |
if (dialog != null) |
456 |
dialog.getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(true);
|
457 |
} |
458 |
|
459 |
/**
|
460 |
* Gestiona los eventos del cambio de escala de la imagen y lla apertura del
|
461 |
* dialogo de selecci?n del nombre del fichero.
|
462 |
*/
|
463 |
public void actionPerformed(ActionEvent e) { |
464 |
obj = e.getSource(); |
465 |
|
466 |
// Selector de Fichero sobre el cual se va a salvar a raster
|
467 |
if (obj.equals(controlPanel.getBSelect())) {
|
468 |
JFileChooser chooser = new JFileChooser(FileOpenWizard.getLastPath()); |
469 |
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero")); |
470 |
|
471 |
// A?adimos las extensiones que hayan sido registradas en el driver
|
472 |
String[] extList = GeoRasterWriter.getDriversExtensions(); |
473 |
for (int i = 0; i < extList.length; i++) |
474 |
chooser.addChoosableFileFilter(new ExtendedFileFilter(extList[i]));
|
475 |
|
476 |
int returnVal = chooser.showOpenDialog(controlPanel);
|
477 |
|
478 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
479 |
ExtendedFileFilter fileFilter = ((ExtendedFileFilter) chooser.getFileFilter()); |
480 |
|
481 |
fName = fileFilter.getNormalizedFilename(new File(fName)); |
482 |
String ext = RasterUtilities.getExtensionFromFileName(fName);
|
483 |
|
484 |
controlPanel.getBProperties().setText( |
485 |
PluginServices.getText(this, "props") + " " + GeoRasterWriter.getDriverType(ext)); |
486 |
|
487 |
controlPanel.getBProperties().setEnabled(true);
|
488 |
controlPanel.getLFileName().setText( |
489 |
fName.substring(fName.lastIndexOf(File.separator) + 1, fName.length())); |
490 |
|
491 |
enableButtons(); |
492 |
FileOpenWizard.setLastPath(chooser.getSelectedFile().getPath().substring(0, chooser.getSelectedFile().getPath().lastIndexOf(File.separator))); |
493 |
} |
494 |
} |
495 |
|
496 |
// Al variar las unidades recalculamos el ancho y el alto
|
497 |
if (e.getSource().equals(controlPanel.getCbMeasureType())) {
|
498 |
setCorrectMeasure(this.widthInPixels, controlPanel.getTWidth());
|
499 |
setCorrectMeasure(this.heightInPixels, controlPanel.getTHeight());
|
500 |
} |
501 |
|
502 |
if (!obj.equals(controlPanel.getBSelect()))
|
503 |
this.recalcParams();
|
504 |
|
505 |
this.enableButtons();
|
506 |
|
507 |
} |
508 |
|
509 |
/**
|
510 |
* Devuelve el nombre del fichero seleccionado
|
511 |
*
|
512 |
* @return Nombre del fichero seleccionado
|
513 |
*/
|
514 |
public String getFileName() { |
515 |
return fName;
|
516 |
} |
517 |
|
518 |
/**
|
519 |
* Pone a null el valor de la variable con el valor del fichero de texto.
|
520 |
*/
|
521 |
public void resetFileName() { |
522 |
fName = null;
|
523 |
controlPanel.getLFileName().setText("");
|
524 |
} |
525 |
|
526 |
/**
|
527 |
* Unused
|
528 |
*/
|
529 |
public void mouseExited(MouseEvent e) { |
530 |
} |
531 |
|
532 |
/**
|
533 |
* Unused. Only for compilant purposes
|
534 |
*/
|
535 |
public void mouseReleased(MouseEvent e) { |
536 |
} |
537 |
|
538 |
/**
|
539 |
* Unused. Only for compilant purposes
|
540 |
*/
|
541 |
public void mouseEntered(MouseEvent e) { |
542 |
} |
543 |
|
544 |
public void mouseClicked(MouseEvent e) { |
545 |
if ((obj.equals(controlPanel.getTHeight()) && e.getSource().equals(
|
546 |
controlPanel.getTWidth())) |
547 |
|| (obj.equals(controlPanel.getTWidth()) && e.getSource() |
548 |
.equals(controlPanel.getTHeight()))) |
549 |
return;
|
550 |
obj = e.getSource(); |
551 |
this.recalcParams();
|
552 |
enableButtons(); |
553 |
} |
554 |
|
555 |
/**
|
556 |
* Unused. Only for compilant purposes
|
557 |
*/
|
558 |
public void mousePressed(MouseEvent e) { |
559 |
} |
560 |
|
561 |
/**
|
562 |
* Unused. Only for compilant purposes
|
563 |
*/
|
564 |
public void focusGained(FocusEvent e) { |
565 |
} |
566 |
|
567 |
/**
|
568 |
* Recalcula el tama?o de la imagen con los datos existentes y activa o
|
569 |
* desactiva los botones.
|
570 |
*/
|
571 |
public void focusLost(FocusEvent e) { |
572 |
obj = e.getSource(); |
573 |
this.recalcParams();
|
574 |
enableButtons(); |
575 |
} |
576 |
|
577 |
/**
|
578 |
* Activa o Desactiva los botones a trav?s de la funci?n que valida los
|
579 |
* campos
|
580 |
*/
|
581 |
public void keyTyped(KeyEvent e) { |
582 |
enableButtons(); |
583 |
} |
584 |
|
585 |
/**
|
586 |
* Activa o Desactiva los botones a trav?s de la funci?n que valida los
|
587 |
* campos
|
588 |
*/
|
589 |
public void keyPressed(KeyEvent e) { |
590 |
enableButtons(); |
591 |
} |
592 |
|
593 |
/**
|
594 |
* Activa o Desactiva los botones a trav?s de la funci?n que valida los
|
595 |
* campos
|
596 |
*/
|
597 |
public void keyReleased(KeyEvent e) { |
598 |
enableButtons(); |
599 |
} |
600 |
|
601 |
/**
|
602 |
* Obtiene la altura en pixels de la imagen de salida
|
603 |
*
|
604 |
* @return entero con la altura en pixels
|
605 |
*/
|
606 |
public double getHeightInPixels() { |
607 |
return heightInPixels;
|
608 |
} |
609 |
|
610 |
/**
|
611 |
* Obtiene la anchura en pixels de la imagen de salida
|
612 |
*
|
613 |
* @return entero con la anchura en pixels
|
614 |
*/
|
615 |
public double getWidthInPixels() { |
616 |
return widthInPixels;
|
617 |
} |
618 |
|
619 |
/**
|
620 |
* Asigna el valor de ancho en pixels
|
621 |
* @param value double
|
622 |
*/
|
623 |
public void setWidthInPixels(double value) { |
624 |
this.widthInPixels = value;
|
625 |
} |
626 |
|
627 |
/**
|
628 |
* Asigna el valor de alto en pixels
|
629 |
* @param value double
|
630 |
*/
|
631 |
public void setHeightInPixels(double value) { |
632 |
this.heightInPixels = value;
|
633 |
} |
634 |
|
635 |
public void actionValueChanged(EventObject e) { |
636 |
if(enableEventValueChanged) {
|
637 |
obj = e.getSource(); |
638 |
this.recalcParams();
|
639 |
enableButtons(); |
640 |
} |
641 |
} |
642 |
} |