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

History | View | Annotate | Download (3.92 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
    }
65

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

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

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

    
85
    public boolean isEnabled() {
86
        ApplicationManager application = ApplicationLocator.getManager();
87

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

    
97
    public boolean isVisible() {
98
        ApplicationManager application = ApplicationLocator.getManager();
99

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