Revision 44246
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.mainplugin/src/main/java/org/gvsig/selectiontools/app/extension/tools/CircleSelectionListener.java | ||
---|---|---|
74 | 74 |
import org.gvsig.fmap.mapcontrol.MapControl; |
75 | 75 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
76 | 76 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
77 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.AbstractCircleListener; |
|
77 | 78 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.CircleListener; |
78 | 79 |
|
79 | 80 |
/** |
... | ... | |
85 | 86 |
* |
86 | 87 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) |
87 | 88 |
*/ |
88 |
public class CircleSelectionListener implements CircleListener {
|
|
89 |
public class CircleSelectionListener extends AbstractCircleListener {
|
|
89 | 90 |
|
90 | 91 |
|
91 | 92 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.selectiontools.app/org.gvsig.selectiontools.app.mainplugin/src/main/java/org/gvsig/selectiontools/app/extension/tools/behavior/CircleSelectionBehavior.java | ||
---|---|---|
60 | 60 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
61 | 61 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.CircleBehavior; |
62 | 62 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
63 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.AbstractCircleListener; |
|
63 | 64 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.CircleListener; |
64 | 65 |
|
65 | 66 |
/** |
... | ... | |
79 | 80 |
*/ |
80 | 81 |
private Point2D m_PointAnt; |
81 | 82 |
|
82 |
public CircleSelectionBehavior(CircleListener zili) { |
|
83 |
public CircleSelectionBehavior(AbstractCircleListener zili) {
|
|
83 | 84 |
super(zili); |
84 | 85 |
|
85 | 86 |
listener = zili; |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/BaseMapTool.java | ||
---|---|---|
17 | 17 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
18 | 18 |
import org.gvsig.fmap.mapcontrol.tools.Events.MoveEvent; |
19 | 19 |
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent; |
20 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.AbstractCircleListener; |
|
20 | 21 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.CircleListener; |
21 | 22 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PanListener; |
22 | 23 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener; |
... | ... | |
24 | 25 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.RectangleListener; |
25 | 26 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
26 | 27 |
|
27 |
public class BaseMapTool implements MapTool, ActionListener, IBehavior, |
|
28 |
ToolListener, CircleListener, PanListener, PointListener, PolylineListener, RectangleListener {
|
|
28 |
public class BaseMapTool extends AbstractCircleListener implements MapTool, ActionListener, IBehavior,
|
|
29 |
ToolListener, PanListener, PointListener, PolylineListener, RectangleListener { |
|
29 | 30 |
|
30 | 31 |
protected int type = TYPE_UNKNOW; |
31 | 32 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/Behavior/Behavior.java | ||
---|---|---|
37 | 37 |
import org.gvsig.fmap.geom.GeometryManager; |
38 | 38 |
import org.gvsig.fmap.geom.primitive.Arc; |
39 | 39 |
import org.gvsig.fmap.geom.primitive.Circle; |
40 |
import org.gvsig.fmap.geom.primitive.Ellipse; |
|
40 | 41 |
import org.gvsig.fmap.geom.primitive.Point; |
41 | 42 |
import org.gvsig.fmap.mapcontrol.MapControl; |
42 | 43 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
... | ... | |
381 | 382 |
|
382 | 383 |
return circle; |
383 | 384 |
} |
385 |
|
|
386 |
protected Ellipse createEllipse(Point2D p1, Point2D p2, Point2D p3) { |
|
387 |
Ellipse ellipse = null; |
|
388 |
double radious = 1; |
|
389 |
try { |
|
390 |
ellipse = (Ellipse) geomManager.create(TYPES.ELLIPSE, SUBTYPES.GEOM2D); |
|
391 |
radious = p2.distance(p3); |
|
392 |
ellipse.setPoints(createPoint(p1), createPoint(p2), radious); |
|
393 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) { |
|
394 |
|
|
395 |
LOG.error("Error creating ellipse with centerX=" + p1.toString() |
|
396 |
+ ", centerY=" + p2.toString() + ", radious=" + radious, |
|
397 |
new CreateGeometryException(TYPES.ELLIPSE, SUBTYPES.GEOM2D, e)); |
|
398 |
} |
|
384 | 399 |
|
400 |
return ellipse; |
|
401 |
} |
|
385 | 402 |
// /** |
386 | 403 |
// * Create a lineString from a GeneralPath. If there is an |
387 | 404 |
// * error return <code>null</code> and add the error |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/Behavior/CircleBehavior.java | ||
---|---|---|
28 | 28 |
import java.awt.event.MouseEvent; |
29 | 29 |
import java.awt.geom.Point2D; |
30 | 30 |
import java.awt.geom.Rectangle2D; |
31 |
import java.awt.image.BufferedImage; |
|
32 |
import java.util.Date; |
|
33 | 31 |
|
34 | 32 |
import org.gvsig.fmap.geom.primitive.Arc; |
35 | 33 |
import org.gvsig.fmap.mapcontext.ViewPort; |
36 | 34 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
37 | 35 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
38 | 36 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
39 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.CircleListener; |
|
37 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.AbstractCircleListener;
|
|
40 | 38 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PolylineListener; |
41 | 39 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
42 | 40 |
|
43 | 41 |
import org.slf4j.Logger; |
44 | 42 |
import org.slf4j.LoggerFactory; |
45 | 43 |
|
46 |
|
|
47 |
|
|
48 | 44 |
/** |
49 |
* <p>Behavior that allows user to draw a circle on the image of the associated |
|
50 |
* <code>MapControl</code> using a {@link PolylineListener PolylineListener}.</p> |
|
45 |
* <p> |
|
46 |
* Behavior that allows user to draw a circle on the image of the associated |
|
47 |
* <code>MapControl</code> using a |
|
48 |
* {@link PolylineListener PolylineListener}.</p> |
|
51 | 49 |
* |
52 | 50 |
* @author Laura |
53 | 51 |
* @author Pablo Piqueras Bartolom? |
54 | 52 |
*/ |
55 | 53 |
public class CircleBehavior extends Behavior { |
56 |
private static final Logger logger = LoggerFactory.getLogger(CircleBehavior.class); |
|
57 | 54 |
|
58 |
/** |
|
59 |
* First point set, that represents the center of the circle. |
|
60 |
*/ |
|
61 |
protected Point2D m_FirstPoint; |
|
55 |
private static final Logger logger = LoggerFactory.getLogger(CircleBehavior.class); |
|
62 | 56 |
|
63 |
/**
|
|
64 |
* Second point set, that permits calculate the radius of the circle.
|
|
65 |
*/
|
|
66 |
protected Point2D m_LastPoint;
|
|
57 |
/**
|
|
58 |
* First point set, that represents the center of the circle.
|
|
59 |
*/
|
|
60 |
protected Point2D m_FirstPoint;
|
|
67 | 61 |
|
68 |
/** |
|
69 |
* Tool listener used to work with the <code>MapControl</code> object. |
|
70 |
* |
|
71 |
* @see #getListener() |
|
72 |
* @see #setListener(ToolListener) |
|
73 |
*/ |
|
74 |
private CircleListener listener; |
|
62 |
/** |
|
63 |
* Second point set, that permits calculate the radius of the circle. |
|
64 |
*/ |
|
65 |
protected Point2D m_LastPoint; |
|
75 | 66 |
|
76 |
/** |
|
77 |
* Determines if user setting the radius of the circle (with one click of the button 1 of the mouse), or not. |
|
78 |
*/ |
|
79 |
protected boolean isClicked = false; |
|
67 |
/** |
|
68 |
* Tool listener used to work with the <code>MapControl</code> object. |
|
69 |
* |
|
70 |
* @see #getListener() |
|
71 |
* @see #setListener(ToolListener) |
|
72 |
*/ |
|
73 |
private AbstractCircleListener listener; |
|
80 | 74 |
|
81 |
/** |
|
82 |
* <p>Creates a new behavior for selecting circle areas.</p> |
|
83 |
* |
|
84 |
* @param zili listener used to permit this object to work with the associated <code>MapControl</code> |
|
85 |
*/ |
|
86 |
public CircleBehavior(CircleListener zili) { |
|
87 |
listener = zili; |
|
88 |
} |
|
75 |
/** |
|
76 |
* Determines if user setting the radius of the circle (with one click of |
|
77 |
* the button 1 of the mouse), or not. |
|
78 |
*/ |
|
79 |
protected boolean isClicked = false; |
|
89 | 80 |
|
90 |
/* |
|
81 |
/** |
|
82 |
* <p> |
|
83 |
* Creates a new behavior for selecting circle areas.</p> |
|
84 |
* |
|
85 |
* @param zili listener used to permit this object to work with the |
|
86 |
* associated <code>MapControl</code> |
|
87 |
*/ |
|
88 |
public CircleBehavior(AbstractCircleListener zili) { |
|
89 |
listener = zili; |
|
90 |
} |
|
91 |
|
|
92 |
/* |
|
91 | 93 |
* (non-Javadoc) |
92 | 94 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics) |
93 |
*/ |
|
94 |
public void paintComponent(MapControlDrawer mapControlDrawer) { |
|
95 |
double radio; |
|
96 |
mapControlDrawer.setColor(Color.black); |
|
95 |
*/ |
|
96 |
@Override |
|
97 |
public void paintComponent(MapControlDrawer mapControlDrawer) { |
|
98 |
double radio; |
|
99 |
mapControlDrawer.setColor(Color.black); |
|
97 | 100 |
|
101 |
if ((m_FirstPoint != null) && (m_LastPoint != null)) { |
|
102 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
103 |
Point2D p1 = vp.toMapPoint(m_FirstPoint); |
|
104 |
Point2D p2 = vp.toMapPoint(m_LastPoint); |
|
98 | 105 |
|
99 |
if ((m_FirstPoint != null) && (m_LastPoint != null)) { |
|
100 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
101 |
Point2D p1 = vp.toMapPoint(m_FirstPoint); |
|
102 |
Point2D p2 = vp.toMapPoint(m_LastPoint); |
|
106 |
radio = p1.distance(p2); |
|
107 |
if (radio > 0.0) { |
|
108 |
Arc arc = null; |
|
109 |
arc = createArc(p1.getX(), p1.getY(), |
|
110 |
radio, 0, Math.PI * 2); |
|
111 |
if (arc != null) { |
|
112 |
mapControlDrawer.draw(arc); |
|
113 |
} |
|
114 |
} |
|
103 | 115 |
|
104 |
radio = p1.distance(p2); |
|
105 |
if(radio!=0.0){ |
|
106 |
Arc arc = null; |
|
107 |
arc = createArc(p1.getX(), p1.getY(), |
|
108 |
radio, 0, Math.PI*2); |
|
109 |
if (arc != null) { |
|
110 |
mapControlDrawer.draw(arc); |
|
111 |
} |
|
112 |
} |
|
116 |
} |
|
117 |
} |
|
113 | 118 |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
/* |
|
119 |
/* |
|
118 | 120 |
* (non-Javadoc) |
119 | 121 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent) |
120 |
*/ |
|
121 |
public void mousePressed(MouseEvent e) { |
|
122 |
if (this.isMyButton(e)) { |
|
123 |
m_FirstPoint = e.getPoint(); |
|
124 |
isClicked = true; |
|
122 |
*/ |
|
123 |
@Override |
|
124 |
public void mousePressed(MouseEvent e) { |
|
125 |
if (this.isMyButton(e)) { |
|
126 |
m_FirstPoint = e.getPoint(); |
|
127 |
isClicked = true; |
|
128 |
getMapControl().repaint(); |
|
129 |
if (listener.cancelDrawing()) { |
|
130 |
getMapControl().cancelDrawing(); |
|
131 |
isClicked = false; |
|
125 | 132 |
getMapControl().repaint(); |
126 |
if (listener.cancelDrawing()) { |
|
127 |
getMapControl().cancelDrawing(); |
|
128 |
isClicked = false; |
|
129 |
getMapControl().repaint(); |
|
130 |
} |
|
131 | 133 |
} |
134 |
} |
|
132 | 135 |
|
136 |
} |
|
133 | 137 |
|
134 |
} |
|
135 |
|
|
136 |
/* |
|
138 |
/* |
|
137 | 139 |
* (non-Javadoc) |
138 | 140 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseReleased(java.awt.event.MouseEvent) |
139 |
*/ |
|
140 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
|
141 |
if( this.isMyButton(e) ) { |
|
142 |
m_FirstPoint = null; |
|
143 |
m_LastPoint = null; |
|
144 |
isClicked = false; |
|
145 |
} |
|
146 |
} |
|
141 |
*/ |
|
142 |
@Override |
|
143 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
|
147 | 144 |
|
148 |
/* |
|
145 |
if (m_FirstPoint == null) { |
|
146 |
return; |
|
147 |
} |
|
148 |
|
|
149 |
m_LastPoint = e.getPoint(); |
|
150 |
|
|
151 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
152 |
|
|
153 |
Point2D p1 = vp.toMapPoint(m_FirstPoint); |
|
154 |
Point2D p2 = vp.toMapPoint(m_LastPoint); |
|
155 |
|
|
156 |
Double[] x = new Double[2]; |
|
157 |
Double[] y = new Double[2]; |
|
158 |
x[0] = p1.getX(); |
|
159 |
x[1] = p2.getX(); |
|
160 |
y[0] = p1.getY(); |
|
161 |
y[1] = p2.getY(); |
|
162 |
MeasureEvent event = new MeasureEvent(x, y, e); |
|
163 |
|
|
164 |
listener.circleFinished(event); |
|
165 |
|
|
166 |
if (this.isMyButton(e)) { |
|
167 |
m_FirstPoint = null; |
|
168 |
m_LastPoint = null; |
|
169 |
isClicked = false; |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
/* |
|
149 | 174 |
* (non-Javadoc) |
150 | 175 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt.event.MouseEvent) |
151 |
*/ |
|
152 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
|
153 |
mouseMoved(e); |
|
154 |
} |
|
176 |
*/ |
|
177 |
@Override |
|
178 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
|
179 |
mouseMoved(e); |
|
180 |
} |
|
155 | 181 |
|
156 |
/*
|
|
182 |
/*
|
|
157 | 183 |
* (non-Javadoc) |
158 | 184 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseMoved(java.awt.event.MouseEvent) |
159 |
*/ |
|
160 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
161 |
if (m_FirstPoint == null) return; |
|
185 |
*/ |
|
186 |
@Override |
|
187 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
188 |
if (m_FirstPoint == null) { |
|
189 |
return; |
|
190 |
} |
|
162 | 191 |
|
163 |
m_LastPoint = e.getPoint();
|
|
192 |
m_LastPoint = e.getPoint();
|
|
164 | 193 |
|
165 |
ViewPort vp = getMapControl().getMapContext().getViewPort();
|
|
194 |
ViewPort vp = getMapControl().getMapContext().getViewPort();
|
|
166 | 195 |
|
167 |
Point2D p1 = vp.toMapPoint(m_FirstPoint);
|
|
168 |
Point2D p2 = vp.toMapPoint(m_LastPoint);
|
|
196 |
Point2D p1 = vp.toMapPoint(m_FirstPoint);
|
|
197 |
Point2D p2 = vp.toMapPoint(m_LastPoint);
|
|
169 | 198 |
|
170 |
// Fijamos el nuevo extent
|
|
171 |
Rectangle2D.Double r = new Rectangle2D.Double();
|
|
172 |
r.setFrameFromDiagonal(p1, p2);
|
|
199 |
// Fijamos el nuevo extent
|
|
200 |
Rectangle2D.Double r = new Rectangle2D.Double();
|
|
201 |
r.setFrameFromDiagonal(p1, p2);
|
|
173 | 202 |
|
174 |
Rectangle2D rectPixel = new Rectangle();
|
|
175 |
rectPixel.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
|
|
203 |
Rectangle2D rectPixel = new Rectangle();
|
|
204 |
rectPixel.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
|
|
176 | 205 |
|
177 |
Double[] x = new Double[2];
|
|
178 |
Double[] y = new Double[2];
|
|
179 |
x[0] = new Double(p1.getX());
|
|
180 |
x[1] = new Double(p2.getX());
|
|
181 |
y[0] = new Double(p1.getY());
|
|
182 |
y[1] = new Double(p2.getY());
|
|
183 |
MeasureEvent event = new MeasureEvent(x, y, e);
|
|
184 |
listener.circle(event);
|
|
185 |
getMapControl().repaint();
|
|
186 |
}
|
|
206 |
Double[] x = new Double[2];
|
|
207 |
Double[] y = new Double[2];
|
|
208 |
x[0] = p1.getX();
|
|
209 |
x[1] = p2.getX();
|
|
210 |
y[0] = p1.getY();
|
|
211 |
y[1] = p2.getY();
|
|
212 |
MeasureEvent event = new MeasureEvent(x, y, e);
|
|
213 |
listener.circle(event);
|
|
214 |
getMapControl().repaint();
|
|
215 |
}
|
|
187 | 216 |
|
188 |
/** |
|
189 |
* <p>Sets a tool listener to work with the <code>MapControl</code> using this behavior.</p> |
|
190 |
* |
|
191 |
* @param listener a <code>CircleListener</code> object for this behavior |
|
192 |
*/ |
|
193 |
public void setListener(ToolListener listener) { |
|
194 |
this.listener = (CircleListener)listener; |
|
195 |
} |
|
217 |
/** |
|
218 |
* <p> |
|
219 |
* Sets a tool listener to work with the <code>MapControl</code> using this |
|
220 |
* behavior.</p> |
|
221 |
* |
|
222 |
* @param listener a <code>CircleListener</code> object for this behavior |
|
223 |
*/ |
|
224 |
public void setListener(ToolListener listener) { |
|
225 |
this.listener = (AbstractCircleListener) listener; |
|
226 |
} |
|
196 | 227 |
|
197 |
/*
|
|
228 |
/*
|
|
198 | 229 |
* (non-Javadoc) |
199 | 230 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener() |
200 |
*/ |
|
201 |
public ToolListener getListener() { |
|
202 |
return listener; |
|
203 |
} |
|
231 |
*/ |
|
232 |
@Override |
|
233 |
public ToolListener getListener() { |
|
234 |
return listener; |
|
235 |
} |
|
204 | 236 |
} |
205 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/Behavior/FreehandBehavior.java | ||
---|---|---|
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.fmap.mapcontrol.tools.Behavior; |
|
25 |
|
|
26 |
import java.awt.Color; |
|
27 |
import java.awt.event.MouseEvent; |
|
28 |
import java.awt.geom.Point2D; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.List; |
|
31 |
import org.gvsig.fmap.geom.Geometry; |
|
32 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
33 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
34 |
|
|
35 |
import org.gvsig.fmap.geom.primitive.Line; |
|
36 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
|
37 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
38 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
|
39 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.PolylineListener; |
|
40 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
|
41 |
|
|
42 |
/** |
|
43 |
* <p> |
|
44 |
* Behavior that allows user to draw a polyline by its vertexes on the image of |
|
45 |
* the associated <code>MapControl</code> using a |
|
46 |
* {@link PolylineListener PolylineListener}.</p> |
|
47 |
* |
|
48 |
* @author Vicente Caballero Navarro |
|
49 |
* @author Pablo Piqueras Bartolom? |
|
50 |
*/ |
|
51 |
public class FreehandBehavior extends Behavior { |
|
52 |
|
|
53 |
/** |
|
54 |
* The abscissa coordinate of all vertexes of the polyline. |
|
55 |
*/ |
|
56 |
protected List<Double> arrayX = new ArrayList<>(); |
|
57 |
|
|
58 |
/** |
|
59 |
* The ordinate coordinate of all vertexes of the polyline. |
|
60 |
*/ |
|
61 |
protected List<Double> arrayY = new ArrayList<>(); |
|
62 |
|
|
63 |
/** |
|
64 |
* Determines if user is setting the vertexes (with one click of the button |
|
65 |
* 1 of the mouse), or not. |
|
66 |
*/ |
|
67 |
protected boolean isClicked = false; |
|
68 |
|
|
69 |
/** |
|
70 |
* Tool listener used to work with the <code>MapControl</code> object. |
|
71 |
* |
|
72 |
* @see #getListener() |
|
73 |
* @see #setListener(ToolListener) |
|
74 |
*/ |
|
75 |
protected PolylineListener listener; |
|
76 |
|
|
77 |
/** |
|
78 |
* <p> |
|
79 |
* Creates a new behavior for drawing a polyline by its vertexes.</p> |
|
80 |
* |
|
81 |
* @param mli listener used to permit this object to work with the |
|
82 |
* associated <code>MapControl</code> |
|
83 |
*/ |
|
84 |
public FreehandBehavior(PolylineListener mli) { |
|
85 |
super(Behavior.BUTTON_LEFT); |
|
86 |
listener = mli; |
|
87 |
} |
|
88 |
|
|
89 |
/* |
|
90 |
* (non-Javadoc) |
|
91 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics) |
|
92 |
*/ |
|
93 |
@Override |
|
94 |
public void paintComponent(MapControlDrawer mapControlDrawer) { |
|
95 |
mapControlDrawer.setColor(Color.black); |
|
96 |
|
|
97 |
if (!arrayX.isEmpty()) { |
|
98 |
drawPolyLine(mapControlDrawer); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
/* |
|
103 |
* (non-Javadoc) |
|
104 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent) |
|
105 |
*/ |
|
106 |
@Override |
|
107 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
|
108 |
if (!isMyButton(e)) { |
|
109 |
return; |
|
110 |
} |
|
111 |
if (e.getClickCount() == 2) { |
|
112 |
listener.polylineFinished(new MeasureEvent((Double[]) arrayX.toArray(new Double[arrayX.size()]), (Double[]) arrayY.toArray(new Double[arrayY.size()]), e)); |
|
113 |
|
|
114 |
arrayX.clear(); |
|
115 |
arrayY.clear(); |
|
116 |
|
|
117 |
isClicked = false; |
|
118 |
} else { |
|
119 |
isClicked = true; |
|
120 |
|
|
121 |
} |
|
122 |
// } else { |
|
123 |
// isClicked = true; |
|
124 |
// Point2D point = getMapControl().getViewPort().toMapPoint(e.getPoint()); |
|
125 |
// addPoint(point); |
|
126 |
// |
|
127 |
// if (arrayX.size() < 2) { |
|
128 |
// addPoint(point); |
|
129 |
// } |
|
130 |
// |
|
131 |
// listener.pointFixed(new MeasureEvent((Double[]) arrayX.toArray(new Double[arrayX.size()]), (Double[]) arrayY.toArray(new Double[arrayY.size()]), e)); |
|
132 |
// } |
|
133 |
} |
|
134 |
|
|
135 |
/* |
|
136 |
* (non-Javadoc) |
|
137 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt.event.MouseEvent) |
|
138 |
*/ |
|
139 |
@Override |
|
140 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
|
141 |
mouseMoved(e); |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* <p> |
|
146 |
* Changes the last point added of the polyline.</p> |
|
147 |
* |
|
148 |
* @param p a point which will replace the last added to the polyline |
|
149 |
*/ |
|
150 |
protected void changeLastPoint(Point2D p) { |
|
151 |
if (arrayX.size() > 0) { |
|
152 |
arrayX.set(arrayX.size() - 1, p.getX()); |
|
153 |
arrayY.set(arrayY.size() - 1, p.getY()); |
|
154 |
} |
|
155 |
} |
|
156 |
|
|
157 |
/* |
|
158 |
* (non-Javadoc) |
|
159 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseMoved(java.awt.event.MouseEvent) |
|
160 |
*/ |
|
161 |
@Override |
|
162 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
163 |
if (isClicked) { |
|
164 |
//System.err.println("moved despues de click"); |
|
165 |
// changeLastPoint(getMapControl().getViewPort().toMapPoint(e.getPoint())); |
|
166 |
Point2D point = getMapControl().getViewPort().toMapPoint(e.getPoint()); |
|
167 |
addPoint(point); |
|
168 |
|
|
169 |
MeasureEvent event = new MeasureEvent((Double[]) arrayX.toArray(new Double[arrayX.size()]), (Double[]) arrayY.toArray(new Double[arrayY.size()]), e); |
|
170 |
|
|
171 |
listener.points(event); |
|
172 |
getMapControl().repaint(); |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* <p> |
|
178 |
* Draws the polyline in the <code>Graphics2D</code> of the associated |
|
179 |
* <code>MapControl</code>.</p> |
|
180 |
* |
|
181 |
* @param mapControlDrawer |
|
182 |
*/ |
|
183 |
protected void drawPolyLine(MapControlDrawer mapControlDrawer) { |
|
184 |
|
|
185 |
// GeneralPathX polyline = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, arrayX.size()); |
|
186 |
// |
|
187 |
// polyline.moveTo(((Double) arrayX.get(0)).doubleValue(), |
|
188 |
// ((Double) arrayY.get(0)).doubleValue()); |
|
189 |
// |
|
190 |
// for (int index = 0; index < arrayX.size(); index++) { |
|
191 |
// polyline.lineTo(((Double) arrayX.get(index)).doubleValue(),((Double) arrayY.get(index)).doubleValue()); |
|
192 |
// } |
|
193 |
try { |
|
194 |
Line line = geomManager.createLine(Geometry.SUBTYPES.GEOM2D); |
|
195 |
for (int index = 0; index < arrayX.size(); index++) { |
|
196 |
line.addVertex(arrayX.get(index), arrayY.get(index)); |
|
197 |
} |
|
198 |
mapControlDrawer.draw(line); |
|
199 |
} catch (Exception ex) { |
|
200 |
LOG.warn("Can't draw polyline", ex); |
|
201 |
} |
|
202 |
} |
|
203 |
|
|
204 |
/** |
|
205 |
* <p> |
|
206 |
* Adds a new point to the polyline.</p> |
|
207 |
* |
|
208 |
* @param p a new point to the polyline |
|
209 |
*/ |
|
210 |
protected void addPoint(Point2D p) { |
|
211 |
arrayX.add(p.getX()); |
|
212 |
arrayY.add(p.getY()); |
|
213 |
} |
|
214 |
|
|
215 |
/** |
|
216 |
* <p> |
|
217 |
* Sets a tool listener to work with the <code>MapControl</code> using this |
|
218 |
* behavior.</p> |
|
219 |
* |
|
220 |
* @param listener a <code>PolylineListener</code> object for this behavior |
|
221 |
*/ |
|
222 |
public void setListener(ToolListener listener) { |
|
223 |
this.listener = (PolylineListener) listener; |
|
224 |
} |
|
225 |
|
|
226 |
/* |
|
227 |
* (non-Javadoc) |
|
228 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener() |
|
229 |
*/ |
|
230 |
@Override |
|
231 |
public ToolListener getListener() { |
|
232 |
return listener; |
|
233 |
} |
|
234 |
} |
|
0 | 235 |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/Behavior/EllipseBehavior.java | ||
---|---|---|
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.fmap.mapcontrol.tools.Behavior; |
|
25 |
|
|
26 |
import java.awt.Color; |
|
27 |
import java.awt.Point; |
|
28 |
import java.awt.event.MouseEvent; |
|
29 |
import java.awt.geom.Point2D; |
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.List; |
|
32 |
import java.util.logging.Level; |
|
33 |
import java.util.logging.Logger; |
|
34 |
import org.gvsig.fmap.geom.Geometry; |
|
35 |
import org.gvsig.fmap.geom.GeometryException; |
|
36 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
|
37 |
import org.gvsig.fmap.geom.primitive.Arc; |
|
38 |
import org.gvsig.fmap.geom.primitive.Ellipse; |
|
39 |
|
|
40 |
import org.gvsig.fmap.geom.primitive.Line; |
|
41 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
42 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
|
43 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
44 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
|
45 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.EllipseListener; |
|
46 |
import org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener; |
|
47 |
|
|
48 |
/** |
|
49 |
* <p> |
|
50 |
* Behavior that allows user to draw a polyline by its vertexes on the image of |
|
51 |
* the associated <code>MapControl</code> using a |
|
52 |
* {@link EllipseListener EllipseListener}.</p> |
|
53 |
* |
|
54 |
* @author Vicente Caballero Navarro |
|
55 |
* @author Pablo Piqueras Bartolom? |
|
56 |
*/ |
|
57 |
public class EllipseBehavior extends Behavior { |
|
58 |
|
|
59 |
/** |
|
60 |
* The abscissa coordinate of all vertexes of the polyline. |
|
61 |
*/ |
|
62 |
protected List<Double> arrayX = new ArrayList<>(); |
|
63 |
|
|
64 |
/** |
|
65 |
* The ordinate coordinate of all vertexes of the polyline. |
|
66 |
*/ |
|
67 |
protected List<Double> arrayY = new ArrayList<>(); |
|
68 |
|
|
69 |
/** |
|
70 |
* Determines if user is setting the vertexes (with one click of the button |
|
71 |
* 1 of the mouse), or not. |
|
72 |
*/ |
|
73 |
protected boolean isClicked = false; |
|
74 |
|
|
75 |
/** |
|
76 |
* Tool listener used to work with the <code>MapControl</code> object. |
|
77 |
* |
|
78 |
* @see #getListener() |
|
79 |
* @see #setListener(ToolListener) |
|
80 |
*/ |
|
81 |
protected EllipseListener listener; |
|
82 |
private Point2D m_FirstPoint; |
|
83 |
private Point2D m_SecondPoint; |
|
84 |
private Point2D m_ThirdPoint; |
|
85 |
|
|
86 |
/** |
|
87 |
* <p> |
|
88 |
* Creates a new behavior for drawing a polyline by its vertexes.</p> |
|
89 |
* |
|
90 |
* @param mli listener used to permit this object to work with the |
|
91 |
* associated <code>MapControl</code> |
|
92 |
*/ |
|
93 |
public EllipseBehavior(EllipseListener mli) { |
|
94 |
super(Behavior.BUTTON_LEFT); |
|
95 |
listener = mli; |
|
96 |
} |
|
97 |
|
|
98 |
/* |
|
99 |
* (non-Javadoc) |
|
100 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics) |
|
101 |
*/ |
|
102 |
@Override |
|
103 |
public void paintComponent(MapControlDrawer mapControlDrawer) { |
|
104 |
mapControlDrawer.setColor(Color.black); |
|
105 |
if (arrayX.size() == 1) { |
|
106 |
drawCircle(mapControlDrawer); |
|
107 |
} else if (arrayX.size() > 1) { |
|
108 |
drawEllipseLine(mapControlDrawer); |
|
109 |
} |
|
110 |
|
|
111 |
} |
|
112 |
|
|
113 |
/* |
|
114 |
* (non-Javadoc) |
|
115 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mousePressed(java.awt.event.MouseEvent) |
|
116 |
*/ |
|
117 |
@Override |
|
118 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
|
119 |
|
|
120 |
if (this.isMyButton(e)) { |
|
121 |
if (arrayX.isEmpty()) { |
|
122 |
Point2D point = getMapControl().getViewPort().toMapPoint(e.getPoint()); |
|
123 |
addPoint(point); |
|
124 |
m_FirstPoint = point; |
|
125 |
} else if (arrayX.size() == 1) { |
|
126 |
Point2D point = getMapControl().getViewPort().toMapPoint(e.getPoint()); |
|
127 |
addPoint(point); |
|
128 |
m_SecondPoint = point; |
|
129 |
} else { |
|
130 |
Point2D point = getMapControl().getViewPort().toMapPoint(e.getPoint()); |
|
131 |
addPoint(point); |
|
132 |
m_ThirdPoint = point; |
|
133 |
// Double[] x = new Double[3]; |
|
134 |
// Double[] y = new Double[3]; |
|
135 |
// |
|
136 |
// x[0] = m_FirstPoint.getX(); |
|
137 |
// x[1] = m_SecondPoint.getX(); |
|
138 |
// x[2] = m_ThirdPoint.getX(); |
|
139 |
// |
|
140 |
// y[0] = m_FirstPoint.getY(); |
|
141 |
// y[1] = m_SecondPoint.getY(); |
|
142 |
// y[2] = m_ThirdPoint.getY(); |
|
143 |
|
|
144 |
MeasureEvent event = new MeasureEvent((Double[]) arrayX.toArray(new Double[arrayX.size()]), (Double[]) arrayY.toArray(new Double[arrayY.size()]), e); |
|
145 |
|
|
146 |
listener.ellipseFinished(event); |
|
147 |
|
|
148 |
arrayX.clear(); |
|
149 |
arrayY.clear(); |
|
150 |
m_FirstPoint = null; |
|
151 |
m_SecondPoint = null; |
|
152 |
m_ThirdPoint = null; |
|
153 |
isClicked = false; |
|
154 |
getMapControl().repaint(); |
|
155 |
return; |
|
156 |
} |
|
157 |
|
|
158 |
isClicked = true; |
|
159 |
|
|
160 |
getMapControl().repaint(); |
|
161 |
if (listener.cancelDrawing()) { |
|
162 |
getMapControl().cancelDrawing(); |
|
163 |
isClicked = false; |
|
164 |
getMapControl().repaint(); |
|
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
|
|
169 |
/* |
|
170 |
* (non-Javadoc) |
|
171 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseDragged(java.awt.event.MouseEvent) |
|
172 |
*/ |
|
173 |
@Override |
|
174 |
public void mouseDragged(MouseEvent e) throws BehaviorException { |
|
175 |
mouseMoved(e); |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* <p> |
|
180 |
* Changes the last point added of the polyline.</p> |
|
181 |
* |
|
182 |
* @param p a point which will replace the last added to the polyline |
|
183 |
*/ |
|
184 |
protected void changeLastPoint(Point2D p) { |
|
185 |
if (arrayX.size() > 0) { |
|
186 |
arrayX.set(arrayX.size() - 1, p.getX()); |
|
187 |
arrayY.set(arrayY.size() - 1, p.getY()); |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
/* |
|
192 |
* (non-Javadoc) |
|
193 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#mouseMoved(java.awt.event.MouseEvent) |
|
194 |
*/ |
|
195 |
@Override |
|
196 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
197 |
if (isClicked) { |
|
198 |
//System.err.println("moved despues de click"); |
|
199 |
// changeLastPoint(getMapControl().getViewPort().toMapPoint(e.getPoint())); |
|
200 |
|
|
201 |
// MeasureEvent event = new MeasureEvent((Double[]) arrayX.toArray(new Double[arrayX.size()]), (Double[]) arrayY.toArray(new Double[arrayY.size()]), e); |
|
202 |
if (arrayX.size() == 1) { |
|
203 |
Point2D point = getMapControl().getViewPort().toMapPoint(e.getPoint()); |
|
204 |
m_SecondPoint = point; |
|
205 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
206 |
Double[] x = new Double[2]; |
|
207 |
Double[] y = new Double[2]; |
|
208 |
// x[0] = vp.toMapPoint(m_FirstPoint).getX(); |
|
209 |
// x[1] = vp.toMapPoint(m_SecondPoint).getX(); |
|
210 |
// y[0] = vp.toMapPoint(m_FirstPoint).getY(); |
|
211 |
// y[1] = vp.toMapPoint(m_SecondPoint).getY(); |
|
212 |
x[0] = m_FirstPoint.getX(); |
|
213 |
x[1] = m_SecondPoint.getX(); |
|
214 |
y[0] = m_FirstPoint.getY(); |
|
215 |
y[1] = m_SecondPoint.getY(); |
|
216 |
MeasureEvent event = new MeasureEvent(x, y, e); |
|
217 |
listener.circle(event); |
|
218 |
} else if (arrayX.size() == 2) { |
|
219 |
Point2D point = getMapControl().getViewPort().toMapPoint(e.getPoint()); |
|
220 |
m_ThirdPoint = point; |
|
221 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
222 |
|
|
223 |
Double[] x = new Double[3]; |
|
224 |
Double[] y = new Double[3]; |
|
225 |
// x[0] = vp.toMapPoint(m_FirstPoint).getX(); |
|
226 |
// x[1] = vp.toMapPoint(m_SecondPoint).getX(); |
|
227 |
// x[2] = vp.toMapPoint(m_ThirdPoint).getX(); |
|
228 |
// |
|
229 |
// y[0] = vp.toMapPoint(m_FirstPoint).getY(); |
|
230 |
// y[1] = vp.toMapPoint(m_SecondPoint).getY(); |
|
231 |
// y[2] = vp.toMapPoint(m_ThirdPoint).getY(); |
|
232 |
|
|
233 |
x[0] = m_FirstPoint.getX(); |
|
234 |
x[1] = m_SecondPoint.getX(); |
|
235 |
x[2] = m_ThirdPoint.getX(); |
|
236 |
|
|
237 |
y[0] = m_FirstPoint.getY(); |
|
238 |
y[1] = m_SecondPoint.getY(); |
|
239 |
y[2] = m_ThirdPoint.getY(); |
|
240 |
MeasureEvent event = new MeasureEvent(x, y, e); |
|
241 |
|
|
242 |
listener.ellipse(event); |
|
243 |
} |
|
244 |
|
|
245 |
getMapControl().repaint(); |
|
246 |
} |
|
247 |
} |
|
248 |
|
|
249 |
/** |
|
250 |
* <p> |
|
251 |
* Draws the polyline in the <code>Graphics2D</code> of the associated |
|
252 |
* <code>MapControl</code>.</p> |
|
253 |
* |
|
254 |
* @param mapControlDrawer |
|
255 |
*/ |
|
256 |
protected void drawEllipseLine(MapControlDrawer mapControlDrawer) { |
|
257 |
|
|
258 |
double radio; |
|
259 |
mapControlDrawer.setColor(Color.black); |
|
260 |
|
|
261 |
if ((m_FirstPoint != null) && (m_SecondPoint != null) && (m_ThirdPoint != null)) { |
|
262 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
263 |
// Point2D p1 = vp.toMapPoint(m_FirstPoint); |
|
264 |
// Point2D p2 = vp.toMapPoint(m_SecondPoint); |
|
265 |
// Point2D p3 = vp.toMapPoint(m_ThirdPoint); |
|
266 |
|
|
267 |
Point2D p1 = m_FirstPoint; |
|
268 |
Point2D p2 = m_SecondPoint; |
|
269 |
Point2D p3 = m_ThirdPoint; |
|
270 |
radio = p2.distance(p3); |
|
271 |
if (radio > 0.0) { |
|
272 |
MultiLine ellipse = null; |
|
273 |
try { |
|
274 |
ellipse = createEllipse(p1, p2, p3).toLines(); |
|
275 |
} catch (GeometryException ex) { |
|
276 |
Logger.getLogger(EllipseBehavior.class.getName()).log(Level.SEVERE, null, ex); |
|
277 |
} |
|
278 |
if (ellipse != null) { |
|
279 |
mapControlDrawer.draw(ellipse); |
|
280 |
} |
|
281 |
} |
|
282 |
|
|
283 |
} |
|
284 |
} |
|
285 |
|
|
286 |
protected void drawCircle(MapControlDrawer mapControlDrawer) { |
|
287 |
double radio; |
|
288 |
mapControlDrawer.setColor(Color.black); |
|
289 |
|
|
290 |
if ((m_FirstPoint != null) && (m_SecondPoint != null)) { |
|
291 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
292 |
// Point2D p1 = vp.toMapPoint(m_FirstPoint); |
|
293 |
// Point2D p2 = vp.toMapPoint(m_SecondPoint); |
|
294 |
Point2D p1 = m_FirstPoint; |
|
295 |
Point2D p2 = m_SecondPoint; |
|
296 |
radio = p1.distance(p2)/2; |
|
297 |
if (radio > 0.0) { |
|
298 |
Arc arc = null; |
|
299 |
arc = createArc((p1.getX()+p2.getX())/2, (p1.getY()+p2.getY())/2, |
|
300 |
radio, 0, Math.PI * 2); |
|
301 |
if (arc != null) { |
|
302 |
mapControlDrawer.draw(arc); |
|
303 |
} |
|
304 |
} |
|
305 |
|
|
306 |
} |
|
307 |
} |
|
308 |
|
|
309 |
/** |
|
310 |
* <p> |
|
311 |
* Adds a new point to the polyline.</p> |
|
312 |
* |
|
313 |
* @param p a new point to the polyline |
|
314 |
*/ |
|
315 |
protected void addPoint(Point2D p) { |
|
316 |
arrayX.add(p.getX()); |
|
317 |
arrayY.add(p.getY()); |
|
318 |
} |
|
319 |
|
|
320 |
/** |
|
321 |
* <p> |
|
322 |
* Sets a tool listener to work with the <code>MapControl</code> using this |
|
323 |
* behavior.</p> |
|
324 |
* |
|
325 |
* @param listener a <code>EllipseListener</code> object for this behavior |
|
326 |
*/ |
|
327 |
public void setListener(ToolListener listener) { |
|
328 |
this.listener = (EllipseListener) listener; |
|
329 |
} |
|
330 |
|
|
331 |
/* |
|
332 |
* (non-Javadoc) |
|
333 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener() |
|
334 |
*/ |
|
335 |
@Override |
|
336 |
public ToolListener getListener() { |
|
337 |
return listener; |
|
338 |
} |
|
339 |
} |
|
0 | 340 |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/Events/MeasureEvent.java | ||
---|---|---|
24 | 24 |
package org.gvsig.fmap.mapcontrol.tools.Events; |
25 | 25 |
|
26 | 26 |
import java.awt.event.MouseEvent; |
27 |
import java.awt.geom.Point2D; |
|
28 |
import java.util.logging.Level; |
|
29 |
import org.gvsig.fmap.geom.Geometry; |
|
30 |
import org.gvsig.fmap.geom.GeometryException; |
|
31 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
32 |
import org.gvsig.fmap.geom.GeometryManager; |
|
33 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
34 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
35 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
36 |
import org.gvsig.fmap.geom.primitive.Circle; |
|
37 |
import org.gvsig.fmap.geom.primitive.Circumference; |
|
38 |
import org.gvsig.fmap.geom.primitive.Ellipse; |
|
27 | 39 |
|
28 | 40 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
41 |
import org.gvsig.fmap.geom.primitive.PeriEllipse; |
|
42 |
import org.gvsig.fmap.geom.primitive.Point; |
|
43 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
44 |
import org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager; |
|
45 |
import org.slf4j.Logger; |
|
46 |
import org.slf4j.LoggerFactory; |
|
29 | 47 |
|
30 | 48 |
/** |
31 |
* <p><code>MeasureEvent</code> is used to notify the selection of a polyline.</p> |
|
49 |
* <p> |
|
50 |
* <code>MeasureEvent</code> is used to notify the selection of a polyline.</p> |
|
32 | 51 |
* |
33 |
* <p>Stores the information about the 2D vertexes and the {@link GeneralPathX GeneralPathX} |
|
34 |
* between them.</p> |
|
52 |
* <p> |
|
53 |
* Stores the information about the 2D vertexes and the |
|
54 |
* {@link GeneralPathX GeneralPathX} between them.</p> |
|
35 | 55 |
* |
36 | 56 |
* @author Vicente Caballero Navarro |
37 | 57 |
*/ |
38 | 58 |
public class MeasureEvent { |
39 |
/** |
|
40 |
* The polyline, broken down in straight lines, and quadratic and cubic (B?zier) curves. |
|
41 |
*/ |
|
42 |
private GeneralPathX gp; |
|
43 | 59 |
|
44 |
/** |
|
45 |
* Vector with the X coordinates. |
|
46 |
*/ |
|
47 |
private Double[] x; |
|
60 |
/** |
|
61 |
* The polyline, broken down in straight lines, and quadratic and cubic |
|
62 |
* (B?zier) curves. |
|
63 |
*/ |
|
64 |
private GeneralPathX gp; |
|
48 | 65 |
|
49 |
/**
|
|
50 |
* Vector with the Y coordinates.
|
|
51 |
*/
|
|
52 |
private Double[] y;
|
|
66 |
/**
|
|
67 |
* Vector with the X coordinates.
|
|
68 |
*/
|
|
69 |
private Double[] x;
|
|
53 | 70 |
|
54 |
/**
|
|
55 |
* Mouse event that has been the cause of creating this event.
|
|
56 |
*/
|
|
57 |
private MouseEvent event;
|
|
71 |
/**
|
|
72 |
* Vector with the Y coordinates.
|
|
73 |
*/
|
|
74 |
private Double[] y;
|
|
58 | 75 |
|
59 |
/** |
|
60 |
* <p>Creates a new <code>MeasureEvent</code> with all necessary data.</p> |
|
61 |
* <p>The general path is calculated according the enclosed regions of the path alternate between interior |
|
62 |
* and exterior areas are traversed from the outside of the path towards a point inside the region.</p> |
|
63 |
* |
|
64 |
* @param x vector with the X coordinates |
|
65 |
* @param y vector with the Y coordinates |
|
66 |
* @param e event that has been the cause of creating this one |
|
67 |
*/ |
|
68 |
public MeasureEvent(Double[] x, Double[] y, MouseEvent e) { |
|
69 |
this.x = x; |
|
70 |
this.y = y; |
|
71 |
this.event = e; |
|
72 |
gp = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, x.length); |
|
73 |
gp.moveTo(x[0].doubleValue(), y[0].doubleValue()); |
|
76 |
/** |
|
77 |
* Mouse event that has been the cause of creating this event. |
|
78 |
*/ |
|
79 |
private MouseEvent event; |
|
74 | 80 |
|
75 |
for (int index = 1; index < x.length; index++) { |
|
76 |
gp.lineTo(x[index].doubleValue(), y[index].doubleValue()); |
|
77 |
} |
|
78 |
} |
|
81 |
private static final Logger logger = LoggerFactory |
|
82 |
.getLogger(MeasureEvent.class); |
|
79 | 83 |
|
80 |
/** |
|
81 |
* <p>Gets the {@link GeneralPathX GeneralPathX} of the measurement.</p> |
|
82 |
* |
|
83 |
* @see GeneralPathX |
|
84 |
* |
|
85 |
* @return geometric path constructed from straight lines, and quadratic and cubic (B?zier) curves |
|
86 |
*/ |
|
87 |
public GeneralPathX getGP() { |
|
88 |
return gp; |
|
89 |
} |
|
84 |
/** |
|
85 |
* <p> |
|
86 |
* Creates a new <code>MeasureEvent</code> with all necessary data.</p> |
|
87 |
* <p> |
|
88 |
* The general path is calculated according the enclosed regions of the path |
|
89 |
* alternate between interior and exterior areas are traversed from the |
|
90 |
* outside of the path towards a point inside the region.</p> |
|
91 |
* |
|
92 |
* @param x vector with the X coordinates |
|
93 |
* @param y vector with the Y coordinates |
|
94 |
* @param e event that has been the cause of creating this one |
|
95 |
*/ |
|
96 |
public MeasureEvent(Double[] x, Double[] y, MouseEvent e) { |
|
97 |
this.x = x; |
|
98 |
this.y = y; |
|
99 |
this.event = e; |
|
100 |
gp = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD, x.length); |
|
101 |
gp.moveTo(x[0].doubleValue(), y[0].doubleValue()); |
|
90 | 102 |
|
91 |
/** |
|
92 |
* <p>Sets the {@link GeneralPathX GeneralPathX} of the measurement.</p> |
|
93 |
* |
|
94 |
* @see GeneralPathX |
|
95 |
* |
|
96 |
* @param gP geometric path constructed from straight lines, and quadratic and cubic (B?zier) curves |
|
97 |
*/ |
|
98 |
public void setGP(GeneralPathX gp) { |
|
99 |
this.gp = gp; |
|
100 |
} |
|
103 |
for (int index = 1; index < x.length; index++) { |
|
104 |
gp.lineTo(x[index].doubleValue(), y[index].doubleValue()); |
|
105 |
} |
|
106 |
} |
|
101 | 107 |
|
102 |
/** |
|
103 |
* <p>Gets a vector with the X coordinates.</p> |
|
104 |
* |
|
105 |
* @return vector with the X coordinates |
|
106 |
*/ |
|
107 |
public Double[] getXs() { |
|
108 |
return x; |
|
109 |
} |
|
108 |
/** |
|
109 |
* <p> |
|
110 |
* Gets the {@link GeneralPathX GeneralPathX} of the measurement.</p> |
|
111 |
* |
|
112 |
* @see GeneralPathX |
|
113 |
* |
|
114 |
* @return geometric path constructed from straight lines, and quadratic and |
|
115 |
* cubic (B?zier) curves |
|
116 |
*/ |
|
117 |
public GeneralPathX getGP() { |
|
118 |
return gp; |
|
119 |
} |
|
110 | 120 |
|
111 |
/** |
|
112 |
* <p>Gets a vector with the Y coordinates.</p> |
|
113 |
* |
|
114 |
* @return vector with the Y coordinates |
|
115 |
*/ |
|
116 |
public Double[] getYs() { |
|
117 |
return y; |
|
118 |
} |
|
121 |
/** |
|
122 |
* <p> |
|
123 |
* Sets the {@link GeneralPathX GeneralPathX} of the measurement.</p> |
|
124 |
* |
|
125 |
* @see GeneralPathX |
|
126 |
* |
|
127 |
* @param gP geometric path constructed from straight lines, and quadratic |
|
128 |
* and cubic (B?zier) curves |
|
129 |
*/ |
|
130 |
public void setGP(GeneralPathX gp) { |
|
131 |
this.gp = gp; |
|
132 |
} |
|
119 | 133 |
|
120 |
/** |
|
121 |
* <p>Gets the event that has been the cause of creating this one.</p> |
|
122 |
* |
|
123 |
* @return mouse event that has been the cause of creating this one |
|
124 |
*/ |
|
125 |
public MouseEvent getEvent() { |
|
126 |
return event; |
|
127 |
} |
|
134 |
/** |
|
135 |
* <p> |
|
136 |
* Gets a vector with the X coordinates.</p> |
|
137 |
* |
|
138 |
* @return vector with the X coordinates |
|
139 |
*/ |
|
140 |
public Double[] getXs() { |
|
141 |
return x; |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* <p> |
|
146 |
* Gets a vector with the Y coordinates.</p> |
|
147 |
* |
|
148 |
* @return vector with the Y coordinates |
|
149 |
*/ |
|
150 |
public Double[] getYs() { |
|
151 |
return y; |
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* <p> |
|
156 |
* Gets the event that has been the cause of creating this one.</p> |
|
157 |
* |
|
158 |
* @return mouse event that has been the cause of creating this one |
|
159 |
*/ |
|
160 |
public MouseEvent getEvent() { |
|
161 |
return event; |
|
162 |
} |
|
163 |
|
|
164 |
public Geometry getCircle() { |
|
165 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
166 |
Point center; |
|
167 |
Geometry geom = null; |
|
168 |
try { |
|
169 |
center = (Point) manager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
170 |
center.setX(this.getXs()[0]); |
|
171 |
center.setY(this.getYs()[0]); |
|
172 |
|
|
173 |
Point point2; |
|
174 |
point2 = (Point) manager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
175 |
point2.setX(this.getXs()[1]); |
|
176 |
point2.setY(this.getYs()[1]); |
|
177 |
|
|
178 |
double radious = center.distance(point2); |
|
179 |
|
|
180 |
Circle circle; |
|
181 |
circle = (Circle) manager.create(Geometry.TYPES.CIRCLE, Geometry.SUBTYPES.GEOM2D); |
|
182 |
circle.setPoints(center, radious); |
|
183 |
geom = circle; |
|
184 |
} catch (CreateGeometryException e) { |
|
185 |
logger.error("Failed_creating_geometry", e); |
|
186 |
} catch (GeometryOperationNotSupportedException e) { |
|
187 |
logger.error("Operation_not_supported", e); |
|
188 |
} catch (GeometryOperationException e) { |
|
189 |
logger.error("Failed_performing_the_operation", e); |
|
190 |
} |
|
191 |
|
|
192 |
return geom; |
|
193 |
} |
|
194 |
|
|
195 |
public Geometry getCircumference() { |
|
196 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
197 |
Point center; |
|
198 |
Geometry geom = null; |
|
199 |
try { |
|
200 |
center = (Point) manager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
201 |
center.setX(this.getXs()[0]); |
|
202 |
center.setY(this.getYs()[0]); |
|
203 |
|
|
204 |
Point point2; |
|
205 |
point2 = (Point) manager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
206 |
point2.setX(this.getXs()[1]); |
|
207 |
point2.setY(this.getYs()[1]); |
|
208 |
|
|
209 |
double radious = center.distance(point2); |
|
210 |
|
|
211 |
Circumference circle; |
|
212 |
circle = (Circumference) manager.create(Geometry.TYPES.CIRCUMFERENCE, Geometry.SUBTYPES.GEOM2D); |
|
213 |
circle.setPoints(center, radious); |
|
214 |
geom = circle; |
|
215 |
} catch (CreateGeometryException e) { |
|
216 |
logger.error("Failed_creating_geometry", e); |
|
217 |
} catch (GeometryOperationNotSupportedException e) { |
|
218 |
logger.error("Operation_not_supported", e); |
|
219 |
} catch (GeometryOperationException e) { |
|
220 |
logger.error("Failed_performing_the_operation", e); |
|
221 |
} |
|
222 |
|
|
223 |
return geom; |
|
224 |
} |
|
225 |
|
|
226 |
public Geometry getEllipse() { |
|
227 |
Geometry geom = null; |
|
228 |
try { |
|
229 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
230 |
Point point1 = (Point) manager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
231 |
point1.setX(this.getXs()[0]); |
|
232 |
point1.setY(this.getYs()[0]); |
|
233 |
Point point2 = (Point) manager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
234 |
point2.setX(this.getXs()[1]); |
|
235 |
point2.setY(this.getYs()[1]); |
|
236 |
Point point3 = (Point) manager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
237 |
point3.setX(this.getXs()[2]); |
|
238 |
point3.setY(this.getYs()[2]); |
|
239 |
double radious = point2.distance(point3); |
|
240 |
|
|
241 |
Ellipse ellipse; |
|
242 |
ellipse = (Ellipse) manager.create(Geometry.TYPES.ELLIPSE, Geometry.SUBTYPES.GEOM2D); |
|
243 |
ellipse.setPoints(point1, point2, radious); |
|
244 |
geom = ellipse; |
|
245 |
} catch (CreateGeometryException e) { |
|
246 |
logger.error("Failed_creating_geometry", e); |
|
247 |
} catch (GeometryOperationNotSupportedException e) { |
|
248 |
logger.error("Operation_not_supported", e); |
|
249 |
} catch (GeometryOperationException e) { |
|
250 |
logger.error("Failed_performing_the_operation", e); |
|
251 |
} |
|
252 |
return geom; |
|
253 |
} |
|
254 |
|
|
255 |
public Geometry getPeriEllipse() { |
|
256 |
Geometry geom = null; |
|
257 |
try { |
|
258 |
GeometryManager manager = GeometryLocator.getGeometryManager(); |
|
259 |
Point point1 = (Point) manager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
260 |
point1.setX(this.getXs()[0]); |
|
261 |
point1.setY(this.getYs()[0]); |
|
262 |
Point point2 = (Point) manager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
263 |
point2.setX(this.getXs()[1]); |
|
264 |
point2.setY(this.getYs()[1]); |
|
265 |
Point point3 = (Point) manager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM2D); |
|
266 |
point3.setX(this.getXs()[2]); |
|
267 |
point3.setY(this.getYs()[2]); |
|
268 |
double radious = point2.distance(point3); |
|
269 |
|
|
270 |
PeriEllipse ellipse; |
|
271 |
ellipse = (PeriEllipse) manager.create(Geometry.TYPES.PERIELLIPSE, Geometry.SUBTYPES.GEOM2D); |
|
272 |
ellipse.setPoints(point1, point2, radious); |
|
273 |
geom = ellipse.toLines(); |
|
274 |
} catch (CreateGeometryException e) { |
|
275 |
logger.error("Failed_creating_geometry", e); |
|
276 |
} catch (GeometryOperationNotSupportedException e) { |
|
277 |
logger.error("Operation_not_supported", e); |
|
278 |
} catch (GeometryOperationException e) { |
|
279 |
logger.error("Failed_performing_the_operation", e); |
|
280 |
} catch (GeometryException e) { |
|
281 |
logger.error("Can't create line geometry from ellipse", e); |
|
282 |
} |
|
283 |
return geom; |
|
284 |
} |
|
128 | 285 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/Listeners/AbstractCircleListener.java | ||
---|---|---|
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.fmap.mapcontrol.tools.Listeners; |
|
25 |
|
|
26 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
* @author osc |
|
31 |
*/ |
|
32 |
public abstract class AbstractCircleListener implements CircleListener { |
|
33 |
|
|
34 |
public void circleFinished(MeasureEvent event) { |
|
35 |
|
|
36 |
} |
|
37 |
|
|
38 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/tools/Listeners/EllipseListener.java | ||
---|---|---|
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.fmap.mapcontrol.tools.Listeners; |
|
25 |
|
|
26 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
27 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
|
28 |
import org.gvsig.fmap.mapcontrol.tools.Events.MeasureEvent; |
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
/** |
|
33 |
* <p>Interface for all tools that reply for a {@link MeasureEvent MeasureEvent} produced in the |
|
34 |
* associated {@link MapControl MapControl} object, as a consequence of a 2D polyline drawn by the mouse.</p> |
|
35 |
* |
|
36 |
* @author Vicente Caballero Navarro |
|
37 |
*/ |
|
38 |
public interface EllipseListener extends ToolListener { |
|
39 |
|
|
40 |
public void circle(MeasureEvent event) throws BehaviorException; |
|
41 |
|
|
42 |
public void ellipseFinished(MeasureEvent event) throws BehaviorException; |
|
43 |
|
|
44 |
public void ellipse(MeasureEvent event); |
|
45 |
} |
|
0 | 46 |
Also available in: Unified diff