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