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