|
1 |
/*
|
|
2 |
* Created on 1-dic-2007
|
|
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.ai2.gvsig3dgui.view;
|
|
48 |
|
|
49 |
import java.awt.Component;
|
|
50 |
import java.awt.geom.AffineTransform;
|
|
51 |
import java.awt.image.BufferedImage;
|
|
52 |
import java.io.File;
|
|
53 |
import java.io.IOException;
|
|
54 |
import java.util.Hashtable;
|
|
55 |
import java.util.Iterator;
|
|
56 |
|
|
57 |
import javax.swing.JFileChooser;
|
|
58 |
import javax.swing.JOptionPane;
|
|
59 |
import javax.swing.filechooser.FileFilter;
|
|
60 |
|
|
61 |
import org.gvsig.raster.dataset.GeoRasterWriter;
|
|
62 |
import org.gvsig.raster.dataset.IBuffer;
|
|
63 |
import org.gvsig.raster.dataset.IDataWriter;
|
|
64 |
import org.gvsig.raster.dataset.NotSupportedExtensionException;
|
|
65 |
import org.gvsig.raster.dataset.io.RasterDriverException;
|
|
66 |
import org.gvsig.raster.datastruct.Extent;
|
|
67 |
|
|
68 |
import com.iver.andami.PluginServices;
|
|
69 |
import com.iver.andami.messages.NotificationManager;
|
|
70 |
import com.iver.andami.plugins.Extension;
|
|
71 |
import com.iver.cit.gvsig.fmap.MapContext;
|
|
72 |
import com.iver.cit.gvsig.fmap.layers.FLayer;
|
|
73 |
import com.iver.cit.gvsig.fmap.layers.FLayers;
|
|
74 |
import com.iver.cit.gvsig.project.documents.view.IProjectView;
|
|
75 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView;
|
|
76 |
import com.iver.cit.gvsig.project.documents.view.gui.View;
|
|
77 |
import com.sun.jimi.core.Jimi;
|
|
78 |
import com.sun.jimi.core.JimiException;
|
|
79 |
|
|
80 |
import es.upv.ai2.libjosg.viewer.IViewerContainer;
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
/**
|
|
85 |
* Extensi?n para exportar en algunos formatos raster la vista3D actual.
|
|
86 |
*
|
|
87 |
* @author ?ngel Fraile.
|
|
88 |
*/
|
|
89 |
public class Export extends Extension {
|
|
90 |
private String lastPath = null;
|
|
91 |
private String path = null;
|
|
92 |
private Hashtable cmsExtensionsSupported = null;
|
|
93 |
private Hashtable jimiExtensionsSupported = null;
|
|
94 |
private IViewerContainer m_canvas3d = null;
|
|
95 |
private String arg0;
|
|
96 |
|
|
97 |
/**
|
|
98 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
|
99 |
*/
|
|
100 |
public boolean isEnabled() {
|
|
101 |
|
|
102 |
View3D f = (View3D) PluginServices.getMDIManager().getActiveWindow();
|
|
103 |
|
|
104 |
if (f == null) {//Si no es una vista3D.
|
|
105 |
return false;
|
|
106 |
}
|
|
107 |
//es una vista 3D, miro sus capas.
|
|
108 |
FLayers layers = f.getModel().getMapContext().getLayers();
|
|
109 |
for (int i=0;i< layers.getLayersCount();i++) {
|
|
110 |
return layers.getLayer(i).isAvailable();
|
|
111 |
}
|
|
112 |
return false;
|
|
113 |
|
|
114 |
}
|
|
115 |
|
|
116 |
/**
|
|
117 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
|
118 |
*/
|
|
119 |
public boolean isVisible() {
|
|
120 |
com.iver.andami.ui.mdiManager.IWindow f = (com.iver.andami.ui.mdiManager.IWindow)
|
|
121 |
PluginServices.getMDIManager().getActiveWindow();
|
|
122 |
|
|
123 |
if (f == null) {
|
|
124 |
return false;
|
|
125 |
}
|
|
126 |
|
|
127 |
return (f instanceof View3D);
|
|
128 |
}
|
|
129 |
|
|
130 |
/**
|
|
131 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
|
132 |
*/
|
|
133 |
public void initialize() {
|
|
134 |
}
|
|
135 |
|
|
136 |
/* (non-Javadoc)
|
|
137 |
* @see com.iver.andami.plugins.Extension#postInitialize()
|
|
138 |
*/
|
|
139 |
public void postInitialize() {
|
|
140 |
cmsExtensionsSupported = new Hashtable();
|
|
141 |
jimiExtensionsSupported = new Hashtable();
|
|
142 |
jimiExtensionsSupported.put("png",new MyFileFilter("png",
|
|
143 |
PluginServices.getText(this, "png"), "jimi"));
|
|
144 |
cmsExtensionsSupported.put("jpg", new MyFileFilter("jpg",
|
|
145 |
PluginServices.getText(this, "jpg"), "cms"));
|
|
146 |
// jimiExtensionsSupported.put("bmp",new MyFileFilter("bmp",
|
|
147 |
// PluginServices.getText(this, "bmp"), "jimi"));
|
|
148 |
|
|
149 |
|
|
150 |
}
|
|
151 |
|
|
152 |
/**
|
|
153 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
|
154 |
*/
|
|
155 |
public void execute(String actionCommand) {
|
|
156 |
JFileChooser jfc = new JFileChooser(lastPath);
|
|
157 |
jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());
|
|
158 |
Iterator iter;
|
|
159 |
|
|
160 |
iter = cmsExtensionsSupported.values().iterator();
|
|
161 |
while (iter.hasNext()){
|
|
162 |
jfc.addChoosableFileFilter((FileFilter)iter.next());
|
|
163 |
}
|
|
164 |
|
|
165 |
iter = jimiExtensionsSupported.values().iterator();
|
|
166 |
while (iter.hasNext()){
|
|
167 |
jfc.addChoosableFileFilter((FileFilter)iter.next());
|
|
168 |
}
|
|
169 |
|
|
170 |
jfc.setFileFilter((FileFilter)jimiExtensionsSupported.get("png"));
|
|
171 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())==JFileChooser.APPROVE_OPTION){
|
|
172 |
|
|
173 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices
|
|
174 |
.getMDIManager().getActiveWindow();
|
|
175 |
File f = jfc.getSelectedFile();
|
|
176 |
if (f.exists()){//file exists in the directory.
|
|
177 |
int resp = JOptionPane.showConfirmDialog(
|
|
178 |
(Component) PluginServices.getMainFrame(),
|
|
179 |
PluginServices.getText(this,
|
|
180 |
"fichero_ya_existe_seguro_desea_guardarlo")+
|
|
181 |
"\n"+
|
|
182 |
f.getAbsolutePath(),
|
|
183 |
PluginServices.getText(this,"guardar"), JOptionPane.YES_NO_OPTION);
|
|
184 |
if (resp != JOptionPane.YES_OPTION) {//cancel pressed.
|
|
185 |
return;
|
|
186 |
}
|
|
187 |
}//if exits.
|
|
188 |
if (activeWindow instanceof View3D ) {
|
|
189 |
View3D view3D;
|
|
190 |
view3D = (View3D) activeWindow;
|
|
191 |
MyFileFilter filter = (MyFileFilter)jfc.getFileFilter();// png, jpg
|
|
192 |
f = filter.normalizeExtension(f);//"name" + "." + "png", "name" + "." + "jpg".
|
|
193 |
view3D.getCanvas3d().getOSGViewer().takeScreenshot(f.getAbsolutePath());//screen snapshop.
|
|
194 |
}//if activeWindow.
|
|
195 |
}//If aprove option.
|
|
196 |
}//void execute.
|
|
197 |
}//end class.
|
|
198 |
|
|
199 |
|
|
200 |
/**
|
|
201 |
*
|
|
202 |
* @version 14/08/2007
|
|
203 |
* @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
|
204 |
*
|
|
205 |
*/
|
|
206 |
class MyFileFilter extends FileFilter{
|
|
207 |
|
|
208 |
private String[] extensiones=new String[1];
|
|
209 |
private String description;
|
|
210 |
private boolean dirs = true;
|
|
211 |
private String info= null;
|
|
212 |
|
|
213 |
public MyFileFilter(String[] ext, String desc) {
|
|
214 |
extensiones = ext;
|
|
215 |
description = desc;
|
|
216 |
}
|
|
217 |
|
|
218 |
public MyFileFilter(String[] ext, String desc,String info) {
|
|
219 |
extensiones = ext;
|
|
220 |
description = desc;
|
|
221 |
this.info = info;
|
|
222 |
}
|
|
223 |
|
|
224 |
public MyFileFilter(String ext, String desc) {
|
|
225 |
extensiones[0] = ext;
|
|
226 |
description = desc;
|
|
227 |
}
|
|
228 |
|
|
229 |
public MyFileFilter(String ext, String desc,String info) {
|
|
230 |
extensiones[0] = ext;
|
|
231 |
description = desc;
|
|
232 |
this.info = info;
|
|
233 |
}
|
|
234 |
|
|
235 |
public MyFileFilter(String ext, String desc, boolean dirs) {
|
|
236 |
extensiones[0] = ext;
|
|
237 |
description = desc;
|
|
238 |
this.dirs = dirs;
|
|
239 |
}
|
|
240 |
|
|
241 |
public MyFileFilter(String ext, String desc, boolean dirs,String info) {
|
|
242 |
extensiones[0] = ext;
|
|
243 |
description = desc;
|
|
244 |
this.dirs = dirs;
|
|
245 |
this.info = info;
|
|
246 |
}
|
|
247 |
|
|
248 |
public boolean accept(File f) {
|
|
249 |
if (f.isDirectory()) {
|
|
250 |
if (dirs) {
|
|
251 |
return true;
|
|
252 |
} else {
|
|
253 |
return false;
|
|
254 |
}
|
|
255 |
}
|
|
256 |
for (int i=0;i<extensiones.length;i++){
|
|
257 |
if (extensiones[i].equals("")){
|
|
258 |
continue;
|
|
259 |
}
|
|
260 |
if (getExtensionOfAFile(f).equalsIgnoreCase(extensiones[i])){
|
|
261 |
return true;
|
|
262 |
}
|
|
263 |
}
|
|
264 |
|
|
265 |
return false;
|
|
266 |
}
|
|
267 |
|
|
268 |
/**
|
|
269 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
|
270 |
*/
|
|
271 |
public String getDescription() {
|
|
272 |
return description;
|
|
273 |
}
|
|
274 |
|
|
275 |
public String[] getExtensions() {
|
|
276 |
return extensiones;
|
|
277 |
}
|
|
278 |
|
|
279 |
public boolean isDirectory(){
|
|
280 |
return dirs;
|
|
281 |
}
|
|
282 |
|
|
283 |
private String getExtensionOfAFile(File file){
|
|
284 |
String name;
|
|
285 |
int dotPos;
|
|
286 |
name = file.getName();
|
|
287 |
dotPos = name.lastIndexOf(".");
|
|
288 |
if (dotPos < 1){
|
|
289 |
return "";
|
|
290 |
}
|
|
291 |
return name.substring(dotPos+1);
|
|
292 |
}
|
|
293 |
|
|
294 |
public File normalizeExtension(File file){
|
|
295 |
String ext = getExtensionOfAFile(file);
|
|
296 |
if (ext.equals("") || !(this.accept(file))){
|
|
297 |
return new File(file.getAbsolutePath() + "." + extensiones[0]);
|
|
298 |
}
|
|
299 |
return file;
|
|
300 |
}
|
|
301 |
|
|
302 |
public String getInfo(){
|
|
303 |
return this.info;
|
|
304 |
}
|
|
305 |
|
|
306 |
public void setInfo(String info){
|
|
307 |
this.info = info;
|
|
308 |
}
|
|
309 |
|
|
310 |
}
|