Statistics
| Revision:

root / branches / Mobile_Compatible_Hito_1 / libFMap / src / es / prodevelop / gvsig / mobile / fmap / core / FPoint2D.java @ 21606

History | View | Annotate | Download (6.7 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
/************************************************
42
 *                                                                                                *
43
 *   Modfied By:                                                                *
44
 *   Prodevelop Integraci?n de Tecnolog?as SL        *
45
 *   Conde Salvatierra de ?lava , 34-10                        *
46
 *   46004 Valencia                                                                *
47
 *   Spain                                                                                *
48
 *                                                                                                *
49
 *   +34 963 510 612                                                        *
50
 *   +34 963 510 968                                                        *
51
 *   gis@prodevelop.es                                                        *
52
 *   http://www.prodevelop.es                                        *
53
 *                                                                                                *
54
 *   gvSIG Mobile Team 2006                                         *
55
 *                                                                                          *         
56
 ************************************************/
57

    
58
package es.prodevelop.gvsig.mobile.fmap.core;
59

    
60
import java.awt.Rectangle;
61
import java.awt.geom.AffineTransform;
62
import java.awt.geom.PathIterator;
63
import java.awt.geom.Point2D;
64
import java.awt.geom.Rectangle2D;
65
import java.util.ArrayList;
66

    
67
import es.prodevelop.gvsig.mobile.fmap.proj.ICoordTrans;
68

    
69
/**
70
 * Punto 2D.
71
 *
72
 * @author Vicente Caballero Navarro
73
 */
74
public class FPoint2D implements FShape {
75
        protected Point2D p;
76

    
77
        /**
78
         * Crea un nuevo Point2D.
79
         *
80
         * @param x Coordenada x del punto.
81
         * @param y Coordenada y del punto.
82
         */
83
        public FPoint2D(double x, double y) {
84
                p = new Point2D.Double(x, y);
85
        }
86
        public FPoint2D(){
87

    
88
        }
89
    public FPoint2D(Point2D p) {
90
        this.p = p;
91
    }
92

    
93
        private void setPoint(double x, double y){
94
                p = new Point2D.Double(x, y);
95
        }
96
        /**
97
         * Aplica la transformaci?n de la matriz de transformaci?n que se pasa como
98
         * par?metro.
99
         *
100
         * @param at Matriz de transformaci?n.
101
         */
102
        public void transform(AffineTransform at) {
103
                at.transform(p, p);
104
        }
105

    
106
        /* (non-Javadoc)
107
         * @see java.awt.Shape#contains(double, double)
108
         */
109
        public boolean contains(double x, double y) {
110
                if ((x == p.getX()) || (y == p.getY())) {
111
                        return true;
112
                } else {
113
                        return false;
114
                }
115
        }
116

    
117
        /* (non-Javadoc)
118
         * @see java.awt.Shape#contains(double, double, double, double)
119
         */
120
        public boolean contains(double x, double y, double w, double h) {
121
                return false;
122
        }
123

    
124
        /* (non-Javadoc)
125
         * @see java.awt.Shape#intersects(double, double, double, double)
126
         */
127
        public boolean intersects(double x, double y, double w, double h) {
128
                Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h);
129

    
130
                return rAux.contains(p.getX(), p.getY());
131
        }
132

    
133
        /* (non-Javadoc)
134
         * @see java.awt.Shape#getBounds()
135
         */
136
        public Rectangle getBounds() {
137
                return new Rectangle((int) p.getX(), (int) p.getY(), 0, 0);
138
        }
139

    
140
        /**
141
         * Devuelve la coordenada x del punto.
142
         *
143
         * @return Coordenada x.
144
         */
145
        public double getX() {
146
                return p.getX();
147
        }
148

    
149
        /**
150
         * Devuelve la coordenada y del punto.
151
         *
152
         * @return Coordenada y.
153
         */
154
        public double getY() {
155
                return p.getY();
156
        }
157

    
158
        /* (non-Javadoc)
159
         * @see java.awt.Shape#contains(java.awt.geom.Point2D)
160
         */
161
        public boolean contains(Point2D p) {
162
                return false;
163
        }
164

    
165
        /* (non-Javadoc)
166
         * @see java.awt.Shape#getBounds2D()
167
         */
168
        public Rectangle2D getBounds2D() {
169
                return new Rectangle2D.Double(p.getX()- 0.01, p.getY() - 0.01, 0.02, 0.02);
170
        }
171

    
172
        /* (non-Javadoc)
173
         * @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
174
         */
175
        public boolean contains(Rectangle2D r) {
176
                return false;
177
        }
178

    
179
        /* (non-Javadoc)
180
         * @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
181
         */
182
        public boolean intersects(Rectangle2D r) {
183
                return r.contains(this.p);
184
        }
185

    
186
        /* (non-Javadoc)
187
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
188
         */
189
        public PathIterator getPathIterator(AffineTransform at) {
190
                return new FPointIterator(p, at);
191
        }
192

    
193
        /* (non-Javadoc)
194
         * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, double)
195
         */
196
        public PathIterator getPathIterator(AffineTransform at, double flatness) {
197
                return new FPointIterator(p, at);
198
        }
199

    
200
        /**
201
         * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
202
         */
203
        public int getShapeType() {
204
                return FShape.POINT;
205
        }
206

    
207
        /* (non-Javadoc)
208
         * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
209
         */
210
        public FShape cloneFShape() {
211
                return new FPoint2D(p.getX(), p.getY());
212
        }
213

    
214
        /* (non-Javadoc)
215
         * @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
216
         */
217
        public void reProject(ICoordTrans ct) {
218
                p = ct.convert(p);
219
        }
220

    
221
        /**
222
         * @see com.iver.cit.gvsig.fmap.core.FShape#getXMLEntity()
223
         *//*
224
        public XMLEntity getXMLEntity() {
225
                XMLEntity xml=new XMLEntity();
226
                xml.putProperty("x",p.getX());
227
                xml.putProperty("y",p.getY());
228
                return xml;
229
        }*//*
230
        public void setXMLEntity(XMLEntity xml){
231
                this.setPoint(xml.getDoubleProperty("x"),xml.getDoubleProperty("y"));//p=new FPoint2D(xml.getDoubleProperty("x"),xml.getDoubleProperty("y"));
232
        }*/
233
        /* (non-Javadoc)
234
         * @see com.iver.cit.gvsig.fmap.core.FShape#getStretchingHandlers()
235
         */
236
        public Handler[] getStretchingHandlers() {
237
                ArrayList handlers = new ArrayList();
238
                handlers.add(new PointHandler(0,p.getX(),p.getY()));
239
                return (Handler[]) handlers.toArray(new Handler[0]);
240
        }
241
        /* (non-Javadoc)
242
         * @see com.iver.cit.gvsig.fmap.core.FShape#getSelectHandlers()
243
         */
244
        public Handler[] getSelectHandlers() {
245
                ArrayList handlers = new ArrayList();
246
                handlers.add(new PointHandler(0,p.getX(),p.getY()));
247
                return (Handler[]) handlers.toArray(new Handler[0]);
248
        }
249
        /**
250
         * 
251
         *
252
         * @author Vicente Caballero Navarro
253
         */
254
        class PointHandler extends AbstractHandler {
255
                /**
256
                 * Crea un nuevo PointHandler.
257
                 *
258
                 * @param x 
259
                 * @param y 
260
                 */
261
                public PointHandler(int i,double x, double y) {
262
                        point = new Point2D.Double(x, y);
263
                        index=i;
264
                }
265

    
266
                /**
267
                 * 
268
                 *
269
                 * @param x 
270
                 * @param y 
271
                 *
272
                 * @return 
273
                 */
274
                public void move(double x, double y) {
275
                        p.setLocation(p.getX()+x,p.getY()+y);
276
                }
277

    
278
                /**
279
                 * @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
280
                 */
281
                public void set(double x, double y) {
282
                        p.setLocation(x, y);
283
                }
284
        }
285
}