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