svn-gvsig-desktop / tags / gvSIGv0_6_1RELEASE / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Panels / SaveRasterDialog.java @ 5222
History | View | Annotate | Download (11.9 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 | 3084 | nacho | * @author Nacho Brodin (brodin_ign@gva.es)
|
71 | 2183 | fernando | */
|
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 | 3992 | nacho | getAcceptButton().setText(PluginServices.getText(this, "aceptar")); |
158 | getCancelButton().setText(PluginServices.getText(this, "cancelar")); |
||
159 | |||
160 | String text = dInput.getBPropiedades().getText();
|
||
161 | dInput.getBPropiedades().setText(PluginServices.getText(this, "propiedades")+" "+text.substring(text.lastIndexOf(" ") + 1,text.length())); |
||
162 | 2183 | fernando | } |
163 | |||
164 | /**
|
||
165 | * Inicializa el jDialog
|
||
166 | *
|
||
167 | * @return javax.swing.JDialog
|
||
168 | */
|
||
169 | private void init() { |
||
170 | setBounds(0, 0, 386, 268); |
||
171 | setName("saveRaster");
|
||
172 | |||
173 | this.getAcceptButton().setEnabled(false); |
||
174 | this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
||
175 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
176 | acceptButtonActionPerformed(evt); |
||
177 | closeJDialog(); |
||
178 | } |
||
179 | }); |
||
180 | this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
||
181 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
182 | closeJDialog(); |
||
183 | } |
||
184 | }); |
||
185 | this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
||
186 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
187 | acceptButtonActionPerformed(evt); |
||
188 | } |
||
189 | }); |
||
190 | |||
191 | //Captura de eventos para el bot?n de propiedades
|
||
192 | |||
193 | ((SaveSetupPanel)this.getContentPanel()).getSaveParameters().getBPropiedades().addActionListener(new java.awt.event.ActionListener() { |
||
194 | public void actionPerformed(java.awt.event.ActionEvent evt) { |
||
195 | propsButtonActionPerformed(evt); |
||
196 | } |
||
197 | }); |
||
198 | |||
199 | } |
||
200 | |||
201 | |||
202 | /**
|
||
203 | * This method initializes jContentPane
|
||
204 | *
|
||
205 | * @return javax.swing.JPanel
|
||
206 | */
|
||
207 | public Container getContentPane() { |
||
208 | return this; |
||
209 | } |
||
210 | |||
211 | /**
|
||
212 | *
|
||
213 | * @param prj
|
||
214 | */
|
||
215 | |||
216 | public void setProjection(IProjection prj) { |
||
217 | this.currentProjection = prj;
|
||
218 | } |
||
219 | |||
220 | /**
|
||
221 | * Asigna el FLayers
|
||
222 | * @param layers
|
||
223 | */
|
||
224 | public void setLayerList(FLayers layers){ |
||
225 | this.layers = layers;
|
||
226 | } |
||
227 | |||
228 | |||
229 | public void closeJDialog() { |
||
230 | this.hide();
|
||
231 | for(int i=0;i<layers.getLayersCount();i++){ |
||
232 | layers.getLayer(i).getFMap().invalidate(); |
||
233 | } |
||
234 | PluginServices.getMDIManager().closeView(SaveRasterDialog.this); |
||
235 | //dlg.dispose();
|
||
236 | } |
||
237 | |||
238 | private void propsButtonActionPerformed(ActionEvent e){ |
||
239 | DataInputSaveRaster dialog = (DataInputSaveRaster)((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getSaveParameters();
|
||
240 | if(dialog.getBPropiedades().getText().endsWith("Ecw")){ |
||
241 | writerProps = new EcwWriter();
|
||
242 | if(driverProps.getProperties("ecw")!=null){ |
||
243 | writerProps.setProps(driverProps.getProperties("ecw"));
|
||
244 | } |
||
245 | } |
||
246 | |||
247 | 3791 | nacho | if( dialog.getBPropiedades().getText().endsWith("GeoTiff") || |
248 | dialog.getBPropiedades().getText().endsWith("Jpeg")){
|
||
249 | 2183 | fernando | writerProps = new GdalWriter("GTiff"); |
250 | if(driverProps.getProperties("tif")!=null){ |
||
251 | writerProps.setProps(driverProps.getProperties("tif"));
|
||
252 | } |
||
253 | } |
||
254 | 3791 | nacho | |
255 | if(dialog.getBPropiedades().getText().endsWith("Jp2")){ |
||
256 | writerProps = new EcwWriter();
|
||
257 | if(driverProps.getProperties("jp2")!=null){ |
||
258 | writerProps.setProps(driverProps.getProperties("jp2"));
|
||
259 | } |
||
260 | } |
||
261 | 3992 | nacho | |
262 | 2183 | fernando | frameSaveRasterProps = new SaveRasterPropsDialog(writerProps);
|
263 | frameSaveRasterProps.setParentDialog(this);
|
||
264 | frameSaveRasterProps.show(); |
||
265 | } |
||
266 | |||
267 | /**
|
||
268 | *
|
||
269 | * @param e
|
||
270 | */
|
||
271 | private void acceptButtonActionPerformed(ActionEvent e) { |
||
272 | DataInputSaveRaster dialog = (DataInputSaveRaster)((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getSaveParameters();
|
||
273 | |||
274 | String fName = ((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getFileName(); |
||
275 | Dimension dimension = new Dimension(Integer.parseInt(dialog.getTancho().getText()), |
||
276 | Integer.parseInt(dialog.getTalto().getText()));
|
||
277 | |||
278 | double lrX = Double.parseDouble(dialog.getTinf_derX().getText()); |
||
279 | double lrY = Double.parseDouble(dialog.getTinf_derY().getText()); |
||
280 | double ulX = Double.parseDouble(dialog.getTsup_izqX().getText()); |
||
281 | double ulY = Double.parseDouble(dialog.getTsup_izqY().getText()); |
||
282 | double width = 0; |
||
283 | 2385 | igbrotru | if(ulX>lrX)width = (double)(ulX-lrX); |
284 | else width = (double)(lrX-ulX); |
||
285 | 2183 | fernando | double height = 0; |
286 | 2385 | igbrotru | if(ulY>lrY)height = (double)(ulY-lrY); |
287 | else height = (double)(lrY-ulY); |
||
288 | 2183 | fernando | Rectangle2D ext = null; |
289 | |||
290 | if(ulY<lrY)
|
||
291 | ext = new Rectangle2D.Double(ulX, ulY, width, height); |
||
292 | else
|
||
293 | ext = new Rectangle2D.Double(ulX, lrY, width, height); |
||
294 | |||
295 | ProgressSaveRasterDialog progressBar = new ProgressSaveRasterDialog(mapCtrl,
|
||
296 | this.layers,
|
||
297 | this.currentProjection,
|
||
298 | dimension, |
||
299 | ext); |
||
300 | |||
301 | progressBar.setProps(driverProps); |
||
302 | progressBar.setWriter(writer); |
||
303 | progressBar.setFName(fName); |
||
304 | progressBar.setBlockSize(sizeBlock); |
||
305 | progressBar.setCompresion(compresion); |
||
306 | progressBar.showWindow(); |
||
307 | |||
308 | /*ViewPort vp = new ViewPort(this.currentProjection);
|
||
309 | vp.setBackColor(mapCtrl.getViewPort().getBackColor());
|
||
310 | vp.setImageSize(dimension);
|
||
311 | vp.setExtent(ext);
|
||
312 | |||
313 | if (fName.endsWith(".ecw")) {
|
||
314 | //System.out.println("Salvando vista a fichero "+fName+" a formato Ecw");
|
||
315 | try{
|
||
316 | |||
317 | RasterizerLayer p = new RasterizerLayer(this.layers, vp, sizeBlock, mapCtrl);
|
||
318 | Extent ex = new Extent(vp.getAdjustedExtent());
|
||
319 | Dimension imgSz = vp.getImageSize();
|
||
320 | ViewPortData vpData = new ViewPortData(vp.getProjection(), ex, imgSz );
|
||
321 | writer = new EcwWriter( ((IDataWriter)p),
|
||
322 | vpData,
|
||
323 | fName,
|
||
324 | sizeBlock,
|
||
325 | 3,
|
||
326 | compresion);
|
||
327 | //Si han sido modificadas las propiedades se asignan los valores modificados
|
||
328 | String[] prp = driverProps.getProperties("ecw");
|
||
329 | if(prp!=null)
|
||
330 | writer.setProps(prp);
|
||
331 | ((EcwWriter)writer).dataWrite();
|
||
332 | ((EcwWriter)writer).writeClose();
|
||
333 | |||
334 | |||
335 | }catch(IOException ev){
|
||
336 | ev.printStackTrace();
|
||
337 | }catch(es.gva.cit.jecwcompress.EcwException r){
|
||
338 | r.printStackTrace();
|
||
339 | }
|
||
340 | |||
341 | }else if (fName.endsWith(".tif")) {
|
||
342 | //System.out.println("Salvando fichero "+fName+" a formato Tif");
|
||
343 | try{
|
||
344 | |||
345 | RasterizerLayer p = new RasterizerLayer(this.layers, vp, sizeBlock, mapCtrl);
|
||
346 | Extent ex = new Extent(vp.getAdjustedExtent());
|
||
347 | writer = new GdalWriter( ((IDataWriter)p),
|
||
348 | dimension.width,
|
||
349 | dimension.height,
|
||
350 | fName,
|
||
351 | ex.maxX(),
|
||
352 | ex.minX(),
|
||
353 | ex.maxY(),
|
||
354 | ex.minY(),
|
||
355 | 3,
|
||
356 | sizeBlock,
|
||
357 | "GTiff");
|
||
358 | //Si han sido modificadas las propiedades se asignan los valores modificados
|
||
359 | String[] prp = driverProps.getProperties("tif");
|
||
360 | if(prp!=null)
|
||
361 | writer.setProps(prp);
|
||
362 | ((GdalWriter)writer).dataWrite();
|
||
363 | ((GdalWriter)writer).writeClose();
|
||
364 | }catch(IOException ev){
|
||
365 | ev.printStackTrace();
|
||
366 | }catch(es.gva.cit.jgdal.GdalException r){
|
||
367 | r.printStackTrace();
|
||
368 | }
|
||
369 | |||
370 | } else {
|
||
371 | System.err.println("Extensi?n del fichero " + fName + " no soportada.");
|
||
372 | }*/
|
||
373 | |||
374 | for(int i=0;i<layers.getLayersCount();i++){ |
||
375 | layers.getLayer(i).getFMap().invalidate(); |
||
376 | } |
||
377 | } |
||
378 | |||
379 | /**
|
||
380 | * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
||
381 | */
|
||
382 | public ViewInfo getViewInfo() {
|
||
383 | ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
||
384 | m_viewinfo.setTitle(PluginServices.getText(this, "salvar_raster")); |
||
385 | return m_viewinfo;
|
||
386 | } |
||
387 | |||
388 | } |