gvsig-3d / 1.10 / trunk / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / import3D / SaveLayerOSG.java @ 96
History | View | Annotate | Download (5.15 KB)
1 | 5 | jzarzoso | /* 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 | |||
70 | View3D vista = (View3D) PluginServices.getMDIManager() |
||
71 | .getActiveWindow(); |
||
72 | IProjectView model = vista.getModel(); |
||
73 | MapContext mapContext = model.getMapContext(); |
||
74 | FLayers layers = mapContext.getLayers(); |
||
75 | FLayer[] actives = layers.getActives();
|
||
76 | OSGCacheService osgCache = null;
|
||
77 | if (actives.length == 1 |
||
78 | && Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
|
||
79 | osgCache = (OSGCacheService) Layer3DProps.getLayer3DProps( |
||
80 | actives[0]).getCacheService();
|
||
81 | |||
82 | } |
||
83 | try {
|
||
84 | Group node = osgCache.getLayerNode();
|
||
85 | File f = ((GvsigDriverOSG) ((FLyrVect) actives[0]).getSource() |
||
86 | .getDriver()).getFile(); |
||
87 | osgDB.writeNodeFile(node, f.getAbsolutePath()); |
||
88 | Layer3DProps.getLayer3DProps( |
||
89 | actives[0]).setNewLayerOSG(false); |
||
90 | |||
91 | JOptionPane.showMessageDialog(null, |
||
92 | PluginServices.getText( |
||
93 | this, "saved_layer_ok")); |
||
94 | |||
95 | // ((GvsigDriverOSG
|
||
96 | // )((FLyrVect)actives[0]).getSource().getDriver()).open(f);
|
||
97 | // /actives[0].getXMLEntity().putProperty("file",f.getAbsolutePath());
|
||
98 | |||
99 | // setProperty("file", f.getAbsolutePath());
|
||
100 | } catch (SaveNodeException e) {
|
||
101 | JOptionPane.showMessageDialog(null, |
||
102 | PluginServices.getText( |
||
103 | this, "saved_layer_error")); |
||
104 | e.printStackTrace(); |
||
105 | } catch (NodeException e) {
|
||
106 | JOptionPane.showMessageDialog(null, |
||
107 | PluginServices.getText( |
||
108 | this, "saved_layer_error")); |
||
109 | e.printStackTrace(); |
||
110 | |||
111 | } |
||
112 | // screen snapshop.
|
||
113 | }// if activeWindow.
|
||
114 | }// If aprove option.
|
||
115 | |||
116 | // }
|
||
117 | // }
|
||
118 | |||
119 | public void initialize() { |
||
120 | PluginServices.getIconTheme().registerDefault( |
||
121 | "save_layer_OSG",
|
||
122 | this.getClass().getClassLoader().getResource(
|
||
123 | "images/plugin_edit.png"));
|
||
124 | } |
||
125 | |||
126 | /**
|
||
127 | * Enable options. Enabled when a layer is selected and this type layer is
|
||
128 | * layer3DOSG
|
||
129 | */
|
||
130 | public boolean isEnabled() { |
||
131 | |||
132 | View3D vista = (View3D) PluginServices.getMDIManager() |
||
133 | .getActiveWindow(); |
||
134 | IProjectView model = vista.getModel(); |
||
135 | MapContext mapContext = model.getMapContext(); |
||
136 | FLayers layers = mapContext.getLayers(); |
||
137 | FLayer[] actives = layers.getActives();
|
||
138 | if (actives.length == 1 |
||
139 | && Layer3DProps.getLayer3DProps(actives[0]) != null |
||
140 | && Layer3DProps.getLayer3DProps(actives[0]).getType() == Layer3DProps.layer3DOSG) {
|
||
141 | |||
142 | return true; |
||
143 | } else
|
||
144 | return false; |
||
145 | } |
||
146 | |||
147 | public boolean isVisible() { |
||
148 | com.iver.andami.ui.mdiManager.IWindow f = PluginServices |
||
149 | .getMDIManager().getActiveWindow(); |
||
150 | |||
151 | if (f == null) { |
||
152 | return false; |
||
153 | } |
||
154 | // Only isVisible = true, where the view has a view3D.
|
||
155 | if (f instanceof View3D) { |
||
156 | return true; |
||
157 | } |
||
158 | return false; |
||
159 | } |
||
160 | |||
161 | } |