root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / tools / MeasureListenerImpl.java @ 38564
History | View | Annotate | Download (4.02 KB)
1 | 21203 | vcaballero | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package org.gvsig.fmap.mapcontrol.tools; |
||
42 | |||
43 | import java.awt.Image; |
||
44 | import java.awt.Point; |
||
45 | |||
46 | 38564 | jjdelcerro | import org.gvsig.fmap.IconThemeHelper; |
47 | 21203 | vcaballero | import org.gvsig.fmap.mapcontext.ViewPort; |
48 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
49 | import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
||
50 | import org.gvsig.fmap.mapcontrol.tools.Listeners.PolylineListener; |
||
51 | 32937 | jjdelcerro | import org.slf4j.Logger; |
52 | import org.slf4j.LoggerFactory; |
||
53 | 21203 | vcaballero | |
54 | |||
55 | |||
56 | /**
|
||
57 | * <p>Listener for calculating the length of the segments of a polyline, defined in the associated {@link MapControl MapControl}
|
||
58 | * object.</p>
|
||
59 | *
|
||
60 | * @author Vicente Caballero Navarro
|
||
61 | */
|
||
62 | public class MeasureListenerImpl implements PolylineListener { |
||
63 | 32937 | jjdelcerro | |
64 | private static final Logger logger = LoggerFactory.getLogger(MeasureListenerImpl.class); |
||
65 | 21203 | vcaballero | /**
|
66 | * The image to display when the cursor is active.
|
||
67 | */
|
||
68 | 38564 | jjdelcerro | // private final Image iruler = PluginServices.getIconTheme().get("cursor-query-area").getImage();
|
69 | 21203 | vcaballero | /**
|
70 | * Reference to the <code>MapControl</code> object that uses.
|
||
71 | */
|
||
72 | protected MapControl mapCtrl;
|
||
73 | |||
74 | /**
|
||
75 | * <p>Creates a new listener for calculating the length of a polyline.</p>
|
||
76 | *
|
||
77 | * @param mc the <code>MapControl</code> where is calculated the length
|
||
78 | */
|
||
79 | public MeasureListenerImpl(MapControl mc) {
|
||
80 | this.mapCtrl = mc;
|
||
81 | } |
||
82 | |||
83 | /*
|
||
84 | * (non-Javadoc)
|
||
85 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#points(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
|
||
86 | */
|
||
87 | public void points(MeasureEvent event) { |
||
88 | double dist = 0; |
||
89 | double distAll = 0; |
||
90 | |||
91 | ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
||
92 | |||
93 | for (int i = 0; i < (event.getXs().length - 1); i++) { |
||
94 | dist = 0;
|
||
95 | |||
96 | Point p = new Point(event.getXs()[i].intValue(), |
||
97 | event.getXs()[i].intValue()); |
||
98 | Point p2 = new Point(event.getXs()[i + 1].intValue(), |
||
99 | event.getXs()[i + 1].intValue());
|
||
100 | |||
101 | ///dist = vp.toMapDistance((int) p.distance(p2));
|
||
102 | dist = vp.distanceWorld(p, p2); |
||
103 | distAll += dist; |
||
104 | } |
||
105 | |||
106 | 32937 | jjdelcerro | logger.debug("Distancia = {}, Distancia Total = {}.",dist,distAll);
|
107 | 21203 | vcaballero | } |
108 | |||
109 | /*
|
||
110 | * (non-Javadoc)
|
||
111 | 23645 | vcaballero | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
|
112 | 21203 | vcaballero | */
|
113 | 23645 | vcaballero | public Image getImageCursor() { |
114 | 38564 | jjdelcerro | return IconThemeHelper.getImage("cursor-query-area"); |
115 | 21203 | vcaballero | } |
116 | |||
117 | /*
|
||
118 | * (non-Javadoc)
|
||
119 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#pointFixed(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
|
||
120 | */
|
||
121 | public void pointFixed(MeasureEvent event) { |
||
122 | } |
||
123 | |||
124 | /*
|
||
125 | * (non-Javadoc)
|
||
126 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
||
127 | */
|
||
128 | public boolean cancelDrawing() { |
||
129 | return false; |
||
130 | } |
||
131 | |||
132 | /*
|
||
133 | * (non-Javadoc)
|
||
134 | * @see com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#polylineFinished(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
|
||
135 | */
|
||
136 | public void polylineFinished(MeasureEvent event) { |
||
137 | } |
||
138 | } |