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