Revision 126
org.gvsig.educa.batovi/trunk/org.gvsig.educa.batovi.mapviewer/org.gvsig.educa.batovi.mapviewer/src/main/java/org/gvsig/educa/batovi/mapviewer/tools/MeasureListener.java | ||
---|---|---|
74 | 74 |
private final StatusBar statusBar; |
75 | 75 |
private final NumberFormat numberFormat; |
76 | 76 |
private final double[] trans2Meter; |
77 |
private final String[] distAbrev; |
|
77 | 78 |
|
78 | 79 |
/** |
79 | 80 |
* <p> |
... | ... | |
91 | 92 |
numberFormat.setMaximumFractionDigits(2); |
92 | 93 |
numberFormat.setMinimumFractionDigits(2); |
93 | 94 |
trans2Meter = MapContext.getDistanceTrans2Meter(); |
95 |
distAbrev = MapContext.getDistanceAbbr(); |
|
94 | 96 |
} |
95 | 97 |
|
96 | 98 |
/* |
... | ... | |
122 | 124 |
} |
123 | 125 |
|
124 | 126 |
double tr2Meter = trans2Meter[vp.getDistanceUnits()]; |
127 |
String strUnits = distAbrev[vp.getDistanceUnits()]; |
|
125 | 128 |
if (statusBar != null) { |
126 | 129 |
StringBuilder sb = new StringBuilder("Dist:"); |
127 | 130 |
sb.append(numberFormat.format(dist / tr2Meter)); |
131 |
sb.append(" "); |
|
132 |
sb.append(strUnits); |
|
128 | 133 |
sb.append(" "); |
129 | 134 |
sb.append("Total:"); |
130 | 135 |
sb.append(numberFormat.format(distAll / tr2Meter)); |
136 |
sb.append(" "); |
|
137 |
sb.append(strUnits); |
|
131 | 138 |
statusBar.setInfo(sb.toString()); |
132 | 139 |
} |
133 | 140 |
} |
org.gvsig.educa.batovi/trunk/org.gvsig.educa.batovi.mapviewer/org.gvsig.educa.batovi.mapviewer/src/main/java/org/gvsig/educa/batovi/mapviewer/tools/AreaListener.java | ||
---|---|---|
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.educa.batovi.mapviewer.tools; |
|
42 |
|
|
43 |
import java.awt.geom.Point2D; |
|
44 |
import java.text.NumberFormat; |
|
45 |
|
|
46 |
import org.gvsig.educa.batovi.mapviewer.StatusBar; |
|
47 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
48 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
49 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
50 |
import org.gvsig.fmap.mapcontrol.tools.AreaListenerImpl; |
|
51 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
|
52 |
|
|
53 |
/** |
|
54 |
* <p> |
|
55 |
* Listener for calculating the area of a polygon, defined in the associated |
|
56 |
* {@link MapControl MapControl} object. |
|
57 |
* </p> |
|
58 |
* <p> |
|
59 |
* Moves the extent of the associated {@link MapControl MapControl} object |
|
60 |
* according the movement between the initial and final points of the line |
|
61 |
* determined by the movement dragged with the third button of the mouse. |
|
62 |
* </p> |
|
63 |
* |
|
64 |
* <p> |
|
65 |
* Updates the status bar of the main frame of the application with the current |
|
66 |
* area. |
|
67 |
* </p> |
|
68 |
* |
|
69 |
* @see AreaListenerImpl |
|
70 |
* |
|
71 |
* @author Vicente Caballero Navarro |
|
72 |
*/ |
|
73 |
public class AreaListener extends AreaListenerImpl { |
|
74 |
|
|
75 |
private final StatusBar statusBar; |
|
76 |
private final NumberFormat numberFormat; |
|
77 |
private final double[] trans2Meter; |
|
78 |
private final String[] areaAbrev; |
|
79 |
private final String[] distAbrev; |
|
80 |
|
|
81 |
/** |
|
82 |
* <p> |
|
83 |
* Creates a new listener for calculating the area of a polygon and |
|
84 |
* displaying it at the status bar of the main frame of the application. |
|
85 |
* </p> |
|
86 |
* |
|
87 |
* @param mc |
|
88 |
* the <code>MapControl</code> where is calculated the area |
|
89 |
*/ |
|
90 |
public AreaListener(MapControl mc, StatusBar statusBar) { |
|
91 |
super(mc); |
|
92 |
this.statusBar = statusBar; |
|
93 |
numberFormat = NumberFormat.getInstance(); |
|
94 |
numberFormat.setMaximumFractionDigits(2); |
|
95 |
numberFormat.setMinimumFractionDigits(2); |
|
96 |
trans2Meter = MapContext.getDistanceTrans2Meter(); |
|
97 |
distAbrev = MapContext.getDistanceAbbr(); |
|
98 |
areaAbrev = MapContext.getAreaAbbr(); |
|
99 |
} |
|
100 |
|
|
101 |
/* |
|
102 |
* (non-Javadoc) |
|
103 |
* |
|
104 |
* @see |
|
105 |
* com.iver.cit.gvsig.fmap.tools.AreaListenerImpl#points(com.iver.cit.gvsig |
|
106 |
* .fmap.tools.Events.MeasureEvent) |
|
107 |
*/ |
|
108 |
@Override |
|
109 |
public void points(MeasureEvent event) { |
|
110 |
this.event = event; |
|
111 |
|
|
112 |
double dist = 0; |
|
113 |
double distAll = 0; |
|
114 |
|
|
115 |
ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
|
116 |
for (int i = 0; i < (event.getXs().length - 1); i++) { |
|
117 |
dist = 0; |
|
118 |
|
|
119 |
Point2D p = |
|
120 |
new Point2D.Double(event.getXs()[i].doubleValue(), |
|
121 |
event.getYs()[i].doubleValue()); |
|
122 |
Point2D p2 = |
|
123 |
new Point2D.Double(event.getXs()[i + 1].doubleValue(), |
|
124 |
event.getYs()[i + 1].doubleValue()); |
|
125 |
dist = vp.distanceWorld(p, p2); |
|
126 |
distAll += dist; |
|
127 |
} |
|
128 |
|
|
129 |
if (statusBar != null) { |
|
130 |
int distanceUnits = vp.getDistanceUnits(); |
|
131 |
int distanceArea = vp.getDistanceArea(); |
|
132 |
StringBuilder sb = new StringBuilder("P: "); |
|
133 |
sb.append(numberFormat.format(distAll / trans2Meter[distanceUnits])); |
|
134 |
sb.append(distAbrev[distanceUnits]); |
|
135 |
sb.append(" "); |
|
136 |
sb.append("A: "); |
|
137 |
sb.append(numberFormat.format(returnArea(new Point2D.Double(event |
|
138 |
.getXs()[event.getXs().length - 2].doubleValue(), |
|
139 |
event.getYs()[event.getYs().length - 2].doubleValue())) |
|
140 |
/ Math.pow(trans2Meter[distanceArea], 2))); |
|
141 |
sb.append(" "); |
|
142 |
sb.append(areaAbrev[distanceArea]); |
|
143 |
statusBar.setInfo(sb.toString()); |
|
144 |
} |
|
145 |
} |
|
146 |
} |
org.gvsig.educa.batovi/trunk/org.gvsig.educa.batovi.mapviewer/org.gvsig.educa.batovi.mapviewer/src/main/java/org/gvsig/educa/batovi/mapviewer/MapToolsRegistrant.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.educa.batovi.mapviewer; |
23 | 23 |
|
24 |
import org.gvsig.educa.batovi.mapviewer.tools.AreaListener; |
|
24 | 25 |
import org.gvsig.educa.batovi.mapviewer.tools.MeasureListener; |
25 | 26 |
import org.gvsig.educa.batovi.mapviewer.tools.StatusBarBehavior; |
26 | 27 |
import org.gvsig.educa.thematicmap.swing.viewer.MapControlToolRegistrant; |
... | ... | |
49 | 50 |
|
50 | 51 |
public static final String TOOL_MEASURE_ID = "mesaure"; |
51 | 52 |
|
53 |
public static final String TOOL_AREA_ID = "area"; |
|
54 |
|
|
52 | 55 |
private final StatusBarBehavior statusBarBehavior = new StatusBarBehavior(); |
53 | 56 |
private final MouseWheelBehavior mouseWheelBehavior = |
54 | 57 |
new MouseWheelBehavior(); |
... | ... | |
73 | 76 |
mapControl.addBehavior(TOOL_MEASURE_ID, new PolylineBehavior( |
74 | 77 |
new MeasureListener(mapControl, statusBar))); |
75 | 78 |
|
79 |
// area |
|
80 |
mapControl.addBehavior(TOOL_AREA_ID, new PolylineBehavior( |
|
81 |
new AreaListener(mapControl, statusBar))); |
|
82 |
|
|
76 | 83 |
mapControl.setTool(TOOL_PAN_ID); |
77 | 84 |
} |
78 | 85 |
|
org.gvsig.educa.batovi/trunk/org.gvsig.educa.batovi.mapviewer/org.gvsig.educa.batovi.mapviewer/src/main/java/org/gvsig/educa/batovi/mapviewer/Main.java | ||
---|---|---|
119 | 119 |
|
120 | 120 |
private AbstractAction setMeasuerToolAction; |
121 | 121 |
|
122 |
private AbstractAction setAreaToolAction; |
|
123 |
|
|
122 | 124 |
public static void main(String args[]) { |
123 | 125 |
new DefaultLibrariesInitializer().fullInitialize(); |
124 | 126 |
|
... | ... | |
254 | 256 |
}; |
255 | 257 |
setMeasuerToolAction.setEnabled(false); |
256 | 258 |
|
259 |
setAreaToolAction = new AbstractAction("Tool area") { |
|
260 |
|
|
261 |
public void actionPerformed(ActionEvent e) { |
|
262 |
setAreaToolAction(); |
|
263 |
} |
|
264 |
}; |
|
265 |
setAreaToolAction.setEnabled(false); |
|
266 |
|
|
257 | 267 |
closeThematicMapAction = new AbstractAction("Close Map") { |
258 | 268 |
|
259 | 269 |
public void actionPerformed(ActionEvent e) { |
... | ... | |
374 | 384 |
toolBar.add(usabManager.createJButton(setPanToolAction)); |
375 | 385 |
toolBar.add(usabManager.createJButton(setZoomToolAction)); |
376 | 386 |
toolBar.add(usabManager.createJButton(setMeasuerToolAction)); |
387 |
toolBar.add(usabManager.createJButton(setAreaToolAction)); |
|
377 | 388 |
|
378 | 389 |
toolBar.addSeparator(sepSize); |
379 | 390 |
toolBar.add(usabManager.createJButton(zoomAllAction)); |
... | ... | |
520 | 531 |
setZoomToolAction.setEnabled(curViewer != null); |
521 | 532 |
setPanToolAction.setEnabled(curViewer != null); |
522 | 533 |
setMeasuerToolAction.setEnabled(curViewer != null); |
534 |
setAreaToolAction.setEnabled(curViewer != null); |
|
523 | 535 |
showHideTocAction.setEnabled(curViewer != null); |
524 | 536 |
closeThematicMapAction.setEnabled(curViewer != null); |
525 | 537 |
zoomAllAction.setEnabled(curViewer != null); |
... | ... | |
594 | 606 |
return; |
595 | 607 |
} |
596 | 608 |
curViewer.setTool(MapToolsRegistrant.TOOL_MEASURE_ID); |
609 |
statusBar.setInfo(""); |
|
597 | 610 |
} |
598 | 611 |
|
612 |
public void setAreaToolAction() { |
|
613 |
if (curViewer == null) { |
|
614 |
return; |
|
615 |
} |
|
616 |
curViewer.setTool(MapToolsRegistrant.TOOL_AREA_ID); |
|
617 |
statusBar.setInfo(""); |
|
618 |
} |
|
619 |
|
|
599 | 620 |
public void createCompilation() { |
600 | 621 |
ThematicMapCompilation compilation = |
601 | 622 |
manager.createCompilationInstance(); |
Also available in: Unified diff