root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FPoint2D.java @ 2196
History | View | Annotate | Download (5.02 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 | 1005 | vcaballero | import org.cresques.cts.ICoordTrans; |
44 | |||
45 | 2183 | fernando | import com.iver.utiles.XMLEntity; |
46 | |||
47 | 305 | fjp | import java.awt.Rectangle; |
48 | import java.awt.geom.AffineTransform; |
||
49 | import java.awt.geom.PathIterator; |
||
50 | import java.awt.geom.Point2D; |
||
51 | 299 | fjp | import java.awt.geom.Rectangle2D; |
52 | 2183 | fernando | import java.util.ArrayList; |
53 | 262 | fjp | |
54 | |||
55 | /**
|
||
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 | |||
74 | } |
||
75 | private void setPoint(double x, double y){ |
||
76 | p = new Point2D.Double(x, y); |
||
77 | } |
||
78 | 1005 | vcaballero | /**
|
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 | 305 | fjp | /* (non-Javadoc)
|
89 | * @see java.awt.Shape#contains(double, double)
|
||
90 | */
|
||
91 | public boolean contains(double x, double y) { |
||
92 | 1005 | vcaballero | if ((x == p.getX()) || (y == p.getY())) {
|
93 | 305 | fjp | return true; |
94 | 1005 | vcaballero | } else {
|
95 | return false; |
||
96 | } |
||
97 | 305 | fjp | } |
98 | 262 | fjp | |
99 | 305 | fjp | /* (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 | 262 | fjp | |
106 | 305 | fjp | /* (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 | 1005 | vcaballero | Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h); |
111 | |||
112 | 703 | fjp | return rAux.contains(p.getX(), p.getY());
|
113 | 305 | fjp | } |
114 | 262 | fjp | |
115 | 305 | fjp | /* (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 | 262 | fjp | |
122 | 1005 | vcaballero | /**
|
123 | * Devuelve la coordenada x del punto.
|
||
124 | *
|
||
125 | * @return Coordenada x.
|
||
126 | */
|
||
127 | public double getX() { |
||
128 | 458 | fjp | return p.getX();
|
129 | } |
||
130 | 1005 | vcaballero | |
131 | /**
|
||
132 | * Devuelve la coordenada y del punto.
|
||
133 | *
|
||
134 | * @return Coordenada y.
|
||
135 | */
|
||
136 | public double getY() { |
||
137 | 458 | fjp | return p.getY();
|
138 | } |
||
139 | 1005 | vcaballero | |
140 | 267 | fjp | /* (non-Javadoc)
|
141 | 305 | fjp | * @see java.awt.Shape#contains(java.awt.geom.Point2D)
|
142 | 267 | fjp | */
|
143 | 305 | fjp | public boolean contains(Point2D p) { |
144 | return false; |
||
145 | 267 | fjp | } |
146 | |||
147 | /* (non-Javadoc)
|
||
148 | 305 | fjp | * @see java.awt.Shape#getBounds2D()
|
149 | 267 | fjp | */
|
150 | public Rectangle2D getBounds2D() { |
||
151 | 2183 | fernando | return new Rectangle2D.Double(p.getX()- 0.01, p.getY() - 0.01, 0.02, 0.02); |
152 | 267 | fjp | } |
153 | |||
154 | 305 | fjp | /* (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 | 500 | vcaballero | return r.contains(this.p); |
166 | 305 | fjp | } |
167 | |||
168 | /* (non-Javadoc)
|
||
169 | * @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
|
||
170 | */
|
||
171 | public PathIterator getPathIterator(AffineTransform at) { |
||
172 | 1005 | vcaballero | return new FPointIterator(p, at); |
173 | 305 | fjp | } |
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 | 1005 | vcaballero | return new FPointIterator(p, at); |
180 | 305 | fjp | } |
181 | |||
182 | 324 | fernando | /**
|
183 | * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
|
||
184 | */
|
||
185 | public int getShapeType() { |
||
186 | return FShape.POINT;
|
||
187 | } |
||
188 | |||
189 | 703 | fjp | /* (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 | 885 | fjp | /* (non-Javadoc)
|
197 | * @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
|
||
198 | */
|
||
199 | public void reProject(ICoordTrans ct) { |
||
200 | 1005 | vcaballero | p = ct.convert(p, p); |
201 | 885 | fjp | } |
202 | 2183 | fernando | |
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 | 262 | fjp | } |