Statistics
| Revision:

root / trunk / extensions / ext3Dgui / src / com / iver / ai2 / gvsig3dgui / navigation / NavigationMenu3D.java @ 20900

History | View | Annotate | Download (12 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
import java.net.URL;
11

    
12
import javax.swing.Icon;
13
import javax.swing.ImageIcon;
14
import javax.swing.JOptionPane;
15

    
16
import org.gvsig.osgvp.planets.CustomTerrainManipulator;
17
import org.gvsig.osgvp.planets.Planet;
18
import org.gvsig.osgvp.planets.PlanetViewer;
19
import org.gvsig.osgvp.viewer.Camera;
20
import org.gvsig.osgvp.viewer.OSGViewer;
21

    
22
import com.iver.ai2.gvsig3d.map3d.MapContext3D;
23
import com.iver.ai2.gvsig3d.navigation.NavigationMode;
24
import com.iver.ai2.gvsig3d.resources.ResourcesFactory;
25
import com.iver.ai2.gvsig3dgui.view.View3D;
26
import com.iver.andami.PluginServices;
27
import com.iver.andami.plugins.Extension;
28
import com.iver.andami.ui.mdiFrame.JMenuItem;
29
import com.iver.andami.ui.mdiFrame.JToolBarButton;
30
import com.iver.cit.gvsig.fmap.layers.FLayers;
31
import com.iver.cit.gvsig.project.documents.view.gui.FPanelLocConfig;
32

    
33
public class NavigationMenu3D extends Extension {
34

    
35
        private boolean activa = true;
36

    
37
        private NavigationMode navMode;
38

    
39
        private boolean wireAct = false;
40

    
41
        JMenuItem myMenu = null;
42

    
43
        Icon iconVis = null;
44

    
45
        Icon iconNoVis = null;
46

    
47
        private ImageIcon iconButtonVis;
48

    
49
        private ImageIcon iconButtonNoVis;
50

    
51
        // cursors
52
        private Cursor navCursor;
53

    
54
        private Cursor zoomCursor;
55

    
56
        private Cursor panCursor;
57

    
58
        private Cursor azimCursor;
59

    
60
        private String buttonPath;
61

    
62
        private String imagesPath;
63

    
64
        public void execute(String actionCommand) {
65
                // System.out.println("EXECUTE");
66

    
67
                // Getting view3
68
                com.iver.andami.ui.mdiManager.IWindow view = PluginServices
69
                                .getMDIManager().getActiveWindow();
70
                if (!(view instanceof View3D))
71
                        return;
72
                // Casting to View3D
73
                View3D vista3D = (View3D) view;
74
                Component viewer = (Component) vista3D.getCanvas3d();
75

    
76
                // remove active tool in MapControl
77
                boolean resetCursor = true;
78

    
79
                navMode = vista3D.getNavMode();
80

    
81
                // Action for ZOOM_SELECT
82
                if (actionCommand.equals("PAN_SELECT")) {
83
                        if (navMode != null) {
84
                                viewer.setCursor(panCursor);
85
                                navMode.SetRollMode();
86
                        }
87
                } else if (actionCommand.equals("ZOOM_SELECT")) {
88
                        if (navMode != null) {
89
                                viewer.setCursor(zoomCursor);
90
                                navMode.SetZoomMode();
91
                        }
92
                } else if (actionCommand.equals("AZIMUT_SELECT")) {
93
                        if (navMode != null) {
94
                                viewer.setCursor(azimCursor);
95
                                navMode.SetAzimutMode();
96
                        }
97
                } else if (actionCommand.equals("DEFAULT_SELECT")) {
98
                        if (navMode != null) {
99
                                viewer.setCursor(navCursor);
100
                                navMode.SetDefaultMode();
101
                        }
102
                } else if (actionCommand.equals("WIRE_FRAME")) {
103
                        resetCursor = false;
104
                        wireAct = !wireAct;
105
                        if (wireAct)
106
                                vista3D.getCanvas3d().getOSGViewer().setPolygonMode(
107
                                                OSGViewer.PolygonModeType.GL_LINE);
108
                        else
109
                                vista3D.getCanvas3d().getOSGViewer().setPolygonMode(
110
                                                OSGViewer.PolygonModeType.GL_FILL);
111
                        vista3D.getCanvas3d().repaint();
112
                } else if (actionCommand.equals("RESET_VIEW")) {
113
                        resetCursor = false;
114
                        MapContext3D map3D = (MapContext3D) vista3D.getMapControl()
115
                                        .getMapContext();
116
                        FLayers layers = map3D.getLayers();
117
                        Rectangle2D ext = layers.getFullExtent();
118
                        if (ext == null) {
119
                                // ext = new Rectangle2D.Double(-90,-180,90,180);
120
                                Camera cam;
121
                                cam = vista3D.getCamera();
122

    
123
                                if (vista3D.getPlanet().getCoordinateSystemType() != Planet.CoordinateSystemType.PROJECTED) {
124
                                        cam.setViewByLookAt(vista3D.getPlanet()
125
                                                        .getRadiusEquatorial() * 8.0, 0, 0, 0, 0, 0, 0, 0,
126
                                                        1);
127

    
128
                                } else {
129
                                        cam.setViewByLookAt(0, 0, 5000000 * 4.6, 0, 0, 0, 0, 1, 0);
130
                                }
131
                                vista3D.getCanvas3d().getOSGViewer().setCamera(cam);
132
                        } else {
133
                                map3D.zoomToExtent(ext);
134
                        }
135
                        vista3D.repaint();
136

    
137

    
138
                        // UtilCoord.imprimeCamara(vista3D.getCamera());
139
                        // System.out.println("CAMBIANDO CAMARAAAAAAAAA!!!!!!!!!");s
140
                } else if (actionCommand.equals("ACTIVE")) {
141
                        resetCursor = false;
142
                        if (vista3D.getPlanet().getCoordinateSystemType() != Planet.CoordinateSystemType.PROJECTED) {
143

    
144
                                CustomTerrainManipulator ctm = ((PlanetViewer) vista3D
145
                                                .getCanvas3d().getOSGViewer())
146
                                                .getCustomTerrainManipulator();
147

    
148
                                JToolBarButton b = (JToolBarButton) PluginServices
149
                                                .getMainFrame().getComponentByName("NORTH");
150
                                if ((!ctm.getNorthOrientation()) && (myMenu != null)) {
151
                                        myMenu.setIcon(iconVis);
152

    
153
                                        if (b != null) {
154
                                                b.setIcon(iconButtonVis);
155
                                                b.setToolTip(PluginServices.getText(this, "Des_north")
156
                                                                + " "
157
                                                                + PluginServices.getText(this, "Active_north"));
158
                                        }
159
                                } else {
160
                                        myMenu.setIcon(iconNoVis);
161

    
162
                                        if (b != null) {
163
                                                b.setIcon(iconButtonNoVis);
164
                                                b.setToolTip(PluginServices.getText(this, "Ac_north")
165
                                                                + " "
166
                                                                + PluginServices.getText(this, "Active_north"));
167
                                        }
168
                                }
169

    
170
                                ctm.setEnabledNorthOrientation(!ctm.getNorthOrientation());
171

    
172
                                // System.out.println("orientacion " +
173
                                // ctm.getNorthOrientation());
174

    
175
                                vista3D.getCanvas3d().repaint();
176
                        } else {
177
                                JOptionPane.showMessageDialog(null, PluginServices.getText(
178
                                                this, "North_plane"));
179
                        }
180

    
181
                }
182
                if (actionCommand.equals("CONFIG_LOCATOR")) {
183
                        // Set up the map overview
184
                        FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista3D
185
                                        .getMapOverview());
186
                        PluginServices.getMDIManager().addWindow(m_panelLoc);
187
                        m_panelLoc.setPreferredSize(m_panelLoc.getSize());
188
                }
189

    
190
                // OJOOOOOOOOO CON ESTO Q ESTA COMENTADO PARA Q COMPILE HAY Q MIRAR COMO
191
                // ARREGLARLO
192
                if (resetCursor)
193
                        vista3D.getMapControl().setCurrentMapTool(null);
194
        }
195

    
196
        public void initialize() {
197

    
198
                // Register new icons
199
                // Default manipulator
200
                
201
                PluginServices.getIconTheme().registerDefault(
202
                                "default-manipulator-icon",
203
                                this.getClass().getClassLoader().getResource(
204
                                "images/DefaultManipulator.png"));
205
                // Roll manipulator
206
                PluginServices.getIconTheme().registerDefault(
207
                                "roll-manipulator-icon",
208
                                this.getClass().getClassLoader().getResource(
209
                                "images/RollManipulator.png"));
210
                // Zoom manipulator
211
                PluginServices.getIconTheme()
212
                .registerDefault(
213
                                "zoom-manipulator-icon",
214
                                this.getClass().getClassLoader().getResource(
215
                                "images/zoom.png"));
216
                // Azimut manipulator
217
                PluginServices.getIconTheme().registerDefault(
218
                                "azimut-manipulator-icon",
219
                                this.getClass().getClassLoader().getResource(
220
                                "images/AzimutManipulator.png"));
221
                // North disable
222
                PluginServices.getIconTheme().registerDefault(
223
                                "north-disable-icon",
224
                                this.getClass().getClassLoader().getResource(
225
                                "images/NorthDes.png"));
226
                // North disable
227
                PluginServices.getIconTheme().registerDefault(
228
                                "global-zoom-icon",
229
                                this.getClass().getClassLoader().getResource(
230
                                "images/Global.png"));
231
                
232
                
233
                this.setActiva(true);
234

    
235
                String oldPath = ResourcesFactory.getExtPath();// Save the path.
236
                ResourcesFactory
237
                                .setExtPath("/gvSIG/extensiones/com.iver.ai2.gvsig3dgui/images/");// my
238
                // new
239
                // path
240
                buttonPath = ResourcesFactory.getResourcesPath();
241
                ResourcesFactory.setExtPath(oldPath);// Restore the old path.
242
                System.out.println(oldPath);
243
                System.out.println(buttonPath);
244
                
245
                URL path;
246
                path = this.getClass().getClassLoader().getResource("images/");
247
                buttonPath = path.getPath(); 
248

    
249
                Image cursorImage = new ImageIcon(buttonPath + "/NavigationCursor.gif")
250
                                .getImage();
251

    
252
                navCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage,
253
                                new Point(16, 16), "");
254
                cursorImage = new ImageIcon(buttonPath + "/ZoomCursor.gif").getImage();
255
                zoomCursor = Toolkit.getDefaultToolkit().createCustomCursor(
256
                                cursorImage, new Point(16, 16), "");
257
                cursorImage = new ImageIcon(buttonPath + "/PanCursor.gif").getImage();
258
                panCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage,
259
                                new Point(16, 16), "");
260
                cursorImage = new ImageIcon(buttonPath + "/AzimuthCursor.gif")
261
                                .getImage();
262
                azimCursor = Toolkit.getDefaultToolkit().createCustomCursor(
263
                                cursorImage, new Point(16, 16), "");
264

    
265
                // Getting view3
266
                com.iver.andami.ui.mdiManager.IWindow view = PluginServices
267
                                .getMDIManager().getActiveWindow();
268

    
269
                // JMenuBar jMenuBar = PluginServices.getMainFrame().getJMenuBar();
270

    
271
                // Iterate over menu bar to get children menus
272
                // for (int i = 0; i < jMenuBar.getMenuCount(); i++) {
273
                // // Getting children
274
                // JMenu menu = jMenuBar.getMenu(i);
275
                // if (menu.getText().equalsIgnoreCase(aux.getText("Vista"))) {
276
                // // Getting children components
277
                // Component[] subMenus = menu.getMenuComponents();
278
                // // Iterate over children menu bar to get children menus
279
                // for (int t = 0; t < subMenus.length; t++) {
280
                // // Getting all children components
281
                // Component component = subMenus[t];
282
                // // Only get instance of JMenu
283
                // if (component instanceof JMenu) {
284
                // JMenu subMenuItem = (JMenu) component;
285
                // // Is "navegacion" menu
286
                // if (subMenuItem.getText().equalsIgnoreCase(
287
                // aux.getText("navegacion"))) {
288
                // // Search north option
289
                // for (int j = 0; j < subMenuItem.getItemCount(); j++) {
290
                // if (subMenuItem.getItem(j).getText()
291
                // .equalsIgnoreCase(
292
                // PluginServices.getText(this,
293
                // "Active_north"))) {
294
                // myMenu = (JMenuItem) subMenuItem.getItem(j);
295
                // }
296
                // }
297
                // }
298
                // }
299
                // }
300
                // }
301
                // }
302
                // This condition are always true.
303
                if (!(view instanceof View3D))
304
                        return;
305
                // // Casting to View3D
306
                // View3D vista3D = (View3D) view;
307
                // //vista3D.getMapControl().setCurrentMapTool(null);
308
                // Component viewer = (Component)vista3D.getCanvas3d();
309
                // viewer.setCursor(navCursor);
310
        }
311

    
312
        public boolean isEnabled() {
313
                return true;
314
        }
315

    
316
        public boolean isVisible() {
317
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices
318
                                .getMDIManager().getActiveWindow();
319

    
320
                if (f == null) {
321
                        return false;
322
                }
323

    
324
                // Only isVisible = true, where the view3D have layers
325
                if (f instanceof View3D) {
326
                        /*******************************************************************
327
                         * This code don`t work because andami activate all buttons when the
328
                         * return value is true
329
                         ******************************************************************/
330
                        View3D vista3D = (View3D) f;
331
                        JToolBarButton b = (JToolBarButton) PluginServices.getMainFrame()
332
                                        .getComponentByName("NORTH");
333
                        if ((vista3D.getPlanet().getCoordinateSystemType() != Planet.CoordinateSystemType.GEOCENTRIC)
334
                                        && (b != null)) {
335
                                b.setEnabled(false);
336
                        }
337
                        /* **************************************************************** */
338
                        return true;
339
                }
340
                return false;
341
        }
342

    
343
        public void terminate() {
344
                super.terminate();
345
        }
346

    
347
        public boolean isActiva() {
348
                return activa;
349
        }
350

    
351
        public void setActiva(boolean activa) {
352
                this.activa = activa;
353
        }
354

    
355
        public void postInitialize() {
356
                // Getting Main menu bar
357
                
358
                PluginServices aux = PluginServices
359
                .getPluginServices("com.iver.cit.gvsig");
360
                
361
                String[] menuPath = new String[3];
362
                menuPath[0] = new String("Vista");
363
                menuPath[1] = new String("navegacion");
364
                menuPath[2] = new String("Active_north");
365
                this.myMenu = (JMenuItem) PluginServices.getMainFrame().getMenuEntry(
366
                                menuPath);
367

    
368
                if (myMenu != null) {
369

    
370
                        File file = new File(this.getClass().getClassLoader().getResource(
371
                                        "images").getFile());
372
                        String path1 = file.getPath() + "/mini_check_2.png";
373
                        String path2 = file.getPath() + "/mini_no_check_2.png";
374

    
375
                        iconVis = new ImageIcon(path1);
376
                        iconNoVis = new ImageIcon(path2);
377

    
378
                        myMenu.setIcon(iconNoVis);
379

    
380
                        String path1B = file.getPath() + "/norte.png";
381
                        String path2B = file.getPath() + "/NorthDes.png";
382
                        iconButtonVis = new ImageIcon(path1B);
383
                        iconButtonNoVis = new ImageIcon(path2B);
384

    
385
                        JToolBarButton b = (JToolBarButton) PluginServices.getMainFrame()
386
                                        .getComponentByName("NORTH");
387
                        if (b != null) {
388
                                b.setToolTip(PluginServices.getText(this, "Ac_north") + " "
389
                                                + PluginServices.getText(this, "Active_north"));
390

    
391
                                // if (vista3D.getPlanet().getType() !=
392
                                // PlanetType.SPHERICAL_MODE) {
393
                                // b.setEnabled(false);
394
                                // }
395
                        }
396

    
397
                }
398

    
399
        }
400
}