Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / Export.java @ 7304

History | View | Annotate | Download (6.01 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.project.documents.view.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
        /**
77
         * @see com.iver.andami.plugins.IExtension#isEnabled()
78
         */
79
        public boolean isEnabled() {
80
                View f = (View) PluginServices.getMDIManager().getActiveWindow();
81

    
82
                if (f == null) {
83
                        return false;
84
                }
85

    
86
                FLayers layers = f.getModel().getMapContext().getLayers();
87
                for (int i=0;i< layers.getLayersCount();i++) {
88
                        return layers.getLayer(i).isAvailable();
89
                }
90
                return false;
91
        }
92

    
93
        /**
94
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
95
         */
96
        public boolean isVisible() {
97
                com.iver.andami.ui.mdiManager.IWindow f = (com.iver.andami.ui.mdiManager.IWindow) PluginServices.getMDIManager()
98
                                                                                                                                                                                                  .getActiveWindow();
99

    
100
                if (f == null) {
101
                        return false;
102
                }
103

    
104
                return (f instanceof View);
105
        }
106

    
107
        /**
108
         * @see com.iver.andami.plugins.IExtension#initialize()
109
         */
110
        public void initialize() {
111
        }
112

    
113
        /**
114
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
115
         */
116
        public void execute(String actionCommand) {
117
                FileFilter pngFilter = new GenericFileFilter("png",
118
                                PluginServices.getText(this, "png"));
119
                String[] s={"jpg","jpeg"};
120
                FileFilter jpgFilter = new GenericFileFilter(s,
121
                                PluginServices.getText(this, "jpg"));
122
                FileFilter bmpFilter = new GenericFileFilter("bmp",
123
                                PluginServices.getText(this, "bmp"));
124
                
125
                JFileChooser jfc = new JFileChooser();
126
                jfc.addChoosableFileFilter(pngFilter);
127
                jfc.addChoosableFileFilter(jpgFilter);
128
                jfc.addChoosableFileFilter(bmpFilter);
129
                jfc.setFileFilter(pngFilter);
130
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
131
                        Image tempImage;
132

    
133
                        tempImage = ((View) PluginServices.getMDIManager().getActiveWindow()).getImage();
134

    
135
                        File f = jfc.getSelectedFile();
136

    
137
                        try {
138
                                JimiRasterImage jrf = Jimi.createRasterImage(tempImage.getSource());
139
                                String tempName = f.getName().toUpperCase().trim();
140
                                if (jfc.getFileFilter().equals(pngFilter)){
141
                                        System.out.println("pngFilter");
142
                                        if (!(tempName.length()>3) || (!(tempName.substring(tempName.length()-4,tempName.length()).equalsIgnoreCase(".png")))){
143
                                                f=new File(f.getPath()+".png");
144
                                        }
145
                                                FileOutputStream fout = new FileOutputStream(f);
146
                                                Jimi.putImage("image/png", jrf, fout);
147
                                                fout.close();
148
                                } else if (jfc.getFileFilter().equals(bmpFilter)){
149
                                        System.out.println("bmpFilter");
150
                                        if (!(tempName.length()>3) || (!(tempName.substring(tempName.length()-4,tempName.length()).equalsIgnoreCase(".bmp")))){
151
                                                f=new File(f.getPath()+".bmp");
152
                                        }
153
                                                FileOutputStream fout = new FileOutputStream(f);
154
                                                Jimi.putImage("image/bmp", jrf, fout);
155
                                                fout.close();
156
                                }else if (jfc.getFileFilter().equals(jpgFilter)){
157
                                        System.out.println("jpgFilter");
158
                                        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"))))){
159
                                                f=new File(f.getPath()+".jpg");
160
                                        }
161
                                                FileOutputStream fout = new FileOutputStream(f);
162
                                                Jimi.putImage("image/jpg", jrf, fout);
163
                                                fout.close();
164
                                        
165
                                }
166
                                /*if (tempName.endsWith(".JPG")) {
167
                                        
168
                                        FileOutputStream fout = new FileOutputStream(f);
169
                                        Jimi.putImage("image/jpg", jrf, fout);
170
                                        fout.close();
171
                                } else if (tempName.endsWith(".PNG")) {
172
                                        FileOutputStream fout = new FileOutputStream(f);
173
                                        Jimi.putImage("image/png", jrf, fout);
174
                                        fout.close();
175
                                } else if (tempName.endsWith(".BMP")) {
176
                                        FileOutputStream fout = new FileOutputStream(f);
177
                                        Jimi.putImage("image/bmp", jrf, fout);
178
                                        fout.close();
179
                                }
180
                                */
181
                        } catch (JimiException e) {
182
                                NotificationManager.addError("Error exportando la imagen", e);
183
                        } catch (FileNotFoundException e) {
184
                                NotificationManager.addError("No se encontr? el fichero", e);
185
                        } catch (IOException e) {
186
                                NotificationManager.addError("Error con el fichero", e);
187
                        }
188
                }
189
        }
190
}