root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / MeasureExtension.java @ 31496
History | View | Annotate | Download (4.91 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.PluginServices; |
46 |
import org.gvsig.andami.plugins.Extension; |
47 |
import org.gvsig.app.project.documents.view.ViewDocument; |
48 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
49 |
import org.gvsig.fmap.mapcontext.MapContext; |
50 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
51 |
import org.gvsig.fmap.mapcontrol.MapControl; |
52 |
|
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 |
private void registerDistanceUnits() { |
62 |
MapContext.addDistanceUnit("Millas_Nauticas","nmi",1852); |
63 |
MapContext.addDistanceUnit("Decimetros","dm",0.1); |
64 |
} |
65 |
private void registerAreaUnits(){ |
66 |
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 |
} |
74 |
/* (non-Javadoc)
|
75 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
76 |
*/
|
77 |
public void initialize() { |
78 |
registerDistanceUnits(); |
79 |
registerAreaUnits(); |
80 |
PluginServices.getIconTheme().registerDefault( |
81 |
"view-query-distance",
|
82 |
this.getClass().getClassLoader().getResource("images/Distancia.png") |
83 |
); |
84 |
|
85 |
PluginServices.getIconTheme().registerDefault( |
86 |
"view-query-area",
|
87 |
this.getClass().getClassLoader().getResource("images/Poligono16.png") |
88 |
); |
89 |
} |
90 |
|
91 |
/* (non-Javadoc)
|
92 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
93 |
*/
|
94 |
public void execute(String s) { |
95 |
org.gvsig.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager() |
96 |
.getActiveWindow(); |
97 |
|
98 |
if (!(view instanceof DefaultViewPanel)) { |
99 |
return;
|
100 |
} |
101 |
|
102 |
DefaultViewPanel vista = (DefaultViewPanel) 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 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
117 |
.getActiveWindow(); |
118 |
|
119 |
if (f == null) { |
120 |
return false; |
121 |
} |
122 |
|
123 |
if (f instanceof DefaultViewPanel) { |
124 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
125 |
ViewDocument 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 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
145 |
.getActiveWindow(); |
146 |
|
147 |
if (f == null) { |
148 |
return false; |
149 |
} |
150 |
|
151 |
if (f instanceof DefaultViewPanel) { |
152 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
153 |
ViewDocument model = vista.getModel(); |
154 |
MapContext mapa = model.getMapContext(); |
155 |
|
156 |
return mapa.getLayers().getLayersCount() > 0; |
157 |
} |
158 |
|
159 |
return false; |
160 |
} |
161 |
} |