svn-gvsig-desktop / tags / v1_1_Build_1000 / extensions / extRasterTools / src / org / gvsig / rasterTools / saveRaster / ui / main / SaveRasterDefaultPanel.java @ 11885
History | View | Annotate | Download (10.1 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.main; |
25 |
|
26 |
import java.awt.Component; |
27 |
import java.awt.Container; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.event.ActionEvent; |
30 |
import java.awt.geom.Rectangle2D; |
31 |
import java.io.File; |
32 |
|
33 |
import javax.swing.JOptionPane; |
34 |
import javax.swing.JPanel; |
35 |
|
36 |
import org.cresques.cts.IProjection; |
37 |
import org.cresques.io.GeoRasterWriter; |
38 |
import org.cresques.ui.DefaultDialogPanel; |
39 |
import org.gvsig.rasterTools.saveRaster.ui.listener.DataInputListener; |
40 |
import org.gvsig.rasterTools.saveRaster.ui.properties.ProgressSaveRasterDialog; |
41 |
import org.gvsig.rasterTools.saveRaster.ui.properties.SaveRasterPropsDialog; |
42 |
import org.gvsig.rasterTools.saveRaster.util.DriverProperties; |
43 |
|
44 |
import com.iver.andami.PluginServices; |
45 |
import com.iver.andami.ui.mdiManager.IWindow; |
46 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
47 |
import com.iver.cit.gvsig.fmap.MapControl; |
48 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
49 |
|
50 |
|
51 |
/**
|
52 |
* Panel que contiene los botones de Aceptar, Cancelar y Aplicar heredando de
|
53 |
* DefaultDialogPanel. Dentro de este estar? el panel con los controles de
|
54 |
* salvar a raster.
|
55 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
56 |
*/
|
57 |
public class SaveRasterDefaultPanel extends DefaultDialogPanel implements IWindow { |
58 |
final private static long serialVersionUID = -3370601314380922368L; |
59 |
private DataInputListener listener = null; |
60 |
private GeoRasterWriter writer = null; |
61 |
private IProjection currentProjection = null; |
62 |
private SaveRasterPropsDialog frameSaveRasterProps = null; |
63 |
private int compresion = 10; |
64 |
private int sizeBlock = GeoRasterWriter.blockSizeDefault;//64; |
65 |
public DriverProperties driverProps = null; |
66 |
private FLayers layers = null; |
67 |
private MapControl mapCtrl = null; |
68 |
|
69 |
/**
|
70 |
* Constructor de la ventana de dialogo para gvSIG.
|
71 |
*/
|
72 |
public SaveRasterDefaultPanel(FLayers layers, MapControl mapCtrl) {
|
73 |
super(false); |
74 |
initialize(); |
75 |
driverProps = new DriverProperties();
|
76 |
this.layers = layers;
|
77 |
this.mapCtrl = mapCtrl;
|
78 |
init(); |
79 |
} |
80 |
|
81 |
/**
|
82 |
* Constructor generico para poder visualizar la ventana desde
|
83 |
* una funci?n main.
|
84 |
*/
|
85 |
public SaveRasterDefaultPanel() {
|
86 |
super(false); |
87 |
initialize(); |
88 |
init(); |
89 |
} |
90 |
|
91 |
|
92 |
/**
|
93 |
* Inicializaci?n del panel.
|
94 |
* @return void
|
95 |
*/
|
96 |
public void init() { |
97 |
super.initialize();
|
98 |
//this.setSize(410, 380);
|
99 |
this.setSize(new java.awt.Dimension(410,390)); |
100 |
this.pButton.setPreferredSize(new java.awt.Dimension(390, 25)); |
101 |
this.getListener();
|
102 |
|
103 |
//Ocultamos el bot?n de aplicar
|
104 |
this.setLocation(new java.awt.Point(0,0)); |
105 |
this.getApplyButton().setVisible(false); |
106 |
this.getAcceptButton().setEnabled(false); |
107 |
|
108 |
setName("saveRaster");
|
109 |
|
110 |
//this.getAcceptButton().setEnabled(false);
|
111 |
this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
112 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
113 |
if(acceptButtonActionPerformed(evt))
|
114 |
closeJDialog(); |
115 |
} |
116 |
}); |
117 |
this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
118 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
119 |
closeJDialog(); |
120 |
} |
121 |
}); |
122 |
this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
123 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
124 |
acceptButtonActionPerformed(evt); |
125 |
} |
126 |
}); |
127 |
|
128 |
//Captura de eventos para el bot?n de propiedades
|
129 |
|
130 |
((SaveRasterControlsPanel)this.getContentPanel()).getBProperties().addActionListener(new java.awt.event.ActionListener() { |
131 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
132 |
propsButtonActionPerformed(evt); |
133 |
} |
134 |
}); |
135 |
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* Cierra esta ventana a trav?s de andami
|
140 |
*/
|
141 |
public void closeJDialog() { |
142 |
this.hide();
|
143 |
for(int i=0;i<layers.getLayersCount();i++){ |
144 |
layers.getLayer(i).getMapContext().invalidate(); |
145 |
} |
146 |
PluginServices.getMDIManager().closeWindow(SaveRasterDefaultPanel.this); |
147 |
} |
148 |
|
149 |
/**
|
150 |
* Funci?n a ejecutar cuando se pulsa el bot?n de propiedades.
|
151 |
* @param e ActionEvent
|
152 |
*/
|
153 |
private void propsButtonActionPerformed(ActionEvent e){ |
154 |
String name = this.getListener().getFileName(); |
155 |
|
156 |
//Si no se ha seleccionado ning?n fichero salimos
|
157 |
if(name == null || name.equals("")) |
158 |
return;
|
159 |
|
160 |
GeoRasterWriter writer = GeoRasterWriter.getWriter(name); |
161 |
String ext = name.toLowerCase().substring(name.lastIndexOf(".") + 1); |
162 |
if(driverProps.getProperties(ext)!=null) |
163 |
writer.setProps(driverProps.getProperties(ext)); |
164 |
|
165 |
frameSaveRasterProps = new SaveRasterPropsDialog(writer);
|
166 |
frameSaveRasterProps.setParentDialog(this);
|
167 |
frameSaveRasterProps.show(); |
168 |
} |
169 |
|
170 |
/**
|
171 |
*
|
172 |
* @param e
|
173 |
*/
|
174 |
private boolean acceptButtonActionPerformed(ActionEvent e) { |
175 |
SaveRasterControlsPanel dialog = (SaveRasterControlsPanel)this.getContentPanel();
|
176 |
|
177 |
String fName = this.getListener().getFileName(); |
178 |
Dimension dimension = new Dimension( this.getListener().getWidthInPixels(), |
179 |
this.getListener().getHeightInPixels() );
|
180 |
|
181 |
//Comprobamos que el en la ruta de destino tengamos permisos de escritura
|
182 |
/*File f = new File(fName);
|
183 |
if(!f.exists()){
|
184 |
if(!checkFileExists(fName))
|
185 |
return false;
|
186 |
}
|
187 |
f = new File(fName.substring(0, fName.lastIndexOf(File.separator)));
|
188 |
if(f.exists() && f.isDirectory() && !f.canWrite()){
|
189 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
|
190 |
PluginServices.getText(this, "error_file_not_writable"));
|
191 |
return false;
|
192 |
}*/
|
193 |
|
194 |
double lrX = Double.parseDouble(dialog.getTInfDerX().getText()); |
195 |
double lrY = Double.parseDouble(dialog.getTInfDerY().getText()); |
196 |
double ulX = Double.parseDouble(dialog.getTSupIzqX().getText()); |
197 |
double ulY = Double.parseDouble(dialog.getTSupIzqY().getText()); |
198 |
double width = 0; |
199 |
if(ulX>lrX)width = (double)(ulX-lrX); |
200 |
else width = (double)(lrX-ulX); |
201 |
double height = 0; |
202 |
if(ulY>lrY)height = (double)(ulY-lrY); |
203 |
else height = (double)(lrY-ulY); |
204 |
Rectangle2D ext = null; |
205 |
|
206 |
if(ulY<lrY)
|
207 |
ext = new Rectangle2D.Double(ulX, ulY, width, height); |
208 |
else
|
209 |
ext = new Rectangle2D.Double(ulX, lrY, width, height); |
210 |
|
211 |
ProgressSaveRasterDialog progressBar = |
212 |
new ProgressSaveRasterDialog(mapCtrl, this.layers, this.currentProjection, |
213 |
dimension, ext, this);
|
214 |
|
215 |
String prop = driverProps.getValue(fName.substring(fName.lastIndexOf(".") + 1, fName.length()), "COMPRESSION"); |
216 |
if(prop != null) //Se ha modificado la compresi?n desde el dialogo |
217 |
compresion = Integer.parseInt(prop);
|
218 |
progressBar.setProps(driverProps); |
219 |
progressBar.setWriter(writer); |
220 |
progressBar.setFName(fName); |
221 |
progressBar.setBlockSize(sizeBlock); |
222 |
progressBar.setCompresion(compresion); |
223 |
progressBar.showWindow(); |
224 |
|
225 |
for(int i=0;i<layers.getLayersCount();i++){ |
226 |
layers.getLayer(i).getMapContext().invalidate(); |
227 |
} |
228 |
return true; |
229 |
} |
230 |
|
231 |
/**
|
232 |
* Comprueba si existe el fichero pasado por par?metro existe solicitando confirmaci?n
|
233 |
* de sobreescritura. Si el usuario acepta devolver? true y si no acepta devuelve false.
|
234 |
* Si se acepta la sobreescritura el fichero es borrado.
|
235 |
* @param file Cadena con el nombre del fichero a comprobar su existencia.
|
236 |
* @return Devuelve true si el fichero existe y va a ser sobreescrito
|
237 |
*/
|
238 |
private boolean checkFileExists(String file){ |
239 |
File f = new File(file); |
240 |
if(f.exists()){
|
241 |
String string1 = PluginServices.getText(this, "yes"); |
242 |
String string2 = PluginServices.getText(this, "no"); |
243 |
Object[] options = {string1, string2}; |
244 |
int n = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
245 |
PluginServices.getText(this, "error_file_exists"), |
246 |
PluginServices.getText(this, "confirmacion"), |
247 |
JOptionPane.YES_NO_OPTION,
|
248 |
JOptionPane.QUESTION_MESSAGE,
|
249 |
null,
|
250 |
options, |
251 |
string1); |
252 |
if (n == JOptionPane.YES_OPTION){ |
253 |
f.delete(); |
254 |
return true; |
255 |
}else
|
256 |
return false; |
257 |
} |
258 |
return true; |
259 |
} |
260 |
|
261 |
/**
|
262 |
* Obtiene el panel con los controles de Salvar a Raster.
|
263 |
* @return
|
264 |
*/
|
265 |
public JPanel getContentPanel() { |
266 |
if (contentPane == null) { |
267 |
contentPane = new SaveRasterControlsPanel();
|
268 |
contentPane.setPreferredSize(new java.awt.Dimension(379, 317)); |
269 |
} |
270 |
return contentPane;
|
271 |
} |
272 |
|
273 |
public DataInputListener getListener() {
|
274 |
if(listener == null){ |
275 |
listener = new DataInputListener((SaveRasterControlsPanel)this.getContentPanel()); |
276 |
listener.setDialogPanel(this);
|
277 |
} |
278 |
return listener;
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* This method initializes jContentPane
|
283 |
*
|
284 |
* @return javax.swing.JPanel
|
285 |
*/
|
286 |
public Container getContentPane() { |
287 |
return this; |
288 |
} |
289 |
|
290 |
/**
|
291 |
*
|
292 |
* @param prj
|
293 |
*/
|
294 |
|
295 |
public void setProjection(IProjection prj) { |
296 |
this.currentProjection = prj;
|
297 |
} |
298 |
|
299 |
/**
|
300 |
* Asigna la lista de capas
|
301 |
* @param layers
|
302 |
*/
|
303 |
public void setLayerList(FLayers layers){ |
304 |
this.layers = layers;
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
309 |
*/
|
310 |
public WindowInfo getWindowInfo() {
|
311 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
312 |
m_viewinfo.setTitle(PluginServices.getText(this, "salvar_raster")); |
313 |
return m_viewinfo;
|
314 |
} |
315 |
|
316 |
/**
|
317 |
* Asigna el tama?o de bloque
|
318 |
* @param sizeBlock
|
319 |
*/
|
320 |
public void setSizeBlock(int sizeBlock) { |
321 |
this.sizeBlock = sizeBlock;
|
322 |
} |
323 |
} |