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 / AngleGeometryListener.java @ 45732
History | View | Annotate | Download (3.67 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40558 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40558 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40558 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.app.project.documents.view.toolListeners; |
||
25 | |||
26 | 45130 | omartinez | import java.awt.Image; |
27 | 40435 | jjdelcerro | import java.text.NumberFormat; |
28 | |||
29 | import org.gvsig.andami.PluginServices; |
||
30 | import org.gvsig.andami.ui.mdiFrame.MainFrame; |
||
31 | 45130 | omartinez | import org.gvsig.fmap.geom.GeometryLocator; |
32 | import org.gvsig.fmap.geom.GeometryManager; |
||
33 | import org.gvsig.fmap.geom.primitive.Point; |
||
34 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontrol.MapControl; |
35 | 45130 | omartinez | import org.gvsig.fmap.mapcontrol.tools.Behavior.LineGeometry; |
36 | import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
||
37 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
38 | 45130 | omartinez | import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
39 | import org.gvsig.fmap.mapcontrol.tools.Listeners.AngleListener; |
||
40 | 40435 | jjdelcerro | |
41 | 45130 | omartinez | public class AngleGeometryListener implements AngleListener { |
42 | 40435 | jjdelcerro | |
43 | 45130 | omartinez | private final MapControl mapCtrl; |
44 | private MeasureEvent event;
|
||
45 | private final Image cursorImg = PluginServices.getIconTheme() |
||
46 | .get("cursor-info-by-point").getImage();
|
||
47 | 40435 | jjdelcerro | |
48 | 45130 | omartinez | private GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
49 | 40435 | jjdelcerro | |
50 | 45130 | omartinez | public AngleGeometryListener(MapControl mc) {
|
51 | this.mapCtrl = mc;
|
||
52 | 40435 | jjdelcerro | |
53 | 45130 | omartinez | } |
54 | 40435 | jjdelcerro | |
55 | 45130 | omartinez | @Override
|
56 | public void point(PointEvent event) throws BehaviorException { |
||
57 | 40435 | jjdelcerro | |
58 | 45130 | omartinez | } |
59 | 40435 | jjdelcerro | |
60 | 45130 | omartinez | private void showAngleStatusBar(double angle) { |
61 | // double angle = angleBetween2Lines(twoSegment.get(0), twoSegment.get(1));
|
||
62 | 40435 | jjdelcerro | MainFrame mF = PluginServices.getMainFrame(); |
63 | 45130 | omartinez | if (mF != null) { |
64 | NumberFormat nf = NumberFormat.getInstance(); |
||
65 | nf.setMaximumFractionDigits(2);
|
||
66 | double smallAngle;
|
||
67 | double bigAngle;
|
||
68 | if (angle>=180) { |
||
69 | smallAngle = angle-180;
|
||
70 | bigAngle = 180 - smallAngle;
|
||
71 | } else {
|
||
72 | smallAngle = angle; |
||
73 | bigAngle = 180 - smallAngle;
|
||
74 | } |
||
75 | if (smallAngle>bigAngle) {
|
||
76 | double temp = bigAngle;
|
||
77 | bigAngle = smallAngle; |
||
78 | smallAngle = temp; |
||
79 | } |
||
80 | 40435 | jjdelcerro | mF.getStatusBar().setMessage("4",
|
81 | 45130 | omartinez | "Ang.1=" + nf.format(smallAngle));
|
82 | |||
83 | mF.getStatusBar().setMessage("5",
|
||
84 | "Ang.2=" + nf.format(bigAngle));
|
||
85 | 40435 | jjdelcerro | } |
86 | } |
||
87 | 45130 | omartinez | |
88 | @Override
|
||
89 | public void pointDoubleClick(PointEvent event) throws BehaviorException { |
||
90 | |||
91 | } |
||
92 | |||
93 | @Override
|
||
94 | public Image getImageCursor() { |
||
95 | return cursorImg;
|
||
96 | } |
||
97 | |||
98 | @Override
|
||
99 | public boolean cancelDrawing() { |
||
100 | return false; |
||
101 | } |
||
102 | |||
103 | @Override
|
||
104 | public double angle(LineGeometry line1, LineGeometry line2, Point cuadrantPoint) { |
||
105 | double angle = 0; |
||
106 | try {
|
||
107 | angle = line1.angleWith(line2, cuadrantPoint); |
||
108 | showAngleStatusBar(angle); |
||
109 | } catch (Exception ex) { |
||
110 | showAngleStatusBar(0);
|
||
111 | } |
||
112 | return angle;
|
||
113 | } |
||
114 | |||
115 | 40435 | jjdelcerro | } |