svn-gvsig-desktop / tags / v1_0_2_Build_892 / extensions / extRasterTools / src / org / gvsig / rasterTools / saveRaster / ui / main / SaveRasterDefaultPanel.java @ 10278
History | View | Annotate | Download (9.91 KB)
1 | 4547 | nacho | /*
|
---|---|---|---|
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 | 4959 | nacho | import java.awt.Component; |
27 | 4547 | nacho | import java.awt.Container; |
28 | import java.awt.Dimension; |
||
29 | import java.awt.event.ActionEvent; |
||
30 | import java.awt.geom.Rectangle2D; |
||
31 | 4959 | nacho | import java.io.File; |
32 | 4547 | nacho | |
33 | 4959 | nacho | import javax.swing.JOptionPane; |
34 | 4547 | nacho | 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 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
46 | 6880 | cesar | import com.iver.andami.ui.mdiManager.WindowInfo; |
47 | 4547 | nacho | 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 | 6877 | cesar | public class SaveRasterDefaultPanel extends DefaultDialogPanel implements IWindow { |
58 | 4547 | nacho | 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 = 1; |
||
64 | 8765 | jjdelcerro | private int sizeBlock = GeoRasterWriter.blockSizeDefault;//64; |
65 | 4547 | nacho | 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 | 6023 | nacho | initialize(); |
75 | 4547 | nacho | 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 | 6023 | nacho | initialize(); |
88 | 4547 | nacho | init(); |
89 | } |
||
90 | |||
91 | 6023 | nacho | |
92 | /**
|
||
93 | 4547 | nacho | * Inicializaci?n del panel.
|
94 | * @return void
|
||
95 | */
|
||
96 | public void init() { |
||
97 | super.initialize();
|
||
98 | 6023 | nacho | //this.setSize(410, 380);
|
99 | 6830 | maquerol | this.setSize(new java.awt.Dimension(410,390)); |
100 | this.pButton.setPreferredSize(new java.awt.Dimension(390, 25)); |
||
101 | 4547 | nacho | 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 | 4959 | nacho | if(acceptButtonActionPerformed(evt))
|
114 | closeJDialog(); |
||
115 | 4547 | nacho | } |
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 | 6881 | cesar | layers.getLayer(i).getMapContext().invalidate(); |
145 | 4547 | nacho | } |
146 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(SaveRasterDefaultPanel.this); |
147 | 4547 | nacho | } |
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 | 4959 | nacho | private boolean acceptButtonActionPerformed(ActionEvent e) { |
175 | 4547 | nacho | 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 | 4959 | nacho | //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 | 4547 | nacho | 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 | progressBar.setProps(driverProps); |
||
216 | progressBar.setWriter(writer); |
||
217 | progressBar.setFName(fName); |
||
218 | progressBar.setBlockSize(sizeBlock); |
||
219 | progressBar.setCompresion(compresion); |
||
220 | progressBar.showWindow(); |
||
221 | |||
222 | for(int i=0;i<layers.getLayersCount();i++){ |
||
223 | 6881 | cesar | layers.getLayer(i).getMapContext().invalidate(); |
224 | 4547 | nacho | } |
225 | 4959 | nacho | return true; |
226 | 4547 | nacho | } |
227 | |||
228 | /**
|
||
229 | 4959 | nacho | * Comprueba si existe el fichero pasado por par?metro existe solicitando confirmaci?n
|
230 | * de sobreescritura. Si el usuario acepta devolver? true y si no acepta devuelve false.
|
||
231 | * Si se acepta la sobreescritura el fichero es borrado.
|
||
232 | * @param file Cadena con el nombre del fichero a comprobar su existencia.
|
||
233 | * @return Devuelve true si el fichero existe y va a ser sobreescrito
|
||
234 | */
|
||
235 | private boolean checkFileExists(String file){ |
||
236 | File f = new File(file); |
||
237 | if(f.exists()){
|
||
238 | String string1 = PluginServices.getText(this, "yes"); |
||
239 | String string2 = PluginServices.getText(this, "no"); |
||
240 | Object[] options = {string1, string2}; |
||
241 | int n = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
||
242 | PluginServices.getText(this, "error_file_exists"), |
||
243 | PluginServices.getText(this, "confirmacion"), |
||
244 | JOptionPane.YES_NO_OPTION,
|
||
245 | JOptionPane.QUESTION_MESSAGE,
|
||
246 | null,
|
||
247 | options, |
||
248 | string1); |
||
249 | if (n == JOptionPane.YES_OPTION){ |
||
250 | f.delete(); |
||
251 | return true; |
||
252 | }else
|
||
253 | return false; |
||
254 | } |
||
255 | return true; |
||
256 | } |
||
257 | |||
258 | /**
|
||
259 | 4547 | nacho | * Obtiene el panel con los controles de Salvar a Raster.
|
260 | * @return
|
||
261 | */
|
||
262 | public JPanel getContentPanel() { |
||
263 | if (contentPane == null) { |
||
264 | contentPane = new SaveRasterControlsPanel();
|
||
265 | 5512 | maquerol | contentPane.setPreferredSize(new java.awt.Dimension(379, 317)); |
266 | 4547 | nacho | } |
267 | return contentPane;
|
||
268 | } |
||
269 | |||
270 | public DataInputListener getListener() {
|
||
271 | if(listener == null){ |
||
272 | listener = new DataInputListener((SaveRasterControlsPanel)this.getContentPanel()); |
||
273 | listener.setDialogPanel(this);
|
||
274 | } |
||
275 | return listener;
|
||
276 | } |
||
277 | |||
278 | /**
|
||
279 | * This method initializes jContentPane
|
||
280 | *
|
||
281 | * @return javax.swing.JPanel
|
||
282 | */
|
||
283 | public Container getContentPane() { |
||
284 | return this; |
||
285 | } |
||
286 | |||
287 | /**
|
||
288 | *
|
||
289 | * @param prj
|
||
290 | */
|
||
291 | |||
292 | public void setProjection(IProjection prj) { |
||
293 | this.currentProjection = prj;
|
||
294 | } |
||
295 | |||
296 | /**
|
||
297 | * Asigna la lista de capas
|
||
298 | * @param layers
|
||
299 | */
|
||
300 | public void setLayerList(FLayers layers){ |
||
301 | this.layers = layers;
|
||
302 | } |
||
303 | |||
304 | /**
|
||
305 | 6880 | cesar | * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
|
306 | 4547 | nacho | */
|
307 | 6880 | cesar | public WindowInfo getWindowInfo() {
|
308 | WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
||
309 | 4547 | nacho | m_viewinfo.setTitle(PluginServices.getText(this, "salvar_raster")); |
310 | return m_viewinfo;
|
||
311 | } |
||
312 | 8765 | jjdelcerro | |
313 | 8608 | nacho | /**
|
314 | * Asigna el tama?o de bloque
|
||
315 | * @param sizeBlock
|
||
316 | */
|
||
317 | public void setSizeBlock(int sizeBlock) { |
||
318 | this.sizeBlock = sizeBlock;
|
||
319 | } |
||
320 | 4547 | nacho | } |