Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / MeasureExtension.java @ 45654

History | View | Annotate | Download (4.1 KB)

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

    
25
import org.gvsig.andami.IconThemeHelper;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.app.ApplicationLocator;
28
import org.gvsig.app.ApplicationManager;
29
import org.gvsig.app.project.documents.view.ViewDocument;
30
import org.gvsig.app.project.documents.view.gui.IView;
31
import org.gvsig.fmap.mapcontext.MapContext;
32
import org.gvsig.fmap.mapcontrol.MapControl;
33

    
34
/**
35
 * Extensi?n que controla las operaciones de medida realizadas sobre la vista.
36
 *
37
 * @author Vicente Caballero Navarro
38
 */
39
public class MeasureExtension extends Extension {
40

    
41
    private void registerDistanceUnits() {
42
        MapContext.addDistanceUnit("Millas_Nauticas", "nmi", 1852);
43
        MapContext.addDistanceUnit("Decimetros", "dm", 0.1);
44
    }
45

    
46
    private void registerAreaUnits() {
47
        MapContext.addAreaUnit("Areas", "a", false, 10);
48
        MapContext.addAreaUnit("Hectareas", "ha", false, 100);
49
        MapContext.addAreaUnit("HanegadasV", "hgV", false, 28.8287);
50
        MapContext.addAreaUnit("HanegadasC", "hgC", false, 80.2467);
51
        MapContext.addAreaUnit("Decimetros", "dm", true, 0.1);
52
        MapContext.addAreaUnit("Acres", "acre", false, 63.6149);
53
        MapContext.addAreaUnit("Millas_Nauticas", "nmi", true, 1852);
54
    }
55
    /* (non-Javadoc)
56
     * @see com.iver.andami.plugins.IExtension#initialize()
57
     */
58

    
59
    public void initialize() {
60
        registerDistanceUnits();
61
        registerAreaUnits();
62
        IconThemeHelper.registerIcon("action", "view-query-distance", this);
63
        IconThemeHelper.registerIcon("action", "view-query-area", this);
64
        IconThemeHelper.registerIcon("action", "view-query-feature-angle", this);
65
    }
66

    
67
    /* (non-Javadoc)
68
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
69
     */
70
    public void execute(String s) {
71
        ApplicationManager application = ApplicationLocator.getManager();
72

    
73
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
74
        if (view == null) {
75
            return;
76
        }
77
        MapControl mapCtrl = view.getMapControl();
78

    
79
        if (s.equals("view-query-distance")) {
80
            mapCtrl.setTool("medicion");
81
        } else if (s.equals("view-query-area")) {
82
            mapCtrl.setTool("area");
83
        } else if (s.equals("view-query-feature-angle")) {
84
            mapCtrl.setTool("feature-angle");
85
        }
86
    }
87

    
88
    public boolean isEnabled() {
89
        ApplicationManager application = ApplicationLocator.getManager();
90

    
91
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
92
        if (view == null) {
93
            return false;
94
        }
95
        return true;
96
//        ViewDocument document = view.getViewDocument();
97
//        return document.getMapContext().hasActiveVectorLayers();
98
    }
99

    
100
    public boolean isVisible() {
101
        ApplicationManager application = ApplicationLocator.getManager();
102

    
103
        IView view = (IView) application.getActiveComponent(ViewDocument.class);
104
        if (view == null) {
105
            return false;
106
        }
107
        return true;
108
//        ViewDocument document = view.getViewDocument();
109
//        MapContext mapa = document.getMapContext();
110
//        return mapa.getLayers().getLayersCount() > 0;
111
    }
112
}