Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / MeasureExtension.java @ 38608

History | View | Annotate | Download (4.79 KB)

1

    
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 org.gvsig.app.extension;
44

    
45
import org.gvsig.andami.IconThemeHelper;
46
import org.gvsig.andami.PluginServices;
47
import org.gvsig.andami.plugins.Extension;
48
import org.gvsig.app.project.documents.view.ViewDocument;
49
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
50
import org.gvsig.fmap.mapcontext.MapContext;
51
import org.gvsig.fmap.mapcontext.layers.FLayers;
52
import org.gvsig.fmap.mapcontrol.MapControl;
53

    
54

    
55

    
56
/**
57
 * Extensi?n que controla las operaciones de medida realizadas sobre la vista.
58
 *
59
 * @author Vicente Caballero Navarro
60
 */
61
public class MeasureExtension extends Extension {
62
    private void registerDistanceUnits() {
63
            MapContext.addDistanceUnit("Millas_Nauticas","nmi",1852);
64
            MapContext.addDistanceUnit("Decimetros","dm",0.1);
65
    }
66
private void registerAreaUnits(){
67
        MapContext.addAreaUnit("Areas","a",false,10);
68
        MapContext.addAreaUnit("Hectareas","ha",false,100);
69
        MapContext.addAreaUnit("HanegadasV","hgV",false,28.8287);
70
        MapContext.addAreaUnit("HanegadasC","hgC",false,80.2467);
71
        MapContext.addAreaUnit("Decimetros","dm",true,0.1);
72
        MapContext.addAreaUnit("Acres","acre",false,63.6149);
73
        MapContext.addAreaUnit("Millas_Nauticas","nmi",true,1852);
74
}
75
        /* (non-Javadoc)
76
     * @see com.iver.andami.plugins.IExtension#initialize()
77
     */
78
    public void initialize() {
79
            registerDistanceUnits();
80
            registerAreaUnits();
81
            IconThemeHelper.registerIcon("action", "view-query-distance", this);
82
            IconThemeHelper.registerIcon("action", "view-query-area", this);
83
    }
84

    
85
    /* (non-Javadoc)
86
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
87
     */
88
    public void execute(String s) {
89
        org.gvsig.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager()
90
                                                                   .getActiveWindow();
91

    
92
        if (!(view instanceof DefaultViewPanel)) {
93
            return;
94
        }
95

    
96
        DefaultViewPanel vista = (DefaultViewPanel) view;
97
        MapControl mapCtrl = vista.getMapControl();
98

    
99
        if (s.equals("MEDICION")) {
100
            mapCtrl.setTool("medicion");
101
        } else if (s.equals("AREA")) {
102
            mapCtrl.setTool("area");
103
        }
104
    }
105

    
106
    /* (non-Javadoc)
107
     * @see com.iver.andami.plugins.IExtension#isEnabled()
108
     */
109
    public boolean isEnabled() {
110
        org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
111
                                                                .getActiveWindow();
112

    
113
        if (f == null) {
114
            return false;
115
        }
116

    
117
        if (f instanceof DefaultViewPanel) {
118
            DefaultViewPanel vista = (DefaultViewPanel) f;
119
            ViewDocument model = vista.getModel();
120
            MapContext mapa = model.getMapContext();
121

    
122
            FLayers layers = mapa.getLayers();
123

    
124
            for (int i = 0; i < layers.getLayersCount(); i++) {
125
                if (layers.getLayer(i).isAvailable()) {
126
                    return true;
127
                }
128
            }
129
        }
130

    
131
        return false;
132
    }
133

    
134
    /* (non-Javadoc)
135
     * @see com.iver.andami.plugins.IExtension#isVisible()
136
     */
137
    public boolean isVisible() {
138
        org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
139
                                                                .getActiveWindow();
140

    
141
        if (f == null) {
142
            return false;
143
        }
144

    
145
        if (f instanceof DefaultViewPanel) {
146
            DefaultViewPanel vista = (DefaultViewPanel) f;
147
            ViewDocument model = vista.getModel();
148
            MapContext mapa = model.getMapContext();
149

    
150
            return mapa.getLayers().getLayersCount() > 0;
151
        }
152

    
153
        return false;
154
    }
155
}