Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap / src / org / gvsig / fmap / core / shapes / FPoint2D.java @ 20989

History | View | Annotate | Download (6.49 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.core.shapes;
42

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

    
50
import org.cresques.cts.ICoordTrans;
51
import org.gvsig.fmap.core.shapes.handlers.AbstractHandler;
52
import org.gvsig.fmap.core.shapes.handlers.Handler;
53
import org.gvsig.fmap.core.shapes.handlers.IFinalHandler;
54

    
55
import com.iver.utiles.XMLEntity;
56

    
57

    
58
/**
59
 * Punto 2D.
60
 *
61
 * @author Vicente Caballero Navarro
62
 */
63
public class FPoint2D implements FShape {
64
        protected Point2D p;
65

    
66
        /**
67
         * Crea un nuevo Point2D.
68
         *
69
         * @param x Coordenada x del punto.
70
         * @param y Coordenada y del punto.
71
         */
72
        public FPoint2D(double x, double y) {
73
                p = new Point2D.Double(x, y);
74
        }
75
        public FPoint2D(){
76

    
77
        }
78
    public FPoint2D(Point2D p) {
79
        this.p = p;
80
    }
81

    
82
        private void setPoint(double x, double y){
83
                p = new Point2D.Double(x, y);
84
        }
85
        /**
86
         * Aplica la transformaci?n de la matriz de transformaci?n que se pasa como
87
         * par?metro.
88
         *
89
         * @param at Matriz de transformaci?n.
90
         */
91
        public void transform(AffineTransform at) {
92
                at.transform(p, p);
93
        }
94

    
95
        /* (non-Javadoc)
96
         * @see java.awt.Shape#contains(double, double)
97
         */
98
        public boolean contains(double x, double y) {
99
                if ((x == p.getX()) || (y == p.getY())) {
100
                        return true;
101
                } else {
102
                        return false;
103
                }
104
        }
105

    
106
        /* (non-Javadoc)
107
         * @see java.awt.Shape#contains(double, double, double, double)
108
         */
109
        public boolean contains(double x, double y, double w, double h) {
110
                return false;
111
        }
112

    
113
        /* (non-Javadoc)
114
         * @see java.awt.Shape#intersects(double, double, double, double)
115
         */
116
        public boolean intersects(double x, double y, double w, double h) {
117
                Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h);
118

    
119
                return rAux.contains(p.getX(), p.getY());
120
        }
121

    
122
        /* (non-Javadoc)
123
         * @see java.awt.Shape#getBounds()
124
         */
125
        public Rectangle getBounds() {
126
                return new Rectangle((int) p.getX(), (int) p.getY(), 0, 0);
127
        }
128

    
129
        /**
130
         * Devuelve la coordenada x del punto.
131
         *
132
         * @return Coordenada x.
133
         */
134
        public double getX() {
135
                return p.getX();
136
        }
137

    
138
        /**
139
         * Devuelve la coordenada y del punto.
140
         *
141
         * @return Coordenada y.
142
         */
143
        public double getY() {
144
                return p.getY();
145
        }
146

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

    
154
        /* (non-Javadoc)
155
         * @see java.awt.Shape#getBounds2D()
156
         */
157
        public Rectangle2D getBounds2D() {
158
                return new Rectangle2D.Double(p.getX()- 0.01, p.getY() - 0.01, 0.02, 0.02);
159
        }
160

    
161
        /* (non-Javadoc)
162
         * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
163
         */
164
        public boolean contains(Rectangle2D r) {
165
                return false;
166
        }
167

    
168
        /* (non-Javadoc)
169
         * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
170
         */
171
        public boolean intersects(Rectangle2D r) {
172
                return r.contains(this.p);
173
        }
174

    
175
        /* (non-Javadoc)
176
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
177
         */
178
        public PathIterator getPathIterator(AffineTransform at) {
179
                return new FPointIterator(p, at);
180
        }
181

    
182
        /* (non-Javadoc)
183
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, double)
184
         */
185
        public PathIterator getPathIterator(AffineTransform at, double flatness) {
186
                return new FPointIterator(p, at);
187
        }
188

    
189
        /**
190
         * @see org.gvsig.fmap.core.shapes.FShape#getShapeType()
191
         */
192
        public int getShapeType() {
193
                return FShape.POINT;
194
        }
195

    
196
        /* (non-Javadoc)
197
         * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
198
         */
199
        public FShape cloneFShape() {
200
                return new FPoint2D(p.getX(), p.getY());
201
        }
202

    
203
        /* (non-Javadoc)
204
         * @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
205
         */
206
        public void reProject(ICoordTrans ct) {
207
                p = ct.convert(p, p);
208
        }
209

    
210
        /**
211
         * @see org.gvsig.fmap.core.shapes.FShape#getXMLEntity()
212
         */
213
        public XMLEntity getXMLEntity() {
214
                XMLEntity xml=new XMLEntity();
215
                xml.putProperty("x",p.getX());
216
                xml.putProperty("y",p.getY());
217
                return xml;
218
        }
219
        public void setXMLEntity(XMLEntity xml){
220
                this.setPoint(xml.getDoubleProperty("x"),xml.getDoubleProperty("y"));//p=new FPoint2D(xml.getDoubleProperty("x"),xml.getDoubleProperty("y"));
221
        }
222
        /* (non-Javadoc)
223
         * @see com.iver.cit.gvsig.fmap.core.FShape#getStretchingHandlers()
224
         */
225
        public Handler[] getStretchingHandlers() {
226
                ArrayList handlers = new ArrayList();
227
                handlers.add(new PointHandler(0,p.getX(),p.getY()));
228
                return (Handler[]) handlers.toArray(new Handler[0]);
229
        }
230
        /* (non-Javadoc)
231
         * @see com.iver.cit.gvsig.fmap.core.FShape#getSelectHandlers()
232
         */
233
        public Handler[] getSelectHandlers() {
234
                ArrayList handlers = new ArrayList();
235
                handlers.add(new PointHandler(0,p.getX(),p.getY()));
236
                return (Handler[]) handlers.toArray(new Handler[0]);
237
        }
238
        /**
239
         * DOCUMENT ME!
240
         *
241
         * @author Vicente Caballero Navarro
242
         */
243
        class PointHandler extends AbstractHandler implements IFinalHandler{
244
                /**
245
                 * Crea un nuevo PointHandler.
246
                 *
247
                 * @param x DOCUMENT ME!
248
                 * @param y DOCUMENT ME!
249
                 */
250
                public PointHandler(int i,double x, double y) {
251
                        point = new Point2D.Double(x, y);
252
                        index=i;
253
                }
254

    
255
                /**
256
                 * DOCUMENT ME!
257
                 *
258
                 * @param x DOCUMENT ME!
259
                 * @param y DOCUMENT ME!
260
                 *
261
                 * @return DOCUMENT ME!
262
                 */
263
                public void move(double x, double y) {
264
                        p.setLocation(p.getX()+x,p.getY()+y);
265
                }
266

    
267
                /**
268
                 * @see org.gvsig.fmap.core.shapes.handlers.Handler#set(double, double)
269
                 */
270
                public void set(double x, double y) {
271
                        p.setLocation(x, y);
272
                }
273
        }
274
}