Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / navigation / NavigationMenu3D.java @ 29938

History | View | Annotate | Download (10.4 KB)

1
package org.gvsig.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.andami.PluginServices;
17
import org.gvsig.andami.plugins.Extension;
18
import org.gvsig.andami.ui.mdiFrame.JMenuItem;
19
import org.gvsig.andami.ui.mdiFrame.JToolBarButton;
20
import org.gvsig.andami.ui.mdiManager.IWindow;
21
import org.gvsig.app.project.documents.view.gui.FPanelLocConfig;
22
import org.gvsig.fmap.mapcontext.layers.FLayers;
23
import org.gvsig.gvsig3d.map3d.MapContext3D;
24
import org.gvsig.gvsig3d.navigation.NavigationMode;
25
import org.gvsig.gvsig3dgui.view.View3D;
26
import org.gvsig.osgvp.planets.CustomTerrainManipulator;
27
import org.gvsig.osgvp.planets.Planet;
28
import org.gvsig.osgvp.planets.PlanetViewer;
29
import org.gvsig.osgvp.viewer.Camera;
30
import org.gvsig.osgvp.viewer.OSGViewer;
31

    
32
import com.iver.ai2.gvsig3d.resources.ResourcesFactory;
33

    
34
public class NavigationMenu3D extends Extension {
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
        private String imagesPath;
64

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

    
68
                // Getting view3
69
                IWindow view = PluginServices.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
                        // TODO:COMENTADO PARA LA 2.0
118
                        // Rectangle2D ext = layers.getFullExtent();
119
                        // if (ext == null) {
120
                        //                
121
                        // Camera cam;
122
                        // cam = vista3D.getCamera();
123
                        //
124
                        // if (vista3D.getPlanet().getCoordinateSystemType() !=
125
                        // Planet.CoordinateSystemType.PROJECTED) {
126
                        // cam.setViewByLookAt(vista3D.getPlanet()
127
                        // .getRadiusEquatorial() * 8.0, 0, 0, 0, 0, 0, 0, 0,
128
                        // 1);
129
                        //
130
                        // } else {
131
                        // cam.setViewByLookAt(0, 0, 5000000 * 4.6, 0, 0, 0, 0, 1, 0);
132
                        // }
133
                        // vista3D.getCanvas3d().getOSGViewer().setCamera(cam);
134
                        // } else {
135
                        // map3D.zoomToExtent(ext);
136
                        // }
137
                        vista3D.repaint();
138

    
139
                } else if (actionCommand.equals("ACTIVE")) {
140
                        resetCursor = false;
141
                        if (vista3D.getPlanet().getCoordinateSystemType() != Planet.CoordinateSystemType.PROJECTED) {
142

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

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

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

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

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

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

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

    
180
                }
181
                if (actionCommand.equals("CONFIG_LOCATOR")) {
182
                        // Set up the map overview
183
                        FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista3D
184
                                        .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().getResource(
203
                                                "images/DefaultManipulator.png"));
204
                // Roll manipulator
205
                PluginServices.getIconTheme().registerDefault(
206
                                "roll-manipulator-icon",
207
                                this.getClass().getClassLoader().getResource(
208
                                                "images/RollManipulator.png"));
209
                // Zoom manipulator
210
                PluginServices.getIconTheme()
211
                                .registerDefault(
212
                                                "zoom-manipulator-icon",
213
                                                this.getClass().getClassLoader().getResource(
214
                                                                "images/zoom.png"));
215
                // Azimut manipulator
216
                PluginServices.getIconTheme().registerDefault(
217
                                "azimut-manipulator-icon",
218
                                this.getClass().getClassLoader().getResource(
219
                                                "images/AzimutManipulator.png"));
220
                // North disable
221
                PluginServices.getIconTheme().registerDefault(
222
                                "north-disable-icon",
223
                                this.getClass().getClassLoader().getResource(
224
                                                "images/NorthDes.png"));
225
                // North disable
226
                PluginServices.getIconTheme().registerDefault(
227
                                "global-zoom-icon",
228
                                this.getClass().getClassLoader().getResource(
229
                                                "images/Global.png"));
230

    
231
                this.setActiva(true);
232

    
233
                String oldPath = ResourcesFactory.getExtPath();// Save the path.
234
                
235
                //TODO:REVISAR 2.0 que no va a ir (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

    
266
        public boolean isEnabled() {
267
                return true;
268
        }
269

    
270
        public boolean isVisible() {
271
        IWindow f = PluginServices
272
                                .getMDIManager().getActiveWindow();
273

    
274
                if (f == null) {
275
                        return false;
276
                }
277

    
278
                // Only isVisible = true, where the view3D have layers
279
                if (f instanceof View3D) {
280
                        /*******************************************************************
281
                         * This code don`t work because andami activate all buttons when the
282
                         * return value is true
283
                         ******************************************************************/
284
                        View3D vista3D = (View3D) f;
285
                        JToolBarButton b = (JToolBarButton) PluginServices.getMainFrame()
286
                                        .getComponentByName("NORTH");
287
                        if ((vista3D.getPlanet().getCoordinateSystemType() != Planet.CoordinateSystemType.GEOCENTRIC)
288
                                        && (b != null)) {
289
                                b.setEnabled(false);
290
                        }
291
                        /* **************************************************************** */
292
                        return true;
293
                }
294
                return false;
295
        }
296

    
297
        public void terminate() {
298
                super.terminate();
299
        }
300

    
301
        public boolean isActiva() {
302
                return activa;
303
        }
304

    
305
        public void setActiva(boolean activa) {
306
                this.activa = activa;
307
        }
308

    
309
        public void postInitialize() {
310
                // Getting Main menu bar
311

    
312
                PluginServices aux = PluginServices
313
                                .getPluginServices("org.gvsig.app");
314

    
315
                String[] menuPath = new String[3];
316
                menuPath[0] = new String("Vista");
317
                menuPath[1] = new String("navegacion");
318
                menuPath[2] = new String("Active_north");
319
                this.myMenu = (JMenuItem) PluginServices.getMainFrame().getMenuEntry(
320
                                menuPath);
321

    
322
                if (myMenu != null) {
323

    
324
                        File file = new File(this.getClass().getClassLoader().getResource(
325
                                        "images").getFile());
326
                        String path1 = file.getPath() + "/mini_check_2.png";
327
                        String path2 = file.getPath() + "/mini_no_check_2.png";
328

    
329
                        iconVis = new ImageIcon(path1);
330
                        iconNoVis = new ImageIcon(path2);
331

    
332
                        myMenu.setIcon(iconNoVis);
333

    
334
                        String path1B = file.getPath() + "/norte.png";
335
                        String path2B = file.getPath() + "/NorthDes.png";
336
                        iconButtonVis = new ImageIcon(path1B);
337
                        iconButtonNoVis = new ImageIcon(path2B);
338

    
339
                        JToolBarButton b = (JToolBarButton) PluginServices.getMainFrame()
340
                                        .getComponentByName("NORTH");
341
                        if (b != null) {
342
                                b.setToolTip(PluginServices.getText(this, "Ac_north") + " "
343
                                                + PluginServices.getText(this, "Active_north"));
344

    
345
                                // if (vista3D.getPlanet().getType() !=
346
                                // PlanetType.SPHERICAL_MODE) {
347
                                // b.setEnabled(false);
348
                                // }
349
                        }
350

    
351
                }
352

    
353
        }
354
}