gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / saveraster / ui / listener / DataInputListener.java @ 2480
History | View | Annotate | Download (20.8 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.tools.app.basic.tool.saveraster.ui.listener; |
23 |
|
24 |
import java.awt.event.ActionEvent; |
25 |
import java.awt.event.ActionListener; |
26 |
import java.awt.event.FocusEvent; |
27 |
import java.awt.event.FocusListener; |
28 |
import java.awt.event.KeyEvent; |
29 |
import java.awt.event.KeyListener; |
30 |
import java.awt.event.MouseEvent; |
31 |
import java.awt.event.MouseListener; |
32 |
import java.io.File; |
33 |
import java.util.EventObject; |
34 |
|
35 |
import org.gvsig.andami.PluginServices; |
36 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
37 |
import org.gvsig.fmap.dal.coverage.util.MathUtils; |
38 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
39 |
import org.gvsig.gui.beans.datainput.DataInputContainer; |
40 |
import org.gvsig.gui.beans.datainput.DataInputContainerListener; |
41 |
import org.gvsig.gui.beans.swing.JFileChooser; |
42 |
import org.gvsig.raster.tools.app.basic.tool.saveraster.ui.SaveRasterDialog; |
43 |
import org.gvsig.raster.tools.app.basic.tool.saveraster.ui.SaveRasterPanel; |
44 |
import org.gvsig.raster.util.ExtendedFileFilter; |
45 |
|
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 |
private MathUtils math = RasterLocator.getManager().getMathUtils();
|
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 math.convertMtsToPixels(Double.parseDouble(value), ppp); |
132 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Cms")) |
133 |
return math.convertCmsToPixels(Double.parseDouble(value), ppp); |
134 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Mms")) |
135 |
return math.convertMmsToPixels(Double.parseDouble(value), ppp); |
136 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Inches")) |
137 |
return math.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(math.clipDecimals(math.convertPixelsToMts(pixel, ppp),5))); |
158 |
|
159 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Cms")) |
160 |
field.setValue(String.valueOf(math.clipDecimals(math.convertPixelsToCms(pixel, ppp),5))); |
161 |
|
162 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Mms")) |
163 |
field.setValue(String.valueOf(math.clipDecimals(math.convertPixelsToMms(pixel, ppp),5))); |
164 |
|
165 |
if(controlPanel.getCbMeasureType().getSelectedItem().equals("Inches")) |
166 |
field.setValue(String.valueOf(math.clipDecimals(math.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 |
try{
|
178 |
double[] size = calcSizeInMts(); |
179 |
if(size != null) { |
180 |
widthMts = size[0];
|
181 |
heightMts = size[1];
|
182 |
} else {
|
183 |
return;
|
184 |
} |
185 |
} catch (NumberFormatException e) { |
186 |
return;
|
187 |
} |
188 |
|
189 |
int resolution = Integer.parseInt((String)controlPanel.getCbResolution().getSelectedItem()); |
190 |
|
191 |
//Al variar la resoluci?n independientemente del m?todo seleccionado recalculamos el ancho y el alto
|
192 |
if (obj.equals(controlPanel.getCbResolution())) {
|
193 |
String escala = controlPanel.getTScale().getValue();
|
194 |
try{
|
195 |
if(controlPanel.getViewPort().getProjection().isProjected())
|
196 |
calcSizeMtsPixel(Double.parseDouble(escala), resolution);
|
197 |
} |
198 |
catch(NumberFormatException exc){ |
199 |
calcSizeMtsPixel(0, resolution);
|
200 |
} |
201 |
return;
|
202 |
} |
203 |
|
204 |
//M?todo por escala seleccionado
|
205 |
if( controlPanel.getRbScale().isSelected() &&
|
206 |
!controlPanel.getTScale().getValue().equals("")) {
|
207 |
double scale = Double.parseDouble(controlPanel.getTScale().getValue()); |
208 |
calcSizeMtsPixel(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 |
calcScaleMtsPixel(this.widthInPixels, this.heightInPixels, resolution); |
220 |
} |
221 |
if( obj != null && obj.equals(controlPanel.getTHeight().getDataInputField()) && |
222 |
!controlPanel.getTHeight().getValue().equals("")) {
|
223 |
this.heightInPixels = this.getCorrectMeasure(controlPanel.getTHeight().getValue()); |
224 |
this.widthInPixels = (int)Math.ceil(this.heightInPixels * rel); |
225 |
calcScaleMtsPixel(this.widthInPixels, this.heightInPixels, resolution); |
226 |
} |
227 |
if( obj != null && |
228 |
obj.equals(controlPanel.getCbMeasureType())) { |
229 |
calcScaleMtsPixel(this.widthInPixels, this.heightInPixels, resolution); |
230 |
} |
231 |
} |
232 |
|
233 |
//M?todo metros por pixel seleccionado
|
234 |
if( controlPanel.getRbMtsPixel().isSelected() &&
|
235 |
!controlPanel.getTMtsPixel().getValue().equals("")) {
|
236 |
double mtsPixel = Double.parseDouble(controlPanel.getTMtsPixel().getValue()); |
237 |
calcSizeScale(mtsPixel, resolution); |
238 |
} |
239 |
} |
240 |
|
241 |
/**
|
242 |
* Comprueba si un campo de texto tiene el tipo de dato entero o double y si no lo
|
243 |
* tiene lo borra ya que su contenido es invalido para operar con el
|
244 |
* @param field Campo de texto a validar
|
245 |
* @param isInt true si el valor a validar es entero y false si es double
|
246 |
*/
|
247 |
private void validateTextField(DataInputContainer field){ |
248 |
try {
|
249 |
Double.parseDouble(field.getValue());
|
250 |
} catch (NumberFormatException e) { |
251 |
field.setValue("0");
|
252 |
} |
253 |
} |
254 |
|
255 |
/**
|
256 |
* Valida los campos de texto
|
257 |
*/
|
258 |
private void validateFields(){ |
259 |
|
260 |
//Validamos la escala si se ha introducido algo
|
261 |
if(!controlPanel.getTScale().getValue().equals("")) |
262 |
validateTextField(controlPanel.getTScale()); |
263 |
|
264 |
//Validamos los mts por pixel si se ha introducido algo
|
265 |
if(!controlPanel.getTMtsPixel().getValue().equals("")) |
266 |
validateTextField(controlPanel.getTMtsPixel()); |
267 |
|
268 |
//Validamos el ancho si se ha introducido algo
|
269 |
if(!controlPanel.getTWidth().getValue().equals("")) |
270 |
validateTextField(controlPanel.getTWidth()); |
271 |
|
272 |
//Validamos el alto si se ha introducido algo
|
273 |
if(!controlPanel.getTHeight().getValue().equals("")) |
274 |
validateTextField(controlPanel.getTHeight()); |
275 |
} |
276 |
|
277 |
/**
|
278 |
* Calcula el tama?o en mtrs a partir de las coordenadas.
|
279 |
*
|
280 |
* @return
|
281 |
* @throws NumberFormatException
|
282 |
*/
|
283 |
private double[] calcSizeInMts()throws NumberFormatException { |
284 |
double lrx = Double.parseDouble(controlPanel.getTInfDerX().getValue()); |
285 |
double lry = Double.parseDouble(controlPanel.getTInfDerY().getValue()); |
286 |
double ulx = Double.parseDouble(controlPanel.getTSupIzqX().getValue()); |
287 |
double uly = Double.parseDouble(controlPanel.getTSupIzqY().getValue()); |
288 |
|
289 |
double distWidth = 0; |
290 |
double distHeight = 0; |
291 |
if (ulx > lrx)
|
292 |
distWidth = ulx - lrx; |
293 |
else
|
294 |
distWidth = lrx - ulx; |
295 |
|
296 |
if (uly > lry)
|
297 |
distHeight = uly - lry; |
298 |
else
|
299 |
distHeight = lry - uly; |
300 |
|
301 |
//Point2D pUL = new Point2D.Double(ulx, uly);
|
302 |
//Point2D pUR = new Point2D.Double(lrx, uly);
|
303 |
//Point2D pLR = new Point2D.Double(lrx, lry);
|
304 |
//double distWidth = controlPanel.getViewPort().distanceWorld(pUL, pUR);
|
305 |
//double distHeight = controlPanel.getViewPort().distanceWorld(pUR, pLR);
|
306 |
//double[] trans2Meter = MapContext.getDistanceTrans2Meter();
|
307 |
//distWidth = distWidth / trans2Meter[controlPanel.getViewPort().getDistanceUnits()];
|
308 |
//distHeight = distHeight / trans2Meter[controlPanel.getViewPort().getDistanceUnits()];
|
309 |
|
310 |
return new double[]{distWidth, distHeight}; |
311 |
} |
312 |
|
313 |
/**
|
314 |
* A partir de la escala y la resoluci?n calcula el tama?o en pixels y los metros por pixel
|
315 |
* @param scale Escala
|
316 |
* @param resolution Resoluci?n
|
317 |
*/
|
318 |
private void calcSizeMtsPixel(double scale, int resolution){ |
319 |
if ((widthMts <= 0) || (heightMts <= 0) || (scale == 0)){ |
320 |
controlPanel.getTWidth().setValue("0");
|
321 |
controlPanel.getTHeight().setValue("0");
|
322 |
return;
|
323 |
} |
324 |
|
325 |
//Calculo del tama?o de la imagen definitiva en pulgadas
|
326 |
double widthInches = (widthMts / scale) * MathUtils.INCHESMTR;
|
327 |
double heightInches = (heightMts / scale) * MathUtils.INCHESMTR;
|
328 |
|
329 |
//Ancho en pixeles = ppp * widthpulgadas
|
330 |
this.widthInPixels = (int) (resolution * widthInches); |
331 |
this.heightInPixels = (int) (resolution * heightInches); |
332 |
|
333 |
mtsPerPixel = (double)(widthMts / this.widthInPixels); |
334 |
//double mtsPixelH = wc_altomts/altoPixels;
|
335 |
|
336 |
//recortamos a 5 decimales
|
337 |
mtsPerPixel = math.clipDecimals(mtsPerPixel, 5);
|
338 |
|
339 |
enableEventValueChanged = false;
|
340 |
controlPanel.getTMtsPixel().setValue(String.valueOf(mtsPerPixel));
|
341 |
enableEventValueChanged = true;
|
342 |
setCorrectMeasure(this.widthInPixels, controlPanel.getTWidth());
|
343 |
setCorrectMeasure(this.heightInPixels, controlPanel.getTHeight());
|
344 |
|
345 |
//int anchopixels =(int) (Toolkit.getDefaultToolkit().getScreenResolution() * anchopulgadas);
|
346 |
//int altopixels = (int) (Toolkit.getDefaultToolkit().getScreenResolution() * altopulgadas);
|
347 |
} |
348 |
|
349 |
/**
|
350 |
* A partir de los metros por pixel y la resoluci?n calcula el tama?o en pixels y la escala
|
351 |
* @param mtsPixel Metros por pixel
|
352 |
* @param resolution Resoluci?n
|
353 |
*/
|
354 |
private void calcSizeScale(double mtsPixel, int resolution){ |
355 |
//N?mero de p?xeles de ancho y alto
|
356 |
this.widthInPixels = (int)(widthMts / mtsPixel); |
357 |
this.heightInPixels = (int)(heightMts / mtsPixel); |
358 |
|
359 |
//Obtenemos los mts/pixel reales ya que el n?mero de pixeles es entero deben redondearse
|
360 |
mtsPerPixel = (double)(widthMts / widthInPixels);
|
361 |
|
362 |
//recortamos a 5 decimales
|
363 |
mtsPerPixel = math.clipDecimals(mtsPerPixel, 5);
|
364 |
|
365 |
//Obtenemos el ancho y alto en pulgadas
|
366 |
double widthInches = (double)(widthInPixels / Integer.parseInt(controlPanel.getCbResolution().getSelectedItem().toString())); |
367 |
// double heightInches = (double)(heightInPixels / Integer.parseInt(controlPanel.getCbResolution().getSelectedItem().toString()));
|
368 |
|
369 |
//Calculo de la escala
|
370 |
int scale = (int)((widthMts * MathUtils.INCHESMTR) / widthInches); |
371 |
|
372 |
controlPanel.getTScale().setValue(String.valueOf(scale));
|
373 |
controlPanel.getTMtsPixel().setValue(String.valueOf(mtsPerPixel));
|
374 |
setCorrectMeasure(widthInPixels, controlPanel.getTWidth()); |
375 |
setCorrectMeasure(heightInPixels, controlPanel.getTHeight()); |
376 |
} |
377 |
|
378 |
/**
|
379 |
* A partir del tama?o en pixels de la imagen y la resoluci?n calcula los metros por pixel y la escala
|
380 |
* @param widthPixels Ancho de la imagen en pixels
|
381 |
* @param heightPixels Alto de la imagen en pixels
|
382 |
* @param resolution Resoluci?n
|
383 |
*/
|
384 |
private void calcScaleMtsPixel(double widthPixels, double heightPixels, int resolution){ |
385 |
this.widthInPixels = widthPixels;
|
386 |
this.heightInPixels = heightPixels;
|
387 |
|
388 |
//Obtenemos los mts/pixel reales ya que el n?mero de pixeles es entero deben redondearse
|
389 |
mtsPerPixel = (double)(widthMts / widthPixels);
|
390 |
|
391 |
//recortamos a 5 decimales
|
392 |
mtsPerPixel = math.clipDecimals(mtsPerPixel, 5);
|
393 |
|
394 |
//Obtenemos el ancho y alto en pulgadas
|
395 |
double widthInches = (double)(widthPixels / Integer.parseInt(controlPanel.getCbResolution().getSelectedItem().toString())); |
396 |
// double heightInches = (double)(heightPixels / Integer.parseInt(controlPanel.getCbResolution().getSelectedItem().toString()));
|
397 |
|
398 |
//Calculo de la escala
|
399 |
int scale = (int)((widthMts * MathUtils.INCHESMTR) / widthInches); |
400 |
|
401 |
controlPanel.getTScale().setValue(String.valueOf(scale));
|
402 |
controlPanel.getTMtsPixel().setValue(String.valueOf(mtsPerPixel));
|
403 |
setCorrectMeasure(widthPixels, controlPanel.getTWidth()); |
404 |
setCorrectMeasure(heightPixels, controlPanel.getTHeight()); |
405 |
} |
406 |
|
407 |
/**
|
408 |
* Controla cuando se cumplen todos los requisitos en el formulario para
|
409 |
* poder activar el bot?n de aceptar.
|
410 |
*/
|
411 |
public void enableButtons() { |
412 |
try {
|
413 |
if (Double.parseDouble(controlPanel.getTWidth().getValue()) == 0 || |
414 |
Double.parseDouble(controlPanel.getTHeight().getValue()) == 0 || |
415 |
controlPanel.getTWidth().getValue().equals("") ||
|
416 |
controlPanel.getTHeight().getValue().equals("") ||
|
417 |
this.fName == null || this.fName.equals("")) { |
418 |
if (dialog != null) |
419 |
dialog.getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(false);
|
420 |
return;
|
421 |
} |
422 |
} catch (NumberFormatException e) { |
423 |
dialog.getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(false);
|
424 |
return;
|
425 |
} |
426 |
|
427 |
if (dialog != null) |
428 |
dialog.getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(true);
|
429 |
} |
430 |
|
431 |
/**
|
432 |
* Gestiona los eventos del cambio de escala de la imagen y lla apertura del
|
433 |
* dialogo de selecci?n del nombre del fichero.
|
434 |
*/
|
435 |
public void actionPerformed(ActionEvent e) { |
436 |
obj = e.getSource(); |
437 |
|
438 |
// Selector de Fichero sobre el cual se va a salvar a raster
|
439 |
if (obj.equals(controlPanel.getBSelect())) {
|
440 |
JFileChooser chooser = new JFileChooser("DATA_INPUT_LISTENER", JFileChooser.getLastPath("DATA_INPUT_LISTENER", null)); |
441 |
chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_fichero")); |
442 |
chooser.setAcceptAllFileFilterUsed(false);
|
443 |
|
444 |
// A?adimos las extensiones que hayan sido registradas en el driver
|
445 |
String[] extList = RasterLocator.getManager().getProviderServices().getDriversExtensions(); |
446 |
ExtendedFileFilter selectedFilter = null;
|
447 |
for (int i = 0; i < extList.length; i++) { |
448 |
ExtendedFileFilter fileFilter = new ExtendedFileFilter(extList[i]);
|
449 |
chooser.addChoosableFileFilter(fileFilter); |
450 |
if (extList[i].toLowerCase().equals("tif")) |
451 |
selectedFilter = fileFilter; |
452 |
} |
453 |
if (selectedFilter != null) |
454 |
chooser.setFileFilter(selectedFilter); |
455 |
|
456 |
int returnVal = chooser.showOpenDialog(controlPanel);
|
457 |
|
458 |
if (returnVal == JFileChooser.APPROVE_OPTION) { |
459 |
ExtendedFileFilter fileFilter = ((ExtendedFileFilter) chooser.getFileFilter()); |
460 |
|
461 |
fName = chooser.getSelectedFile().toString(); |
462 |
fName = fileFilter.getNormalizedFilename(chooser.getSelectedFile()); |
463 |
String ext = RasterLocator.getManager().getFileUtils().getExtensionFromFileName(fName);
|
464 |
|
465 |
controlPanel.getBProperties().setText( |
466 |
PluginServices.getText(this, "props") + " " + RasterLocator.getManager().getProviderServices().getWriteDriverType(ext)); |
467 |
|
468 |
controlPanel.getBProperties().setEnabled(true);
|
469 |
controlPanel.getLFileName().setText( |
470 |
fName.substring(fName.lastIndexOf(File.separator) + 1, fName.length())); |
471 |
|
472 |
enableButtons(); |
473 |
JFileChooser.setLastPath("DATA_INPUT_LISTENER", chooser.getSelectedFile()); |
474 |
} |
475 |
} |
476 |
|
477 |
// Al variar las unidades recalculamos el ancho y el alto
|
478 |
if (e.getSource().equals(controlPanel.getCbMeasureType())) {
|
479 |
setCorrectMeasure(this.widthInPixels, controlPanel.getTWidth());
|
480 |
setCorrectMeasure(this.heightInPixels, controlPanel.getTHeight());
|
481 |
} |
482 |
|
483 |
if (!obj.equals(controlPanel.getBSelect()))
|
484 |
this.recalcParams();
|
485 |
|
486 |
this.enableButtons();
|
487 |
|
488 |
} |
489 |
|
490 |
/**
|
491 |
* Devuelve el nombre del fichero seleccionado
|
492 |
*
|
493 |
* @return Nombre del fichero seleccionado
|
494 |
*/
|
495 |
public String getFileName() { |
496 |
return fName;
|
497 |
} |
498 |
|
499 |
/**
|
500 |
* Pone a null el valor de la variable con el valor del fichero de texto.
|
501 |
*/
|
502 |
public void resetFileName() { |
503 |
fName = null;
|
504 |
controlPanel.getLFileName().setText("");
|
505 |
} |
506 |
|
507 |
public void mouseClicked(MouseEvent e) { |
508 |
if ((obj.equals(controlPanel.getTHeight()) && e.getSource().equals(
|
509 |
controlPanel.getTWidth())) |
510 |
|| (obj.equals(controlPanel.getTWidth()) && e.getSource() |
511 |
.equals(controlPanel.getTHeight()))) |
512 |
return;
|
513 |
obj = e.getSource(); |
514 |
this.recalcParams();
|
515 |
enableButtons(); |
516 |
} |
517 |
|
518 |
/**
|
519 |
* Recalcula el tama?o de la imagen con los datos existentes y activa o
|
520 |
* desactiva los botones.
|
521 |
*/
|
522 |
public void focusLost(FocusEvent e) { |
523 |
obj = e.getSource(); |
524 |
this.recalcParams();
|
525 |
enableButtons(); |
526 |
} |
527 |
|
528 |
/**
|
529 |
* Activa o Desactiva los botones a trav?s de la funci?n que valida los
|
530 |
* campos
|
531 |
*/
|
532 |
public void keyTyped(KeyEvent e) { |
533 |
enableButtons(); |
534 |
} |
535 |
|
536 |
/**
|
537 |
* Activa o Desactiva los botones a trav?s de la funci?n que valida los
|
538 |
* campos
|
539 |
*/
|
540 |
public void keyPressed(KeyEvent e) { |
541 |
enableButtons(); |
542 |
} |
543 |
|
544 |
/**
|
545 |
* Activa o Desactiva los botones a trav?s de la funci?n que valida los
|
546 |
* campos
|
547 |
*/
|
548 |
public void keyReleased(KeyEvent e) { |
549 |
enableButtons(); |
550 |
} |
551 |
|
552 |
/**
|
553 |
* Obtiene la altura en pixels de la imagen de salida
|
554 |
*
|
555 |
* @return entero con la altura en pixels
|
556 |
*/
|
557 |
public double getHeightInPixels() { |
558 |
return heightInPixels;
|
559 |
} |
560 |
|
561 |
/**
|
562 |
* Obtiene la anchura en pixels de la imagen de salida
|
563 |
*
|
564 |
* @return entero con la anchura en pixels
|
565 |
*/
|
566 |
public double getWidthInPixels() { |
567 |
return widthInPixels;
|
568 |
} |
569 |
|
570 |
/**
|
571 |
* Asigna el valor de ancho en pixels
|
572 |
* @param value double
|
573 |
*/
|
574 |
public void setWidthInPixels(double value) { |
575 |
this.widthInPixels = value;
|
576 |
} |
577 |
|
578 |
/**
|
579 |
* Asigna el valor de alto en pixels
|
580 |
* @param value double
|
581 |
*/
|
582 |
public void setHeightInPixels(double value) { |
583 |
this.heightInPixels = value;
|
584 |
} |
585 |
|
586 |
public void actionValueChanged(EventObject e) { |
587 |
if(enableEventValueChanged) {
|
588 |
obj = e.getSource(); |
589 |
this.recalcParams();
|
590 |
enableButtons(); |
591 |
} |
592 |
} |
593 |
|
594 |
public void mouseExited(MouseEvent e) {} |
595 |
public void mouseReleased(MouseEvent e) {} |
596 |
public void mouseEntered(MouseEvent e) {} |
597 |
public void mousePressed(MouseEvent e) {} |
598 |
public void focusGained(FocusEvent e) {} |
599 |
} |