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 @ 44601
History | View | Annotate | Download (3.92 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 41248 | jjdelcerro | * This program is free software; you can redistribute it and/or modify it under
|
7 | * the terms of the GNU General Public License as published by the Free Software
|
||
8 | * Foundation; either version 3 of the License, or (at your option) any later
|
||
9 | * version.
|
||
10 | 40558 | jjdelcerro | *
|
11 | 41248 | jjdelcerro | * This program is distributed in the hope that it will be useful, but WITHOUT
|
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
13 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
14 | * details.
|
||
15 | 40558 | jjdelcerro | *
|
16 | 41248 | jjdelcerro | * You should have received a copy of the GNU General Public License along with
|
17 | * this program; if not, write to the Free Software Foundation, Inc., 51
|
||
18 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
19 | 40558 | jjdelcerro | *
|
20 | 41248 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40558 | jjdelcerro | */
|
23 | 40435 | jjdelcerro | package org.gvsig.app.extension; |
24 | |||
25 | import org.gvsig.andami.IconThemeHelper; |
||
26 | import org.gvsig.andami.plugins.Extension; |
||
27 | 41248 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
28 | import org.gvsig.app.ApplicationManager; |
||
29 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
30 | 41248 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.IView; |
31 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.MapContext; |
32 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
33 | |||
34 | /**
|
||
35 | * Extensi?n que controla las operaciones de medida realizadas sobre la vista.
|
||
36 | *
|
||
37 | * @author Vicente Caballero Navarro
|
||
38 | */
|
||
39 | public class MeasureExtension extends Extension { |
||
40 | 41248 | jjdelcerro | |
41 | 40435 | jjdelcerro | private void registerDistanceUnits() { |
42 | 41248 | jjdelcerro | MapContext.addDistanceUnit("Millas_Nauticas", "nmi", 1852); |
43 | MapContext.addDistanceUnit("Decimetros", "dm", 0.1); |
||
44 | 40435 | jjdelcerro | } |
45 | 41248 | jjdelcerro | |
46 | private void registerAreaUnits() { |
||
47 | MapContext.addAreaUnit("Areas", "a", false, 10); |
||
48 | MapContext.addAreaUnit("Hectareas", "ha", false, 100); |
||
49 | MapContext.addAreaUnit("HanegadasV", "hgV", false, 28.8287); |
||
50 | MapContext.addAreaUnit("HanegadasC", "hgC", false, 80.2467); |
||
51 | MapContext.addAreaUnit("Decimetros", "dm", true, 0.1); |
||
52 | MapContext.addAreaUnit("Acres", "acre", false, 63.6149); |
||
53 | MapContext.addAreaUnit("Millas_Nauticas", "nmi", true, 1852); |
||
54 | } |
||
55 | /* (non-Javadoc)
|
||
56 | 40435 | jjdelcerro | * @see com.iver.andami.plugins.IExtension#initialize()
|
57 | */
|
||
58 | 41248 | jjdelcerro | |
59 | 40435 | jjdelcerro | public void initialize() { |
60 | 41248 | jjdelcerro | registerDistanceUnits(); |
61 | registerAreaUnits(); |
||
62 | IconThemeHelper.registerIcon("action", "view-query-distance", this); |
||
63 | IconThemeHelper.registerIcon("action", "view-query-area", this); |
||
64 | 40435 | jjdelcerro | } |
65 | |||
66 | /* (non-Javadoc)
|
||
67 | * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
||
68 | */
|
||
69 | public void execute(String s) { |
||
70 | 41248 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
71 | 40435 | jjdelcerro | |
72 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
73 | if (view == null) { |
||
74 | 40435 | jjdelcerro | return;
|
75 | } |
||
76 | 41248 | jjdelcerro | MapControl mapCtrl = view.getMapControl(); |
77 | 40435 | jjdelcerro | |
78 | if (s.equals("view-query-distance")) { |
||
79 | mapCtrl.setTool("medicion");
|
||
80 | } else if (s.equals("view-query-area")) { |
||
81 | mapCtrl.setTool("area");
|
||
82 | } |
||
83 | } |
||
84 | |||
85 | public boolean isEnabled() { |
||
86 | 41248 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
87 | 40435 | jjdelcerro | |
88 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
89 | if (view == null) { |
||
90 | 40435 | jjdelcerro | return false; |
91 | } |
||
92 | 41841 | jjdelcerro | return true; |
93 | // ViewDocument document = view.getViewDocument();
|
||
94 | // return document.getMapContext().hasActiveVectorLayers();
|
||
95 | 40435 | jjdelcerro | } |
96 | |||
97 | public boolean isVisible() { |
||
98 | 41248 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
99 | 40435 | jjdelcerro | |
100 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
101 | if (view == null) { |
||
102 | 40435 | jjdelcerro | return false; |
103 | } |
||
104 | 41841 | jjdelcerro | return true; |
105 | // ViewDocument document = view.getViewDocument();
|
||
106 | // MapContext mapa = document.getMapContext();
|
||
107 | // return mapa.getLayers().getLayersCount() > 0;
|
||
108 | 40435 | jjdelcerro | } |
109 | } |