svn-gvsig-desktop / branches / gvSIG_GisPlanet / applications / appgvSIG / src / com / iver / cit / gvsig / gui / Panels / SaveRasterDialog.java @ 2123
History | View | Annotate | Download (10.7 KB)
1 |
/*
|
---|---|
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 |
import java.io.IOException; |
54 |
|
55 |
import org.cresques.cts.IProjection; |
56 |
import org.cresques.geo.ViewPortData; |
57 |
import org.cresques.io.EcwWriter; |
58 |
import org.cresques.io.GdalWriter; |
59 |
import org.cresques.io.GeoRasterWriter; |
60 |
import org.cresques.io.IDataWriter; |
61 |
import org.cresques.px.Extent; |
62 |
import org.cresques.ui.raster.DataInputSaveRaster; |
63 |
import org.cresques.ui.raster.SaveRasterDialogPanel; |
64 |
import org.cresques.ui.raster.SaveSetupPanel; |
65 |
|
66 |
import com.iver.andami.PluginServices; |
67 |
import com.iver.andami.ui.mdiManager.View; |
68 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
69 |
import com.iver.cit.gvsig.RasterizerLayer; |
70 |
import com.iver.cit.gvsig.fmap.MapControl; |
71 |
import com.iver.cit.gvsig.fmap.ViewPort; |
72 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
73 |
|
74 |
/**
|
75 |
* Dialogo para abrir fichero.
|
76 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
77 |
*/
|
78 |
//public class SaveRasterDialog extends JDialog{
|
79 |
public class SaveRasterDialog extends SaveRasterDialogPanel implements View { |
80 |
|
81 |
//private SaveRasterDialogPanel contentPane = null;
|
82 |
private GeoRasterWriter writer=null; |
83 |
private GeoRasterWriter writerProps=null; |
84 |
private IProjection currentProjection = null; |
85 |
private SaveRasterPropsDialog frameSaveRasterProps = null; |
86 |
private int compresion = 1; |
87 |
private int sizeBlock = 64; |
88 |
public DriverProperties driverProps = null; |
89 |
private FLayers layers = null; |
90 |
private MapControl mapCtrl = null; |
91 |
|
92 |
class DriverProperties{ |
93 |
|
94 |
private String[][] driversProps = null; |
95 |
private String[] driversExtension = null; |
96 |
|
97 |
DriverProperties(){ |
98 |
|
99 |
driversProps = new String[GeoRasterWriter.getNDrivers()][]; |
100 |
for(int i=0;i<GeoRasterWriter.getNDrivers();i++) |
101 |
driversProps[i] = null;
|
102 |
driversExtension = GeoRasterWriter.getDriversExtensions(); |
103 |
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* Asigna un vector de propiedades de driver de escritura.
|
108 |
* @param ext extensi?n del driver.
|
109 |
* @param props propiedades.
|
110 |
*/
|
111 |
public void setProperties(String ext, String[] props){ |
112 |
for(int i=0;i<driversExtension.length;i++){ |
113 |
if(ext.equals(driversExtension[i])){
|
114 |
driversProps[i] = props; |
115 |
} |
116 |
} |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Obtiene un vector de propiedades de driver de escritura.
|
121 |
* @param ext extensi?n del driver.
|
122 |
* @return propiedades.
|
123 |
*/
|
124 |
public String[] getProperties(String ext){ |
125 |
for(int i=0;i<driversExtension.length;i++){ |
126 |
if(ext.equals(driversExtension[i])){
|
127 |
return driversProps[i];
|
128 |
} |
129 |
} |
130 |
return null; |
131 |
} |
132 |
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* Constructor de la ventana de dialogo.
|
137 |
*
|
138 |
*/
|
139 |
public SaveRasterDialog(FLayers layers, MapControl mapCtrl) {
|
140 |
super();
|
141 |
//super.setModal(true);
|
142 |
driverProps = new DriverProperties();
|
143 |
this.layers = layers;
|
144 |
this.mapCtrl = mapCtrl;
|
145 |
init(); |
146 |
} |
147 |
|
148 |
/**
|
149 |
* Inicializa el jDialog
|
150 |
*
|
151 |
* @return javax.swing.JDialog
|
152 |
*/
|
153 |
private void init() { |
154 |
setBounds(0, 0, 386, 268); |
155 |
setName("saveRaster");
|
156 |
|
157 |
this.getAcceptButton().setEnabled(false); |
158 |
this.getAcceptButton().addActionListener(new java.awt.event.ActionListener() { |
159 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
160 |
acceptButtonActionPerformed(evt); |
161 |
closeJDialog(); |
162 |
} |
163 |
}); |
164 |
this.getCancelButton().addActionListener(new java.awt.event.ActionListener() { |
165 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
166 |
closeJDialog(); |
167 |
} |
168 |
}); |
169 |
this.getApplyButton().addActionListener(new java.awt.event.ActionListener() { |
170 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
171 |
acceptButtonActionPerformed(evt); |
172 |
} |
173 |
}); |
174 |
|
175 |
//Captura de eventos para el bot?n de propiedades
|
176 |
|
177 |
((SaveSetupPanel)this.getContentPanel()).getSaveParameters().getBPropiedades().addActionListener(new java.awt.event.ActionListener() { |
178 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
179 |
propsButtonActionPerformed(evt); |
180 |
} |
181 |
}); |
182 |
|
183 |
} |
184 |
|
185 |
|
186 |
/**
|
187 |
* This method initializes jContentPane
|
188 |
*
|
189 |
* @return javax.swing.JPanel
|
190 |
*/
|
191 |
public Container getContentPane() { |
192 |
return this; |
193 |
} |
194 |
|
195 |
/**
|
196 |
*
|
197 |
* @param prj
|
198 |
*/
|
199 |
|
200 |
public void setProjection(IProjection prj) { |
201 |
this.currentProjection = prj;
|
202 |
} |
203 |
|
204 |
/**
|
205 |
* Asigna el FLayers
|
206 |
* @param layers
|
207 |
*/
|
208 |
public void setLayerList(FLayers layers){ |
209 |
this.layers = layers;
|
210 |
} |
211 |
|
212 |
|
213 |
public void closeJDialog() { |
214 |
this.hide();
|
215 |
for(int i=0;i<layers.getLayersCount();i++){ |
216 |
layers.getLayer(i).getFMap().invalidate(); |
217 |
} |
218 |
PluginServices.getMDIManager().closeView(SaveRasterDialog.this); |
219 |
//dlg.dispose();
|
220 |
} |
221 |
|
222 |
private void propsButtonActionPerformed(ActionEvent e){ |
223 |
DataInputSaveRaster dialog = (DataInputSaveRaster)((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getSaveParameters();
|
224 |
if(dialog.getBPropiedades().getText().endsWith("Ecw")){ |
225 |
writerProps = new EcwWriter();
|
226 |
if(driverProps.getProperties("ecw")!=null){ |
227 |
writerProps.setProps(driverProps.getProperties("ecw"));
|
228 |
} |
229 |
} |
230 |
|
231 |
if(dialog.getBPropiedades().getText().endsWith("GeoTiff")){ |
232 |
writerProps = new GdalWriter("GTiff"); |
233 |
if(driverProps.getProperties("tif")!=null){ |
234 |
writerProps.setProps(driverProps.getProperties("tif"));
|
235 |
} |
236 |
} |
237 |
|
238 |
frameSaveRasterProps = new SaveRasterPropsDialog(writerProps);
|
239 |
frameSaveRasterProps.setParentDialog(this);
|
240 |
frameSaveRasterProps.show(); |
241 |
} |
242 |
|
243 |
/**
|
244 |
*
|
245 |
* @param e
|
246 |
*/
|
247 |
private void acceptButtonActionPerformed(ActionEvent e) { |
248 |
DataInputSaveRaster dialog = (DataInputSaveRaster)((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getSaveParameters();
|
249 |
|
250 |
String fName = ((SaveSetupPanel)((SaveRasterDialogPanel)this.getContentPane()).getContentPanel()).getFileName(); |
251 |
Dimension dimension = new Dimension(Integer.parseInt(dialog.getTancho().getText()), |
252 |
Integer.parseInt(dialog.getTalto().getText()));
|
253 |
|
254 |
double lrX = Double.parseDouble(dialog.getTinf_derX().getText()); |
255 |
double lrY = Double.parseDouble(dialog.getTinf_derY().getText()); |
256 |
double ulX = Double.parseDouble(dialog.getTsup_izqX().getText()); |
257 |
double ulY = Double.parseDouble(dialog.getTsup_izqY().getText()); |
258 |
double width = 0; |
259 |
if(ulX>lrX)width = ulX-lrX;
|
260 |
else width = lrX-ulX;
|
261 |
double height = 0; |
262 |
if(ulY>lrY)height = ulY-lrY;
|
263 |
else height = lrY-ulY;
|
264 |
Rectangle2D ext = null; |
265 |
|
266 |
if(ulY<lrY)
|
267 |
ext = new Rectangle2D.Double(ulX, ulY, width, height); |
268 |
else
|
269 |
ext = new Rectangle2D.Double(ulX, lrY, width, height); |
270 |
|
271 |
ProgressSaveRasterDialog progressBar = new ProgressSaveRasterDialog(mapCtrl,
|
272 |
this.layers,
|
273 |
this.currentProjection,
|
274 |
dimension, |
275 |
ext); |
276 |
|
277 |
progressBar.setProps(driverProps); |
278 |
progressBar.setWriter(writer); |
279 |
progressBar.setFName(fName); |
280 |
progressBar.setBlockSize(sizeBlock); |
281 |
progressBar.setCompresion(compresion); |
282 |
progressBar.showWindow(); |
283 |
|
284 |
/*ViewPort vp = new ViewPort(this.currentProjection);
|
285 |
vp.setBackColor(mapCtrl.getViewPort().getBackColor());
|
286 |
vp.setImageSize(dimension);
|
287 |
vp.setExtent(ext);
|
288 |
|
289 |
if (fName.endsWith(".ecw")) {
|
290 |
//System.out.println("Salvando vista a fichero "+fName+" a formato Ecw");
|
291 |
try{
|
292 |
|
293 |
RasterizerLayer p = new RasterizerLayer(this.layers, vp, sizeBlock, mapCtrl);
|
294 |
Extent ex = new Extent(vp.getAdjustedExtent());
|
295 |
Dimension imgSz = vp.getImageSize();
|
296 |
ViewPortData vpData = new ViewPortData(vp.getProjection(), ex, imgSz );
|
297 |
writer = new EcwWriter( ((IDataWriter)p),
|
298 |
vpData,
|
299 |
fName,
|
300 |
sizeBlock,
|
301 |
3,
|
302 |
compresion);
|
303 |
//Si han sido modificadas las propiedades se asignan los valores modificados
|
304 |
String[] prp = driverProps.getProperties("ecw");
|
305 |
if(prp!=null)
|
306 |
writer.setProps(prp);
|
307 |
((EcwWriter)writer).dataWrite();
|
308 |
((EcwWriter)writer).writeClose();
|
309 |
|
310 |
|
311 |
}catch(IOException ev){
|
312 |
ev.printStackTrace();
|
313 |
}catch(es.gva.cit.jecwcompress.EcwException r){
|
314 |
r.printStackTrace();
|
315 |
}
|
316 |
|
317 |
}else if (fName.endsWith(".tif")) {
|
318 |
//System.out.println("Salvando fichero "+fName+" a formato Tif");
|
319 |
try{
|
320 |
|
321 |
RasterizerLayer p = new RasterizerLayer(this.layers, vp, sizeBlock, mapCtrl);
|
322 |
Extent ex = new Extent(vp.getAdjustedExtent());
|
323 |
writer = new GdalWriter( ((IDataWriter)p),
|
324 |
dimension.width,
|
325 |
dimension.height,
|
326 |
fName,
|
327 |
ex.maxX(),
|
328 |
ex.minX(),
|
329 |
ex.maxY(),
|
330 |
ex.minY(),
|
331 |
3,
|
332 |
sizeBlock,
|
333 |
"GTiff");
|
334 |
//Si han sido modificadas las propiedades se asignan los valores modificados
|
335 |
String[] prp = driverProps.getProperties("tif");
|
336 |
if(prp!=null)
|
337 |
writer.setProps(prp);
|
338 |
((GdalWriter)writer).dataWrite();
|
339 |
((GdalWriter)writer).writeClose();
|
340 |
}catch(IOException ev){
|
341 |
ev.printStackTrace();
|
342 |
}catch(es.gva.cit.jgdal.GdalException r){
|
343 |
r.printStackTrace();
|
344 |
}
|
345 |
|
346 |
} else {
|
347 |
System.err.println("Extensi?n del fichero " + fName + " no soportada.");
|
348 |
}*/
|
349 |
|
350 |
for(int i=0;i<layers.getLayersCount();i++){ |
351 |
layers.getLayer(i).getFMap().invalidate(); |
352 |
} |
353 |
} |
354 |
|
355 |
/**
|
356 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
357 |
*/
|
358 |
public ViewInfo getViewInfo() {
|
359 |
ViewInfo m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
360 |
m_viewinfo.setTitle(PluginServices.getText(this, "salvar_raster")); |
361 |
return m_viewinfo;
|
362 |
} |
363 |
|
364 |
} |