Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / MeasureExtension.java @ 28460

History | View | Annotate | Download (4.79 KB)

1 13745 caballero
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42
43
package com.iver.cit.gvsig;
44
45
import com.iver.andami.PluginServices;
46
import com.iver.andami.plugins.Extension;
47
48
import com.iver.cit.gvsig.fmap.MapContext;
49
import com.iver.cit.gvsig.fmap.MapControl;
50
import com.iver.cit.gvsig.fmap.layers.FLayers;
51
import com.iver.cit.gvsig.project.documents.view.IProjectView;
52
import com.iver.cit.gvsig.project.documents.view.gui.View;
53
54
55
/**
56
 * Extensi?n que controla las operaciones de medida realizadas sobre la vista.
57
 *
58
 * @author Vicente Caballero Navarro
59
 */
60
public class MeasureExtension extends Extension {
61 20334 vcaballero
    private void registerDistanceUnits() {
62
            MapContext.addDistanceUnit("Millas_Nauticas","nmi",1852);
63
            MapContext.addDistanceUnit("Decimetros","dm",0.1);
64 20345 vcaballero
    }
65 20334 vcaballero
private void registerAreaUnits(){
66 20345 vcaballero
        MapContext.addAreaUnit("Areas","a",false,10);
67
        MapContext.addAreaUnit("Hectareas","ha",false,100);
68
        MapContext.addAreaUnit("HanegadasV","hgV",false,28.8287);
69
        MapContext.addAreaUnit("HanegadasC","hgC",false,80.2467);
70
        MapContext.addAreaUnit("Decimetros","dm",true,0.1);
71
        MapContext.addAreaUnit("Acres","acre",false,63.6149);
72
        MapContext.addAreaUnit("Millas_Nauticas","nmi",true,1852);
73 20334 vcaballero
}
74
        /* (non-Javadoc)
75 13745 caballero
     * @see com.iver.andami.plugins.IExtension#initialize()
76
     */
77
    public void initialize() {
78 20334 vcaballero
            registerDistanceUnits();
79
            registerAreaUnits();
80 15647 jmvivo
            PluginServices.getIconTheme().registerDefault(
81 14821 jmvivo
                                "view-query-distance",
82
                                this.getClass().getClassLoader().getResource("images/Distancia.png")
83
                        );
84
85 15647 jmvivo
            PluginServices.getIconTheme().registerDefault(
86 14821 jmvivo
                                "view-query-area",
87
                                this.getClass().getClassLoader().getResource("images/Poligono16.png")
88
                        );
89 13745 caballero
    }
90
91
    /* (non-Javadoc)
92
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
93
     */
94
    public void execute(String s) {
95
        com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager()
96
                                                                   .getActiveWindow();
97
98
        if (!(view instanceof View)) {
99
            return;
100
        }
101
102
        View vista = (View) view;
103
        MapControl mapCtrl = vista.getMapControl();
104
105
        if (s.equals("MEDICION")) {
106
            mapCtrl.setTool("medicion");
107
        } else if (s.equals("AREA")) {
108
            mapCtrl.setTool("area");
109
        }
110
    }
111
112
    /* (non-Javadoc)
113
     * @see com.iver.andami.plugins.IExtension#isEnabled()
114
     */
115
    public boolean isEnabled() {
116
        com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
117
                                                                .getActiveWindow();
118
119
        if (f == null) {
120
            return false;
121
        }
122
123
        if (f instanceof View) {
124
            View vista = (View) f;
125
            IProjectView model = vista.getModel();
126
            MapContext mapa = model.getMapContext();
127
128
            FLayers layers = mapa.getLayers();
129
130
            for (int i = 0; i < layers.getLayersCount(); i++) {
131
                if (layers.getLayer(i).isAvailable()) {
132
                    return true;
133
                }
134
            }
135
        }
136
137
        return false;
138
    }
139
140
    /* (non-Javadoc)
141
     * @see com.iver.andami.plugins.IExtension#isVisible()
142
     */
143
    public boolean isVisible() {
144
        com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
145
                                                                .getActiveWindow();
146
147
        if (f == null) {
148
            return false;
149
        }
150
151
        if (f instanceof View) {
152
            View vista = (View) f;
153
            IProjectView model = vista.getModel();
154
            MapContext mapa = model.getMapContext();
155
156
            return mapa.getLayers().getLayersCount() > 0;
157
        }
158
159
        return false;
160
    }
161
}