gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.extension / src / main / java / org / gvsig / gvsig3d / app / navigation / NavigationMenu3D.java @ 314
History | View | Annotate | Download (11.5 KB)
1 |
package org.gvsig.gvsig3d.app.navigation; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.Cursor; |
5 |
import java.awt.Image; |
6 |
import java.awt.Point; |
7 |
import java.awt.Toolkit; |
8 |
import java.io.File; |
9 |
import java.net.URL; |
10 |
|
11 |
import javax.swing.Icon; |
12 |
import javax.swing.ImageIcon; |
13 |
import javax.swing.JOptionPane; |
14 |
|
15 |
import org.gvsig.andami.PluginServices; |
16 |
import org.gvsig.andami.plugins.Extension; |
17 |
import org.gvsig.andami.ui.mdiFrame.JMenuItem; |
18 |
import org.gvsig.andami.ui.mdiFrame.JToolBarButton; |
19 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
20 |
import org.gvsig.app.project.documents.view.gui.FPanelLocConfig; |
21 |
import org.gvsig.fmap.geom.primitive.Envelope; |
22 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
23 |
import org.gvsig.gvsig3d.app.extension.DefaultView3DPanel; |
24 |
import org.gvsig.gvsig3d.app.resources.ResourcesFactory; |
25 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
26 |
import org.gvsig.gvsig3d.navigation.NavigationMode; |
27 |
import org.gvsig.osgvp.terrain.Terrain; |
28 |
import org.gvsig.osgvp.terrain.TerrainCameraManipulator; |
29 |
import org.gvsig.osgvp.terrain.TerrainViewer; |
30 |
import org.gvsig.osgvp.viewer.Camera; |
31 |
import org.gvsig.osgvp.viewer.OSGViewer; |
32 |
import org.gvsig.osgvp.viewer.manipulator.TerrainManipulator; |
33 |
|
34 |
/**
|
35 |
* @author AI2
|
36 |
* @version $Id$
|
37 |
*
|
38 |
*/
|
39 |
public class NavigationMenu3D extends Extension { |
40 |
|
41 |
private boolean activa = true; |
42 |
//
|
43 |
|
44 |
private NavigationMode navMode;
|
45 |
|
46 |
private boolean wireAct = false; |
47 |
|
48 |
JMenuItem myMenu = null; |
49 |
|
50 |
Icon iconVis = null; |
51 |
|
52 |
Icon iconNoVis = null; |
53 |
|
54 |
private ImageIcon iconButtonVis; |
55 |
|
56 |
private ImageIcon iconButtonNoVis; |
57 |
|
58 |
// cursors
|
59 |
private Cursor navCursor; |
60 |
|
61 |
private Cursor zoomCursor; |
62 |
|
63 |
private Cursor panCursor; |
64 |
|
65 |
private Cursor azimCursor; |
66 |
|
67 |
private String buttonPath; |
68 |
|
69 |
private String imagesPath; |
70 |
|
71 |
public void execute(String actionCommand) { |
72 |
|
73 |
IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
74 |
|
75 |
if (!(view instanceof DefaultView3DPanel)) |
76 |
return;
|
77 |
|
78 |
DefaultView3DPanel vista3D = (DefaultView3DPanel) view; |
79 |
Component viewer = (Component) vista3D.getCanvas3d(); |
80 |
|
81 |
// remove active tool in MapControl
|
82 |
boolean resetCursor = false; |
83 |
|
84 |
navMode = vista3D.getNavMode(); |
85 |
|
86 |
// Action for ZOOM_SELECT
|
87 |
if (actionCommand.equals("PAN_SELECT")) { |
88 |
if (navMode != null) { |
89 |
viewer.setCursor(panCursor); |
90 |
navMode.SetRollMode(); |
91 |
} |
92 |
} else if (actionCommand.equals("ZOOM_SELECT")) { |
93 |
if (navMode != null) { |
94 |
viewer.setCursor(zoomCursor); |
95 |
navMode.SetZoomMode(); |
96 |
} |
97 |
} else if (actionCommand.equals("AZIMUT_SELECT")) { |
98 |
if (navMode != null) { |
99 |
viewer.setCursor(azimCursor); |
100 |
navMode.SetAzimutMode(); |
101 |
} |
102 |
} else if (actionCommand.equals("DEFAULT_SELECT")) { |
103 |
if (navMode != null) { |
104 |
viewer.setCursor(navCursor); |
105 |
navMode.SetDefaultMode(); |
106 |
} |
107 |
} else if (actionCommand.equals("WIRE_FRAME")) { |
108 |
resetCursor = false;
|
109 |
wireAct = !wireAct; |
110 |
if (wireAct)
|
111 |
vista3D.getCanvas3d().getOSGViewer() |
112 |
.setPolygonMode(OSGViewer.PolygonModeType.GL_LINE); |
113 |
else
|
114 |
vista3D.getCanvas3d().getOSGViewer() |
115 |
.setPolygonMode(OSGViewer.PolygonModeType.GL_FILL); |
116 |
vista3D.getCanvas3d().repaint(); |
117 |
} else if (actionCommand.equals("RESET_VIEW")) { |
118 |
resetCursor = false;
|
119 |
MapContext3D map3D = (MapContext3D) vista3D.getMapControl() |
120 |
.getMapContext(); |
121 |
FLayers layers = map3D.getLayers(); |
122 |
Envelope env = layers.getFullEnvelope(); |
123 |
if (env == null) { |
124 |
Camera cam; |
125 |
cam = vista3D.getCamera(); |
126 |
|
127 |
if (vista3D.getTerrain().getCoordinateSystemType() != Terrain.CoordinateSystemType.PROJECTED) {
|
128 |
cam.setViewByLookAt(vista3D.getTerrain() |
129 |
.getRadiusEquatorial() * 8.0, 0, 0, 0, 0, 0, 0, 0, |
130 |
1);
|
131 |
|
132 |
} else {
|
133 |
cam.setViewByLookAt(0, 0, 5000000 * 4.6, 0, 0, 0, 0, 1, 0); |
134 |
} |
135 |
vista3D.getCanvas3d().getOSGViewer().setCamera(cam); |
136 |
} else {
|
137 |
map3D.zoomToEnvelope(env); |
138 |
} |
139 |
vista3D.repaint(); |
140 |
|
141 |
} else if (actionCommand.equals("ACTIVE")) { |
142 |
resetCursor = false;
|
143 |
if (vista3D.getTerrain().getCoordinateSystemType() != Terrain.CoordinateSystemType.PROJECTED) {
|
144 |
|
145 |
TerrainCameraManipulator ctm = ((TerrainViewer) vista3D |
146 |
.getCanvas3d().getOSGViewer()) |
147 |
.getTerrainCameraManipulator(); |
148 |
|
149 |
JToolBarButton b = (JToolBarButton) PluginServices |
150 |
.getMainFrame().getComponentByName("NORTH");
|
151 |
if ((!ctm.getEnabledNorthOrientation()) && (myMenu != null)) { |
152 |
myMenu.setIcon(iconVis); |
153 |
|
154 |
if (b != null) { |
155 |
b.setIcon(iconButtonVis); |
156 |
b.setToolTip(PluginServices.getText(this, "Des_north") |
157 |
+ " "
|
158 |
+ PluginServices.getText(this, "Active_north")); |
159 |
} |
160 |
} else {
|
161 |
myMenu.setIcon(iconNoVis); |
162 |
|
163 |
if (b != null) { |
164 |
b.setIcon(iconButtonNoVis); |
165 |
b.setToolTip(PluginServices.getText(this, "Ac_north") |
166 |
+ " "
|
167 |
+ PluginServices.getText(this, "Active_north")); |
168 |
} |
169 |
} |
170 |
|
171 |
ctm.setEnabledNorthOrientation(!ctm |
172 |
.getEnabledNorthOrientation()); |
173 |
|
174 |
vista3D.getCanvas3d().repaint(); |
175 |
} else {
|
176 |
JOptionPane.showMessageDialog(null, |
177 |
PluginServices.getText(this, "North_plane")); |
178 |
} |
179 |
|
180 |
} |
181 |
if (actionCommand.equals("CONFIG_LOCATOR")) { |
182 |
// Set up the map overview
|
183 |
FPanelLocConfig m_panelLoc = new FPanelLocConfig(
|
184 |
vista3D.getMapOverview()); |
185 |
PluginServices.getMDIManager().addWindow(m_panelLoc); |
186 |
m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
187 |
} |
188 |
|
189 |
// OJOOOOOOOOO CON ESTO Q ESTA COMENTADO PARA Q COMPILE HAY Q MIRAR COMO
|
190 |
// ARREGLARLO
|
191 |
if (resetCursor)
|
192 |
vista3D.getMapControl().setCurrentMapTool(null);
|
193 |
} |
194 |
|
195 |
public void initialize() { |
196 |
|
197 |
// Register new icons
|
198 |
// Default manipulator
|
199 |
|
200 |
PluginServices.getIconTheme().registerDefault( |
201 |
"default-manipulator-icon",
|
202 |
this.getClass().getClassLoader()
|
203 |
.getResource("images/DefaultManipulator.png"));
|
204 |
// Roll manipulator
|
205 |
PluginServices.getIconTheme().registerDefault( |
206 |
"roll-manipulator-icon",
|
207 |
this.getClass().getClassLoader()
|
208 |
.getResource("images/RollManipulator.png"));
|
209 |
// Zoom manipulator
|
210 |
PluginServices.getIconTheme() |
211 |
.registerDefault( |
212 |
"zoom-manipulator-icon",
|
213 |
this.getClass().getClassLoader()
|
214 |
.getResource("images/zoom.png"));
|
215 |
// Azimut manipulator
|
216 |
PluginServices.getIconTheme().registerDefault( |
217 |
"azimut-manipulator-icon",
|
218 |
this.getClass().getClassLoader()
|
219 |
.getResource("images/AzimutManipulator.png"));
|
220 |
// North disable
|
221 |
PluginServices.getIconTheme().registerDefault( |
222 |
"north-disable-icon",
|
223 |
this.getClass().getClassLoader()
|
224 |
.getResource("images/NorthDes.png"));
|
225 |
// North disable
|
226 |
PluginServices.getIconTheme().registerDefault( |
227 |
"global-zoom-icon",
|
228 |
this.getClass().getClassLoader()
|
229 |
.getResource("images/Global.png"));
|
230 |
|
231 |
this.setActiva(true); |
232 |
|
233 |
String oldPath = ResourcesFactory.getExtPath();// Save the path. |
234 |
ResourcesFactory |
235 |
.setExtPath("/gvSIG/extensiones/com.iver.ai2.gvsig3dgui/images/");// my |
236 |
// new
|
237 |
// path
|
238 |
buttonPath = ResourcesFactory.getResourcesPath(); |
239 |
ResourcesFactory.setExtPath(oldPath);// Restore the old path.
|
240 |
System.out.println(oldPath);
|
241 |
System.out.println(buttonPath);
|
242 |
|
243 |
URL path;
|
244 |
path = this.getClass().getClassLoader().getResource("images/"); |
245 |
buttonPath = path.getPath(); |
246 |
|
247 |
Image cursorImage = new ImageIcon(buttonPath + "/NavigationCursor.gif") |
248 |
.getImage(); |
249 |
|
250 |
navCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage,
|
251 |
new Point(16, 16), ""); |
252 |
cursorImage = new ImageIcon(buttonPath + "/ZoomCursor.gif").getImage(); |
253 |
zoomCursor = Toolkit.getDefaultToolkit().createCustomCursor(
|
254 |
cursorImage, new Point(16, 16), ""); |
255 |
cursorImage = new ImageIcon(buttonPath + "/PanCursor.gif").getImage(); |
256 |
panCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage,
|
257 |
new Point(16, 16), ""); |
258 |
cursorImage = new ImageIcon(buttonPath + "/AzimuthCursor.gif") |
259 |
.getImage(); |
260 |
azimCursor = Toolkit.getDefaultToolkit().createCustomCursor(
|
261 |
cursorImage, new Point(16, 16), ""); |
262 |
|
263 |
// Getting view3
|
264 |
IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
265 |
|
266 |
// JMenuBar jMenuBar = PluginServices.getMainFrame().getJMenuBar();
|
267 |
|
268 |
// Iterate over menu bar to get children menus
|
269 |
// for (int i = 0; i < jMenuBar.getMenuCount(); i++) {
|
270 |
// // Getting children
|
271 |
// JMenu menu = jMenuBar.getMenu(i);
|
272 |
// if (menu.getText().equalsIgnoreCase(aux.getText("Vista"))) {
|
273 |
// // Getting children components
|
274 |
// Component[] subMenus = menu.getMenuComponents();
|
275 |
// // Iterate over children menu bar to get children menus
|
276 |
// for (int t = 0; t < subMenus.length; t++) {
|
277 |
// // Getting all children components
|
278 |
// Component component = subMenus[t];
|
279 |
// // Only get instance of JMenu
|
280 |
// if (component instanceof JMenu) {
|
281 |
// JMenu subMenuItem = (JMenu) component;
|
282 |
// // Is "navegacion" menu
|
283 |
// if (subMenuItem.getText().equalsIgnoreCase(
|
284 |
// aux.getText("navegacion"))) {
|
285 |
// // Search north option
|
286 |
// for (int j = 0; j < subMenuItem.getItemCount(); j++) {
|
287 |
// if (subMenuItem.getItem(j).getText()
|
288 |
// .equalsIgnoreCase(
|
289 |
// PluginServices.getText(this,
|
290 |
// "Active_north"))) {
|
291 |
// myMenu = (JMenuItem) subMenuItem.getItem(j);
|
292 |
// }
|
293 |
// }
|
294 |
// }
|
295 |
// }
|
296 |
// }
|
297 |
// }
|
298 |
// }
|
299 |
// This condition are always true.
|
300 |
if (!(view instanceof DefaultView3DPanel)) |
301 |
return;
|
302 |
// // Casting to View3D
|
303 |
// View3D vista3D = (View3D) view;
|
304 |
// //vista3D.getMapControl().setCurrentMapTool(null);
|
305 |
// Component viewer = (Component)vista3D.getCanvas3d();
|
306 |
// viewer.setCursor(navCursor);
|
307 |
} |
308 |
|
309 |
public boolean isEnabled() { |
310 |
return true; |
311 |
} |
312 |
|
313 |
public boolean isVisible() { |
314 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
315 |
|
316 |
if (f == null) { |
317 |
return false; |
318 |
} |
319 |
|
320 |
// Only isVisible = true, where the view3D have layers
|
321 |
if (f instanceof DefaultView3DPanel) { |
322 |
/*******************************************************************
|
323 |
* This code don`t work because andami activate all buttons when the
|
324 |
* return value is true
|
325 |
******************************************************************/
|
326 |
DefaultView3DPanel vista3D = (DefaultView3DPanel) f; |
327 |
JToolBarButton b = (JToolBarButton) PluginServices.getMainFrame() |
328 |
.getComponentByName("NORTH");
|
329 |
if ((vista3D.getTerrain().getCoordinateSystemType() != Terrain.CoordinateSystemType.GEOCENTRIC)
|
330 |
&& (b != null)) {
|
331 |
b.setEnabled(false);
|
332 |
} |
333 |
/* **************************************************************** */
|
334 |
return true; |
335 |
} |
336 |
return false; |
337 |
} |
338 |
|
339 |
public void terminate() { |
340 |
super.terminate();
|
341 |
} |
342 |
|
343 |
public boolean isActiva() { |
344 |
return activa;
|
345 |
} |
346 |
|
347 |
public void setActiva(boolean activa) { |
348 |
this.activa = activa;
|
349 |
} |
350 |
|
351 |
public void postInitialize() { |
352 |
// Getting Main menu bar
|
353 |
|
354 |
PluginServices aux = PluginServices |
355 |
.getPluginServices("com.iver.cit.gvsig");
|
356 |
|
357 |
String[] menuPath = new String[3]; |
358 |
menuPath[0] = new String("Vista"); |
359 |
menuPath[1] = new String("navegacion"); |
360 |
menuPath[2] = new String("Active_north"); |
361 |
this.myMenu = (JMenuItem) PluginServices.getMainFrame().getMenuEntry( |
362 |
menuPath); |
363 |
|
364 |
if (myMenu != null) { |
365 |
|
366 |
File file = new File(this.getClass().getClassLoader() |
367 |
.getResource("images").getFile());
|
368 |
String path1 = file.getPath() + "/mini_check_2.png"; |
369 |
String path2 = file.getPath() + "/mini_no_check_2.png"; |
370 |
|
371 |
iconVis = new ImageIcon(path1); |
372 |
iconNoVis = new ImageIcon(path2); |
373 |
|
374 |
myMenu.setIcon(iconNoVis); |
375 |
|
376 |
String path1B = file.getPath() + "/norte.png"; |
377 |
String path2B = file.getPath() + "/NorthDes.png"; |
378 |
iconButtonVis = new ImageIcon(path1B); |
379 |
iconButtonNoVis = new ImageIcon(path2B); |
380 |
|
381 |
JToolBarButton b = (JToolBarButton) PluginServices.getMainFrame() |
382 |
.getComponentByName("NORTH");
|
383 |
if (b != null) { |
384 |
b.setToolTip(PluginServices.getText(this, "Ac_north") + " " |
385 |
+ PluginServices.getText(this, "Active_north")); |
386 |
|
387 |
// if (vista3D.getPlanet().getType() !=
|
388 |
// PlanetType.SPHERICAL_MODE) {
|
389 |
// b.setEnabled(false);
|
390 |
// }
|
391 |
} |
392 |
|
393 |
} |
394 |
|
395 |
} |
396 |
} |