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