Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / ext3Dgui / src / org / gvsig / gvsig3dgui / layer / MenuZoom3D.java @ 29938

History | View | Annotate | Download (4.19 KB)

1
package org.gvsig.gvsig3dgui.layer;
2

    
3
import java.awt.geom.Rectangle2D;
4

    
5
import javax.swing.JOptionPane;
6

    
7
import org.gvsig.andami.PluginServices;
8
import org.gvsig.andami.plugins.Extension;
9
import org.gvsig.andami.ui.mdiManager.IWindow;
10
import org.gvsig.app.project.documents.view.IProjectView;
11
import org.gvsig.app.project.documents.view.gui.BaseView;
12
import org.gvsig.fmap.mapcontext.MapContext;
13
import org.gvsig.fmap.mapcontext.layers.FLayer;
14
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
15
import org.gvsig.gvsig3dgui.view.View3D;
16

    
17
import com.iver.ai2.gvsig3d.map3d.layers.Layer3DProps;
18

    
19
public class MenuZoom3D extends Extension {
20

    
21
        private boolean activa = true;
22

    
23
        public void execute(String actionCommand) {
24
                // System.out.println("EXECUTE");
25

    
26
                // Getting view3
27
                IWindow view = PluginServices.getMDIManager().getActiveWindow();
28
                if (!(view instanceof View3D))
29
                        return;
30
                // Casting to View3D
31
                View3D vista3D = (View3D) view;
32
                IProjectView model = vista3D.getModel();
33
                MapContext mapa = model.getMapContext();
34

    
35
                // Action for ZOOM_SELECT
36
                if (actionCommand.equals("ZOOM_SELECT")) {
37
                        // Getting all selected Extent
38
                        FLayer[] selectedExtent = mapa.getLayers().getActives();
39

    
40
                        // If there is not one and is available
41
                        if (selectedExtent.length == 1 && selectedExtent[0].isAvailable()
42
                                        && (selectedExtent[0] instanceof FLyrVect)) {
43
                                // Getting selected layer
44
                                FLyrVect lyr3D = (FLyrVect) selectedExtent[0];
45
                                
46
                                // TODO:COMENTADO 2.0
47
                                // Gettin extend
48
                                // Rectangle2D ex = mapa.getSelectionBounds();
49
                                // ex = lyr3D.getFullExtent();
50
                                // if (ex != null)
51
                                // Doing zoom
52
                                // mapa.zoomToExtent(ex);
53
                        }
54

    
55
                }
56
                // Action for TRANSPARENCY
57
                if (actionCommand.equals("TRANSPARENCY")) {
58
                        FLayer[] selectedExtent = mapa.getLayers().getActives();
59

    
60
                        // If there is not one and is available
61
                        if (selectedExtent.length == 1 && selectedExtent[0].isAvailable()) {
62
                                // // && (selectedExtent[0] instanceof FLyrVect)) {
63
                                FLayer lyr3D = selectedExtent[0];
64
                                Layer3DProps props = Layer3DProps.getLayer3DProps(lyr3D);
65
                                if (props.getType() == Layer3DProps.layer3DImage) {
66
                                        // Generating transparency panel
67
                                        TransparencyPanel transparencyPanel = new TransparencyPanel(
68
                                                        vista3D.getModel());
69
                                        // Showing it
70
                                        PluginServices.getMDIManager().addWindow(transparencyPanel);
71
                                } else {
72
                                        JOptionPane.showMessageDialog(null, PluginServices.getText(
73
                                                        this, "No_available"));
74
                                }
75
                        }
76

    
77
                }
78

    
79
        }
80

    
81
        public void initialize() {
82

    
83
                // Register new icons
84
                // zoom to selection
85
                PluginServices.getIconTheme().registerDefault(
86
                                "zoom-selection-icon",
87
                                this.getClass().getClassLoader().getResource(
88
                                                "images/ZoomSeleccion.png"));
89
                // transparency
90
                PluginServices.getIconTheme().registerDefault(
91
                                "transparency-icon",
92
                                this.getClass().getClassLoader()
93
                                                .getResource("images/Alpha.png"));
94

    
95
                this.setActiva(true);
96
        }
97

    
98
        public boolean isEnabled() {
99
                View3D f = (View3D) PluginServices.getMDIManager().getActiveWindow();
100

    
101
                if (f == null) {
102
                        return false;
103
                }
104
                try {
105

    
106
                        // If the selected layer is instance of FlyrVect isEnable = true
107
                        FLayer[] selected = f.getModel().getMapContext().getLayers()
108
                                        .getActives();
109
                        Layer3DProps props = Layer3DProps.getLayer3DProps(selected[0]);
110
                        if ((selected.length == 1) && (selected[0].isAvailable())) {
111
                                if ((props.getType() == Layer3DProps.layer3DImage)
112
                                                || (props.getType() == Layer3DProps.layer3DVector))
113
                                        return true;
114
                        }
115
                } catch (Exception e) {
116
                        return false;
117
                }
118

    
119
                return false;
120
        
121
        }
122

    
123
        public boolean isVisible() {
124
                IWindow f = PluginServices.getMDIManager().getActiveWindow();
125

    
126
                if (f == null) {
127
                        return false;
128
                }
129

    
130
                // Only isVisible = true, where the view3D have layers
131
                if (f instanceof View3D) {
132
                        BaseView vista = (BaseView) f;
133
                        IProjectView model = vista.getModel();
134
                        MapContext mapa = model.getMapContext();
135

    
136
                        return mapa.getLayers().getLayersCount() > 0;
137
                }
138
                return false;
139
        }
140

    
141
        public void terminate() {
142
                super.terminate();
143
        }
144

    
145
        public boolean isActiva() {
146
                return activa;
147
        }
148

    
149
        public void setActiva(boolean activa) {
150
                this.activa = activa;
151
        }
152
}