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