root / trunk / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / Point2D.java @ 20899
History | View | Annotate | Download (7.68 KB)
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.fmap.geom.primitive; |
42 |
|
43 |
import java.awt.Rectangle; |
44 |
import java.awt.geom.AffineTransform; |
45 |
import java.awt.geom.PathIterator; |
46 |
import java.awt.geom.Rectangle2D; |
47 |
import java.util.ArrayList; |
48 |
|
49 |
import org.cresques.cts.ICoordTrans; |
50 |
import org.cresques.cts.IProjection; |
51 |
import org.gvsig.fmap.geom.GeometryManager; |
52 |
import org.gvsig.fmap.geom.handler.AbstractHandler; |
53 |
import org.gvsig.fmap.geom.handler.FinalHandler; |
54 |
import org.gvsig.fmap.geom.handler.Handler; |
55 |
import org.gvsig.fmap.geom.operation.println.PrintlnPoint2D; |
56 |
import org.gvsig.fmap.geom.type.GeometryType; |
57 |
|
58 |
/**
|
59 |
* Punto 2D.
|
60 |
*
|
61 |
* @author Vicente Caballero Navarro
|
62 |
*/
|
63 |
public class Point2D extends AbstractPrimitive implements Point { |
64 |
|
65 |
private static final long serialVersionUID = 1L; |
66 |
protected java.awt.geom.Point2D p;
|
67 |
|
68 |
/** Instancia de GeometryType obtenida al registrar esta clase */
|
69 |
private static final GeometryType geomType = GeometryManager.getInstance() |
70 |
.registerGeometryType(Point2D.class);
|
71 |
|
72 |
/** CTEs para identificar las operaciones registradas para el tipo de geometría geomType */
|
73 |
public static final int OPERATION_PRINTLN = GeometryManager.getInstance() |
74 |
.registerGeometryOperation("println", new PrintlnPoint2D(), geomType); |
75 |
|
76 |
/**
|
77 |
* Crea un nuevo Point2D.
|
78 |
*
|
79 |
* @param x
|
80 |
* Coordenada x del punto.
|
81 |
* @param y
|
82 |
* Coordenada y del punto.
|
83 |
*/
|
84 |
public Point2D(String id, IProjection projection, double x, double y) { |
85 |
super(id, projection);
|
86 |
p = new java.awt.geom.Point2D.Double(x, y);
|
87 |
} |
88 |
|
89 |
public Point2D(String id, IProjection projection, java.awt.geom.Point2D p) { |
90 |
super(id, projection);
|
91 |
this.p = p;
|
92 |
} |
93 |
|
94 |
public Point2D(java.awt.geom.Point2D p) { |
95 |
this(null, null, p); |
96 |
} |
97 |
|
98 |
public Point2D() { |
99 |
this(null, null, null); |
100 |
} |
101 |
|
102 |
public Point2D(double x, double y) { |
103 |
this(null, null, x, y); |
104 |
} |
105 |
|
106 |
/*
|
107 |
* private void setPoint(double x, double y){ p = new
|
108 |
* java.awt.geom.Point2D.Double(x, y); }
|
109 |
*/
|
110 |
|
111 |
/**
|
112 |
* Aplica la transformaci�n de la matriz de transformaci�n que se pasa como
|
113 |
* par�metro.
|
114 |
*
|
115 |
* @param at
|
116 |
* Matriz de transformaci�n.
|
117 |
*/
|
118 |
public void transform(AffineTransform at) { |
119 |
at.transform(p, p); |
120 |
} |
121 |
|
122 |
/*
|
123 |
* (non-Javadoc)
|
124 |
*
|
125 |
* @see java.awt.Shape#contains(double, double)
|
126 |
*/
|
127 |
public boolean contains(double x, double y) { |
128 |
if ((x == p.getX()) || (y == p.getY())) {
|
129 |
return true; |
130 |
} else {
|
131 |
return false; |
132 |
} |
133 |
} |
134 |
|
135 |
/*
|
136 |
* (non-Javadoc)
|
137 |
*
|
138 |
* @see java.awt.Shape#contains(double, double, double, double)
|
139 |
*/
|
140 |
public boolean contains(double x, double y, double w, double h) { |
141 |
return false; |
142 |
} |
143 |
|
144 |
/*
|
145 |
* (non-Javadoc)
|
146 |
*
|
147 |
* @see java.awt.Shape#intersects(double, double, double, double)
|
148 |
*/
|
149 |
public boolean intersects(double x, double y, double w, double h) { |
150 |
Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h); |
151 |
|
152 |
return rAux.contains(p.getX(), p.getY());
|
153 |
} |
154 |
|
155 |
/*
|
156 |
* (non-Javadoc)
|
157 |
*
|
158 |
* @see java.awt.Shape#getBounds()
|
159 |
*/
|
160 |
public Rectangle getBounds() { |
161 |
return new Rectangle((int) p.getX(), (int) p.getY(), 0, 0); |
162 |
} |
163 |
|
164 |
/**
|
165 |
* Devuelve la coordenada x del punto.
|
166 |
*
|
167 |
* @return Coordenada x.
|
168 |
*/
|
169 |
public double getX() { |
170 |
return p.getX();
|
171 |
} |
172 |
|
173 |
/**
|
174 |
* Devuelve la coordenada y del punto.
|
175 |
*
|
176 |
* @return Coordenada y.
|
177 |
*/
|
178 |
public double getY() { |
179 |
return p.getY();
|
180 |
} |
181 |
|
182 |
/*
|
183 |
* (non-Javadoc)
|
184 |
*
|
185 |
* @see java.awt.Shape#contains(java.awt.geom.Point2D)
|
186 |
*/
|
187 |
public boolean contains(java.awt.geom.Point2D p) { |
188 |
return false; |
189 |
} |
190 |
|
191 |
/*
|
192 |
* (non-Javadoc)
|
193 |
*
|
194 |
* @see java.awt.Shape#getBounds2D()
|
195 |
*/
|
196 |
public Rectangle2D getBounds2D() { |
197 |
return new Rectangle2D.Double(p.getX() - 0.01, p.getY() - 0.01, 0.02, |
198 |
0.02);
|
199 |
} |
200 |
|
201 |
/*
|
202 |
* (non-Javadoc)
|
203 |
*
|
204 |
* @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
|
205 |
*/
|
206 |
public boolean contains(Rectangle2D r) { |
207 |
return false; |
208 |
} |
209 |
|
210 |
/*
|
211 |
* (non-Javadoc)
|
212 |
*
|
213 |
* @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
|
214 |
*/
|
215 |
public boolean intersects(Rectangle2D r) { |
216 |
return r.contains(this.p); |
217 |
} |
218 |
|
219 |
/*
|
220 |
* (non-Javadoc)
|
221 |
*
|
222 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
|
223 |
*/
|
224 |
public PathIterator getPathIterator(AffineTransform at) { |
225 |
return new PointIterator(p, at); |
226 |
} |
227 |
|
228 |
/*
|
229 |
* (non-Javadoc)
|
230 |
*
|
231 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform,
|
232 |
* double)
|
233 |
*/
|
234 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
235 |
return new PointIterator(p, at); |
236 |
} |
237 |
|
238 |
/**
|
239 |
* @see org.gvsig.fmap.geom.primitive.FShape#getShapeType()
|
240 |
*/
|
241 |
public int getShapeType() { |
242 |
return FShape.POINT;
|
243 |
} |
244 |
|
245 |
/**
|
246 |
* Devuelve el tipo de geometría (cte definido en interfaz)
|
247 |
*/
|
248 |
public int getGeomTypeAsInt() { |
249 |
return Point.GEOM_TYPE; |
250 |
} |
251 |
|
252 |
/*
|
253 |
* (non-Javadoc)
|
254 |
*
|
255 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
256 |
*/
|
257 |
public FShape cloneFShape() {
|
258 |
return new Point2D(id, projection, p.getX(), p.getY()); |
259 |
} |
260 |
|
261 |
/*
|
262 |
* (non-Javadoc)
|
263 |
*
|
264 |
* @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
|
265 |
*/
|
266 |
public void reProject(ICoordTrans ct) { |
267 |
p = ct.convert(p, p); |
268 |
} |
269 |
|
270 |
/*
|
271 |
* (non-Javadoc)
|
272 |
*
|
273 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getStretchingHandlers()
|
274 |
*/
|
275 |
public Handler[] getStretchingHandlers() { |
276 |
ArrayList handlers = new ArrayList(); |
277 |
handlers.add(new PointHandler(0, p.getX(), p.getY())); |
278 |
return (Handler[]) handlers.toArray(new Handler[0]); |
279 |
} |
280 |
|
281 |
/*
|
282 |
* (non-Javadoc)
|
283 |
*
|
284 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getSelectHandlers()
|
285 |
*/
|
286 |
public Handler[] getSelectHandlers() { |
287 |
ArrayList handlers = new ArrayList(); |
288 |
handlers.add(new PointHandler(0, p.getX(), p.getY())); |
289 |
return (Handler[]) handlers.toArray(new Handler[0]); |
290 |
} |
291 |
|
292 |
/**
|
293 |
* DOCUMENT ME!
|
294 |
*
|
295 |
* @author Vicente Caballero Navarro
|
296 |
*/
|
297 |
class PointHandler extends AbstractHandler implements FinalHandler { |
298 |
/**
|
299 |
* Crea un nuevo PointHandler.
|
300 |
*
|
301 |
* @param x
|
302 |
* DOCUMENT ME!
|
303 |
* @param y
|
304 |
* DOCUMENT ME!
|
305 |
*/
|
306 |
public PointHandler(int i, double x, double y) { |
307 |
point = new java.awt.geom.Point2D.Double(x, y);
|
308 |
index = i; |
309 |
} |
310 |
|
311 |
/**
|
312 |
* DOCUMENT ME!
|
313 |
*
|
314 |
* @param x
|
315 |
* DOCUMENT ME!
|
316 |
* @param y
|
317 |
* DOCUMENT ME!
|
318 |
*
|
319 |
* @return DOCUMENT ME!
|
320 |
*/
|
321 |
public void move(double x, double y) { |
322 |
p.setLocation(p.getX() + x, p.getY() + y); |
323 |
} |
324 |
|
325 |
/**
|
326 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
327 |
*/
|
328 |
public void set(double x, double y) { |
329 |
p.setLocation(x, y); |
330 |
} |
331 |
} |
332 |
|
333 |
/*
|
334 |
* (non-Javadoc)
|
335 |
*
|
336 |
* @see org.gvsig.geometries.iso.GM_Object#coordinateDimension()
|
337 |
*/
|
338 |
public int getCoordinateDimension() { |
339 |
return 2; |
340 |
} |
341 |
|
342 |
public GeometryType getGeometryType() {
|
343 |
return geomType;
|
344 |
} |
345 |
} |