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 @ 471

History | View | Annotate | Download (4.55 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.fmap.mapcontext.MapContext;
34
import org.gvsig.fmap.mapcontext.layers.FLayers;
35
import org.gvsig.view3d.swing.api.MapControl3D;
36
import org.gvsig.view3d.swing.api.View3DPanel;
37
import org.gvsig.view3d.swing.api.View3DSwingLocator;
38
import org.gvsig.view3d.swing.api.View3DSwingManager;
39
import org.gvsig.view3d.swing.api.View3DSwingManager.TYPE;
40

    
41
/**
42
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
43
 *
44
 */
45
public class View3DExtension extends Extension {
46

    
47
    public void initialize() {
48
        registerIcons();
49
    }
50

    
51
    private void registerIcons() {
52
        IconThemeHelper.registerIcon("view3d", "sphere-view-3d", this);
53
        IconThemeHelper.registerIcon("view3d", "flat-view-3d", this);
54
    }
55

    
56
    public void execute(String actionCommand) {
57

    
58
        TYPE type = getType(actionCommand);
59

    
60
        IView view = getActiveView();
61

    
62
        if (view != null && type != null) {
63
            View3DSwingManager manager = View3DSwingLocator.getManager();
64

    
65
            MapControl3D mapControl3D =
66
                manager.getMapControl3D(view.getMapControl().getMapContext(),
67
                    type);
68
            if (mapControl3D == null || mapControl3D.getType() != type) {
69
                View3DPanel view3DPanel =
70
                    manager.createView3DPanel(view.getMapControl()
71
                        .getMapContext(), type);
72
                view3DPanel.show();
73
            }
74
        }
75
    }
76

    
77
    private TYPE getType(String actionCommand) {
78
        if ("sphere-view-3d".equals(actionCommand)) {
79
            return TYPE.SPHERE;
80
        } else if ("flat-view-3d".equals(actionCommand)) {
81
            return TYPE.FLAT;
82
        }
83
        return null;
84
    }
85

    
86
    public boolean isEnabled() {
87
        return true;
88
    }
89

    
90
    public boolean isVisible() {
91
        return true;
92
    }
93

    
94
    @Override
95
    public boolean isEnabled(String actionCommand) {
96

    
97
        IView view = getActiveView();
98
        if (view != null
99
            && ("sphere-view-3d".equals(actionCommand) || "flat-view-3d"
100
                .equals(actionCommand))) {
101

    
102
            View3DSwingManager manager = View3DSwingLocator.getManager();
103
            MapContext mapContext = view.getMapControl().getMapContext();
104
            TYPE type = getType(actionCommand);
105
            
106
            if(type != null){
107
                
108
                MapControl3D mapControl3D =
109
                    manager.getMapControl3D(mapContext, getType(actionCommand));
110
                
111
                FLayers layers = mapContext.getLayers();
112
                
113
                boolean isEPSG4326 =
114
                    mapContext.getProjection().getAbrev().equals("EPSG:4326");
115
                
116
                if (mapControl3D == null && layers.getLayersCount() > 0
117
                    && isEPSG4326) {
118
                    return true;
119
                }
120
            }
121
        }
122
        return false;
123
    }
124

    
125
    @Override
126
    public boolean isVisible(String actionCommand) {
127
        IView view = getActiveView();
128
        if (view != null) {
129
            return true;
130
        }
131
        return false;
132
    }
133

    
134
    private IView getActiveView() {
135
        ApplicationManager application = ApplicationLocator.getManager();
136
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
137
        return view;
138
    }
139

    
140
    @Override
141
    public boolean canQueryByAction() {
142
        return true;
143
    }
144

    
145
}