Revision 22893
trunk/extensions/extTopology/src/org/gvsig/fmap/tools/behavior/VectorBehavior.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 10-abr-2006 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id: |
|
47 |
* $Log: |
|
48 |
*/ |
|
49 |
package org.gvsig.fmap.tools.behavior; |
|
50 |
|
|
51 |
import java.awt.Color; |
|
52 |
import java.awt.Graphics; |
|
53 |
import java.awt.Graphics2D; |
|
54 |
import java.awt.Point; |
|
55 |
import java.awt.Rectangle; |
|
56 |
import java.awt.Stroke; |
|
57 |
import java.awt.event.MouseEvent; |
|
58 |
import java.awt.geom.AffineTransform; |
|
59 |
import java.awt.geom.Point2D; |
|
60 |
import java.awt.geom.Rectangle2D; |
|
61 |
import java.awt.image.BufferedImage; |
|
62 |
|
|
63 |
import org.gvsig.fmap.core.FGeometryUtil; |
|
64 |
import org.gvsig.fmap.tools.listeners.VectorListener; |
|
65 |
|
|
66 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
67 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
|
68 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
69 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
70 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
|
71 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
|
72 |
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent; |
|
73 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
|
74 |
|
|
75 |
/** |
|
76 |
* Behavior to digitize two points vectors in mapcontrol |
|
77 |
* @author azabala |
|
78 |
*/ |
|
79 |
public class VectorBehavior extends Behavior { |
|
80 |
private Point2D m_FirstPoint; |
|
81 |
private Point2D m_LastPoint; |
|
82 |
private VectorListener listener; |
|
83 |
|
|
84 |
protected int lenghtArrow = 15; |
|
85 |
protected int widthArrow = 10; |
|
86 |
protected Color arrowColor = java.awt.Color.RED; |
|
87 |
protected int rgb; |
|
88 |
private Stroke stroke; |
|
89 |
protected static BufferedImage img = new BufferedImage(1, 1, |
|
90 |
BufferedImage.TYPE_INT_ARGB); |
|
91 |
protected static Rectangle rect = new Rectangle(0, 0, 1, 1); |
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
/** |
|
97 |
* Crea un nuevo RectangleBehavior. |
|
98 |
* |
|
99 |
* @param zili listener. |
|
100 |
*/ |
|
101 |
public VectorBehavior(VectorListener zili) { |
|
102 |
listener = zili; |
|
103 |
|
|
104 |
Graphics2D g2 = img.createGraphics(); |
|
105 |
drawInsideRectangle(g2, g2.getTransform(), rect); |
|
106 |
rgb = img.getRGB(0, 0); |
|
107 |
|
|
108 |
} |
|
109 |
|
|
110 |
private void drawInsideRectangle(Graphics2D g, AffineTransform scale, |
|
111 |
Rectangle r) { |
|
112 |
FShape shp; |
|
113 |
AffineTransform mT = new AffineTransform(); |
|
114 |
mT.setToIdentity(); |
|
115 |
|
|
116 |
Rectangle rect = mT.createTransformedShape(r).getBounds(); |
|
117 |
GeneralPathX line = new GeneralPathX(); |
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
line.moveTo(rect.x, rect.y + (rect.height / 2)); |
|
122 |
line.curveTo(rect.x + (rect.width / 3), |
|
123 |
rect.y + (2 * rect.height), |
|
124 |
rect.x + ((2 * rect.width) / 3), rect.y - rect.height, |
|
125 |
rect.x + rect.width, rect.y + (rect.height / 2)); |
|
126 |
|
|
127 |
shp = new FPolyline2D(line); |
|
128 |
drawLineWithArrow(g, mT, shp); |
|
129 |
|
|
130 |
|
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#paintComponent(java.awt.Graphics) |
|
135 |
*/ |
|
136 |
public void paintComponent(Graphics g) { |
|
137 |
BufferedImage img = getMapControl().getImage(); |
|
138 |
g.drawImage(img, 0, 0, null); |
|
139 |
g.setColor(Color.black); |
|
140 |
g.setXORMode(Color.white); |
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
// Dibujamos el actual |
|
145 |
if ((m_FirstPoint != null) && (m_LastPoint != null)) { |
|
146 |
GeneralPathX line = new GeneralPathX(); |
|
147 |
line.moveTo(m_FirstPoint.getX(), m_FirstPoint.getY()); |
|
148 |
line.lineTo(m_LastPoint.getX(), m_LastPoint.getY()); |
|
149 |
FPolyline2D shp = new FPolyline2D(line); |
|
150 |
drawLineWithArrow((Graphics2D)g, getMapControl().getViewPort().getAffineTransform(), shp); |
|
151 |
} |
|
152 |
g.setPaintMode(); |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* Reimplementaci?n del m?todo mousePressed de Behavior. |
|
157 |
* |
|
158 |
* @param e MouseEvent |
|
159 |
*/ |
|
160 |
public void mousePressed(MouseEvent e) { |
|
161 |
// if (e.getButton() == MouseEvent.BUTTON1) { |
|
162 |
m_FirstPoint = e.getPoint(); |
|
163 |
getMapControl().repaint(); |
|
164 |
// } |
|
165 |
if (listener.cancelDrawing()) { |
|
166 |
getMapControl().cancelDrawing(); |
|
167 |
getMapControl().repaint(); |
|
168 |
} |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* Reimplementaci?n del m?todo mouseReleased de Behavior. |
|
173 |
* |
|
174 |
* @param e MouseEvent |
|
175 |
* |
|
176 |
* @throws BehaviorException Excepci?n lanzada cuando el Behavior. |
|
177 |
*/ |
|
178 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
|
179 |
if (m_FirstPoint == null) return; |
|
180 |
Point2D p1; |
|
181 |
Point2D p2; |
|
182 |
Point pScreen = e.getPoint(); |
|
183 |
|
|
184 |
ViewPort vp = getMapControl().getMapContext().getViewPort(); |
|
185 |
|
|
186 |
p1 = vp.toMapPoint(m_FirstPoint); |
|
187 |
p2 = vp.toMapPoint(pScreen); |
|
188 |
|
|
189 |
// if (e.getButton() == MouseEvent.BUTTON1) { |
|
190 |
// Fijamos el nuevo extent |
|
191 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
192 |
r.setFrameFromDiagonal(p1, p2); |
|
193 |
|
|
194 |
MoveEvent event = new MoveEvent(m_FirstPoint, e.getPoint(), e); |
|
195 |
listener.vector(event); |
|
196 |
// } |
|
197 |
|
|
198 |
m_FirstPoint = null; |
|
199 |
m_LastPoint = null; |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* Reimplementaci?n del m?todo mouseDragged de Behavior. |
|
204 |
* |
|
205 |
* @param e MouseEvent |
|
206 |
*/ |
|
207 |
public void mouseDragged(MouseEvent e) { |
|
208 |
m_LastPoint = e.getPoint(); |
|
209 |
getMapControl().repaint(); |
|
210 |
} |
|
211 |
|
|
212 |
/** |
|
213 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#setListener(com.iver.cit.gvsig.fmap.tools.ToolListener) |
|
214 |
*/ |
|
215 |
public void setListener(ToolListener listener) { |
|
216 |
this.listener = (VectorListener) listener; |
|
217 |
} |
|
218 |
|
|
219 |
/** |
|
220 |
* @see com.iver.cit.gvsig.fmap.tools.Behavior.Behavior#getListener() |
|
221 |
*/ |
|
222 |
public ToolListener getListener() { |
|
223 |
return listener; |
|
224 |
} |
|
225 |
|
|
226 |
|
|
227 |
private void drawLineWithArrow(Graphics2D g, AffineTransform affineTransform, FShape shp){ |
|
228 |
FGeometryUtil.drawLineWithArrow(g, affineTransform, shp, arrowColor, stroke, lenghtArrow, widthArrow); |
|
229 |
|
|
230 |
} |
|
231 |
|
|
232 |
} |
|
233 |
|
trunk/extensions/extTopology/src/org/gvsig/fmap/tools/listeners/VectorListener.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 10-abr-2006 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id: |
|
47 |
* $Log: |
|
48 |
*/ |
|
49 |
package org.gvsig.fmap.tools.listeners; |
|
50 |
|
|
51 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
|
52 |
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent; |
|
53 |
import com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener; |
|
54 |
|
|
55 |
public interface VectorListener extends ToolListener { |
|
56 |
/** |
|
57 |
* Invocado cuando el usuario digitaliza un vector de dos puntos en la vista. |
|
58 |
* |
|
59 |
* @param event vector. |
|
60 |
* |
|
61 |
* @throws BehaviorException |
|
62 |
*/ |
|
63 |
public void vector(MoveEvent event) throws BehaviorException; |
|
64 |
} |
trunk/extensions/extTopology/src/org/gvsig/fmap/tools/VectorListenerImpl.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 10-abr-2006 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
/* CVS MESSAGES: |
|
45 |
* |
|
46 |
* $Id: |
|
47 |
* $Log: |
|
48 |
*/ |
|
49 |
package org.gvsig.fmap.tools; |
|
50 |
|
|
51 |
import java.awt.Cursor; |
|
52 |
import java.awt.geom.Point2D; |
|
53 |
|
|
54 |
import org.gvsig.fmap.tools.listeners.VectorListener; |
|
55 |
import org.gvsig.referencing.DisactivableMappedPosition; |
|
56 |
import org.gvsig.referencing.MappedPositionContainer; |
|
57 |
import org.gvsig.referencing.ReferencingUtil; |
|
58 |
import org.opengis.spatialschema.geometry.DirectPosition; |
|
59 |
|
|
60 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
61 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
62 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
|
63 |
import com.iver.cit.gvsig.fmap.tools.Events.MoveEvent; |
|
64 |
|
|
65 |
/** |
|
66 |
* Vector listener impl that creates vector errors to compute vectorial layers |
|
67 |
* transformations. |
|
68 |
* |
|
69 |
* For each digitized vector error in screen, it creates a geotools MappedPosition |
|
70 |
* instance. |
|
71 |
* */ |
|
72 |
public class VectorListenerImpl implements VectorListener { |
|
73 |
|
|
74 |
// private final Image img = new ImageIcon(MapControl.class. |
|
75 |
// getResource("images/PointSelectCursor.gif")). |
|
76 |
// getImage(); |
|
77 |
|
|
78 |
// private Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(img, |
|
79 |
// new Point(16, 16), ""); |
|
80 |
|
|
81 |
private Cursor cur = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); |
|
82 |
|
|
83 |
/** |
|
84 |
* MapControl creator of digitizing events. |
|
85 |
*/ |
|
86 |
protected MapControl mapCtrl; |
|
87 |
|
|
88 |
/** |
|
89 |
* Collection of existing digitized links, to add new vector error. |
|
90 |
*/ |
|
91 |
MappedPositionContainer linksList; |
|
92 |
|
|
93 |
|
|
94 |
public VectorListenerImpl(MapControl mapCtrl, MappedPositionContainer linksList) { |
|
95 |
super(); |
|
96 |
this.mapCtrl = mapCtrl; |
|
97 |
this.linksList = linksList; |
|
98 |
} |
|
99 |
|
|
100 |
public void vector(MoveEvent event) throws BehaviorException { |
|
101 |
|
|
102 |
ViewPort vp = mapCtrl.getMapContext().getViewPort(); |
|
103 |
|
|
104 |
Point2D from = vp.toMapPoint(event.getFrom()); |
|
105 |
Point2D to = vp.toMapPoint(event.getTo()); |
|
106 |
|
|
107 |
ReferencingUtil referencing = ReferencingUtil.getInstance(); |
|
108 |
|
|
109 |
//TODO Ver como pasar a GeoAPI la proyeccion del mapControl (libJCRS) |
|
110 |
//de momento estamos pasando null |
|
111 |
DirectPosition source = |
|
112 |
referencing.create(new double[]{from.getX(), from.getY()}, null); |
|
113 |
|
|
114 |
DirectPosition destination = |
|
115 |
referencing.create(new double[]{to.getX(), to.getY()}, null); |
|
116 |
|
|
117 |
|
|
118 |
// MappedPosition mappedPosition = |
|
119 |
// new MappedPosition(source, destination); |
|
120 |
DisactivableMappedPosition mappedPosition |
|
121 |
= new DisactivableMappedPosition(source, destination); |
|
122 |
|
|
123 |
this.linksList.addMappedPosition(mappedPosition); |
|
124 |
|
|
125 |
} |
|
126 |
|
|
127 |
public boolean cancelDrawing() { |
|
128 |
return false; |
|
129 |
} |
|
130 |
|
|
131 |
public Cursor getCursor() { |
|
132 |
return cur; |
|
133 |
} |
|
134 |
|
|
135 |
} |
Also available in: Unified diff