root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FPoint2D.java @ 8949
History | View | Annotate | Download (6.33 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 |
public FPoint2D(Point2D p) { |
76 |
this.p = p;
|
77 |
} |
78 |
|
79 |
private void setPoint(double x, double y){ |
80 |
p = new Point2D.Double(x, y); |
81 |
} |
82 |
/**
|
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 |
/* (non-Javadoc)
|
93 |
* @see java.awt.Shape#contains(double, double)
|
94 |
*/
|
95 |
public boolean contains(double x, double y) { |
96 |
if ((x == p.getX()) || (y == p.getY())) {
|
97 |
return true; |
98 |
} else {
|
99 |
return false; |
100 |
} |
101 |
} |
102 |
|
103 |
/* (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 |
|
110 |
/* (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 |
Rectangle2D.Double rAux = new Rectangle2D.Double(x, y, w, h); |
115 |
|
116 |
return rAux.contains(p.getX(), p.getY());
|
117 |
} |
118 |
|
119 |
/* (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 |
|
126 |
/**
|
127 |
* Devuelve la coordenada x del punto.
|
128 |
*
|
129 |
* @return Coordenada x.
|
130 |
*/
|
131 |
public double getX() { |
132 |
return p.getX();
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* Devuelve la coordenada y del punto.
|
137 |
*
|
138 |
* @return Coordenada y.
|
139 |
*/
|
140 |
public double getY() { |
141 |
return p.getY();
|
142 |
} |
143 |
|
144 |
/* (non-Javadoc)
|
145 |
* @see java.awt.Shape#contains(java.awt.geom.Point2D)
|
146 |
*/
|
147 |
public boolean contains(Point2D p) { |
148 |
return false; |
149 |
} |
150 |
|
151 |
/* (non-Javadoc)
|
152 |
* @see java.awt.Shape#getBounds2D()
|
153 |
*/
|
154 |
public Rectangle2D getBounds2D() { |
155 |
return new Rectangle2D.Double(p.getX()- 0.01, p.getY() - 0.01, 0.02, 0.02); |
156 |
} |
157 |
|
158 |
/* (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 |
return r.contains(this.p); |
170 |
} |
171 |
|
172 |
/* (non-Javadoc)
|
173 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
|
174 |
*/
|
175 |
public PathIterator getPathIterator(AffineTransform at) { |
176 |
return new FPointIterator(p, at); |
177 |
} |
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 |
return new FPointIterator(p, at); |
184 |
} |
185 |
|
186 |
/**
|
187 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
|
188 |
*/
|
189 |
public int getShapeType() { |
190 |
return FShape.POINT;
|
191 |
} |
192 |
|
193 |
/* (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 |
/* (non-Javadoc)
|
201 |
* @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
|
202 |
*/
|
203 |
public void reProject(ICoordTrans ct) { |
204 |
p = ct.convert(p, p); |
205 |
} |
206 |
|
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 |
/* (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 |
class PointHandler extends AbstractHandler implements IFinalHandler{ |
241 |
/**
|
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 |
} |