root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / Export.java @ 9212
History | View | Annotate | Download (6.16 KB)
1 | 312 | 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 | 1103 | fjp | /* 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 | 312 | fernando | package com.iver.cit.gvsig; |
48 | |||
49 | 596 | fernando | 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 | 5005 | jorpiell | import com.iver.andami.PluginServices; |
60 | import com.iver.andami.messages.NotificationManager; |
||
61 | import com.iver.andami.plugins.Extension; |
||
62 | 6778 | jmvivo | import com.iver.cit.gvsig.fmap.layers.FLayers; |
63 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
64 | 5005 | jorpiell | 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 | 596 | fernando | |
69 | 5005 | jorpiell | |
70 | 312 | fernando | /**
|
71 | 1219 | vcaballero | * Extensi?n para exportar en algunos formatos raster la vista actual.
|
72 | 312 | fernando | *
|
73 | * @author Fernando Gonz?lez Cort?s
|
||
74 | */
|
||
75 | 5005 | jorpiell | public class Export extends Extension { |
76 | 7385 | jaume | private String lastPath = null; |
77 | |||
78 | 596 | fernando | /**
|
79 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
80 | 596 | fernando | */
|
81 | public boolean isEnabled() { |
||
82 | 6880 | cesar | View f = (View) PluginServices.getMDIManager().getActiveWindow(); |
83 | 312 | fernando | |
84 | 596 | fernando | if (f == null) { |
85 | return false; |
||
86 | } |
||
87 | 312 | fernando | |
88 | 6778 | jmvivo | 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 | 596 | fernando | } |
94 | 312 | fernando | |
95 | 596 | fernando | /**
|
96 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
97 | 596 | fernando | */
|
98 | public boolean isVisible() { |
||
99 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = (com.iver.andami.ui.mdiManager.IWindow) PluginServices.getMDIManager() |
100 | 6880 | cesar | .getActiveWindow(); |
101 | 312 | fernando | |
102 | 596 | fernando | if (f == null) { |
103 | return false; |
||
104 | } |
||
105 | 312 | fernando | |
106 | 5900 | jorpiell | return (f instanceof View); |
107 | 596 | fernando | } |
108 | 312 | fernando | |
109 | 596 | fernando | /**
|
110 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
111 | 596 | fernando | */
|
112 | 5005 | jorpiell | public void initialize() { |
113 | 596 | fernando | } |
114 | 312 | fernando | |
115 | 596 | fernando | /**
|
116 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
117 | 596 | fernando | */
|
118 | public void execute(String actionCommand) { |
||
119 | FileFilter pngFilter = new GenericFileFilter("png", |
||
120 | PluginServices.getText(this, "png")); |
||
121 | 1319 | vcaballero | String[] s={"jpg","jpeg"}; |
122 | FileFilter jpgFilter = new GenericFileFilter(s, |
||
123 | 596 | fernando | PluginServices.getText(this, "jpg")); |
124 | FileFilter bmpFilter = new GenericFileFilter("bmp", |
||
125 | PluginServices.getText(this, "bmp")); |
||
126 | 7385 | jaume | |
127 | JFileChooser jfc = new JFileChooser(lastPath); |
||
128 | 596 | fernando | jfc.addChoosableFileFilter(pngFilter); |
129 | jfc.addChoosableFileFilter(jpgFilter); |
||
130 | jfc.addChoosableFileFilter(bmpFilter); |
||
131 | 1319 | vcaballero | jfc.setFileFilter(pngFilter); |
132 | 596 | fernando | if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
133 | Image tempImage;
|
||
134 | 312 | fernando | |
135 | 6880 | cesar | tempImage = ((View) PluginServices.getMDIManager().getActiveWindow()).getImage();
|
136 | 312 | fernando | |
137 | 596 | fernando | File f = jfc.getSelectedFile();
|
138 | 312 | fernando | |
139 | 596 | fernando | try {
|
140 | JimiRasterImage jrf = Jimi.createRasterImage(tempImage.getSource()); |
||
141 | String tempName = f.getName().toUpperCase().trim();
|
||
142 | 1319 | vcaballero | 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 | 7385 | jaume | |
167 | 1319 | vcaballero | } |
168 | 7385 | jaume | String filePath = f.getAbsolutePath();
|
169 | lastPath = filePath.substring(0, filePath.lastIndexOf(File.separatorChar)); |
||
170 | 1319 | vcaballero | /*if (tempName.endsWith(".JPG")) {
|
171 | 7385 | jaume | |
172 | 596 | fernando | FileOutputStream fout = new FileOutputStream(f);
|
173 | Jimi.putImage("image/jpg", jrf, fout);
|
||
174 | fout.close();
|
||
175 | } else if (tempName.endsWith(".PNG")) {
|
||
176 | FileOutputStream fout = new FileOutputStream(f);
|
||
177 | Jimi.putImage("image/png", jrf, fout);
|
||
178 | fout.close();
|
||
179 | } else if (tempName.endsWith(".BMP")) {
|
||
180 | FileOutputStream fout = new FileOutputStream(f);
|
||
181 | Jimi.putImage("image/bmp", jrf, fout);
|
||
182 | fout.close();
|
||
183 | }
|
||
184 | 1319 | vcaballero | */
|
185 | 596 | fernando | } catch (JimiException e) {
|
186 | NotificationManager.addError("Error exportando la imagen", e);
|
||
187 | } catch (FileNotFoundException e) { |
||
188 | NotificationManager.addError("No se encontr? el fichero", e);
|
||
189 | } catch (IOException e) { |
||
190 | NotificationManager.addError("Error con el fichero", e);
|
||
191 | } |
||
192 | } |
||
193 | } |
||
194 | 312 | fernando | } |