gvsig-3d / 2.1 / branches / extrusion / org.gvsig.view3d.app / org.gvsig.view3d.app.common / src / main / java / org / gvsig / view3d / app / mainplugin / View3DExtension.java @ 657
History | View | Annotate | Download (7.68 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.i18n.I18nManager; |
44 |
import org.gvsig.tools.observer.Notification; |
45 |
import org.gvsig.tools.observer.Observable; |
46 |
import org.gvsig.tools.observer.Observer; |
47 |
import org.gvsig.view3d.app.properties.General3DPreferencePage; |
48 |
import org.gvsig.view3d.app.properties.LayerProperties3DThemeManagerPage; |
49 |
import org.gvsig.view3d.app.properties.RasterLayerProperties3DPanel; |
50 |
import org.gvsig.view3d.app.properties.ViewProperties3DPageFactory; |
51 |
import org.gvsig.view3d.swing.api.MapControl3D; |
52 |
import org.gvsig.view3d.swing.api.View3DPanel; |
53 |
import org.gvsig.view3d.swing.api.View3DSwingLocator; |
54 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
55 |
import org.gvsig.view3d.swing.api.View3DSwingManager.TYPE; |
56 |
|
57 |
/**
|
58 |
* The main View3d extension.
|
59 |
*
|
60 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
61 |
*
|
62 |
*/
|
63 |
public class View3DExtension extends Extension implements Observer { |
64 |
|
65 |
private static final String EPSG_4326 = "EPSG:4326"; |
66 |
private static final String GENERAL_PROPERTIES_VIEW_3D = "general-properties-view-3d"; |
67 |
private static final String FLAT_VIEW_3D = "flat-view-3d"; |
68 |
private static final String SPHERICAL_VIEW_3D = "spherical-view-3d"; |
69 |
|
70 |
public void initialize() { |
71 |
// Register general 3D properties
|
72 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
73 |
ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager(); |
74 |
ExtensionPoint ep = extensionPoints.add("AplicationPreferences", ""); |
75 |
ep.append(i18nManager.getTranslation("3D"), "", new General3DPreferencePage()); |
76 |
|
77 |
// Register vectorial layer 3D properties panel
|
78 |
ThemeManagerWindow.addPage(LayerProperties3DThemeManagerPage.class); |
79 |
ThemeManagerWindow.setTabEnabledForLayer( |
80 |
LayerProperties3DThemeManagerPage.class, FLyrVect.class, true);
|
81 |
|
82 |
// Regsiter raster layer 3D properties panel
|
83 |
ExtensionPoint point = extensionPoints.get("RasterSEPropertiesDialog");
|
84 |
if (point != null) { |
85 |
point.append("3D", "3D Raster properties panel", |
86 |
RasterLayerProperties3DPanel.class); |
87 |
} |
88 |
|
89 |
// Register view properties
|
90 |
PropertiesPageManager manager = MapControlLocator.getPropertiesPageManager(); |
91 |
manager.registerFactory(new ViewProperties3DPageFactory());
|
92 |
|
93 |
registerIcons(); |
94 |
} |
95 |
|
96 |
private void registerIcons() { |
97 |
IconThemeHelper.registerIcon("view3d", SPHERICAL_VIEW_3D, this); |
98 |
IconThemeHelper.registerIcon("view3d", FLAT_VIEW_3D, this); |
99 |
IconThemeHelper.registerIcon("view3d", GENERAL_PROPERTIES_VIEW_3D, this); |
100 |
} |
101 |
|
102 |
public void execute(String actionCommand) { |
103 |
|
104 |
TYPE type = getType(actionCommand); |
105 |
|
106 |
IView view = getActiveView(); |
107 |
|
108 |
if (view != null && type != null) { |
109 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
110 |
|
111 |
ViewDocument viewDocument = view.getViewDocument(); |
112 |
MapControl3D mapControl3D = |
113 |
manager.getMapControl3D( |
114 |
(ExtendedPropertiesSupport) viewDocument, type); |
115 |
if (mapControl3D == null || mapControl3D.getType() != type) { |
116 |
View3DPanel view3DPanel = |
117 |
manager.createView3DPanel(view.getMapControl() |
118 |
.getMapContext(), viewDocument.getName(), type, |
119 |
(ExtendedPropertiesSupport) viewDocument); |
120 |
view3DPanel.getMapControl3D().addObserver(this);
|
121 |
view3DPanel.show(); |
122 |
} |
123 |
} |
124 |
} |
125 |
|
126 |
private TYPE getType(String actionCommand) { |
127 |
if (SPHERICAL_VIEW_3D.equals(actionCommand)) {
|
128 |
return TYPE.SPHERE;
|
129 |
} else if (FLAT_VIEW_3D.equals(actionCommand)) { |
130 |
return TYPE.FLAT;
|
131 |
} |
132 |
return null; |
133 |
} |
134 |
|
135 |
public boolean isEnabled() { |
136 |
return true; |
137 |
} |
138 |
|
139 |
public boolean isVisible() { |
140 |
return true; |
141 |
} |
142 |
|
143 |
@Override
|
144 |
public boolean isEnabled(String actionCommand) { |
145 |
|
146 |
IView view = getActiveView(); |
147 |
if (view != null |
148 |
&& (SPHERICAL_VIEW_3D.equals(actionCommand) || FLAT_VIEW_3D |
149 |
.equals(actionCommand))) { |
150 |
|
151 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
152 |
MapContext mapContext = view.getMapControl().getMapContext(); |
153 |
TYPE type = getType(actionCommand); |
154 |
|
155 |
if (type != null) { |
156 |
|
157 |
MapControl3D mapControl3D = |
158 |
manager.getMapControl3D( |
159 |
(ExtendedPropertiesSupport) view.getViewDocument(), |
160 |
getType(actionCommand)); |
161 |
|
162 |
FLayers layers = mapContext.getLayers(); |
163 |
|
164 |
boolean isEPSG4326 =
|
165 |
mapContext.getProjection().getAbrev().equals(EPSG_4326); |
166 |
|
167 |
if (mapControl3D == null && layers.getLayersCount() > 0 |
168 |
&& isEPSG4326) { |
169 |
return true; |
170 |
} |
171 |
} |
172 |
} |
173 |
return false; |
174 |
} |
175 |
|
176 |
@Override
|
177 |
public boolean isVisible(String actionCommand) { |
178 |
IView view = getActiveView(); |
179 |
if (view != null) { |
180 |
return true; |
181 |
} |
182 |
return false; |
183 |
} |
184 |
|
185 |
private IView getActiveView() {
|
186 |
ApplicationManager application = ApplicationLocator.getManager(); |
187 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
188 |
return view;
|
189 |
} |
190 |
|
191 |
@Override
|
192 |
public boolean canQueryByAction() { |
193 |
return true; |
194 |
} |
195 |
|
196 |
public void update(Observable observable, Object notification) { |
197 |
if (observable instanceof MapControl3D |
198 |
&& notification instanceof Notification) { |
199 |
|
200 |
Notification n = (Notification) notification; |
201 |
if (n.getType().equalsIgnoreCase(
|
202 |
MapControl3D.AFTER_DISPOSE_MAPCONTEX3D_NOTIFICATION)) { |
203 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
204 |
appManager.refreshMenusAndToolBars(); |
205 |
} |
206 |
} |
207 |
|
208 |
} |
209 |
} |