svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toolListeners / CircleMeasureListener.java @ 40558
History | View | Annotate | Download (4 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
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 |
* as published by the Free Software Foundation; either version 3
|
9 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view.toolListeners; |
25 |
|
26 |
|
27 |
import java.awt.Image; |
28 |
import java.awt.geom.Point2D; |
29 |
import java.text.NumberFormat; |
30 |
|
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.fmap.mapcontext.MapContext; |
33 |
import org.gvsig.fmap.mapcontext.ViewPort; |
34 |
import org.gvsig.fmap.mapcontrol.MapControl; |
35 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
36 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
37 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.CircleListener; |
38 |
|
39 |
|
40 |
|
41 |
/**
|
42 |
* <p>Listener for tools that measure using a circular area, displaying
|
43 |
* its radius at the status bar of the application's main frame.</p>
|
44 |
*
|
45 |
* @see CircleListener
|
46 |
*
|
47 |
* @author Laura
|
48 |
*/
|
49 |
public class CircleMeasureListener implements CircleListener { |
50 |
/**
|
51 |
* The image to display when the cursor is active.
|
52 |
*/
|
53 |
private final Image img = PluginServices.getIconTheme().get("cursor-query-distance").getImage(); |
54 |
|
55 |
/**
|
56 |
* The cursor used to work with this tool listener.
|
57 |
*
|
58 |
* @see #getCursor()
|
59 |
*/
|
60 |
// private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img,
|
61 |
// new Point(16, 16), "");
|
62 |
|
63 |
/**
|
64 |
* Reference to the <code>MapControl</code> object that uses.
|
65 |
*/
|
66 |
private MapControl mapCtrl;
|
67 |
|
68 |
/**
|
69 |
* <p>Creates a new listener for measure circular areas.</p>
|
70 |
*
|
71 |
* @param mc the <code>MapControl</code> object where the measures are made
|
72 |
*/
|
73 |
public CircleMeasureListener(MapControl mc) {
|
74 |
this.mapCtrl = mc;
|
75 |
} |
76 |
|
77 |
/*
|
78 |
* (non-Javadoc)
|
79 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.CircleListener#circle(com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent)
|
80 |
*/
|
81 |
public void circle(MeasureEvent event) throws BehaviorException { |
82 |
double dist = 0; |
83 |
double distAll = 0; |
84 |
|
85 |
ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
86 |
|
87 |
for (int i = 0; i < (event.getXs().length - 1); i++) { |
88 |
dist = 0;
|
89 |
|
90 |
Point2D p = new Point2D.Double(event.getXs()[i].doubleValue(), |
91 |
event.getYs()[i].doubleValue()); |
92 |
Point2D p2 = new Point2D.Double(event.getXs()[i + 1].doubleValue(), |
93 |
event.getYs()[i + 1].doubleValue());
|
94 |
|
95 |
///dist = vp.toMapDistance((int) p.distance(p2));
|
96 |
dist = vp.distanceWorld(p, p2); |
97 |
distAll += dist; |
98 |
} |
99 |
//System.out.println("Distancia = " + dist + " Distancia Total = " +
|
100 |
// (distAll));
|
101 |
NumberFormat nf = NumberFormat.getInstance(); |
102 |
nf.setMaximumFractionDigits(2);
|
103 |
if (PluginServices.getMainFrame() != null) |
104 |
{ |
105 |
double[] trans2Meter=MapContext.getDistanceTrans2Meter(); |
106 |
PluginServices.getMainFrame().getStatusBar().setMessage("4",
|
107 |
"Dist:" + nf.format(dist/trans2Meter[mapCtrl.getViewPort().getDistanceUnits()]) + ""); |
108 |
PluginServices.getMainFrame().getStatusBar().setMessage("5",
|
109 |
"Total:" + nf.format(distAll/trans2Meter[mapCtrl.getViewPort().getDistanceUnits()]) + ""); |
110 |
} |
111 |
} |
112 |
|
113 |
/*
|
114 |
* (non-Javadoc)
|
115 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getImageCursor()
|
116 |
*/
|
117 |
public Image getImageCursor() { |
118 |
return img;
|
119 |
} |
120 |
|
121 |
/*
|
122 |
* (non-Javadoc)
|
123 |
* @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
|
124 |
*/
|
125 |
public boolean cancelDrawing() { |
126 |
return false; |
127 |
} |
128 |
} |