Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FPoint2D.java @ 38563

History | View | Annotate | Download (6.33 KB)

1 1100 fjp
/* 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 262 fjp
package com.iver.cit.gvsig.fmap.core;
42
43 305 fjp
import java.awt.Rectangle;
44
import java.awt.geom.AffineTransform;
45
import java.awt.geom.PathIterator;
46
import java.awt.geom.Point2D;
47 299 fjp
import java.awt.geom.Rectangle2D;
48 2183 fernando
import java.util.ArrayList;
49 262 fjp
50 10627 caballero
import org.cresques.cts.ICoordTrans;
51 262 fjp
52 10627 caballero
import com.iver.utiles.XMLEntity;
53
54
55 262 fjp
/**
56
 * Punto 2D.
57
 *
58
 * @author Vicente Caballero Navarro
59
 */
60 324 fernando
public class FPoint2D implements FShape {
61 1005 vcaballero
        protected Point2D p;
62 262 fjp
63 1005 vcaballero
        /**
64
         * Crea un nuevo Point2D.
65
         *
66
         * @param x Coordenada x del punto.
67
         * @param y Coordenada y del punto.
68
         */
69
        public FPoint2D(double x, double y) {
70
                p = new Point2D.Double(x, y);
71
        }
72 2183 fernando
        public FPoint2D(){
73 3833 caballero
74 2183 fernando
        }
75 3035 fjp
    public FPoint2D(Point2D p) {
76
        this.p = p;
77
    }
78
79 2183 fernando
        private void setPoint(double x, double y){
80
                p = new Point2D.Double(x, y);
81
        }
82 1005 vcaballero
        /**
83
         * Aplica la transformaci?n de la matriz de transformaci?n que se pasa como
84
         * par?metro.
85
         *
86
         * @param at Matriz de transformaci?n.
87
         */
88
        public void transform(AffineTransform at) {
89
                at.transform(p, p);
90
        }
91
92 305 fjp
        /* (non-Javadoc)
93
         * @see java.awt.Shape#contains(double, double)
94
         */
95
        public boolean contains(double x, double y) {
96 1005 vcaballero
                if ((x == p.getX()) || (y == p.getY())) {
97 305 fjp
                        return true;
98 1005 vcaballero
                } else {
99
                        return false;
100
                }
101 305 fjp
        }
102 262 fjp
103 305 fjp
        /* (non-Javadoc)
104
         * @see java.awt.Shape#contains(double, double, double, double)
105
         */
106
        public boolean contains(double x, double y, double w, double h) {
107
                return false;
108
        }
109 262 fjp
110 305 fjp
        /* (non-Javadoc)
111
         * @see java.awt.Shape#intersects(double, double, double, double)
112
         */
113
        public boolean intersects(double x, double y, double w, double h) {
114 1005 vcaballero
                Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h);
115
116 703 fjp
                return rAux.contains(p.getX(), p.getY());
117 305 fjp
        }
118 262 fjp
119 305 fjp
        /* (non-Javadoc)
120
         * @see java.awt.Shape#getBounds()
121
         */
122
        public Rectangle getBounds() {
123
                return new Rectangle((int) p.getX(), (int) p.getY(), 0, 0);
124
        }
125 262 fjp
126 1005 vcaballero
        /**
127
         * Devuelve la coordenada x del punto.
128
         *
129
         * @return Coordenada x.
130
         */
131
        public double getX() {
132 458 fjp
                return p.getX();
133
        }
134 1005 vcaballero
135
        /**
136
         * Devuelve la coordenada y del punto.
137
         *
138
         * @return Coordenada y.
139
         */
140
        public double getY() {
141 458 fjp
                return p.getY();
142
        }
143 1005 vcaballero
144 267 fjp
        /* (non-Javadoc)
145 305 fjp
         * @see java.awt.Shape#contains(java.awt.geom.Point2D)
146 267 fjp
         */
147 305 fjp
        public boolean contains(Point2D p) {
148
                return false;
149 267 fjp
        }
150
151
        /* (non-Javadoc)
152 305 fjp
         * @see java.awt.Shape#getBounds2D()
153 267 fjp
         */
154
        public Rectangle2D getBounds2D() {
155 2183 fernando
                return new Rectangle2D.Double(p.getX()- 0.01, p.getY() - 0.01, 0.02, 0.02);
156 267 fjp
        }
157
158 305 fjp
        /* (non-Javadoc)
159
         * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
160
         */
161
        public boolean contains(Rectangle2D r) {
162
                return false;
163
        }
164
165
        /* (non-Javadoc)
166
         * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
167
         */
168
        public boolean intersects(Rectangle2D r) {
169 500 vcaballero
                return r.contains(this.p);
170 305 fjp
        }
171
172
        /* (non-Javadoc)
173
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
174
         */
175
        public PathIterator getPathIterator(AffineTransform at) {
176 1005 vcaballero
                return new FPointIterator(p, at);
177 305 fjp
        }
178
179
        /* (non-Javadoc)
180
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, double)
181
         */
182
        public PathIterator getPathIterator(AffineTransform at, double flatness) {
183 1005 vcaballero
                return new FPointIterator(p, at);
184 305 fjp
        }
185
186 324 fernando
        /**
187
         * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
188
         */
189
        public int getShapeType() {
190
                return FShape.POINT;
191
        }
192
193 703 fjp
        /* (non-Javadoc)
194
         * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
195
         */
196
        public FShape cloneFShape() {
197
                return new FPoint2D(p.getX(), p.getY());
198
        }
199
200 885 fjp
        /* (non-Javadoc)
201
         * @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
202
         */
203
        public void reProject(ICoordTrans ct) {
204 1005 vcaballero
                p = ct.convert(p, p);
205 885 fjp
        }
206 2183 fernando
207
        /**
208
         * @see com.iver.cit.gvsig.fmap.core.FShape#getXMLEntity()
209
         */
210
        public XMLEntity getXMLEntity() {
211
                XMLEntity xml=new XMLEntity();
212
                xml.putProperty("x",p.getX());
213
                xml.putProperty("y",p.getY());
214
                return xml;
215
        }
216
        public void setXMLEntity(XMLEntity xml){
217
                this.setPoint(xml.getDoubleProperty("x"),xml.getDoubleProperty("y"));//p=new FPoint2D(xml.getDoubleProperty("x"),xml.getDoubleProperty("y"));
218
        }
219 3833 caballero
        /* (non-Javadoc)
220
         * @see com.iver.cit.gvsig.fmap.core.FShape#getStretchingHandlers()
221
         */
222
        public Handler[] getStretchingHandlers() {
223
                ArrayList handlers = new ArrayList();
224
                handlers.add(new PointHandler(0,p.getX(),p.getY()));
225
                return (Handler[]) handlers.toArray(new Handler[0]);
226
        }
227
        /* (non-Javadoc)
228
         * @see com.iver.cit.gvsig.fmap.core.FShape#getSelectHandlers()
229
         */
230
        public Handler[] getSelectHandlers() {
231
                ArrayList handlers = new ArrayList();
232
                handlers.add(new PointHandler(0,p.getX(),p.getY()));
233
                return (Handler[]) handlers.toArray(new Handler[0]);
234
        }
235
        /**
236
         * DOCUMENT ME!
237
         *
238
         * @author Vicente Caballero Navarro
239
         */
240 8949 caballero
        class PointHandler extends AbstractHandler implements IFinalHandler{
241 3833 caballero
                /**
242
                 * Crea un nuevo PointHandler.
243
                 *
244
                 * @param x DOCUMENT ME!
245
                 * @param y DOCUMENT ME!
246
                 */
247
                public PointHandler(int i,double x, double y) {
248
                        point = new Point2D.Double(x, y);
249
                        index=i;
250
                }
251
252
                /**
253
                 * DOCUMENT ME!
254
                 *
255
                 * @param x DOCUMENT ME!
256
                 * @param y DOCUMENT ME!
257
                 *
258
                 * @return DOCUMENT ME!
259
                 */
260
                public void move(double x, double y) {
261
                        p.setLocation(p.getX()+x,p.getY()+y);
262
                }
263
264
                /**
265
                 * @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
266
                 */
267
                public void set(double x, double y) {
268
                        p.setLocation(x, y);
269
                }
270
        }
271 262 fjp
}