Statistics
| Revision:

gvsig-3d / 2.1 / trunk / org.gvsig.view3d / org.gvsig.view3d.app / org.gvsig.view3d.app.common / src / main / java / org / gvsig / view3d / app / mainplugin / View3DExtension.java @ 539

History | View | Annotate | Download (7.38 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 gvSIG Association
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

    
25
package org.gvsig.view3d.app.mainplugin;
26

    
27
import org.gvsig.andami.IconThemeHelper;
28
import org.gvsig.andami.plugins.Extension;
29
import org.gvsig.app.ApplicationLocator;
30
import org.gvsig.app.ApplicationManager;
31
import org.gvsig.app.project.documents.view.ViewDocument;
32
import org.gvsig.app.project.documents.view.gui.IView;
33
import org.gvsig.app.project.documents.view.legend.gui.ThemeManagerWindow;
34
import org.gvsig.fmap.mapcontext.MapContext;
35
import org.gvsig.fmap.mapcontext.layers.ExtendedPropertiesSupport;
36
import org.gvsig.fmap.mapcontext.layers.FLayers;
37
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
38
import org.gvsig.fmap.mapcontrol.MapControlLocator;
39
import org.gvsig.propertypage.PropertiesPageManager;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.extensionpoint.ExtensionPoint;
42
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
43
import org.gvsig.tools.i18n.I18nManager;
44
import org.gvsig.tools.observer.Notification;
45
import org.gvsig.tools.observer.Observable;
46
import org.gvsig.tools.observer.Observer;
47
import org.gvsig.view3d.app.properties.General3DPreferencePage;
48
import org.gvsig.view3d.app.properties.LayerProperties3DThemeManagerPage;
49
import org.gvsig.view3d.app.properties.RasterLayerProperties3DPanel;
50
import org.gvsig.view3d.app.properties.ViewProperties3DPageFactory;
51
import org.gvsig.view3d.swing.api.MapControl3D;
52
import org.gvsig.view3d.swing.api.View3DPanel;
53
import org.gvsig.view3d.swing.api.View3DSwingLocator;
54
import org.gvsig.view3d.swing.api.View3DSwingManager;
55
import org.gvsig.view3d.swing.api.View3DSwingManager.TYPE;
56

    
57
/**
58
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
59
 *
60
 */
61
public class View3DExtension extends Extension implements Observer {
62

    
63
    public void initialize() {
64
        // Register general 3D properties
65
        I18nManager i18nManager = ToolsLocator.getI18nManager();
66
        ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager();
67
        ExtensionPoint ep = extensionPoints.add("AplicationPreferences", "");
68
        ep.append(i18nManager.getTranslation("3D"), "", new General3DPreferencePage());
69
        
70
        // Register vectorial layer 3D properties panel
71
        ThemeManagerWindow.addPage(LayerProperties3DThemeManagerPage.class);
72
        ThemeManagerWindow.setTabEnabledForLayer(
73
            LayerProperties3DThemeManagerPage.class, FLyrVect.class, true);
74
        
75
        // Regsiter raster layer 3D properties panel
76
        ExtensionPoint point = extensionPoints.get("RasterSEPropertiesDialog");
77
        if (point != null) {
78
            point.append("3D", "3D Raster properties panel",
79
                RasterLayerProperties3DPanel.class);
80
        }
81
        
82
        // Regsiter view properties
83
        PropertiesPageManager manager = MapControlLocator.getPropertiesPageManager();
84
        manager.registerFactory(new ViewProperties3DPageFactory());
85
        
86
        registerIcons();
87
    }
88

    
89
    private void registerIcons() {
90
        IconThemeHelper.registerIcon("view3d", "spherical-view-3d", this);
91
        IconThemeHelper.registerIcon("view3d", "flat-view-3d", this);
92
        IconThemeHelper.registerIcon("view3d", "general-properties-view-3d", this);
93
    }
94

    
95
    public void execute(String actionCommand) {
96

    
97
        TYPE type = getType(actionCommand);
98

    
99
        IView view = getActiveView();
100

    
101
        if (view != null && type != null) {
102
            View3DSwingManager manager = View3DSwingLocator.getManager();
103

    
104
            ViewDocument viewDocument = view.getViewDocument();
105
            MapControl3D mapControl3D =
106
                manager.getMapControl3D(
107
                    (ExtendedPropertiesSupport) viewDocument, type);
108
            if (mapControl3D == null || mapControl3D.getType() != type) {
109
                View3DPanel view3DPanel =
110
                    manager.createView3DPanel(view.getMapControl()
111
                        .getMapContext(), viewDocument.getName(), type,
112
                        (ExtendedPropertiesSupport) viewDocument);
113
                view3DPanel.getMapControl3D().addObserver(this);
114
                view3DPanel.show();
115
            }
116
        }
117
    }
118

    
119
    private TYPE getType(String actionCommand) {
120
        if ("spherical-view-3d".equals(actionCommand)) {
121
            return TYPE.SPHERE;
122
        } else if ("flat-view-3d".equals(actionCommand)) {
123
            return TYPE.FLAT;
124
        }
125
        return null;
126
    }
127

    
128
    public boolean isEnabled() {
129
        return true;
130
    }
131

    
132
    public boolean isVisible() {
133
        return true;
134
    }
135

    
136
    @Override
137
    public boolean isEnabled(String actionCommand) {
138

    
139
        IView view = getActiveView();
140
        if (view != null
141
            && ("spherical-view-3d".equals(actionCommand) || "flat-view-3d"
142
                .equals(actionCommand))) {
143

    
144
            View3DSwingManager manager = View3DSwingLocator.getManager();
145
            MapContext mapContext = view.getMapControl().getMapContext();
146
            TYPE type = getType(actionCommand);
147

    
148
            if (type != null) {
149

    
150
                MapControl3D mapControl3D =
151
                    manager.getMapControl3D(
152
                        (ExtendedPropertiesSupport) view.getViewDocument(),
153
                        getType(actionCommand));
154

    
155
                FLayers layers = mapContext.getLayers();
156

    
157
                boolean isEPSG4326 =
158
                    mapContext.getProjection().getAbrev().equals("EPSG:4326");
159

    
160
                if (mapControl3D == null && layers.getLayersCount() > 0
161
                    && isEPSG4326) {
162
                    return true;
163
                }
164
            }
165
        }
166
        return false;
167
    }
168

    
169
    @Override
170
    public boolean isVisible(String actionCommand) {
171
        IView view = getActiveView();
172
        if (view != null) {
173
            return true;
174
        }
175
        return false;
176
    }
177

    
178
    private IView getActiveView() {
179
        ApplicationManager application = ApplicationLocator.getManager();
180
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
181
        return view;
182
    }
183

    
184
    @Override
185
    public boolean canQueryByAction() {
186
        return true;
187
    }
188

    
189
    public void update(Observable observable, Object notification) {
190
        if (observable instanceof MapControl3D
191
            && notification instanceof Notification) {
192

    
193
            Notification n = (Notification) notification;
194
            if (n.getType().equalsIgnoreCase(
195
                MapControl3D.AFTER_DISPOSE_MAPCONTEX3D_NOTIFICATION)) {
196
                ApplicationManager appManager = ApplicationLocator.getManager();
197
                appManager.refreshMenusAndToolBars();
198
            }
199
        }
200

    
201
    }
202
}