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 @ 40596
History | View | Annotate | Download (4.55 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 |
package org.gvsig.app.extension; |
26 |
|
27 |
import org.gvsig.andami.IconThemeHelper; |
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.andami.plugins.Extension; |
30 |
import org.gvsig.app.project.documents.view.ViewDocument; |
31 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
32 |
import org.gvsig.fmap.mapcontext.MapContext; |
33 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
34 |
import org.gvsig.fmap.mapcontrol.MapControl; |
35 |
|
36 |
|
37 |
|
38 |
/**
|
39 |
* Extensi?n que controla las operaciones de medida realizadas sobre la vista.
|
40 |
*
|
41 |
* @author Vicente Caballero Navarro
|
42 |
*/
|
43 |
public class MeasureExtension extends Extension { |
44 |
private void registerDistanceUnits() { |
45 |
MapContext.addDistanceUnit("Millas_Nauticas","nmi",1852); |
46 |
MapContext.addDistanceUnit("Decimetros","dm",0.1); |
47 |
} |
48 |
private void registerAreaUnits(){ |
49 |
MapContext.addAreaUnit("Areas","a",false,10); |
50 |
MapContext.addAreaUnit("Hectareas","ha",false,100); |
51 |
MapContext.addAreaUnit("HanegadasV","hgV",false,28.8287); |
52 |
MapContext.addAreaUnit("HanegadasC","hgC",false,80.2467); |
53 |
MapContext.addAreaUnit("Decimetros","dm",true,0.1); |
54 |
MapContext.addAreaUnit("Acres","acre",false,63.6149); |
55 |
MapContext.addAreaUnit("Millas_Nauticas","nmi",true,1852); |
56 |
} |
57 |
/* (non-Javadoc)
|
58 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
59 |
*/
|
60 |
public void initialize() { |
61 |
registerDistanceUnits(); |
62 |
registerAreaUnits(); |
63 |
IconThemeHelper.registerIcon("action", "view-query-distance", this); |
64 |
IconThemeHelper.registerIcon("action", "view-query-area", this); |
65 |
} |
66 |
|
67 |
/* (non-Javadoc)
|
68 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
69 |
*/
|
70 |
public void execute(String s) { |
71 |
org.gvsig.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager() |
72 |
.getActiveWindow(); |
73 |
|
74 |
if (!(view instanceof DefaultViewPanel)) { |
75 |
return;
|
76 |
} |
77 |
|
78 |
DefaultViewPanel vista = (DefaultViewPanel) view; |
79 |
MapControl mapCtrl = vista.getMapControl(); |
80 |
|
81 |
if (s.equals("view-query-distance")) { |
82 |
mapCtrl.setTool("medicion");
|
83 |
} else if (s.equals("view-query-area")) { |
84 |
mapCtrl.setTool("area");
|
85 |
} |
86 |
} |
87 |
|
88 |
/* (non-Javadoc)
|
89 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
90 |
*/
|
91 |
public boolean isEnabled() { |
92 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
93 |
.getActiveWindow(); |
94 |
|
95 |
if (f == null) { |
96 |
return false; |
97 |
} |
98 |
|
99 |
if (f instanceof DefaultViewPanel) { |
100 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
101 |
ViewDocument model = vista.getModel(); |
102 |
MapContext mapa = model.getMapContext(); |
103 |
|
104 |
FLayers layers = mapa.getLayers(); |
105 |
|
106 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
107 |
if (layers.getLayer(i).isAvailable()) {
|
108 |
return true; |
109 |
} |
110 |
} |
111 |
} |
112 |
|
113 |
return false; |
114 |
} |
115 |
|
116 |
/* (non-Javadoc)
|
117 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
118 |
*/
|
119 |
public boolean isVisible() { |
120 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
121 |
.getActiveWindow(); |
122 |
|
123 |
if (f == null) { |
124 |
return false; |
125 |
} |
126 |
|
127 |
if (f instanceof DefaultViewPanel) { |
128 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
129 |
ViewDocument model = vista.getModel(); |
130 |
MapContext mapa = model.getMapContext(); |
131 |
|
132 |
return mapa.getLayers().getLayersCount() > 0; |
133 |
} |
134 |
|
135 |
return false; |
136 |
} |
137 |
} |