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