Statistics
| Revision:

svn-gvsig-desktop / branches / gvSIG_19_ext3D_osgVP_2_2_0 / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / import3D / SaveLayerOSG.java @ 32462

History | View | Annotate | Download (6.42 KB)

1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19

    
20
package org.gvsig.gvsig3dgui.import3D;
21

    
22
import java.awt.Component;
23
import java.io.File;
24
import java.util.Hashtable;
25
import java.util.Iterator;
26

    
27
import javax.swing.JFileChooser;
28
import javax.swing.JOptionPane;
29
import javax.swing.filechooser.FileFilter;
30

    
31
import org.gvsig.gvsig3d.cacheservices.OSGCacheService;
32
import org.gvsig.gvsig3d.drivers.GvsigDriverOSG;
33
import org.gvsig.gvsig3dgui.view.View3D;
34
import org.gvsig.osgvp.core.osg.Group;
35
import org.gvsig.osgvp.core.osgdb.osgDB;
36
import org.gvsig.osgvp.exceptions.node.NodeException;
37
import org.gvsig.osgvp.exceptions.node.SaveNodeException;
38

    
39
import com.hardcode.gdbms.driver.exceptions.OpenDriverException;
40
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
41
import com.iver.andami.PluginServices;
42
import com.iver.andami.plugins.Extension;
43
import com.iver.cit.gvsig.fmap.MapContext;
44
import com.iver.cit.gvsig.fmap.layers.FLayer;
45
import com.iver.cit.gvsig.fmap.layers.FLayers;
46
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
47
import com.iver.cit.gvsig.fmap.layers.XMLException;
48
import com.iver.cit.gvsig.project.documents.view.IProjectView;
49

    
50
/**
51
 * @author �ngel Fraile Gri��n e-mail: angel.fraile@iver.es
52
 * @since 1.1
53
 * 
54
 */
55
public class SaveLayerOSG extends Extension {
56

    
57
        private Hashtable _iveExtensionsSupported = null;
58
        private Hashtable _osgExtensionsSupported = null;
59
        private String _lastPath = null;
60

    
61
        /**
62
         * Creating save panel options
63
         */
64
        public void execute(String actionCommand) {
65
                if (actionCommand.equals("SALVARCAPA")) {
66
                        com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices
67
                                        .getMDIManager().getActiveWindow();
68

    
69
                        // JFileChooser jfc = new JFileChooser(_lastPath);
70
                        // jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());
71
                        // _iveExtensionsSupported = new Hashtable();
72
                        // _osgExtensionsSupported = new Hashtable();
73
                        // _iveExtensionsSupported.put("ive", new MyFileFilter("ive",
74
                        // PluginServices.getText(this, "Ficheros *.ive"), "ive"));
75
                        // _osgExtensionsSupported.put("osg", new MyFileFilter("osg",
76
                        // PluginServices.getText(this, "Ficheros *.osg"), "osg"));
77
                        //
78
                        // Iterator iter = _osgExtensionsSupported.values().iterator();
79
                        // while (iter.hasNext()) {
80
                        // jfc.addChoosableFileFilter((FileFilter) iter.next());
81
                        // }
82
                        //
83
                        // iter = _iveExtensionsSupported.values().iterator();
84
                        // while (iter.hasNext()) {
85
                        // jfc.addChoosableFileFilter((FileFilter) iter.next());
86
                        // }
87
                        //
88
                        // if (jfc.showSaveDialog((Component) PluginServices.getMainFrame())
89
                        // == JFileChooser.APPROVE_OPTION) {
90
                        // File f = jfc.getSelectedFile();
91
                        // if (f.exists()){//file exists in the directory.
92
                        // int resp = JOptionPane.showConfirmDialog(
93
                        // (Component) PluginServices.getMainFrame(),
94
                        // PluginServices.getText(this,
95
                        // "fichero_ya_existe_seguro_desea_guardarlo")+
96
                        // "\n"+
97
                        // f.getAbsolutePath(),
98
                        // PluginServices.getText(this,"guardar"),
99
                        // JOptionPane.YES_NO_OPTION);
100
                        // if (resp != JOptionPane.YES_OPTION) {//cancel pressed.
101
                        // return;
102
                        // }
103
                        // }//if exits.
104
                        // if (activeWindow instanceof View3D ) {
105
                        //
106
                        // MyFileFilter filter = (MyFileFilter)jfc.getFileFilter();// ive,
107
                        // osg
108
                        // f = filter.normalizeExtension(f);
109

    
110
                        View3D vista = (View3D) PluginServices.getMDIManager()
111
                                        .getActiveWindow();
112
                        IProjectView model = vista.getModel();
113
                        MapContext mapContext = model.getMapContext();
114
                        FLayers layers = mapContext.getLayers();
115
                        FLayer[] actives = layers.getActives();
116
                        OSGCacheService osgCache = null;
117
                        if (actives.length == 1
118
                                        && Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
119
                                osgCache = (OSGCacheService) Layer3DProps.getLayer3DProps(
120
                                                actives[0]).getCacheService();
121

    
122
                        }
123
                        try {
124
                                Group node = osgCache.getLayerNode();
125
                                File f = ((GvsigDriverOSG) ((FLyrVect) actives[0]).getSource()
126
                                                .getDriver()).getFile();
127
                                osgDB.writeNodeFile(node, f.getAbsolutePath());
128
                                
129
                                // ((GvsigDriverOSG
130
                                // )((FLyrVect)actives[0]).getSource().getDriver()).open(f);
131
                                // /actives[0].getXMLEntity().putProperty("file",f.getAbsolutePath());
132

    
133
                                // setProperty("file", f.getAbsolutePath());
134
                        } catch (SaveNodeException e) {
135
                                // TODO Auto-generated catch block
136
                                e.printStackTrace();
137
                        } catch (NodeException e) {
138
                                // TODO Auto-generated catch block
139
                                e.printStackTrace();
140

    
141
                        }
142
                        // screen snapshop.
143
                }// if activeWindow.
144
        }// If aprove option.
145

    
146
        // }
147
        // }
148

    
149
        public void initialize() {
150
                PluginServices.getIconTheme().registerDefault(
151
                                "save_layer_OSG",
152
                                this.getClass().getClassLoader().getResource(
153
                                                "images/plugin_edit.png"));
154
        }
155

    
156
        /**
157
         * Enable options. Enabled when a layer is selected and this type layer is
158
         * layer3DOSG
159
         */
160
        public boolean isEnabled() {
161

    
162
                View3D vista = (View3D) PluginServices.getMDIManager()
163
                                .getActiveWindow();
164
                IProjectView model = vista.getModel();
165
                MapContext mapContext = model.getMapContext();
166
                FLayers layers = mapContext.getLayers();
167
                FLayer[] actives = layers.getActives();
168
                if (actives.length == 1
169
                                && Layer3DProps.getLayer3DProps(actives[0]) != null
170
                                && Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
171

    
172
                        return true;
173
                } else
174
                        return false;
175
        }
176

    
177
        public boolean isVisible() {
178
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices
179
                                .getMDIManager().getActiveWindow();
180

    
181
                if (f == null) {
182
                        return false;
183
                }
184
                // Only isVisible = true, where the view has a view3D.
185
                if (f instanceof View3D) {
186
                        return true;
187
                }
188
                return false;
189
        }
190

    
191
}