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