root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / tools / MeasureListenerImpl.java @ 36684
History | View | Annotate | Download (4.04 KB)
1 |
/* 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 |
import javax.swing.ImageIcon; |
47 |
|
48 |
import org.gvsig.fmap.mapcontext.ViewPort; |
49 |
import org.gvsig.fmap.mapcontrol.MapControl; |
50 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
51 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PolylineListener; |
52 |
import org.slf4j.Logger; |
53 |
import org.slf4j.LoggerFactory; |
54 |
|
55 |
|
56 |
|
57 |
/**
|
58 |
* <p>Listener for calculating the length of the segments of a polyline, defined in the associated {@link MapControl MapControl}
|
59 |
* object.</p>
|
60 |
*
|
61 |
* @author Vicente Caballero Navarro
|
62 |
*/
|
63 |
public class MeasureListenerImpl implements PolylineListener { |
64 |
|
65 |
private static final Logger logger = LoggerFactory.getLogger(MeasureListenerImpl.class); |
66 |
/**
|
67 |
* The image to display when the cursor is active.
|
68 |
*/
|
69 |
private final Image iruler = new ImageIcon(MapControl.class.getClassLoader().getResource( |
70 |
"org/gvsig/fmap/mapcontrol/images/RulerCursor.gif")).getImage();
|
71 |
|
72 |
/**
|
73 |
* Reference to the <code>MapControl</code> object that uses.
|
74 |
*/
|
75 |
protected MapControl mapCtrl;
|
76 |
|
77 |
/**
|
78 |
* <p>Creates a new listener for calculating the length of a polyline.</p>
|
79 |
*
|
80 |
* @param mc the <code>MapControl</code> where is calculated the length
|
81 |
*/
|
82 |
public MeasureListenerImpl(MapControl mc) {
|
83 |
this.mapCtrl = mc;
|
84 |
} |
85 |
|
86 |
/*
|
87 |
* (non-Javadoc)
|
88 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#points(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
|
89 |
*/
|
90 |
public void points(MeasureEvent event) { |
91 |
double dist = 0; |
92 |
double distAll = 0; |
93 |
|
94 |
ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
95 |
|
96 |
for (int i = 0; i < (event.getXs().length - 1); i++) { |
97 |
dist = 0;
|
98 |
|
99 |
Point p = new Point(event.getXs()[i].intValue(), |
100 |
event.getXs()[i].intValue()); |
101 |
Point p2 = new Point(event.getXs()[i + 1].intValue(), |
102 |
event.getXs()[i + 1].intValue());
|
103 |
|
104 |
///dist = vp.toMapDistance((int) p.distance(p2));
|
105 |
dist = vp.distanceWorld(p, p2); |
106 |
distAll += dist; |
107 |
} |
108 |
|
109 |
logger.debug("Distancia = {}, Distancia Total = {}.",dist,distAll);
|
110 |
} |
111 |
|
112 |
/*
|
113 |
* (non-Javadoc)
|
114 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
|
115 |
*/
|
116 |
public Image getImageCursor() { |
117 |
return iruler;
|
118 |
} |
119 |
|
120 |
/*
|
121 |
* (non-Javadoc)
|
122 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#pointFixed(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
|
123 |
*/
|
124 |
public void pointFixed(MeasureEvent event) { |
125 |
} |
126 |
|
127 |
/*
|
128 |
* (non-Javadoc)
|
129 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
130 |
*/
|
131 |
public boolean cancelDrawing() { |
132 |
return false; |
133 |
} |
134 |
|
135 |
/*
|
136 |
* (non-Javadoc)
|
137 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener#polylineFinished(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
|
138 |
*/
|
139 |
public void polylineFinished(MeasureEvent event) { |
140 |
} |
141 |
} |