Statistics
| Revision:

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

History | View | Annotate | Download (4.52 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
                FileFilter jpgFilter = new GenericFileFilter("jpg",
119
                                PluginServices.getText(this, "jpg"));
120
                FileFilter bmpFilter = new GenericFileFilter("bmp",
121
                                PluginServices.getText(this, "bmp"));
122
                JFileChooser jfc = new JFileChooser();
123
                jfc.addChoosableFileFilter(pngFilter);
124
                jfc.addChoosableFileFilter(jpgFilter);
125
                jfc.addChoosableFileFilter(bmpFilter);
126

    
127
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
128
                        Image tempImage;
129

    
130
                        tempImage = ((View) PluginServices.getMDIManager().getActiveView()).getImage();
131

    
132
                        File f = jfc.getSelectedFile();
133

    
134
                        try {
135
                                JimiRasterImage jrf = Jimi.createRasterImage(tempImage.getSource());
136
                                String tempName = f.getName().toUpperCase().trim();
137

    
138
                                if (tempName.endsWith(".JPG")) {
139
                                        FileOutputStream fout = new FileOutputStream(f);
140
                                        Jimi.putImage("image/jpg", jrf, fout);
141
                                        fout.close();
142
                                } else if (tempName.endsWith(".PNG")) {
143
                                        FileOutputStream fout = new FileOutputStream(f);
144
                                        Jimi.putImage("image/png", jrf, fout);
145
                                        fout.close();
146
                                } else if (tempName.endsWith(".BMP")) {
147
                                        FileOutputStream fout = new FileOutputStream(f);
148
                                        Jimi.putImage("image/bmp", jrf, fout);
149
                                        fout.close();
150
                                }
151
                        } catch (JimiException e) {
152
                                NotificationManager.addError("Error exportando la imagen", e);
153
                        } catch (FileNotFoundException e) {
154
                                NotificationManager.addError("No se encontr? el fichero", e);
155
                        } catch (IOException e) {
156
                                NotificationManager.addError("Error con el fichero", e);
157
                        }
158
                }
159
        }
160
}