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 @ 488
History | View | Annotate | Download (6.38 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.tools.ToolsLocator; |
39 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
40 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
41 |
import org.gvsig.tools.observer.Notification; |
42 |
import org.gvsig.tools.observer.Observable; |
43 |
import org.gvsig.tools.observer.Observer; |
44 |
import org.gvsig.view3d.app.properties.LayerProperties3DThemeManagerPage; |
45 |
import org.gvsig.view3d.app.properties.RasterLayerProperties3DPanel; |
46 |
import org.gvsig.view3d.swing.api.MapControl3D; |
47 |
import org.gvsig.view3d.swing.api.View3DPanel; |
48 |
import org.gvsig.view3d.swing.api.View3DSwingLocator; |
49 |
import org.gvsig.view3d.swing.api.View3DSwingManager; |
50 |
import org.gvsig.view3d.swing.api.View3DSwingManager.TYPE; |
51 |
|
52 |
/**
|
53 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
54 |
*
|
55 |
*/
|
56 |
public class View3DExtension extends Extension implements Observer { |
57 |
|
58 |
public void initialize() { |
59 |
|
60 |
ThemeManagerWindow.addPage(LayerProperties3DThemeManagerPage.class); |
61 |
ThemeManagerWindow.setTabEnabledForLayer( |
62 |
LayerProperties3DThemeManagerPage.class, FLyrVect.class, true);
|
63 |
|
64 |
ExtensionPointManager extensionPoints = |
65 |
ToolsLocator.getExtensionPointManager(); |
66 |
ExtensionPoint point = extensionPoints.get("RasterSEPropertiesDialog");
|
67 |
if (point != null) { |
68 |
point.append("3D", "3D Raster properties panel", |
69 |
RasterLayerProperties3DPanel.class); |
70 |
} |
71 |
registerIcons(); |
72 |
} |
73 |
|
74 |
private void registerIcons() { |
75 |
IconThemeHelper.registerIcon("view3d", "sphere-view-3d", this); |
76 |
IconThemeHelper.registerIcon("view3d", "flat-view-3d", this); |
77 |
} |
78 |
|
79 |
public void execute(String actionCommand) { |
80 |
|
81 |
TYPE type = getType(actionCommand); |
82 |
|
83 |
IView view = getActiveView(); |
84 |
|
85 |
if (view != null && type != null) { |
86 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
87 |
|
88 |
MapControl3D mapControl3D = |
89 |
manager.getMapControl3D( |
90 |
(ExtendedPropertiesSupport) view.getViewDocument(), type); |
91 |
if (mapControl3D == null || mapControl3D.getType() != type) { |
92 |
View3DPanel view3DPanel = |
93 |
manager.createView3DPanel(view.getMapControl() |
94 |
.getMapContext(), type, |
95 |
(ExtendedPropertiesSupport) view.getViewDocument()); |
96 |
view3DPanel.getMapControl3D().addObserver(this);
|
97 |
view3DPanel.show(); |
98 |
} |
99 |
} |
100 |
} |
101 |
|
102 |
private TYPE getType(String actionCommand) { |
103 |
if ("sphere-view-3d".equals(actionCommand)) { |
104 |
return TYPE.SPHERE;
|
105 |
} else if ("flat-view-3d".equals(actionCommand)) { |
106 |
return TYPE.FLAT;
|
107 |
} |
108 |
return null; |
109 |
} |
110 |
|
111 |
public boolean isEnabled() { |
112 |
return true; |
113 |
} |
114 |
|
115 |
public boolean isVisible() { |
116 |
return true; |
117 |
} |
118 |
|
119 |
@Override
|
120 |
public boolean isEnabled(String actionCommand) { |
121 |
|
122 |
IView view = getActiveView(); |
123 |
if (view != null |
124 |
&& ("sphere-view-3d".equals(actionCommand) || "flat-view-3d" |
125 |
.equals(actionCommand))) { |
126 |
|
127 |
View3DSwingManager manager = View3DSwingLocator.getManager(); |
128 |
MapContext mapContext = view.getMapControl().getMapContext(); |
129 |
TYPE type = getType(actionCommand); |
130 |
|
131 |
if (type != null) { |
132 |
|
133 |
MapControl3D mapControl3D = |
134 |
manager.getMapControl3D( |
135 |
(ExtendedPropertiesSupport) view.getViewDocument(), |
136 |
getType(actionCommand)); |
137 |
|
138 |
FLayers layers = mapContext.getLayers(); |
139 |
|
140 |
boolean isEPSG4326 =
|
141 |
mapContext.getProjection().getAbrev().equals("EPSG:4326");
|
142 |
|
143 |
if (mapControl3D == null && layers.getLayersCount() > 0 |
144 |
&& isEPSG4326) { |
145 |
return true; |
146 |
} |
147 |
} |
148 |
} |
149 |
return false; |
150 |
} |
151 |
|
152 |
@Override
|
153 |
public boolean isVisible(String actionCommand) { |
154 |
IView view = getActiveView(); |
155 |
if (view != null) { |
156 |
return true; |
157 |
} |
158 |
return false; |
159 |
} |
160 |
|
161 |
private IView getActiveView() {
|
162 |
ApplicationManager application = ApplicationLocator.getManager(); |
163 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
164 |
return view;
|
165 |
} |
166 |
|
167 |
@Override
|
168 |
public boolean canQueryByAction() { |
169 |
return true; |
170 |
} |
171 |
|
172 |
public void update(Observable observable, Object notification) { |
173 |
if (observable instanceof MapControl3D |
174 |
&& notification instanceof Notification) { |
175 |
|
176 |
Notification n = (Notification) notification; |
177 |
if (n.getType().equalsIgnoreCase(
|
178 |
MapControl3D.AFTER_DISPOSE_MAPCONTEX3D_NOTIFICATION)) { |
179 |
ApplicationManager appManager = ApplicationLocator.getManager(); |
180 |
appManager.refreshMenusAndToolBars(); |
181 |
} |
182 |
} |
183 |
|
184 |
} |
185 |
} |