root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toolListeners / CircleMeasureListener.java @ 38605
History | View | Annotate | Download (4.26 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.app.project.documents.view.toolListeners; |
42 |
|
43 |
|
44 |
import java.awt.Image; |
45 |
import java.awt.geom.Point2D; |
46 |
import java.text.NumberFormat; |
47 |
|
48 |
import org.gvsig.andami.PluginServices; |
49 |
import org.gvsig.fmap.mapcontext.MapContext; |
50 |
import org.gvsig.fmap.mapcontext.ViewPort; |
51 |
import org.gvsig.fmap.mapcontrol.MapControl; |
52 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
53 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
54 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.CircleListener; |
55 |
|
56 |
|
57 |
|
58 |
/**
|
59 |
* <p>Listener for tools that measure using a circular area, displaying
|
60 |
* its radius at the status bar of the application's main frame.</p>
|
61 |
*
|
62 |
* @see CircleListener
|
63 |
*
|
64 |
* @author Laura
|
65 |
*/
|
66 |
public class CircleMeasureListener implements CircleListener { |
67 |
/**
|
68 |
* The image to display when the cursor is active.
|
69 |
*/
|
70 |
private final Image img = PluginServices.getIconTheme().get("cursor-query-distance").getImage(); |
71 |
|
72 |
/**
|
73 |
* The cursor used to work with this tool listener.
|
74 |
*
|
75 |
* @see #getCursor()
|
76 |
*/
|
77 |
// private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img,
|
78 |
// new Point(16, 16), "");
|
79 |
|
80 |
/**
|
81 |
* Reference to the <code>MapControl</code> object that uses.
|
82 |
*/
|
83 |
private MapControl mapCtrl;
|
84 |
|
85 |
/**
|
86 |
* <p>Creates a new listener for measure circular areas.</p>
|
87 |
*
|
88 |
* @param mc the <code>MapControl</code> object where the measures are made
|
89 |
*/
|
90 |
public CircleMeasureListener(MapControl mc) {
|
91 |
this.mapCtrl = mc;
|
92 |
} |
93 |
|
94 |
/*
|
95 |
* (non-Javadoc)
|
96 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.CircleListener#circle(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
|
97 |
*/
|
98 |
public void circle(MeasureEvent event) throws BehaviorException { |
99 |
double dist = 0; |
100 |
double distAll = 0; |
101 |
|
102 |
ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
103 |
|
104 |
for (int i = 0; i < (event.getXs().length - 1); i++) { |
105 |
dist = 0;
|
106 |
|
107 |
Point2D p = new Point2D.Double(event.getXs()[i].doubleValue(), |
108 |
event.getYs()[i].doubleValue()); |
109 |
Point2D p2 = new Point2D.Double(event.getXs()[i + 1].doubleValue(), |
110 |
event.getYs()[i + 1].doubleValue());
|
111 |
|
112 |
///dist = vp.toMapDistance((int) p.distance(p2));
|
113 |
dist = vp.distanceWorld(p, p2); |
114 |
distAll += dist; |
115 |
} |
116 |
//System.out.println("Distancia = " + dist + " Distancia Total = " +
|
117 |
// (distAll));
|
118 |
NumberFormat nf = NumberFormat.getInstance(); |
119 |
nf.setMaximumFractionDigits(2);
|
120 |
if (PluginServices.getMainFrame() != null) |
121 |
{ |
122 |
double[] trans2Meter=MapContext.getDistanceTrans2Meter(); |
123 |
PluginServices.getMainFrame().getStatusBar().setMessage("4",
|
124 |
"Dist:" + nf.format(dist/trans2Meter[mapCtrl.getViewPort().getDistanceUnits()]) + ""); |
125 |
PluginServices.getMainFrame().getStatusBar().setMessage("5",
|
126 |
"Total:" + nf.format(distAll/trans2Meter[mapCtrl.getViewPort().getDistanceUnits()]) + ""); |
127 |
} |
128 |
} |
129 |
|
130 |
/*
|
131 |
* (non-Javadoc)
|
132 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
|
133 |
*/
|
134 |
public Image getImageCursor() { |
135 |
return img;
|
136 |
} |
137 |
|
138 |
/*
|
139 |
* (non-Javadoc)
|
140 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
141 |
*/
|
142 |
public boolean cancelDrawing() { |
143 |
return false; |
144 |
} |
145 |
} |