Statistics
| Revision:

root / branches / pilotoDWG / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FPoint2D.java @ 1570

History | View | Annotate | Download (5.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 com.iver.cit.gvsig.fmap.core;
42

    
43
import org.cresques.cts.ICoordTrans;
44

    
45
import java.awt.Rectangle;
46
import java.awt.geom.AffineTransform;
47
import java.awt.geom.PathIterator;
48
import java.awt.geom.Point2D;
49
import java.awt.geom.Rectangle2D;
50
import java.util.ArrayList;
51

    
52

    
53
/**
54
 * Punto 2D.
55
 *
56
 * @author Vicente Caballero Navarro
57
 */
58
public class FPoint2D implements FShape {
59
        protected Point2D p;
60

    
61
        /**
62
         * Crea un nuevo Point2D.
63
         *
64
         * @param x Coordenada x del punto.
65
         * @param y Coordenada y del punto.
66
         */
67
        public FPoint2D(double x, double y) {
68
                p = new Point2D.Double(x, y);
69
        }
70

    
71
        /**
72
         * Aplica la transformaci?n de la matriz de transformaci?n que se pasa como
73
         * par?metro.
74
         *
75
         * @param at Matriz de transformaci?n.
76
         */
77
        public void transform(AffineTransform at) {
78
                at.transform(p, p);
79
        }
80

    
81
        /* (non-Javadoc)
82
         * @see java.awt.Shape#contains(double, double)
83
         */
84
        public boolean contains(double x, double y) {
85
                if ((x == p.getX()) || (y == p.getY())) {
86
                        return true;
87
                } else {
88
                        return false;
89
                }
90
        }
91

    
92
        /* (non-Javadoc)
93
         * @see java.awt.Shape#contains(double, double, double, double)
94
         */
95
        public boolean contains(double x, double y, double w, double h) {
96
                return false;
97
        }
98

    
99
        /* (non-Javadoc)
100
         * @see java.awt.Shape#intersects(double, double, double, double)
101
         */
102
        public boolean intersects(double x, double y, double w, double h) {
103
                Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h);
104

    
105
                return rAux.contains(p.getX(), p.getY());
106
        }
107

    
108
        /* (non-Javadoc)
109
         * @see java.awt.Shape#getBounds()
110
         */
111
        public Rectangle getBounds() {
112
                return new Rectangle((int) p.getX(), (int) p.getY(), 0, 0);
113
        }
114

    
115
        /**
116
         * Devuelve la coordenada x del punto.
117
         *
118
         * @return Coordenada x.
119
         */
120
        public double getX() {
121
                return p.getX();
122
        }
123

    
124
        /**
125
         * Devuelve la coordenada y del punto.
126
         *
127
         * @return Coordenada y.
128
         */
129
        public double getY() {
130
                return p.getY();
131
        }
132

    
133
        /* (non-Javadoc)
134
         * @see java.awt.Shape#contains(java.awt.geom.Point2D)
135
         */
136
        public boolean contains(Point2D p) {
137
                return false;
138
        }
139

    
140
        /* (non-Javadoc)
141
         * @see java.awt.Shape#getBounds2D()
142
         */
143
        public Rectangle2D getBounds2D() {
144
                return new Rectangle2D.Double(p.getX()- 1000, p.getY() - 1000, 2000, 2000);
145
        }
146

    
147
        /* (non-Javadoc)
148
         * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
149
         */
150
        public boolean contains(Rectangle2D r) {
151
                return false;
152
        }
153

    
154
        /* (non-Javadoc)
155
         * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
156
         */
157
        public boolean intersects(Rectangle2D r) {
158
                return r.contains(this.p);
159
        }
160

    
161
        /* (non-Javadoc)
162
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
163
         */
164
        public PathIterator getPathIterator(AffineTransform at) {
165
                return new FPointIterator(p, at);
166
        }
167

    
168
        /* (non-Javadoc)
169
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, double)
170
         */
171
        public PathIterator getPathIterator(AffineTransform at, double flatness) {
172
                return new FPointIterator(p, at);
173
        }
174

    
175
        /**
176
         * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
177
         */
178
        public int getShapeType() {
179
                return FShape.POINT;
180
        }
181

    
182
        /* (non-Javadoc)
183
         * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
184
         */
185
        public FShape cloneFShape() {
186
                return new FPoint2D(p.getX(), p.getY());
187
        }
188

    
189
        /* (non-Javadoc)
190
         * @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
191
         */
192
        public void reProject(ICoordTrans ct) {
193
                p = ct.convert(p, p);
194
        }
195

    
196
        /**
197
         * @see com.iver.cit.gvsig.fmap.core.FShape#getStretchingHandlers()
198
         */
199
        public Handler[] getStretchingHandlers() {
200
                ArrayList handlers = new ArrayList();
201
                handlers.add(new PointHandler(0,p.getX(),p.getY()));
202
                return (Handler[]) handlers.toArray(new Handler[0]);
203
        }
204
        /**
205
         * DOCUMENT ME!
206
         *
207
         * @author Vicente Caballero Navarro
208
         */
209
        class PointHandler extends AbstractHandler {
210
                /**
211
                 * Crea un nuevo PointHandler.
212
                 *
213
                 * @param x DOCUMENT ME!
214
                 * @param y DOCUMENT ME!
215
                 */
216
                public PointHandler(int i,double x, double y) {
217
                        point = new Point2D.Double(x, y);
218
                        index=i;
219
                }
220

    
221
                /**
222
                 * DOCUMENT ME!
223
                 *
224
                 * @param x DOCUMENT ME!
225
                 * @param y DOCUMENT ME!
226
                 *
227
                 * @return DOCUMENT ME!
228
                 */
229
                public void move(double x, double y) {
230
                        p.setLocation(p.getX()+x,p.getY()+y);
231
                }
232

    
233
                /**
234
                 * @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
235
                 */
236
                public void set(double x, double y) {
237
                        p.setLocation(x, y);
238
                }
239
        }
240
        /**
241
         * @see com.iver.cit.gvsig.fmap.core.FShape#getSelectHandlers()
242
         */
243
        public Handler[] getSelectHandlers() {
244
                ArrayList handlers = new ArrayList();
245
                handlers.add(new PointHandler(0,p.getX(),p.getY()));
246
                return (Handler[]) handlers.toArray(new Handler[0]);
247
        }
248
}