root / branches / gvSIG_19_ext3D_osgVP_2_2_0 / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / import3D / CreateNewLayerOSG.java @ 32530
History | View | Annotate | Download (5.29 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.gvsig3d.map3d.MapContext3D; |
34 |
import org.gvsig.gvsig3dgui.view.View3D; |
35 |
|
36 |
import com.hardcode.gdbms.driver.exceptions.OpenDriverException; |
37 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
38 |
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps; |
39 |
import com.iver.andami.PluginServices; |
40 |
import com.iver.andami.plugins.Extension; |
41 |
import com.iver.andami.ui.mdiManager.IWindow; |
42 |
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
43 |
|
44 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
45 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
46 |
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter; |
47 |
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend; |
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 CreateNewLayerOSG extends Extension { |
56 |
protected FLyrVect _layerOSG;
|
57 |
private File _file = null; |
58 |
|
59 |
/**
|
60 |
* Creating a new layer OSG editable, ready to insert OSG objects
|
61 |
*/
|
62 |
public void execute(String actionCommand) { |
63 |
if (actionCommand.equals("CREARCAPA")) { |
64 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices |
65 |
.getMDIManager().getActiveWindow(); |
66 |
|
67 |
if (activeWindow instanceof View3D) { |
68 |
PluginServices.getMDIManager().addCentredWindow(new CreateNewLayerOSGPanel());
|
69 |
} |
70 |
} |
71 |
|
72 |
if(actionCommand.equals("GUARDARCAPA")) { |
73 |
com.iver.andami.ui.mdiManager.IWindow activeWindow = PluginServices |
74 |
.getMDIManager().getActiveWindow(); |
75 |
|
76 |
if (activeWindow instanceof View3D) { |
77 |
if(_file == null) return; |
78 |
|
79 |
GvsigDriverOSG d = new GvsigDriverOSG();
|
80 |
try {
|
81 |
d.open(_file); |
82 |
} catch (OpenDriverException e2) {
|
83 |
// TODO Auto-generated catch block
|
84 |
e2.printStackTrace(); |
85 |
} |
86 |
try {
|
87 |
d.initialize(); |
88 |
} catch (ReadDriverException e1) {
|
89 |
// TODO Auto-generated catch block
|
90 |
e1.printStackTrace(); |
91 |
} |
92 |
|
93 |
VectorialAdapter adapter = new VectorialFileAdapter(_file);
|
94 |
adapter.setDriver(d); |
95 |
|
96 |
_layerOSG = new FLyrVect();
|
97 |
|
98 |
View3D vista = (View3D) PluginServices.getMDIManager().getActiveWindow(); |
99 |
IProjectView model = vista.getModel(); |
100 |
|
101 |
MapContext3D mapa = (MapContext3D) model.getMapContext(); |
102 |
_layerOSG.setName(_file.getName()); |
103 |
_layerOSG.setSource(adapter); |
104 |
try {
|
105 |
_layerOSG.setLegend((IVectorLegend) d.getDefaultLegend()); |
106 |
_layerOSG.setLabelingStrategy(d |
107 |
.getDefaultLabelingStrategy()); |
108 |
} catch (LegendLayerException e) {
|
109 |
// TODO Auto-generated catch block
|
110 |
e.printStackTrace(); |
111 |
} |
112 |
|
113 |
// add 3D properties, mainly to keep track of hooked state
|
114 |
Layer3DProps props3D = new Layer3DProps();
|
115 |
props3D.setType(Layer3DProps.layer3DOSG); |
116 |
props3D.setChooseType(false);
|
117 |
props3D.setLayer(_layerOSG); |
118 |
props3D.setNewLayerOSG(true);
|
119 |
_layerOSG.setProperty("3DLayerExtension", props3D);
|
120 |
_layerOSG.setProjection(mapa.getProjection()); |
121 |
mapa.getLayers().addLayer(_layerOSG); |
122 |
OSGCacheService osgCacheService = (OSGCacheService) props3D |
123 |
.getCacheService(); |
124 |
osgCacheService.startEditing(); |
125 |
} |
126 |
} |
127 |
} |
128 |
|
129 |
public void initialize() { |
130 |
PluginServices.getIconTheme().registerDefault( |
131 |
"create_new_layer_OSG",
|
132 |
this.getClass().getClassLoader().getResource(
|
133 |
"images/plugin_link.png"));
|
134 |
} |
135 |
|
136 |
public void setFile(File f) { |
137 |
_file = f; |
138 |
} |
139 |
|
140 |
public File getFile() { |
141 |
return _file;
|
142 |
} |
143 |
|
144 |
public boolean isEnabled() { |
145 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices |
146 |
.getMDIManager().getActiveWindow(); |
147 |
|
148 |
if (f == null) { |
149 |
return false; |
150 |
} |
151 |
|
152 |
// Only isEnable = true, where the view has a view3D.
|
153 |
if (f instanceof View3D) { |
154 |
return true; |
155 |
} |
156 |
return false; |
157 |
|
158 |
} |
159 |
|
160 |
public boolean isVisible() { |
161 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices |
162 |
.getMDIManager().getActiveWindow(); |
163 |
|
164 |
if (f == null) { |
165 |
return false; |
166 |
} |
167 |
|
168 |
// Only isVisible = true, where the view has a view3D.
|
169 |
if (f instanceof View3D) { |
170 |
return true; |
171 |
} |
172 |
return false; |
173 |
|
174 |
} |
175 |
|
176 |
} |