Statistics
| Revision:

svn-gvsig-desktop / import / ext3D / trunk / ext3D / src / com / iver / ai2 / gvsig3d / gui / NavigationMenu3D.java @ 15487

History | View | Annotate | Download (7.4 KB)

1
package com.iver.ai2.gvsig3d.gui;
2

    
3
import java.awt.Component;
4
import java.awt.geom.Rectangle2D;
5
import java.io.File;
6

    
7
import javax.swing.Icon;
8
import javax.swing.ImageIcon;
9
import javax.swing.JMenu;
10
import javax.swing.JMenuBar;
11
import javax.swing.JOptionPane;
12

    
13
import com.iver.ai2.gvsig3d.map3d.layers.FLayers3D;
14
import com.iver.ai2.gvsig3d.navigation.NavigationMode;
15
import com.iver.andami.PluginServices;
16
import com.iver.andami.plugins.Extension;
17
import com.iver.andami.ui.mdiFrame.JMenuItem;
18
import com.iver.andami.ui.mdiFrame.JToolBarButton;
19
import com.iver.cit.gvsig.fmap.DriverException;
20
import com.iver.cit.gvsig.project.documents.gui.FOpenDialog;
21

    
22
import es.upv.ai2.libjosg.planets.Planet.PlanetType;
23
import es.upv.ai2.libjosg.viewer.CustomTerrainManipulator;
24
import es.upv.ai2.libjosg.viewer.OSGViewer;
25

    
26
public class NavigationMenu3D extends Extension {
27

    
28
        public FOpenDialog fopen = null;
29

    
30
        private boolean activa = true;
31

    
32
        private NavigationMode navMode;
33

    
34
        private boolean wireAct = false;
35

    
36
        JMenuItem myMenu = null;
37

    
38
        Icon iconVis = null;
39

    
40
        Icon iconNoVis = null;
41

    
42
        private ImageIcon iconButtonVis;
43

    
44
        private ImageIcon iconButtonNoVis;
45

    
46
        public void execute(String actionCommand) {
47
                // System.out.println("EXECUTE");
48

    
49
                // Getting view3
50
                com.iver.andami.ui.mdiManager.IWindow view = PluginServices
51
                                .getMDIManager().getActiveWindow();
52
                if (!(view instanceof View3D))
53
                        return;
54
                // Casting to View3D
55
                View3D vista3D = (View3D) view;
56

    
57
                navMode = vista3D.getNavMode();
58

    
59
                // Action for ZOOM_SELECT
60
                if (actionCommand.equals("PAN_SELECT")) {
61
                        if (navMode != null)
62
                                navMode.SetRollMode();
63
                } else if (actionCommand.equals("ZOOM_SELECT")) {
64
                        if (navMode != null)
65
                                navMode.SetZoomMode();
66
                } else if (actionCommand.equals("AZIMUT_SELECT")) {
67
                        if (navMode != null)
68
                                navMode.SetAzimutMode();
69
                } else if (actionCommand.equals("DEFAULT_SELECT")) {
70
                        if (navMode != null)
71
                                navMode.SetDefaultMode();
72
                } else if (actionCommand.equals("WIRE_FRAME")) {
73
                        wireAct = !wireAct;
74
                        if (wireAct)
75
                                vista3D.getCanvas3d().getOSGViewer().setPolygonMode(
76
                                                OSGViewer.PolygonModeType.GL_LINE);
77
                        else
78
                                vista3D.getCanvas3d().getOSGViewer().setPolygonMode(
79
                                                OSGViewer.PolygonModeType.GL_FILL);
80
                        vista3D.getCanvas3d().repaint();
81
                } else if (actionCommand.equals("RESET_VIEW")) { // this conditional is to reset view
82
                        // getting the layers 
83
                        FLayers3D layers = (FLayers3D) vista3D.getMapControl()
84
                                        .getMapContext().getLayers();
85
                        try {
86
                                // getting the full extent of all layers added
87
                                Rectangle2D ext = layers.getFullExtent();
88
                                // if there were not layers i would have to insert by code the extent
89
                                if (ext != null)
90
                                        layers.zoomToExtent(ext, 0.0);
91
                                else {
92
                                        // Spherical extent
93
                                        if (vista3D.getPlanet().getType() == PlanetType.SPHERICAL_MODE) {
94
                                                ext = new Rectangle2D.Double(-180.0, -90.0, 360.0,
95
                                                                180.0);
96
                                        } else { // Plane extent
97
                                                ext = new Rectangle2D.Double(-20000000.0, -10000000.0,
98
                                                                40000000.0, 20000000.0);
99
                                        }
100
                                        layers.zoomToExtent(ext, 0.0);
101
                                }
102
                        } catch (DriverException e) {
103
                                // TODO Auto-generated catch block
104
                                e.printStackTrace();
105
                        }
106
                        vista3D.repaint();
107

    
108
                } else if (actionCommand.equals("ACTIVE")) {
109
                        if (vista3D.getPlanet().getType() != PlanetType.PLANE_MODE) {
110

    
111
                                CustomTerrainManipulator ctm = vista3D.getCanvas3d()
112
                                                .getOSGViewer().getCustomTerrainManipulator();
113

    
114
                                JToolBarButton b = (JToolBarButton) PluginServices
115
                                                .getMainFrame().getComponentByName("NORTH");
116
                                if ((!ctm.getNorthOrientation()) && (myMenu != null)) {
117
                                        myMenu.setIcon(iconVis);
118

    
119
                                        if (b != null) {
120
                                                b.setIcon(iconButtonVis);
121
                                                b.setToolTip(PluginServices.getText(this, "Des_north")
122
                                                                + " "
123
                                                                + PluginServices.getText(this, "Active_north"));
124
                                        }
125
                                } else {
126
                                        myMenu.setIcon(iconNoVis);
127

    
128
                                        if (b != null) {
129
                                                b.setIcon(iconButtonNoVis);
130
                                                b.setToolTip(PluginServices.getText(this, "Ac_north")
131
                                                                + " "
132
                                                                + PluginServices.getText(this, "Active_north"));
133
                                        }
134
                                }
135

    
136
                                ctm.setEnabledNorthOrientation(!ctm.getNorthOrientation());
137

    
138
                                // System.out.println("orientacion " +
139
                                // ctm.getNorthOrientation());
140

    
141
                                vista3D.getCanvas3d().repaint();
142
                        } else {
143
                                JOptionPane.showMessageDialog(null, PluginServices.getText(
144
                                                this, "North_plane"));
145
                        }
146

    
147
                }
148

    
149
        }
150

    
151
        public void initialize() {
152
                this.setActiva(true);
153

    
154
                // Getting Main menu bar
155
                JMenuBar jMenuBar = PluginServices.getMainFrame().getJMenuBar();
156

    
157
                PluginServices aux = PluginServices
158
                                .getPluginServices("com.iver.cit.gvsig");
159

    
160
                // Iterate over menu bar to get children menus
161
                for (int i = 0; i < jMenuBar.getMenuCount(); i++) {
162
                        // Getting children
163
                        JMenu menu = jMenuBar.getMenu(i);
164
                        if (menu.getText().equalsIgnoreCase(aux.getText("Vista"))) {
165
                                // Getting children components
166
                                Component[] subMenus = menu.getMenuComponents();
167
                                // Iterate over children menu bar to get children menus
168
                                for (int t = 0; t < subMenus.length; t++) {
169
                                        // Getting all children components
170
                                        Component component = subMenus[t];
171
                                        // Only get instance of JMenu
172
                                        if (component instanceof JMenu) {
173
                                                JMenu subMenuItem = (JMenu) component;
174
                                                // Is "navegacion" menu
175
                                                if (subMenuItem.getText().equalsIgnoreCase(
176
                                                                aux.getText("navegacion"))) {
177
                                                        // Search north option
178
                                                        for (int j = 0; j < subMenuItem.getItemCount(); j++) {
179
                                                                if (subMenuItem.getItem(j).getText()
180
                                                                                .equalsIgnoreCase(
181
                                                                                                PluginServices.getText(this,
182
                                                                                                                "Active_north"))) {
183
                                                                        myMenu = (JMenuItem) subMenuItem.getItem(j);
184
                                                                }
185
                                                        }
186
                                                }
187
                                        }
188
                                }
189
                        }
190
                }
191

    
192
                if (myMenu != null) {
193

    
194
                        File file = new File(this.getClass().getClassLoader().getResource(
195
                                        "images").getFile());
196
                        String path1 = file.getPath() + "/mini_check_2.png";
197
                        String path2 = file.getPath() + "/mini_no_check_2.png";
198

    
199
                        iconVis = new ImageIcon(path1);
200
                        iconNoVis = new ImageIcon(path2);
201

    
202
                        myMenu.setIcon(iconNoVis);
203

    
204
                        String path1B = file.getPath() + "/norte.png";
205
                        String path2B = file.getPath() + "/NorthDes.png";
206
                        iconButtonVis = new ImageIcon(path1B);
207
                        iconButtonNoVis = new ImageIcon(path2B);
208

    
209
                        JToolBarButton b = (JToolBarButton) PluginServices.getMainFrame()
210
                                        .getComponentByName("NORTH");
211
                        if (b != null) {
212
                                b.setToolTip(PluginServices.getText(this, "Ac_north") + " "
213
                                                + PluginServices.getText(this, "Active_north"));
214
                                // if view is in plane mode
215
                                com.iver.andami.ui.mdiManager.IWindow view = PluginServices
216
                                                .getMDIManager().getActiveWindow();
217
                                if (!(view instanceof View3D))
218
                                        return;
219
                                // Casting to View3D
220
                                View3D vista3D = (View3D) view;
221
                                if (vista3D.getPlanet().getType() != PlanetType.SPHERICAL_MODE) {
222
                                        b.setEnabled(false);
223
                                }
224
                        }
225

    
226
                }
227

    
228
        }
229

    
230
        public boolean isEnabled() {
231
                return true;
232
        }
233

    
234
        public boolean isVisible() {
235
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices
236
                                .getMDIManager().getActiveWindow();
237

    
238
                if (f == null) {
239
                        return false;
240
                }
241

    
242
                // Only isVisible = true, where the view3D have layers
243
                if (f instanceof View3D) {
244
                        return true;
245
                }
246
                return false;
247
        }
248

    
249
        public void terminate() {
250
                super.terminate();
251
        }
252

    
253
        public boolean isActiva() {
254
                return activa;
255
        }
256

    
257
        public void setActiva(boolean activa) {
258
                this.activa = activa;
259
        }
260
}