Statistics
| Revision:

root / trunk / extensions / ext3Dgui / src / com / iver / ai2 / gvsig3dgui / view / Export.java @ 20900

History | View | Annotate | Download (7.6 KB)

1
/*
2
 * Created on 1-dic-2007
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.ai2.gvsig3dgui.view;
48

    
49
import java.awt.Component;
50
import java.io.File;
51
import java.util.Hashtable;
52
import java.util.Iterator;
53

    
54
import javax.swing.JFileChooser;
55
import javax.swing.JOptionPane;
56
import javax.swing.filechooser.FileFilter;
57

    
58
import org.gvsig.osgvp.viewer.IViewerContainer;
59

    
60
import com.iver.andami.PluginServices;
61
import com.iver.andami.plugins.Extension;
62
import com.iver.cit.gvsig.fmap.layers.FLayers;
63

    
64

    
65

    
66
/**
67
 * Extensi?n para exportar en algunos formatos raster la vista3D actual.
68
 *
69
 * @author ?ngel Fraile.
70
 */
71
public class Export extends Extension {
72
        private String lastPath = null;
73
        private String path = null;
74
        private Hashtable cmsExtensionsSupported = null;
75
        private Hashtable jimiExtensionsSupported = null;
76
        private IViewerContainer m_canvas3d = null;
77
        private String arg0;
78

    
79
        /**
80
         * @see com.iver.andami.plugins.IExtension#isEnabled()
81
         */
82
        public boolean isEnabled() {
83
                
84
                View3D f = (View3D) PluginServices.getMDIManager().getActiveWindow();
85

    
86
                if (f == null) {//Si no es una vista3D.
87
                        return false;
88
                }
89
                //es una vista 3D, miro sus capas.
90
                FLayers layers = f.getModel().getMapContext().getLayers();
91
                for (int i=0;i< layers.getLayersCount();i++) {
92
                        return layers.getLayer(i).isAvailable();
93
                }
94
                return false;
95

    
96
        }
97

    
98
        /**
99
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
100
         */
101
        public boolean isVisible() {
102
                com.iver.andami.ui.mdiManager.IWindow f = (com.iver.andami.ui.mdiManager.IWindow) 
103
                PluginServices.getMDIManager().getActiveWindow();
104

    
105
                if (f == null) {
106
                        return false;
107
                }
108

    
109
                return (f instanceof View3D);
110
        }
111

    
112
        /**
113
         * @see com.iver.andami.plugins.IExtension#initialize()
114
         */
115
        public void initialize() {
116
        }
117

    
118
        /* (non-Javadoc)
119
         * @see com.iver.andami.plugins.Extension#postInitialize()
120
         */
121
        public void postInitialize() {
122
                cmsExtensionsSupported = new Hashtable();
123
                jimiExtensionsSupported = new Hashtable();
124
                jimiExtensionsSupported.put("png",new MyFileFilter("png",
125
                                PluginServices.getText(this, "png"), "jimi"));
126
                cmsExtensionsSupported.put("jpg", new MyFileFilter("jpg",
127
                                PluginServices.getText(this, "jpg"), "cms"));                
128
//                jimiExtensionsSupported.put("bmp",new MyFileFilter("bmp",
129
//                                PluginServices.getText(this, "bmp"), "jimi"));
130

    
131

    
132
        }
133

    
134
        /**
135
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
136
         */
137
        public void execute(String actionCommand) {
138
                JFileChooser jfc = new JFileChooser(lastPath);
139
                jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());
140
                Iterator iter;
141
                
142
                iter = cmsExtensionsSupported.values().iterator();
143
                while (iter.hasNext()){
144
                        jfc.addChoosableFileFilter((FileFilter)iter.next());
145
                }
146

    
147
                iter = jimiExtensionsSupported.values().iterator();
148
                while (iter.hasNext()){
149
                        jfc.addChoosableFileFilter((FileFilter)iter.next());
150
                }
151

    
152
                jfc.setFileFilter((FileFilter)jimiExtensionsSupported.get("png"));
153
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())==JFileChooser.APPROVE_OPTION){
154
                        
155
                        com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices
156
                        .getMDIManager().getActiveWindow();
157
                        File f = jfc.getSelectedFile();
158
                                if (f.exists()){//file exists in the directory.
159
                                        int resp = JOptionPane.showConfirmDialog(
160
                                                        (Component) PluginServices.getMainFrame(),
161
                                                        PluginServices.getText(this,
162
                                                                        "fichero_ya_existe_seguro_desea_guardarlo")+
163
                                                                        "\n"+
164
                                                                        f.getAbsolutePath(),
165
                                                        PluginServices.getText(this,"guardar"), JOptionPane.YES_NO_OPTION);
166
                                        if (resp != JOptionPane.YES_OPTION) {//cancel pressed.
167
                                                return;
168
                                        }
169
                                }//if exits.
170
                                if (activeWindow instanceof View3D ) {
171
                                        View3D view3D;
172
                                        view3D = (View3D) activeWindow;
173
                                        MyFileFilter filter = (MyFileFilter)jfc.getFileFilter();// png, jpg
174
                                        f = filter.normalizeExtension(f);//"name" + "." + "png", "name" + "." + "jpg".
175
                                        view3D.getCanvas3d().getOSGViewer().takeScreenshot(f.getAbsolutePath());//screen snapshop.
176
                        }//if activeWindow.
177
                }//If aprove option.
178
        }//void execute.
179
}//end class.
180

    
181

    
182
/**
183
*
184
* @version 14/08/2007
185
* @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
186
*
187
*/
188
class MyFileFilter extends FileFilter{
189

    
190
        private String[] extensiones=new String[1];
191
        private String description;
192
        private boolean dirs = true;
193
        private String info= null;
194

    
195
        public MyFileFilter(String[] ext, String desc) {
196
                extensiones = ext;
197
                description = desc;
198
        }
199

    
200
        public MyFileFilter(String[] ext, String desc,String info) {
201
                extensiones = ext;
202
                description = desc;
203
                this.info = info;
204
        }
205

    
206
        public MyFileFilter(String ext, String desc) {
207
                extensiones[0] = ext;
208
                description = desc;
209
        }
210

    
211
        public MyFileFilter(String ext, String desc,String info) {
212
                extensiones[0] = ext;
213
                description = desc;
214
                this.info = info;
215
        }
216

    
217
        public MyFileFilter(String ext, String desc, boolean dirs) {
218
                extensiones[0] = ext;
219
                description = desc;
220
                this.dirs = dirs;
221
        }
222

    
223
        public MyFileFilter(String ext, String desc, boolean dirs,String info) {
224
                extensiones[0] = ext;
225
                description = desc;
226
                this.dirs = dirs;
227
                this.info = info;
228
        }
229

    
230
        public boolean accept(File f) {
231
                if (f.isDirectory()) {
232
                        if (dirs) {
233
                                return true;
234
                        } else {
235
                                return false;
236
                        }
237
                }
238
                for (int i=0;i<extensiones.length;i++){
239
                        if (extensiones[i].equals("")){
240
                                continue;
241
                        }
242
                        if (getExtensionOfAFile(f).equalsIgnoreCase(extensiones[i])){
243
                                return true;
244
                        }
245
                }
246

    
247
                return false;
248
        }
249

    
250
        /**
251
         * @see javax.swing.filechooser.FileFilter#getDescription()
252
         */
253
        public String getDescription() {
254
                return description;
255
        }
256

    
257
        public String[] getExtensions() {
258
                return extensiones;
259
        }
260

    
261
        public boolean isDirectory(){
262
                return dirs;
263
        }
264

    
265
        private String getExtensionOfAFile(File file){
266
                String name;
267
                int dotPos;
268
                name = file.getName();
269
                dotPos = name.lastIndexOf(".");
270
                if (dotPos < 1){
271
                        return "";
272
                }
273
                return name.substring(dotPos+1);
274
        }
275

    
276
        public File normalizeExtension(File file){
277
                String ext = getExtensionOfAFile(file);
278
                if (ext.equals("") || !(this.accept(file))){
279
                        return new File(file.getAbsolutePath() + "." + extensiones[0]);
280
                }
281
                return file;
282
        }
283

    
284
        public String getInfo(){
285
                return this.info;
286
        }
287

    
288
        public void setInfo(String info){
289
                this.info = info;
290
        }
291

    
292
}