Statistics
| Revision:

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

History | View | Annotate | Download (5.02 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 com.iver.utiles.XMLEntity;
46

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

    
54

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

    
63
        /**
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
        public FPoint2D(){
73
                
74
        }
75
        private void setPoint(double x, double y){
76
                p = new Point2D.Double(x, y);
77
        }
78
        /**
79
         * Aplica la transformaci?n de la matriz de transformaci?n que se pasa como
80
         * par?metro.
81
         *
82
         * @param at Matriz de transformaci?n.
83
         */
84
        public void transform(AffineTransform at) {
85
                at.transform(p, p);
86
        }
87

    
88
        /* (non-Javadoc)
89
         * @see java.awt.Shape#contains(double, double)
90
         */
91
        public boolean contains(double x, double y) {
92
                if ((x == p.getX()) || (y == p.getY())) {
93
                        return true;
94
                } else {
95
                        return false;
96
                }
97
        }
98

    
99
        /* (non-Javadoc)
100
         * @see java.awt.Shape#contains(double, double, double, double)
101
         */
102
        public boolean contains(double x, double y, double w, double h) {
103
                return false;
104
        }
105

    
106
        /* (non-Javadoc)
107
         * @see java.awt.Shape#intersects(double, double, double, double)
108
         */
109
        public boolean intersects(double x, double y, double w, double h) {
110
                Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h);
111

    
112
                return rAux.contains(p.getX(), p.getY());
113
        }
114

    
115
        /* (non-Javadoc)
116
         * @see java.awt.Shape#getBounds()
117
         */
118
        public Rectangle getBounds() {
119
                return new Rectangle((int) p.getX(), (int) p.getY(), 0, 0);
120
        }
121

    
122
        /**
123
         * Devuelve la coordenada x del punto.
124
         *
125
         * @return Coordenada x.
126
         */
127
        public double getX() {
128
                return p.getX();
129
        }
130

    
131
        /**
132
         * Devuelve la coordenada y del punto.
133
         *
134
         * @return Coordenada y.
135
         */
136
        public double getY() {
137
                return p.getY();
138
        }
139

    
140
        /* (non-Javadoc)
141
         * @see java.awt.Shape#contains(java.awt.geom.Point2D)
142
         */
143
        public boolean contains(Point2D p) {
144
                return false;
145
        }
146

    
147
        /* (non-Javadoc)
148
         * @see java.awt.Shape#getBounds2D()
149
         */
150
        public Rectangle2D getBounds2D() {
151
                return new Rectangle2D.Double(p.getX()- 0.01, p.getY() - 0.01, 0.02, 0.02);
152
        }
153

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

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

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

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

    
182
        /**
183
         * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
184
         */
185
        public int getShapeType() {
186
                return FShape.POINT;
187
        }
188

    
189
        /* (non-Javadoc)
190
         * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
191
         */
192
        public FShape cloneFShape() {
193
                return new FPoint2D(p.getX(), p.getY());
194
        }
195

    
196
        /* (non-Javadoc)
197
         * @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
198
         */
199
        public void reProject(ICoordTrans ct) {
200
                p = ct.convert(p, p);
201
        }
202

    
203
        /**
204
         * @see com.iver.cit.gvsig.fmap.core.FShape#getXMLEntity()
205
         */
206
        public XMLEntity getXMLEntity() {
207
                XMLEntity xml=new XMLEntity();
208
                xml.putProperty("x",p.getX());
209
                xml.putProperty("y",p.getY());
210
                return xml;
211
        }
212
        public void setXMLEntity(XMLEntity xml){
213
                this.setPoint(xml.getDoubleProperty("x"),xml.getDoubleProperty("y"));//p=new FPoint2D(xml.getDoubleProperty("x"),xml.getDoubleProperty("y"));
214
        }
215
}