gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.app / org.gvsig.view3d.app.common / src / main / java / org / gvsig / view3d / app / mainplugin / View3DExtension.java @ 494
History | View | Annotate | Download (6.86 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright ? 2007-2015 gvSIG Association
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.view3d.app.mainplugin; |
26 |
|
27 |
import org.gvsig.andami.IconThemeHelper; |
28 |
import org.gvsig.andami.plugins.Extension; |
29 |
import org.gvsig.app.ApplicationLocator; |
30 |
import org.gvsig.app.ApplicationManager; |
31 |
import org.gvsig.app.project.documents.view.ViewDocument; |
32 |
import org.gvsig.app.project.documents.view.gui.IView; |
33 |
import org.gvsig.app.project.documents.view.legend.gui.ThemeManagerWindow; |
34 |
import org.gvsig.fmap.mapcontext.MapContext; |
35 |
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
37 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
38 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
39 |
import org.gvsig.propertypage.PropertiesPageManager; |
40 |
import org.gvsig.tools.ToolsLocator; |
41 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
42 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
43 |
import org.gvsig.tools.observer.Notification; |
44 |
import org.gvsig.tools.observer.Observable; |
45 |
import org.gvsig.tools.observer.Observer; |
46 |
import org.gvsig.view3d.app.properties.LayerProperties3DThemeManagerPage; |
47 |
import org.gvsig.view3d.app.properties.RasterLayerProperties3DPanel; |
48 |
import org.gvsig.view3d.app.properties.ViewProperties3DPageFactory; |
49 |
import org.gvsig.view3d.swing.api.MapControl3D; |
50 |
import org.gvsig.view3d.swing.api.View3DPanel; |
51 |
import org.gvsig.view3d.swing.api.View3DSwingLocator; |
52 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
53 |
import org.gvsig.view3d.swing.api.View3DSwingManager.TYPE; |
54 |
|
55 |
/**
|
56 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
57 |
*
|
58 |
*/
|
59 |
public class View3DExtension extends Extension implements Observer { |
60 |
|
61 |
public void initialize() { |
62 |
// Register vectorial layer 3D properties panel
|
63 |
ThemeManagerWindow.addPage(LayerProperties3DThemeManagerPage.class); |
64 |
ThemeManagerWindow.setTabEnabledForLayer( |
65 |
LayerProperties3DThemeManagerPage.class, FLyrVect.class, true);
|
66 |
|
67 |
// Regsiter raster layer 3D properties panel
|
68 |
ExtensionPointManager extensionPoints = |
69 |
ToolsLocator.getExtensionPointManager(); |
70 |
ExtensionPoint point = extensionPoints.get("RasterSEPropertiesDialog");
|
71 |
if (point != null) { |
72 |
point.append("3D", "3D Raster properties panel", |
73 |
RasterLayerProperties3DPanel.class); |
74 |
} |
75 |
|
76 |
// Regsiter view properties
|
77 |
PropertiesPageManager manager = MapControlLocator.getPropertiesPageManager(); |
78 |
manager.registerFactory(new ViewProperties3DPageFactory());
|
79 |
|
80 |
registerIcons(); |
81 |
} |
82 |
|
83 |
private void registerIcons() { |
84 |
IconThemeHelper.registerIcon("view3d", "sphere-view-3d", this); |
85 |
IconThemeHelper.registerIcon("view3d", "flat-view-3d", this); |
86 |
} |
87 |
|
88 |
public void execute(String actionCommand) { |
89 |
|
90 |
TYPE type = getType(actionCommand); |
91 |
|
92 |
IView view = getActiveView(); |
93 |
|
94 |
if (view != null && type != null) { |
95 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
96 |
|
97 |
MapControl3D mapControl3D = |
98 |
manager.getMapControl3D( |
99 |
(ExtendedPropertiesSupport) view.getViewDocument(), type); |
100 |
if (mapControl3D == null || mapControl3D.getType() != type) { |
101 |
View3DPanel view3DPanel = |
102 |
manager.createView3DPanel(view.getMapControl() |
103 |
.getMapContext(), type, |
104 |
(ExtendedPropertiesSupport) view.getViewDocument()); |
105 |
view3DPanel.getMapControl3D().addObserver(this);
|
106 |
view3DPanel.show(); |
107 |
} |
108 |
} |
109 |
} |
110 |
|
111 |
private TYPE getType(String actionCommand) { |
112 |
if ("sphere-view-3d".equals(actionCommand)) { |
113 |
return TYPE.SPHERE;
|
114 |
} else if ("flat-view-3d".equals(actionCommand)) { |
115 |
return TYPE.FLAT;
|
116 |
} |
117 |
return null; |
118 |
} |
119 |
|
120 |
public boolean isEnabled() { |
121 |
return true; |
122 |
} |
123 |
|
124 |
public boolean isVisible() { |
125 |
return true; |
126 |
} |
127 |
|
128 |
@Override
|
129 |
public boolean isEnabled(String actionCommand) { |
130 |
|
131 |
IView view = getActiveView(); |
132 |
if (view != null |
133 |
&& ("sphere-view-3d".equals(actionCommand) || "flat-view-3d" |
134 |
.equals(actionCommand))) { |
135 |
|
136 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
137 |
MapContext mapContext = view.getMapControl().getMapContext(); |
138 |
TYPE type = getType(actionCommand); |
139 |
|
140 |
if (type != null) { |
141 |
|
142 |
MapControl3D mapControl3D = |
143 |
manager.getMapControl3D( |
144 |
(ExtendedPropertiesSupport) view.getViewDocument(), |
145 |
getType(actionCommand)); |
146 |
|
147 |
FLayers layers = mapContext.getLayers(); |
148 |
|
149 |
boolean isEPSG4326 =
|
150 |
mapContext.getProjection().getAbrev().equals("EPSG:4326");
|
151 |
|
152 |
if (mapControl3D == null && layers.getLayersCount() > 0 |
153 |
&& isEPSG4326) { |
154 |
return true; |
155 |
} |
156 |
} |
157 |
} |
158 |
return false; |
159 |
} |
160 |
|
161 |
@Override
|
162 |
public boolean isVisible(String actionCommand) { |
163 |
IView view = getActiveView(); |
164 |
if (view != null) { |
165 |
return true; |
166 |
} |
167 |
return false; |
168 |
} |
169 |
|
170 |
private IView getActiveView() {
|
171 |
ApplicationManager application = ApplicationLocator.getManager(); |
172 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
173 |
return view;
|
174 |
} |
175 |
|
176 |
@Override
|
177 |
public boolean canQueryByAction() { |
178 |
return true; |
179 |
} |
180 |
|
181 |
public void update(Observable observable, Object notification) { |
182 |
if (observable instanceof MapControl3D |
183 |
&& notification instanceof Notification) { |
184 |
|
185 |
Notification n = (Notification) notification; |
186 |
if (n.getType().equalsIgnoreCase(
|
187 |
MapControl3D.AFTER_DISPOSE_MAPCONTEX3D_NOTIFICATION)) { |
188 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
189 |
appManager.refreshMenusAndToolBars(); |
190 |
} |
191 |
} |
192 |
|
193 |
} |
194 |
} |