Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / Point2D.java @ 21732

History | View | Annotate | Download (7.69 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.Geometry;
52
import org.gvsig.fmap.geom.GeometryManager;
53
import org.gvsig.fmap.geom.handler.AbstractHandler;
54
import org.gvsig.fmap.geom.handler.FinalHandler;
55
import org.gvsig.fmap.geom.handler.Handler;
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
                        .registerBasicGeometryType(Point2D.class,null,TYPES.POINT);
71

    
72
        public static final int CODE = geomType.getType();
73

    
74

    
75
        /**
76
         * Crea un nuevo Point2D.
77
         *
78
         * @param x
79
         *            Coordenada x del punto.
80
         * @param y
81
         *            Coordenada y del punto.
82
         */
83
        public Point2D(String id, IProjection projection, double x, double y) {
84
                super(id, projection);
85
                p = new java.awt.geom.Point2D.Double(x, y);
86
        }
87

    
88
        public Point2D(String id, IProjection projection, java.awt.geom.Point2D p) {
89
                super(id, projection);
90
                this.p = p;
91
        }
92

    
93
        public Point2D(java.awt.geom.Point2D p) {
94
                this(null, null, p);
95
        }
96

    
97
        public Point2D() {
98
                this(null, null, null);
99
        }
100

    
101
        public Point2D(double x, double y) {
102
                this(null, null, x, y);
103
        }
104

    
105
        /*
106
         * private void setPoint(double x, double y){ p = new
107
         * java.awt.geom.Point2D.Double(x, y); }
108
         */
109

    
110
        /**
111
         * Aplica la transformaci?n de la matriz de transformaci?n que se pasa como
112
         * par?metro.
113
         *
114
         * @param at
115
         *            Matriz de transformaci?n.
116
         */
117
        public void transform(AffineTransform at) {
118
                at.transform(p, p);
119
        }
120

    
121
        /*
122
         * (non-Javadoc)
123
         *
124
         * @see java.awt.Shape#contains(double, double)
125
         */
126
        public boolean contains(double x, double y) {
127
                if ((x == p.getX()) || (y == p.getY())) {
128
                        return true;
129
                } else {
130
                        return false;
131
                }
132
        }
133

    
134
        /*
135
         * (non-Javadoc)
136
         *
137
         * @see java.awt.Shape#contains(double, double, double, double)
138
         */
139
        public boolean contains(double x, double y, double w, double h) {
140
                return false;
141
        }
142

    
143
        /*
144
         * (non-Javadoc)
145
         *
146
         * @see java.awt.Shape#intersects(double, double, double, double)
147
         */
148
        public boolean intersects(double x, double y, double w, double h) {
149
                Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h);
150

    
151
                return rAux.contains(p.getX(), p.getY());
152
        }
153

    
154
        /*
155
         * (non-Javadoc)
156
         *
157
         * @see java.awt.Shape#getBounds()
158
         */
159
        public Rectangle getBounds() {
160
                return new Rectangle((int) p.getX(), (int) p.getY(), 0, 0);
161
        }
162

    
163
        /**
164
         * Devuelve la coordenada x del punto.
165
         *
166
         * @return Coordenada x.
167
         */
168
        public double getX() {
169
                return p.getX();
170
        }
171

    
172
        /**
173
         * Devuelve la coordenada y del punto.
174
         *
175
         * @return Coordenada y.
176
         */
177
        public double getY() {
178
                return p.getY();
179
        }
180

    
181
        /*
182
         * (non-Javadoc)
183
         *
184
         * @see java.awt.Shape#contains(java.awt.geom.Point2D)
185
         */
186
        public boolean contains(java.awt.geom.Point2D p) {
187
                return false;
188
        }
189

    
190
        /*
191
         * (non-Javadoc)
192
         *
193
         * @see java.awt.Shape#getBounds2D()
194
         */
195
        public Rectangle2D getBounds2D() {
196
                return new Rectangle2D.Double(p.getX() - 0.01, p.getY() - 0.01, 0.02,
197
                                0.02);
198
        }
199

    
200
        /*
201
         * (non-Javadoc)
202
         *
203
         * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
204
         */
205
        public boolean contains(Rectangle2D r) {
206
                return false;
207
        }
208

    
209
        /*
210
         * (non-Javadoc)
211
         *
212
         * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
213
         */
214
        public boolean intersects(Rectangle2D r) {
215
                return r.contains(this.p);
216
        }
217

    
218
        /*
219
         * (non-Javadoc)
220
         *
221
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
222
         */
223
        public PathIterator getPathIterator(AffineTransform at) {
224
                return new PointIterator(p, at);
225
        }
226

    
227
        /*
228
         * (non-Javadoc)
229
         *
230
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform,
231
         *      double)
232
         */
233
        public PathIterator getPathIterator(AffineTransform at, double flatness) {
234
                return new PointIterator(p, at);
235
        }
236

    
237
        /**
238
         * @see org.gvsig.fmap.geom.primitive.FShape#getShapeType()
239
         */
240
        public int getShapeType() {
241
                return FShape.POINT;
242
        }
243

    
244
        /**
245
         * Devuelve el tipo de geometr?a (cte definido en interfaz)
246
         */
247
        public int getType() {
248
                return CODE;
249
        }
250

    
251
        /*
252
         * (non-Javadoc)
253
         *
254
         * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
255
         */
256
        public FShape cloneFShape() {
257
                return new Point2D(id, projection, p.getX(), p.getY());
258
        }
259

    
260
        /*
261
         * (non-Javadoc)
262
         *
263
         * @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
264
         */
265
        public void reProject(ICoordTrans ct) {
266
                p = ct.convert(p, p);
267
        }
268

    
269
        /*
270
         * (non-Javadoc)
271
         *
272
         * @see com.iver.cit.gvsig.fmap.core.FShape#getStretchingHandlers()
273
         */
274
        public Handler[] getStretchingHandlers() {
275
                ArrayList handlers = new ArrayList();
276
                handlers.add(new PointHandler(0, p.getX(), p.getY()));
277
                return (Handler[]) handlers.toArray(new Handler[0]);
278
        }
279

    
280
        /*
281
         * (non-Javadoc)
282
         *
283
         * @see com.iver.cit.gvsig.fmap.core.FShape#getSelectHandlers()
284
         */
285
        public Handler[] getSelectHandlers() {
286
                ArrayList handlers = new ArrayList();
287
                handlers.add(new PointHandler(0, p.getX(), p.getY()));
288
                return (Handler[]) handlers.toArray(new Handler[0]);
289
        }
290

    
291
        /**
292
         * DOCUMENT ME!
293
         *
294
         * @author Vicente Caballero Navarro
295
         */
296
        class PointHandler extends AbstractHandler implements FinalHandler {
297
                /**
298
                 * Crea un nuevo PointHandler.
299
                 *
300
                 * @param x
301
                 *            DOCUMENT ME!
302
                 * @param y
303
                 *            DOCUMENT ME!
304
                 */
305
                public PointHandler(int i, double x, double y) {
306
                        point = new java.awt.geom.Point2D.Double(x, y);
307
                        index = i;
308
                }
309

    
310
                /**
311
                 * DOCUMENT ME!
312
                 *
313
                 * @param x
314
                 *            DOCUMENT ME!
315
                 * @param y
316
                 *            DOCUMENT ME!
317
                 *
318
                 * @return DOCUMENT ME!
319
                 */
320
                public void move(double x, double y) {
321
                        p.setLocation(p.getX() + x, p.getY() + y);
322
                }
323

    
324
                /**
325
                 * @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
326
                 */
327
                public void set(double x, double y) {
328
                        p.setLocation(x, y);
329
                }
330
        }
331

    
332
        /*
333
         * (non-Javadoc)
334
         *
335
         * @see org.gvsig.geometries.iso.GM_Object#coordinateDimension()
336
         */
337
        public int getCoordinateDimension() {
338
                return 2;
339
        }
340

    
341
        public GeometryType getGeometryType() {
342
                return geomType;
343
        }
344

    
345
        public Envelope getEnvelope() {
346
                return new DefaultEnvelope(2,new double[]{p.getX() - 0.01, p.getY() - 0.01},new double[]{ p.getX()+0.02,p.getY()+
347
                                0.02});
348
        }
349

    
350
        public GeneralPathX getGeneralPath() {
351
                // TODO Auto-generated method stub
352
                return null;
353
        }
354
}