root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Panels / SaveRasterDialog.java @ 2970
History | View | Annotate | Download (11.4 KB)
1 | 2183 | fernando | /*
|
---|---|---|---|
2 | * Created on 17-feb-2004
|
||
3 | *
|
||
4 | * To change the template for this generated file go to
|
||
5 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
6 | */
|
||
7 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
8 | *
|
||
9 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
10 | *
|
||
11 | * This program is free software; you can redistribute it and/or
|
||
12 | * modify it under the terms of the GNU General Public License
|
||
13 | * as published by the Free Software Foundation; either version 2
|
||
14 | * of the License, or (at your option) any later version.
|
||
15 | *
|
||
16 | * This program is distributed in the hope that it will be useful,
|
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
19 | * GNU General Public License for more details.
|
||
20 | *
|
||
21 | * You should have received a copy of the GNU General Public License
|
||
22 | * along with this program; if not, write to the Free Software
|
||
23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
24 | *
|
||
25 | * For more information, contact:
|
||
26 | *
|
||
27 | * Generalitat Valenciana
|
||
28 | * Conselleria d'Infraestructures i Transport
|
||
29 | * Av. Blasco Ib??ez, 50
|
||
30 | * 46010 VALENCIA
|
||
31 | * SPAIN
|
||
32 | *
|
||
33 | * +34 963862235
|
||
34 | * gvsig@gva.es
|
||
35 | * www.gvsig.gva.es
|
||
36 | *
|
||
37 | * or
|
||
38 | *
|
||
39 | * IVER T.I. S.A
|
||
40 | * Salamanca 50
|
||
41 | * 46005 Valencia
|
||
42 | * Spain
|
||
43 | *
|
||
44 | * +34 963163400
|
||
45 | * dac@iver.es
|
||
46 | */
|
||
47 | package com.iver.cit.gvsig.gui.Panels; |
||
48 | |||
49 | import java.awt.Container; |
||
50 | import java.awt.Dimension; |
||
51 | import java.awt.event.ActionEvent; |
||
52 | import java.awt.geom.Rectangle2D; |
||
53 | |||
54 | import org.cresques.cts.IProjection; |
||
55 | import org.cresques.io.EcwWriter; |
||
56 | import org.cresques.io.GdalWriter; |
||
57 | import org.cresques.io.GeoRasterWriter; |
||
58 | import org.cresques.ui.raster.DataInputSaveRaster; |
||
59 | import org.cresques.ui.raster.SaveRasterDialogPanel; |
||
60 | import org.cresques.ui.raster.SaveSetupPanel; |
||
61 | |||
62 | import com.iver.andami.PluginServices; |
||
63 | import com.iver.andami.ui.mdiManager.View; |
||
64 | import com.iver.andami.ui.mdiManager.ViewInfo; |
||
65 | import com.iver.cit.gvsig.fmap.MapControl; |
||
66 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
67 | |||
68 | /**
|
||
69 | * Dialogo para abrir fichero.
|
||
70 | * @author Nacho Brodin <brodin_ign@gva.es>
|
||
71 | */
|
||
72 | //public class SaveRasterDialog extends JDialog{
|
||
73 | public class SaveRasterDialog extends SaveRasterDialogPanel implements View { |
||
74 | |||
75 | //private SaveRasterDialogPanel contentPane = null;
|
||
76 | private GeoRasterWriter writer=null; |
||
77 | private GeoRasterWriter writerProps=null; |
||
78 | private IProjection currentProjection = null; |
||
79 | private SaveRasterPropsDialog frameSaveRasterProps = null; |
||
80 | private int compresion = 1; |
||
81 | private int sizeBlock = 64; |
||
82 | public DriverProperties driverProps = null; |
||
83 | private FLayers layers = null; |
||
84 | private MapControl mapCtrl = null; |
||
85 | |||
86 | class DriverProperties{ |
||
87 | |||
88 | private String[][] driversProps = null; |
||
89 | private String[] driversExtension = null; |
||
90 | |||
91 | DriverProperties(){ |
||
92 | |||
93 | driversProps = new String[GeoRasterWriter.getNDrivers()][]; |
||
94 | for(int i=0;i<GeoRasterWriter.getNDrivers();i++) |
||
95 | driversProps[i] = null;
|
||
96 | driversExtension = GeoRasterWriter.getDriversExtensions(); |
||
97 | |||
98 | } |
||
99 | |||
100 | /**
|
||
101 | * Asigna un vector de propiedades de driver de escritura.
|
||
102 | * @param ext extensi?n del driver.
|
||
103 | * @param props propiedades.
|
||
104 | */
|
||
105 | public void setProperties(String ext, String[] props){ |
||
106 | for(int i=0;i<driversExtension.length;i++){ |
||
107 | if(ext.equals(driversExtension[i])){
|
||
108 | driversProps[i] = props; |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | |||
113 | /**
|
||
114 | * Obtiene un vector de propiedades de driver de escritura.
|
||
115 | * @param ext extensi?n del driver.
|
||
116 | * @return propiedades.
|
||
117 | */
|
||
118 | public String[] getProperties(String ext){ |
||
119 | for(int i=0;i<driversExtension.length;i++){ |
||
120 | if(ext.equals(driversExtension[i])){
|
||
121 | return driversProps[i];
|
||
122 | } |
||
123 | } |
||
124 | return null; |
||
125 | } |
||
126 | |||
127 | } |
||
128 | |||
129 | /**
|
||
130 | * Constructor de la ventana de dialogo.
|
||
131 | *
|
||
132 | */
|
||
133 | public SaveRasterDialog(FLayers layers, MapControl mapCtrl) {
|
||
134 | super();
|
||
135 | //super.setModal(true);
|
||
136 | driverProps = new DriverProperties();
|
||
137 | this.layers = layers;
|
||
138 | this.mapCtrl = mapCtrl;
|
||
139 | init(); |
||
140 | this.setTranslation();
|
||
141 | } |
||
142 | |||
143 | /**
|
||
144 | * Asigna los textos a los paneles
|
||
145 | */
|
||
146 | public void setTranslation(){ |
||
147 | DataInputSaveRaster dInput = ((SaveSetupPanel)super.getContentPanel()).getSaveParameters();
|
||
148 | 2706 | nacho | dInput.lSupIzq.setText(PluginServices.getText(this,"lsup_izq")+":"); |
149 | dInput.lInfDer.setText(PluginServices.getText(this,"linf_der")+":"); |
||
150 | dInput.lFile.setText(PluginServices.getText(this,"Fichero")+":"); |
||
151 | dInput.lResolucion.setText(PluginServices.getText(this,"resolucion")); |
||
152 | dInput.lEscala.setText(PluginServices.getText(this,"escala")+" 1:"); |
||
153 | dInput.lPpp.setText(PluginServices.getText(this,"lppp")); |
||
154 | dInput.bSeleccion.setText(PluginServices.getText(this,"Seleccionar")); |
||
155 | dInput.lAncho.setText(PluginServices.getText(this,"ancho")+"."); |
||
156 | dInput.lAlto.setText(PluginServices.getText(this,"alto")+"."); |
||
157 | 2183 | fernando | |
158 | } |
||
159 | |||
160 | /**
|
||
161 | * Inicializa el jDialog
|
||
162 | *
|
||
163 | * @return javax.swing.JDialog
|
||
164 | */
|
||
165 | private void init() { |
||
166 | setBounds(0, 0, 386, 268); |
||
167 | setName("saveRaster");
|
||
168 | |||
169 | this.getAcceptButton().setEnabled(false); |
||
170 | this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
||
171 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
172 | acceptButtonActionPerformed(evt); |
||
173 | closeJDialog(); |
||
174 | } |
||
175 | }); |
||
176 | this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
||
177 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
178 | closeJDialog(); |
||
179 | } |
||
180 | }); |
||
181 | this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
||
182 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
183 | acceptButtonActionPerformed(evt); |
||
184 | } |
||
185 | }); |
||
186 | |||
187 | //Captura de eventos para el bot?n de propiedades
|
||
188 | |||
189 | ((SaveSetupPanel)this.getContentPanel()).getSaveParameters().getBPropiedades().addActionListener(new java.awt.event.ActionListener() { |
||
190 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
191 | propsButtonActionPerformed(evt); |
||
192 | } |
||
193 | }); |
||
194 | |||
195 | } |
||
196 | |||
197 | |||
198 | /**
|
||
199 | * This method initializes jContentPane
|
||
200 | *
|
||
201 | * @return javax.swing.JPanel
|
||
202 | */
|
||
203 | public Container getContentPane() { |
||
204 | return this; |
||
205 | } |
||
206 | |||
207 | /**
|
||
208 | *
|
||
209 | * @param prj
|
||
210 | */
|
||
211 | |||
212 | public void setProjection(IProjection prj) { |
||
213 | this.currentProjection = prj;
|
||
214 | } |
||
215 | |||
216 | /**
|
||
217 | * Asigna el FLayers
|
||
218 | * @param layers
|
||
219 | */
|
||
220 | public void setLayerList(FLayers layers){ |
||
221 | this.layers = layers;
|
||
222 | } |
||
223 | |||
224 | |||
225 | public void closeJDialog() { |
||
226 | this.hide();
|
||
227 | for(int i=0;i<layers.getLayersCount();i++){ |
||
228 | layers.getLayer(i).getFMap().invalidate(); |
||
229 | } |
||
230 | PluginServices.getMDIManager().closeView(SaveRasterDialog.this); |
||
231 | //dlg.dispose();
|
||
232 | } |
||
233 | |||
234 | private void propsButtonActionPerformed(ActionEvent e){ |
||
235 | DataInputSaveRaster dialog = (DataInputSaveRaster)((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getSaveParameters();
|
||
236 | if(dialog.getBPropiedades().getText().endsWith("Ecw")){ |
||
237 | writerProps = new EcwWriter();
|
||
238 | if(driverProps.getProperties("ecw")!=null){ |
||
239 | writerProps.setProps(driverProps.getProperties("ecw"));
|
||
240 | } |
||
241 | } |
||
242 | |||
243 | if(dialog.getBPropiedades().getText().endsWith("GeoTiff")){ |
||
244 | writerProps = new GdalWriter("GTiff"); |
||
245 | if(driverProps.getProperties("tif")!=null){ |
||
246 | writerProps.setProps(driverProps.getProperties("tif"));
|
||
247 | } |
||
248 | } |
||
249 | |||
250 | frameSaveRasterProps = new SaveRasterPropsDialog(writerProps);
|
||
251 | frameSaveRasterProps.setParentDialog(this);
|
||
252 | frameSaveRasterProps.show(); |
||
253 | } |
||
254 | |||
255 | /**
|
||
256 | *
|
||
257 | * @param e
|
||
258 | */
|
||
259 | private void acceptButtonActionPerformed(ActionEvent e) { |
||
260 | DataInputSaveRaster dialog = (DataInputSaveRaster)((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getSaveParameters();
|
||
261 | |||
262 | String fName = ((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getFileName(); |
||
263 | Dimension dimension = new Dimension(Integer.parseInt(dialog.getTancho().getText()), |
||
264 | Integer.parseInt(dialog.getTalto().getText()));
|
||
265 | |||
266 | double lrX = Double.parseDouble(dialog.getTinf_derX().getText()); |
||
267 | double lrY = Double.parseDouble(dialog.getTinf_derY().getText()); |
||
268 | double ulX = Double.parseDouble(dialog.getTsup_izqX().getText()); |
||
269 | double ulY = Double.parseDouble(dialog.getTsup_izqY().getText()); |
||
270 | double width = 0; |
||
271 | 2385 | igbrotru | if(ulX>lrX)width = (double)(ulX-lrX); |
272 | else width = (double)(lrX-ulX); |
||
273 | 2183 | fernando | double height = 0; |
274 | 2385 | igbrotru | if(ulY>lrY)height = (double)(ulY-lrY); |
275 | else height = (double)(lrY-ulY); |
||
276 | 2183 | fernando | Rectangle2D ext = null; |
277 | |||
278 | if(ulY<lrY)
|
||
279 | ext = new Rectangle2D.Double(ulX, ulY, width, height); |
||
280 | else
|
||
281 | ext = new Rectangle2D.Double(ulX, lrY, width, height); |
||
282 | |||
283 | ProgressSaveRasterDialog progressBar = new ProgressSaveRasterDialog(mapCtrl,
|
||
284 | this.layers,
|
||
285 | this.currentProjection,
|
||
286 | dimension, |
||
287 | ext); |
||
288 | |||
289 | progressBar.setProps(driverProps); |
||
290 | progressBar.setWriter(writer); |
||
291 | progressBar.setFName(fName); |
||
292 | progressBar.setBlockSize(sizeBlock); |
||
293 | progressBar.setCompresion(compresion); |
||
294 | progressBar.showWindow(); |
||
295 | |||
296 | /*ViewPort vp = new ViewPort(this.currentProjection);
|
||
297 | vp.setBackColor(mapCtrl.getViewPort().getBackColor());
|
||
298 | vp.setImageSize(dimension);
|
||
299 | vp.setExtent(ext);
|
||
300 | |||
301 | if (fName.endsWith(".ecw")) {
|
||
302 | //System.out.println("Salvando vista a fichero "+fName+" a formato Ecw");
|
||
303 | try{
|
||
304 | |||
305 | RasterizerLayer p = new RasterizerLayer(this.layers, vp, sizeBlock, mapCtrl);
|
||
306 | Extent ex = new Extent(vp.getAdjustedExtent());
|
||
307 | Dimension imgSz = vp.getImageSize();
|
||
308 | ViewPortData vpData = new ViewPortData(vp.getProjection(), ex, imgSz );
|
||
309 | writer = new EcwWriter( ((IDataWriter)p),
|
||
310 | vpData,
|
||
311 | fName,
|
||
312 | sizeBlock,
|
||
313 | 3,
|
||
314 | compresion);
|
||
315 | //Si han sido modificadas las propiedades se asignan los valores modificados
|
||
316 | String[] prp = driverProps.getProperties("ecw");
|
||
317 | if(prp!=null)
|
||
318 | writer.setProps(prp);
|
||
319 | ((EcwWriter)writer).dataWrite();
|
||
320 | ((EcwWriter)writer).writeClose();
|
||
321 | |||
322 | |||
323 | }catch(IOException ev){
|
||
324 | ev.printStackTrace();
|
||
325 | }catch(es.gva.cit.jecwcompress.EcwException r){
|
||
326 | r.printStackTrace();
|
||
327 | }
|
||
328 | |||
329 | }else if (fName.endsWith(".tif")) {
|
||
330 | //System.out.println("Salvando fichero "+fName+" a formato Tif");
|
||
331 | try{
|
||
332 | |||
333 | RasterizerLayer p = new RasterizerLayer(this.layers, vp, sizeBlock, mapCtrl);
|
||
334 | Extent ex = new Extent(vp.getAdjustedExtent());
|
||
335 | writer = new GdalWriter( ((IDataWriter)p),
|
||
336 | dimension.width,
|
||
337 | dimension.height,
|
||
338 | fName,
|
||
339 | ex.maxX(),
|
||
340 | ex.minX(),
|
||
341 | ex.maxY(),
|
||
342 | ex.minY(),
|
||
343 | 3,
|
||
344 | sizeBlock,
|
||
345 | "GTiff");
|
||
346 | //Si han sido modificadas las propiedades se asignan los valores modificados
|
||
347 | String[] prp = driverProps.getProperties("tif");
|
||
348 | if(prp!=null)
|
||
349 | writer.setProps(prp);
|
||
350 | ((GdalWriter)writer).dataWrite();
|
||
351 | ((GdalWriter)writer).writeClose();
|
||
352 | }catch(IOException ev){
|
||
353 | ev.printStackTrace();
|
||
354 | }catch(es.gva.cit.jgdal.GdalException r){
|
||
355 | r.printStackTrace();
|
||
356 | }
|
||
357 | |||
358 | } else {
|
||
359 | System.err.println("Extensi?n del fichero " + fName + " no soportada.");
|
||
360 | }*/
|
||
361 | |||
362 | for(int i=0;i<layers.getLayersCount();i++){ |
||
363 | layers.getLayer(i).getFMap().invalidate(); |
||
364 | } |
||
365 | } |
||
366 | |||
367 | /**
|
||
368 | * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
||
369 | */
|
||
370 | public ViewInfo getViewInfo() {
|
||
371 | ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
||
372 | m_viewinfo.setTitle(PluginServices.getText(this, "salvar_raster")); |
||
373 | return m_viewinfo;
|
||
374 | } |
||
375 | |||
376 | } |