svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / fmap / mapcontrol / tools / MeasureListenerImpl.java @ 43510
History | View | Annotate | Download (3.75 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.fmap.mapcontrol.tools; |
||
25 | |||
26 | import java.awt.Image; |
||
27 | import java.awt.Point; |
||
28 | |||
29 | import org.gvsig.fmap.IconThemeHelper; |
||
30 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
31 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
32 | import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
||
33 | import org.gvsig.fmap.mapcontrol.tools.Listeners.PolylineListener; |
||
34 | import org.slf4j.Logger; |
||
35 | import org.slf4j.LoggerFactory; |
||
36 | |||
37 | |||
38 | |||
39 | /**
|
||
40 | * <p>Listener for calculating the length of the segments of a polyline, defined in the associated {@link MapControl MapControl}
|
||
41 | * object.</p>
|
||
42 | *
|
||
43 | * @author Vicente Caballero Navarro
|
||
44 | */
|
||
45 | public class MeasureListenerImpl implements PolylineListener { |
||
46 | |||
47 | private static final Logger logger = LoggerFactory.getLogger(MeasureListenerImpl.class); |
||
48 | /**
|
||
49 | * The image to display when the cursor is active.
|
||
50 | */
|
||
51 | // private final Image iruler = PluginServices.getIconTheme().get("cursor-query-area").getImage();
|
||
52 | /**
|
||
53 | * Reference to the <code>MapControl</code> object that uses.
|
||
54 | */
|
||
55 | protected MapControl mapCtrl;
|
||
56 | |||
57 | /**
|
||
58 | * <p>Creates a new listener for calculating the length of a polyline.</p>
|
||
59 | *
|
||
60 | * @param mc the <code>MapControl</code> where is calculated the length
|
||
61 | */
|
||
62 | public MeasureListenerImpl(MapControl mc) {
|
||
63 | this.mapCtrl = mc;
|
||
64 | } |
||
65 | |||
66 | /*
|
||
67 | * (non-Javadoc)
|
||
68 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#points(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
|
||
69 | */
|
||
70 | public void points(MeasureEvent event) { |
||
71 | double dist = 0; |
||
72 | double distAll = 0; |
||
73 | |||
74 | ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
||
75 | |||
76 | for (int i = 0; i < (event.getXs().length - 1); i++) { |
||
77 | dist = 0;
|
||
78 | |||
79 | Point p = new Point(event.getXs()[i].intValue(), |
||
80 | event.getXs()[i].intValue()); |
||
81 | Point p2 = new Point(event.getXs()[i + 1].intValue(), |
||
82 | event.getXs()[i + 1].intValue());
|
||
83 | |||
84 | ///dist = vp.toMapDistance((int) p.distance(p2));
|
||
85 | dist = vp.distanceWorld(p, p2); |
||
86 | distAll += dist; |
||
87 | } |
||
88 | |||
89 | logger.debug("Distancia = {}, Distancia Total = {}.",dist,distAll);
|
||
90 | } |
||
91 | |||
92 | /*
|
||
93 | * (non-Javadoc)
|
||
94 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
|
||
95 | */
|
||
96 | public Image getImageCursor() { |
||
97 | return IconThemeHelper.getImage("cursor-query-area"); |
||
98 | } |
||
99 | |||
100 | /*
|
||
101 | * (non-Javadoc)
|
||
102 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#pointFixed(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
|
||
103 | */
|
||
104 | public void pointFixed(MeasureEvent event) { |
||
105 | } |
||
106 | |||
107 | /*
|
||
108 | * (non-Javadoc)
|
||
109 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
110 | */
|
||
111 | public boolean cancelDrawing() { |
||
112 | return false; |
||
113 | } |
||
114 | |||
115 | /*
|
||
116 | * (non-Javadoc)
|
||
117 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#polylineFinished(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
|
||
118 | */
|
||
119 | public void polylineFinished(MeasureEvent event) { |
||
120 | } |
||
121 | } |