svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / Export.java @ 8745
History | View | Annotate | Download (6.14 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; |
48 |
|
49 |
import java.awt.Component; |
50 |
import java.awt.Image; |
51 |
import java.io.File; |
52 |
import java.io.FileNotFoundException; |
53 |
import java.io.FileOutputStream; |
54 |
import java.io.IOException; |
55 |
|
56 |
import javax.swing.JFileChooser; |
57 |
import javax.swing.filechooser.FileFilter; |
58 |
|
59 |
import com.iver.andami.PluginServices; |
60 |
import com.iver.andami.messages.NotificationManager; |
61 |
import com.iver.andami.plugins.Extension; |
62 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
63 |
import com.iver.cit.gvsig.gui.View; |
64 |
import com.iver.utiles.GenericFileFilter; |
65 |
import com.sun.jimi.core.Jimi; |
66 |
import com.sun.jimi.core.JimiException; |
67 |
import com.sun.jimi.core.raster.JimiRasterImage; |
68 |
|
69 |
|
70 |
/**
|
71 |
* Extensi?n para exportar en algunos formatos raster la vista actual.
|
72 |
*
|
73 |
* @author Fernando Gonz?lez Cort?s
|
74 |
*/
|
75 |
public class Export extends Extension { |
76 |
private String lastPath = null; |
77 |
|
78 |
/**
|
79 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
80 |
*/
|
81 |
public boolean isEnabled() { |
82 |
View f = (View) PluginServices.getMDIManager().getActiveWindow(); |
83 |
|
84 |
if (f == null) { |
85 |
return false; |
86 |
} |
87 |
|
88 |
FLayers layers = f.getModel().getMapContext().getLayers(); |
89 |
for (int i=0;i< layers.getLayersCount();i++) { |
90 |
return layers.getLayer(i).isAvailable();
|
91 |
} |
92 |
return false; |
93 |
} |
94 |
|
95 |
/**
|
96 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
97 |
*/
|
98 |
public boolean isVisible() { |
99 |
com.iver.andami.ui.mdiManager.IWindow f = (com.iver.andami.ui.mdiManager.IWindow) PluginServices.getMDIManager() |
100 |
.getActiveWindow(); |
101 |
|
102 |
if (f == null) { |
103 |
return false; |
104 |
} |
105 |
|
106 |
return (f instanceof View); |
107 |
} |
108 |
|
109 |
/**
|
110 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
111 |
*/
|
112 |
public void initialize() { |
113 |
} |
114 |
|
115 |
/**
|
116 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
117 |
*/
|
118 |
public void execute(String actionCommand) { |
119 |
FileFilter pngFilter = new GenericFileFilter("png", |
120 |
PluginServices.getText(this, "png")); |
121 |
String[] s={"jpg","jpeg"}; |
122 |
FileFilter jpgFilter = new GenericFileFilter(s, |
123 |
PluginServices.getText(this, "jpg")); |
124 |
FileFilter bmpFilter = new GenericFileFilter("bmp", |
125 |
PluginServices.getText(this, "bmp")); |
126 |
|
127 |
JFileChooser jfc = new JFileChooser(lastPath); |
128 |
jfc.addChoosableFileFilter(pngFilter); |
129 |
jfc.addChoosableFileFilter(jpgFilter); |
130 |
jfc.addChoosableFileFilter(bmpFilter); |
131 |
jfc.setFileFilter(pngFilter); |
132 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
133 |
Image tempImage;
|
134 |
|
135 |
tempImage = ((View) PluginServices.getMDIManager().getActiveWindow()).getImage();
|
136 |
|
137 |
File f = jfc.getSelectedFile();
|
138 |
|
139 |
try {
|
140 |
JimiRasterImage jrf = Jimi.createRasterImage(tempImage.getSource()); |
141 |
String tempName = f.getName().toUpperCase().trim();
|
142 |
if (jfc.getFileFilter().equals(pngFilter)){
|
143 |
System.out.println("pngFilter"); |
144 |
if (!(tempName.length()>3) || (!(tempName.substring(tempName.length()-4,tempName.length()).equalsIgnoreCase(".png")))){ |
145 |
f=new File(f.getPath()+".png"); |
146 |
} |
147 |
FileOutputStream fout = new FileOutputStream(f); |
148 |
Jimi.putImage("image/png", jrf, fout);
|
149 |
fout.close(); |
150 |
} else if (jfc.getFileFilter().equals(bmpFilter)){ |
151 |
System.out.println("bmpFilter"); |
152 |
if (!(tempName.length()>3) || (!(tempName.substring(tempName.length()-4,tempName.length()).equalsIgnoreCase(".bmp")))){ |
153 |
f=new File(f.getPath()+".bmp"); |
154 |
} |
155 |
FileOutputStream fout = new FileOutputStream(f); |
156 |
Jimi.putImage("image/bmp", jrf, fout);
|
157 |
fout.close(); |
158 |
}else if (jfc.getFileFilter().equals(jpgFilter)){ |
159 |
System.out.println("jpgFilter"); |
160 |
if (!(tempName.length()>3) || ((tempName.length()>3 && !(tempName.substring(tempName.length()-4,tempName.length()).equalsIgnoreCase(".jpg")) || (tempName.length()>4 &&tempName.substring(tempName.length()-5,tempName.length()).equalsIgnoreCase(".jpeg"))))){ |
161 |
f=new File(f.getPath()+".jpg"); |
162 |
} |
163 |
FileOutputStream fout = new FileOutputStream(f); |
164 |
Jimi.putImage("image/jpg", jrf, fout);
|
165 |
fout.close(); |
166 |
|
167 |
} |
168 |
|
169 |
String filePath = f.getAbsolutePath();
|
170 |
lastPath = filePath.substring(0, filePath.lastIndexOf(File.separatorChar)); |
171 |
|
172 |
/*if (tempName.endsWith(".JPG")) {
|
173 |
|
174 |
FileOutputStream fout = new FileOutputStream(f);
|
175 |
Jimi.putImage("image/jpg", jrf, fout);
|
176 |
fout.close();
|
177 |
} else if (tempName.endsWith(".PNG")) {
|
178 |
FileOutputStream fout = new FileOutputStream(f);
|
179 |
Jimi.putImage("image/png", jrf, fout);
|
180 |
fout.close();
|
181 |
} else if (tempName.endsWith(".BMP")) {
|
182 |
FileOutputStream fout = new FileOutputStream(f);
|
183 |
Jimi.putImage("image/bmp", jrf, fout);
|
184 |
fout.close();
|
185 |
}
|
186 |
*/
|
187 |
} catch (JimiException e) {
|
188 |
NotificationManager.addError("Error exportando la imagen", e);
|
189 |
} catch (FileNotFoundException e) { |
190 |
NotificationManager.addError("No se encontr? el fichero", e);
|
191 |
} catch (IOException e) { |
192 |
NotificationManager.addError("Error con el fichero", e);
|
193 |
} |
194 |
} |
195 |
} |
196 |
} |