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

History | View | Annotate | Download (5.75 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
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
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
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
26
 *
27
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
28
 *
29
 * This program is free software; you can redistribute it and/or
30
 * modify it under the terms of the GNU General Public License
31
 * as published by the Free Software Foundation; either version 2
32
 * of the License, or (at your option) any later version.
33
 *
34
 * This program is distributed in the hope that it will be useful,
35
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
 * GNU General Public License for more details.
38
 *
39
 * You should have received a copy of the GNU General Public License
40
 * along with this program; if not, write to the Free Software
41
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
42
 *
43
 * For more information, contact:
44
 *
45
 *  Generalitat Valenciana
46
 *   Conselleria d'Infraestructures i Transport
47
 *   Av. Blasco Ib??ez, 50
48
 *   46010 VALENCIA
49
 *   SPAIN
50
 *
51
 *      +34 963862235
52
 *   gvsig@gva.es
53
 *      www.gvsig.gva.es
54
 *
55
 *    or
56
 *
57
 *   IVER T.I. S.A
58
 *   Salamanca 50
59
 *   46005 Valencia
60
 *   Spain
61
 *
62
 *   +34 963163400
63
 *   dac@iver.es
64
 */
65

    
66
package org.gvsig.app.extension;
67

    
68
import org.gvsig.andami.IconThemeHelper;
69
import org.gvsig.andami.PluginServices;
70
import org.gvsig.andami.plugins.Extension;
71
import org.gvsig.app.project.documents.view.ViewDocument;
72
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
73
import org.gvsig.fmap.mapcontext.MapContext;
74
import org.gvsig.fmap.mapcontext.layers.FLayers;
75
import org.gvsig.fmap.mapcontrol.MapControl;
76

    
77

    
78

    
79
/**
80
 * Extensi?n que controla las operaciones de medida realizadas sobre la vista.
81
 *
82
 * @author Vicente Caballero Navarro
83
 */
84
public class MeasureExtension extends Extension {
85
    private void registerDistanceUnits() {
86
            MapContext.addDistanceUnit("Millas_Nauticas","nmi",1852);
87
            MapContext.addDistanceUnit("Decimetros","dm",0.1);
88
    }
89
private void registerAreaUnits(){
90
        MapContext.addAreaUnit("Areas","a",false,10);
91
        MapContext.addAreaUnit("Hectareas","ha",false,100);
92
        MapContext.addAreaUnit("HanegadasV","hgV",false,28.8287);
93
        MapContext.addAreaUnit("HanegadasC","hgC",false,80.2467);
94
        MapContext.addAreaUnit("Decimetros","dm",true,0.1);
95
        MapContext.addAreaUnit("Acres","acre",false,63.6149);
96
        MapContext.addAreaUnit("Millas_Nauticas","nmi",true,1852);
97
}
98
        /* (non-Javadoc)
99
     * @see com.iver.andami.plugins.IExtension#initialize()
100
     */
101
    public void initialize() {
102
            registerDistanceUnits();
103
            registerAreaUnits();
104
            IconThemeHelper.registerIcon("action", "view-query-distance", this);
105
            IconThemeHelper.registerIcon("action", "view-query-area", this);
106
    }
107

    
108
    /* (non-Javadoc)
109
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
110
     */
111
    public void execute(String s) {
112
        org.gvsig.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager()
113
                                                                   .getActiveWindow();
114

    
115
        if (!(view instanceof DefaultViewPanel)) {
116
            return;
117
        }
118

    
119
        DefaultViewPanel vista = (DefaultViewPanel) view;
120
        MapControl mapCtrl = vista.getMapControl();
121

    
122
        if (s.equals("view-query-distance")) {
123
            mapCtrl.setTool("medicion");
124
        } else if (s.equals("view-query-area")) {
125
            mapCtrl.setTool("area");
126
        }
127
    }
128

    
129
    /* (non-Javadoc)
130
     * @see com.iver.andami.plugins.IExtension#isEnabled()
131
     */
132
    public boolean isEnabled() {
133
        org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
134
                                                                .getActiveWindow();
135

    
136
        if (f == null) {
137
            return false;
138
        }
139

    
140
        if (f instanceof DefaultViewPanel) {
141
            DefaultViewPanel vista = (DefaultViewPanel) f;
142
            ViewDocument model = vista.getModel();
143
            MapContext mapa = model.getMapContext();
144

    
145
            FLayers layers = mapa.getLayers();
146

    
147
            for (int i = 0; i < layers.getLayersCount(); i++) {
148
                if (layers.getLayer(i).isAvailable()) {
149
                    return true;
150
                }
151
            }
152
        }
153

    
154
        return false;
155
    }
156

    
157
    /* (non-Javadoc)
158
     * @see com.iver.andami.plugins.IExtension#isVisible()
159
     */
160
    public boolean isVisible() {
161
        org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
162
                                                                .getActiveWindow();
163

    
164
        if (f == null) {
165
            return false;
166
        }
167

    
168
        if (f instanceof DefaultViewPanel) {
169
            DefaultViewPanel vista = (DefaultViewPanel) f;
170
            ViewDocument model = vista.getModel();
171
            MapContext mapa = model.getMapContext();
172

    
173
            return mapa.getLayers().getLayersCount() > 0;
174
        }
175

    
176
        return false;
177
    }
178
}