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