Revision 34118 branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/primitive/impl/OrientablePrimitive2D.java
OrientablePrimitive2D.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import org.cresques.cts.ICoordTrans; |
12 | 12 |
import org.cresques.cts.IProjection; |
13 |
|
|
13 | 14 |
import org.gvsig.fmap.geom.handler.AbstractHandler; |
14 | 15 |
import org.gvsig.fmap.geom.handler.FinalHandler; |
15 | 16 |
import org.gvsig.fmap.geom.handler.Handler; |
... | ... | |
17 | 18 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
18 | 19 |
import org.gvsig.fmap.geom.primitive.GeneralPathXIterator; |
19 | 20 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
21 |
import org.gvsig.fmap.geom.primitive.Point; |
|
20 | 22 |
import org.gvsig.fmap.geom.type.GeometryType; |
21 |
import org.gvsig.fmap.geom.util.Converter; |
|
22 | 23 |
|
23 | 24 |
|
24 | 25 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
... | ... | |
74 | 75 |
* @author Jorge Piera Llodr? (jorge.piera@iver.es) |
75 | 76 |
*/ |
76 | 77 |
public abstract class OrientablePrimitive2D extends AbstractPrimitive implements OrientablePrimitive { |
77 |
private static final long serialVersionUID = -820881421374434713L;
|
|
78 |
protected GeneralPathX gp;
|
|
78 |
private static final long serialVersionUID = -820881421374434713L;
|
|
79 |
protected GeneralPathX gp;
|
|
79 | 80 |
|
80 |
/** |
|
81 |
* The constructor with the GeometryType like and argument |
|
82 |
* is used by the {@link GeometryType}{@link #create()} |
|
83 |
* to create the geometry |
|
84 |
* @param type |
|
85 |
* The geometry type |
|
86 |
*/ |
|
87 |
public OrientablePrimitive2D(GeometryType geometryType) { |
|
88 |
super(geometryType, null, null); |
|
89 |
} |
|
90 |
|
|
91 |
public OrientablePrimitive2D(GeometryType geometryType, String id, IProjection projection, GeneralPathX gp){ |
|
92 |
super(geometryType, id, projection); |
|
93 |
this.gp = gp; |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* TODO método creado para dar visibilidad a gp despues de la refactorización |
|
98 |
* @return |
|
99 |
*/ |
|
100 |
public GeneralPathX getGeneralPathX() { |
|
101 |
return gp; |
|
102 |
} |
|
81 |
/** |
|
82 |
* The constructor with the GeometryType like and argument |
|
83 |
* is used by the {@link GeometryType}{@link #create()} |
|
84 |
* to create the geometry |
|
85 |
* @param type |
|
86 |
* The geometry type |
|
87 |
*/ |
|
88 |
public OrientablePrimitive2D(GeometryType geometryType) { |
|
89 |
super(geometryType, null, null); |
|
90 |
} |
|
103 | 91 |
|
104 |
/* (non-Javadoc) |
|
105 |
* @see java.awt.Shape#contains(double, double) |
|
106 |
*/ |
|
107 |
public boolean contains(double x, double y) { |
|
108 |
return gp.contains(x, y); |
|
109 |
} |
|
92 |
public OrientablePrimitive2D(GeometryType geometryType, String id, IProjection projection, GeneralPathX gp){ |
|
93 |
super(geometryType, id, projection); |
|
94 |
this.gp = gp; |
|
95 |
} |
|
110 | 96 |
|
111 |
/* (non-Javadoc) |
|
112 |
* @see java.awt.Shape#contains(double, double, double, double) |
|
113 |
*/ |
|
114 |
public boolean contains(double x, double y, double w, double h) { |
|
115 |
return gp.contains(x, y, w, h); |
|
116 |
} |
|
97 |
/** |
|
98 |
* TODO método creado para dar visibilidad a gp despues de la refactorización |
|
99 |
* @return |
|
100 |
*/ |
|
101 |
public GeneralPathX getGeneralPathX() { |
|
102 |
return gp; |
|
103 |
} |
|
117 | 104 |
|
118 |
/* (non-Javadoc) |
|
119 |
* @see java.awt.Shape#intersects(double, double, double, double) |
|
120 |
*/ |
|
121 |
public boolean intersects(double x, double y, double w, double h) { |
|
122 |
// M�s r�pido |
|
123 |
return gp.intersects(x, y, w, h); |
|
124 |
} |
|
105 |
/* (non-Javadoc) |
|
106 |
* @see java.awt.Shape#contains(double, double) |
|
107 |
*/ |
|
108 |
public boolean contains(double x, double y) { |
|
109 |
return gp.contains(x, y); |
|
110 |
} |
|
125 | 111 |
|
126 |
/* (non-Javadoc)
|
|
127 |
* @see java.awt.Shape#getBounds()
|
|
128 |
*/
|
|
129 |
public Rectangle getBounds() {
|
|
130 |
return gp.getBounds();
|
|
131 |
}
|
|
112 |
/* (non-Javadoc)
|
|
113 |
* @see java.awt.Shape#contains(double, double, double, double)
|
|
114 |
*/
|
|
115 |
public boolean contains(double x, double y, double w, double h) {
|
|
116 |
return gp.contains(x, y, w, h);
|
|
117 |
}
|
|
132 | 118 |
|
133 |
/* (non-Javadoc) |
|
134 |
* @see java.awt.Shape#contains(java.awt.geom.Point2D) |
|
135 |
*/ |
|
136 |
public boolean contains(Point2D p) { |
|
137 |
return gp.contains(p); |
|
138 |
} |
|
119 |
/* (non-Javadoc) |
|
120 |
* @see java.awt.Shape#intersects(double, double, double, double) |
|
121 |
*/ |
|
122 |
public boolean intersects(double x, double y, double w, double h) { |
|
123 |
// M�s r�pido |
|
124 |
return gp.intersects(x, y, w, h); |
|
125 |
} |
|
139 | 126 |
|
140 |
/* (non-Javadoc)
|
|
141 |
* @see java.awt.Shape#getBounds2D()
|
|
142 |
*/
|
|
143 |
public Rectangle2D getBounds2D() {
|
|
144 |
return gp.getBounds2D();
|
|
145 |
}
|
|
127 |
/* (non-Javadoc)
|
|
128 |
* @see java.awt.Shape#getBounds()
|
|
129 |
*/
|
|
130 |
public Rectangle getBounds() {
|
|
131 |
return gp.getBounds();
|
|
132 |
}
|
|
146 | 133 |
|
147 |
/* (non-Javadoc)
|
|
148 |
* @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
|
|
149 |
*/
|
|
150 |
public boolean contains(Rectangle2D r) {
|
|
151 |
return gp.contains(r);
|
|
152 |
}
|
|
134 |
/* (non-Javadoc)
|
|
135 |
* @see java.awt.Shape#contains(java.awt.geom.Point2D)
|
|
136 |
*/
|
|
137 |
public boolean contains(Point2D p) {
|
|
138 |
return gp.contains(p);
|
|
139 |
}
|
|
153 | 140 |
|
154 |
/** |
|
155 |
* El m�todo intersects de java.awt.Shape que define la intersecci�n entre |
|
156 |
* una polil�nea y un Rectangle2D considera la polil�nea como un Shape |
|
157 |
* gen�rico y se producen errores en la selecci�n de polil�neas. Por este |
|
158 |
* motivo se ha modificado este m�todo intersect() de FPolyline2D para que |
|
159 |
* realize la intersecci�n estricta entre el Rectangle2D y la polil�nea en |
|
160 |
* cuesti�n. El precio es un incremento de tiempo m�ximo del 50%. |
|
161 |
* |
|
162 |
* @param r Rect�ngulo. |
|
163 |
* |
|
164 |
* @return True si intersecta con el rectangulo que se pasa como par�metro. |
|
165 |
*/ |
|
166 |
public boolean intersects(Rectangle2D r) { |
|
167 |
//return gp.intersects(r); |
|
168 |
// M�s exacto |
|
169 |
boolean bool = false; |
|
170 |
if (gp.intersects(r)) { |
|
171 |
ArrayList arrayCoords; |
|
172 |
int theType; |
|
173 |
//Use this array to store segment coordinate data |
|
174 |
double[] theData = new double[6]; |
|
175 |
PathIterator theIterator; |
|
141 |
/* (non-Javadoc) |
|
142 |
* @see java.awt.Shape#getBounds2D() |
|
143 |
*/ |
|
144 |
public Rectangle2D getBounds2D() { |
|
145 |
return gp.getBounds2D(); |
|
146 |
} |
|
176 | 147 |
|
177 |
Point2D p1 = new Point2D.Double(r.getMinX(),r.getMinY()); |
|
178 |
Point2D p2 = new Point2D.Double(r.getMinX(),r.getMaxY()); |
|
179 |
Point2D p3 = new Point2D.Double(r.getMaxX(),r.getMaxY()); |
|
180 |
Point2D p4 = new Point2D.Double(r.getMaxX(),r.getMinY()); |
|
181 |
Line2D l1 = new Line2D.Double(p1,p2); |
|
182 |
Line2D l2 = new Line2D.Double(p2,p3); |
|
183 |
Line2D l3 = new Line2D.Double(p3,p4); |
|
184 |
Line2D l4 = new Line2D.Double(p4,p1); |
|
148 |
/* (non-Javadoc) |
|
149 |
* @see java.awt.Shape#contains(java.awt.geom.Rectangle2D) |
|
150 |
*/ |
|
151 |
public boolean contains(Rectangle2D r) { |
|
152 |
return gp.contains(r); |
|
153 |
} |
|
185 | 154 |
|
186 |
theIterator = this.getPathIterator(null, geomManager.getFlatness()); |
|
187 |
arrayCoords = new ArrayList(); |
|
188 |
while(!theIterator.isDone()) { |
|
189 |
theType = theIterator.currentSegment(theData); |
|
190 |
if (theType==PathIterator.SEG_MOVETO) { |
|
191 |
arrayCoords.add(new Point2D.Double(theData[0], theData[1])); |
|
192 |
} else if (theType==PathIterator.SEG_LINETO) { |
|
193 |
arrayCoords.add(new Point2D.Double(theData[0], theData[1])); |
|
194 |
Point2D pAnt = (Point2D)arrayCoords.get(arrayCoords.size()-2); |
|
195 |
Line2D l = new Line2D.Double(pAnt.getX(),pAnt.getY(),theData[0],theData[1]); |
|
196 |
if (l.intersectsLine(l1.getX1(),l1.getY1(),l1.getX2(),l1.getY2()) |
|
197 |
|| l.intersectsLine(l2.getX1(),l2.getY1(),l2.getX2(),l2.getY2()) |
|
198 |
|| l.intersectsLine(l3.getX1(),l3.getY1(),l3.getX2(),l3.getY2()) |
|
199 |
|| l.intersectsLine(l4.getX1(),l4.getY1(),l4.getX2(),l4.getY2()) |
|
200 |
|| r.intersectsLine(l)) { |
|
201 |
bool = true; |
|
202 |
} |
|
203 |
} else if(theType==PathIterator.SEG_CLOSE){ |
|
204 |
Point2D firstPoint=(Point2D)arrayCoords.get(0); |
|
205 |
Point2D pAnt = (Point2D)arrayCoords.get(arrayCoords.size()-1); |
|
206 |
Line2D l = new Line2D.Double(pAnt.getX(),pAnt.getY(),firstPoint.getX(),firstPoint.getY()); |
|
207 |
if (l.intersectsLine(l1.getX1(),l1.getY1(),l1.getX2(),l1.getY2()) |
|
208 |
|| l.intersectsLine(l2.getX1(),l2.getY1(),l2.getX2(),l2.getY2()) |
|
209 |
|| l.intersectsLine(l3.getX1(),l3.getY1(),l3.getX2(),l3.getY2()) |
|
210 |
|| l.intersectsLine(l4.getX1(),l4.getY1(),l4.getX2(),l4.getY2()) |
|
211 |
|| r.intersectsLine(l)) { |
|
212 |
bool = true; |
|
213 |
} |
|
214 |
}else { |
|
215 |
System.out.println("Not supported here"); |
|
216 |
} |
|
217 |
theIterator.next(); |
|
218 |
} |
|
219 |
} |
|
220 |
return bool; |
|
221 |
} |
|
155 |
/** |
|
156 |
* El m�todo intersects de java.awt.Shape que define la intersecci�n entre |
|
157 |
* una polil�nea y un Rectangle2D considera la polil�nea como un Shape |
|
158 |
* gen�rico y se producen errores en la selecci�n de polil�neas. Por este |
|
159 |
* motivo se ha modificado este m�todo intersect() de FPolyline2D para que |
|
160 |
* realize la intersecci�n estricta entre el Rectangle2D y la polil�nea en |
|
161 |
* cuesti�n. El precio es un incremento de tiempo m�ximo del 50%. |
|
162 |
* |
|
163 |
* @param r Rect�ngulo. |
|
164 |
* |
|
165 |
* @return True si intersecta con el rectangulo que se pasa como par�metro. |
|
166 |
*/ |
|
167 |
public boolean intersects(Rectangle2D r) { |
|
168 |
//return gp.intersects(r); |
|
169 |
// M�s exacto |
|
170 |
boolean bool = false; |
|
171 |
if (gp.intersects(r)) { |
|
172 |
ArrayList arrayCoords; |
|
173 |
int theType; |
|
174 |
//Use this array to store segment coordinate data |
|
175 |
double[] theData = new double[6]; |
|
176 |
PathIterator theIterator; |
|
222 | 177 |
|
223 |
/* (non-Javadoc) |
|
224 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform) |
|
225 |
*/ |
|
226 |
public PathIterator getPathIterator(AffineTransform at) { |
|
227 |
return gp.getPathIterator(at); |
|
228 |
} |
|
178 |
Point2D p1 = new Point2D.Double(r.getMinX(),r.getMinY()); |
|
179 |
Point2D p2 = new Point2D.Double(r.getMinX(),r.getMaxY()); |
|
180 |
Point2D p3 = new Point2D.Double(r.getMaxX(),r.getMaxY()); |
|
181 |
Point2D p4 = new Point2D.Double(r.getMaxX(),r.getMinY()); |
|
182 |
Line2D l1 = new Line2D.Double(p1,p2); |
|
183 |
Line2D l2 = new Line2D.Double(p2,p3); |
|
184 |
Line2D l3 = new Line2D.Double(p3,p4); |
|
185 |
Line2D l4 = new Line2D.Double(p4,p1); |
|
229 | 186 |
|
230 |
/* (non-Javadoc) |
|
231 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, double) |
|
232 |
*/ |
|
233 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
|
234 |
return gp.getPathIterator(at, flatness); |
|
235 |
} |
|
187 |
theIterator = this.getPathIterator(null, geomManager.getFlatness()); |
|
188 |
arrayCoords = new ArrayList(); |
|
189 |
while(!theIterator.isDone()) { |
|
190 |
theType = theIterator.currentSegment(theData); |
|
191 |
if (theType==PathIterator.SEG_MOVETO) { |
|
192 |
arrayCoords.add(new Point2D.Double(theData[0], theData[1])); |
|
193 |
} else if (theType==PathIterator.SEG_LINETO) { |
|
194 |
arrayCoords.add(new Point2D.Double(theData[0], theData[1])); |
|
195 |
Point2D pAnt = (Point2D)arrayCoords.get(arrayCoords.size()-2); |
|
196 |
Line2D l = new Line2D.Double(pAnt.getX(),pAnt.getY(),theData[0],theData[1]); |
|
197 |
if (l.intersectsLine(l1.getX1(),l1.getY1(),l1.getX2(),l1.getY2()) |
|
198 |
|| l.intersectsLine(l2.getX1(),l2.getY1(),l2.getX2(),l2.getY2()) |
|
199 |
|| l.intersectsLine(l3.getX1(),l3.getY1(),l3.getX2(),l3.getY2()) |
|
200 |
|| l.intersectsLine(l4.getX1(),l4.getY1(),l4.getX2(),l4.getY2()) |
|
201 |
|| r.intersectsLine(l)) { |
|
202 |
bool = true; |
|
203 |
} |
|
204 |
} else if(theType==PathIterator.SEG_CLOSE){ |
|
205 |
Point2D firstPoint=(Point2D)arrayCoords.get(0); |
|
206 |
Point2D pAnt = (Point2D)arrayCoords.get(arrayCoords.size()-1); |
|
207 |
Line2D l = new Line2D.Double(pAnt.getX(),pAnt.getY(),firstPoint.getX(),firstPoint.getY()); |
|
208 |
if (l.intersectsLine(l1.getX1(),l1.getY1(),l1.getX2(),l1.getY2()) |
|
209 |
|| l.intersectsLine(l2.getX1(),l2.getY1(),l2.getX2(),l2.getY2()) |
|
210 |
|| l.intersectsLine(l3.getX1(),l3.getY1(),l3.getX2(),l3.getY2()) |
|
211 |
|| l.intersectsLine(l4.getX1(),l4.getY1(),l4.getX2(),l4.getY2()) |
|
212 |
|| r.intersectsLine(l)) { |
|
213 |
bool = true; |
|
214 |
} |
|
215 |
}else { |
|
216 |
System.out.println("Not supported here"); |
|
217 |
} |
|
218 |
theIterator.next(); |
|
219 |
} |
|
220 |
} |
|
221 |
return bool; |
|
222 |
} |
|
236 | 223 |
|
237 |
/**
|
|
238 |
* DOCUMENT ME!
|
|
239 |
*
|
|
240 |
* @param at DOCUMENT ME!
|
|
241 |
*/
|
|
242 |
public void transform(AffineTransform at) {
|
|
224 |
/* (non-Javadoc)
|
|
225 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
|
|
226 |
*/
|
|
227 |
public PathIterator getPathIterator(AffineTransform at) {
|
|
228 |
return gp.getPathIterator(at);
|
|
229 |
}
|
|
243 | 230 |
|
231 |
/* (non-Javadoc) |
|
232 |
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform, double) |
|
233 |
*/ |
|
234 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
|
235 |
return gp.getPathIterator(at, flatness); |
|
236 |
} |
|
237 |
|
|
238 |
/** |
|
239 |
* DOCUMENT ME! |
|
240 |
* |
|
241 |
* @param at DOCUMENT ME! |
|
242 |
*/ |
|
243 |
public void transform(AffineTransform at) { |
|
244 |
|
|
244 | 245 |
// TODO: PRUEBA. BORRAR ESTA LINEA |
245 | 246 |
// gp = FConverter.transformToInts(gp, at); |
246 | 247 |
|
247 |
gp.transform(at);
|
|
248 |
}
|
|
248 |
gp.transform(at);
|
|
249 |
}
|
|
249 | 250 |
|
250 |
/* (non-Javadoc)
|
|
251 |
* @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
|
|
252 |
*/
|
|
253 |
public void reProject(ICoordTrans ct) {
|
|
254 |
gp.reProject(ct);
|
|
255 |
}
|
|
251 |
/* (non-Javadoc)
|
|
252 |
* @see com.iver.cit.gvsig.fmap.core.FShape#reProject(org.cresques.cts.ICoordTrans)
|
|
253 |
*/
|
|
254 |
public void reProject(ICoordTrans ct) {
|
|
255 |
gp.reProject(ct);
|
|
256 |
}
|
|
256 | 257 |
|
257 |
/* (non-Javadoc)
|
|
258 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getStretchingHandlers()
|
|
259 |
*/
|
|
260 |
public Handler[] getStretchingHandlers() {
|
|
261 |
ArrayList handlers = new ArrayList();
|
|
262 |
GeneralPathXIterator gpi = null;
|
|
263 |
gpi = (GeneralPathXIterator) getPathIterator(null);
|
|
258 |
/* (non-Javadoc)
|
|
259 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getStretchingHandlers()
|
|
260 |
*/
|
|
261 |
public Handler[] getStretchingHandlers() {
|
|
262 |
ArrayList handlers = new ArrayList();
|
|
263 |
GeneralPathXIterator gpi = null;
|
|
264 |
gpi = (GeneralPathXIterator) getPathIterator(null);
|
|
264 | 265 |
|
265 |
double[] theData = new double[6];
|
|
266 |
int i=0;
|
|
267 |
while (!gpi.isDone()) {
|
|
268 |
gpi.currentSegment(theData);
|
|
269 |
//g.fillRect((int)(theData[0]-3),(int)(theData[1]-3),6,6);
|
|
270 |
handlers.add(new PointHandler(i,theData[0], theData[1]));
|
|
271 |
i++;
|
|
272 |
gpi.next();
|
|
273 |
}
|
|
266 |
double[] theData = new double[6];
|
|
267 |
int i=0;
|
|
268 |
while (!gpi.isDone()) {
|
|
269 |
gpi.currentSegment(theData);
|
|
270 |
//g.fillRect((int)(theData[0]-3),(int)(theData[1]-3),6,6);
|
|
271 |
handlers.add(new PointHandler(i,theData[0], theData[1]));
|
|
272 |
i++;
|
|
273 |
gpi.next();
|
|
274 |
}
|
|
274 | 275 |
|
275 |
return (Handler[]) handlers.toArray(new Handler[0]); |
|
276 |
} |
|
277 |
|
|
278 |
/* (non-Javadoc) |
|
279 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getCoordinateAt(int, int) |
|
280 |
*/ |
|
281 |
public double getCoordinateAt(int index, int dimension) { |
|
282 |
GeneralPathXIterator gpi = null; |
|
283 |
gpi = (GeneralPathXIterator) getPathIterator(null); |
|
276 |
return (Handler[]) handlers.toArray(new Handler[0]); |
|
277 |
} |
|
284 | 278 |
|
285 |
double[] theData = new double[6]; |
|
286 |
int i=0; |
|
287 |
while (!gpi.isDone()) { |
|
288 |
if (index==i){ |
|
289 |
gpi.currentSegment(theData); |
|
290 |
return theData[dimension]; |
|
291 |
} |
|
292 |
i++; |
|
293 |
gpi.next(); |
|
294 |
} |
|
295 |
throw new ArrayIndexOutOfBoundsException(); |
|
296 |
} |
|
279 |
/* (non-Javadoc) |
|
280 |
* @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getCoordinateAt(int, int) |
|
281 |
*/ |
|
282 |
public double getCoordinateAt(int index, int dimension) { |
|
283 |
GeneralPathXIterator gpi = null; |
|
284 |
gpi = (GeneralPathXIterator) getPathIterator(null); |
|
297 | 285 |
|
298 |
/* (non-Javadoc) |
|
299 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getSelectHandlers() |
|
300 |
*/ |
|
301 |
public Handler[] getSelectHandlers() { |
|
302 |
ArrayList handlers = new ArrayList(); |
|
303 |
GeneralPathXIterator gpi = null; |
|
304 |
gpi = (GeneralPathXIterator) getPathIterator(null); |
|
286 |
double[] theData = new double[6]; |
|
287 |
int i=0; |
|
288 |
while (!gpi.isDone()) { |
|
289 |
if (index==i){ |
|
290 |
gpi.currentSegment(theData); |
|
291 |
return theData[dimension]; |
|
292 |
} |
|
293 |
i++; |
|
294 |
gpi.next(); |
|
295 |
} |
|
296 |
throw new ArrayIndexOutOfBoundsException(); |
|
297 |
} |
|
305 | 298 |
|
306 |
double[] theData = new double[6]; |
|
307 |
int i=0; |
|
308 |
//boolean isFirst=true; |
|
309 |
while (!gpi.isDone()) { |
|
310 |
int theType = gpi.currentSegment(theData); |
|
311 |
//g.fillRect((int)(theData[0]-3),(int)(theData[1]-3),6,6); |
|
312 |
/* if (!(this instanceof FPolygon2D && isFirst)){ |
|
299 |
/* (non-Javadoc) |
|
300 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getSelectHandlers() |
|
301 |
*/ |
|
302 |
public Handler[] getSelectHandlers() { |
|
303 |
ArrayList handlers = new ArrayList(); |
|
304 |
GeneralPathXIterator gpi = null; |
|
305 |
gpi = (GeneralPathXIterator) getPathIterator(null); |
|
306 |
|
|
307 |
double[] theData = new double[6]; |
|
308 |
int i=0; |
|
309 |
//boolean isFirst=true; |
|
310 |
while (!gpi.isDone()) { |
|
311 |
int theType = gpi.currentSegment(theData); |
|
312 |
//g.fillRect((int)(theData[0]-3),(int)(theData[1]-3),6,6); |
|
313 |
/* if (!(this instanceof FPolygon2D && isFirst)){ |
|
313 | 314 |
handlers.add(new PointSelHandler(i,theData[0], theData[1])); |
314 | 315 |
i++; |
315 | 316 |
} |
316 | 317 |
isFirst=false; */ |
317 |
switch (theType)
|
|
318 |
{
|
|
319 |
case GeneralPathXIterator.SEG_MOVETO:
|
|
320 |
handlers.add(new PointSelHandler(i++,theData[0], theData[1]));
|
|
321 |
break;
|
|
322 |
case GeneralPathXIterator.SEG_LINETO:
|
|
323 |
handlers.add(new PointSelHandler(i++,theData[0], theData[1]));
|
|
324 |
break;
|
|
325 |
case GeneralPathXIterator.SEG_CLOSE:
|
|
326 |
break;
|
|
327 |
case GeneralPathXIterator.SEG_QUADTO:
|
|
328 |
handlers.add(new PointSelHandler(i++,theData[0], theData[1]));
|
|
329 |
handlers.add(new PointSelHandler(i++,theData[2], theData[3]));
|
|
330 |
break;
|
|
331 |
case GeneralPathXIterator.SEG_CUBICTO:
|
|
332 |
handlers.add(new PointSelHandler(i++,theData[0], theData[1]));
|
|
333 |
handlers.add(new PointSelHandler(i++,theData[2], theData[3]));
|
|
334 |
handlers.add(new PointSelHandler(i++,theData[4], theData[5]));
|
|
335 |
break;
|
|
318 |
switch (theType)
|
|
319 |
{
|
|
320 |
case GeneralPathXIterator.SEG_MOVETO:
|
|
321 |
handlers.add(new PointSelHandler(i++,theData[0], theData[1]));
|
|
322 |
break;
|
|
323 |
case GeneralPathXIterator.SEG_LINETO:
|
|
324 |
handlers.add(new PointSelHandler(i++,theData[0], theData[1]));
|
|
325 |
break;
|
|
326 |
case GeneralPathXIterator.SEG_CLOSE:
|
|
327 |
break;
|
|
328 |
case GeneralPathXIterator.SEG_QUADTO:
|
|
329 |
handlers.add(new PointSelHandler(i++,theData[0], theData[1]));
|
|
330 |
handlers.add(new PointSelHandler(i++,theData[2], theData[3]));
|
|
331 |
break;
|
|
332 |
case GeneralPathXIterator.SEG_CUBICTO:
|
|
333 |
handlers.add(new PointSelHandler(i++,theData[0], theData[1]));
|
|
334 |
handlers.add(new PointSelHandler(i++,theData[2], theData[3]));
|
|
335 |
handlers.add(new PointSelHandler(i++,theData[4], theData[5]));
|
|
336 |
break;
|
|
336 | 337 |
|
337 |
}
|
|
338 |
gpi.next();
|
|
338 |
}
|
|
339 |
gpi.next();
|
|
339 | 340 |
|
340 | 341 |
|
341 |
}
|
|
342 |
}
|
|
342 | 343 |
|
343 |
return (Handler[]) handlers.toArray(new Handler[0]);
|
|
344 |
}
|
|
345 |
/**
|
|
346 |
* DOCUMENT ME!
|
|
347 |
*
|
|
348 |
* @author Vicente Caballero Navarro
|
|
349 |
*/
|
|
350 |
class PointHandler extends AbstractHandler implements FinalHandler{
|
|
351 |
/**
|
|
352 |
* Crea un nuevo PointHandler.
|
|
353 |
*
|
|
354 |
* @param x DOCUMENT ME!
|
|
355 |
* @param y DOCUMENT ME!
|
|
356 |
*/
|
|
357 |
public PointHandler(int i,double x, double y) {
|
|
358 |
point = new Point2D.Double(x, y);
|
|
359 |
index=i;
|
|
360 |
}
|
|
344 |
return (Handler[]) handlers.toArray(new Handler[0]);
|
|
345 |
}
|
|
346 |
/**
|
|
347 |
* DOCUMENT ME!
|
|
348 |
*
|
|
349 |
* @author Vicente Caballero Navarro
|
|
350 |
*/
|
|
351 |
class PointHandler extends AbstractHandler implements FinalHandler{
|
|
352 |
/**
|
|
353 |
* Crea un nuevo PointHandler.
|
|
354 |
*
|
|
355 |
* @param x DOCUMENT ME!
|
|
356 |
* @param y DOCUMENT ME!
|
|
357 |
*/
|
|
358 |
public PointHandler(int i,double x, double y) {
|
|
359 |
point = new Point2D.Double(x, y);
|
|
360 |
index=i;
|
|
361 |
}
|
|
361 | 362 |
|
362 |
/**
|
|
363 |
* DOCUMENT ME!
|
|
364 |
*
|
|
365 |
* @param x DOCUMENT ME!
|
|
366 |
* @param y DOCUMENT ME!
|
|
367 |
*
|
|
368 |
* @return DOCUMENT ME!
|
|
369 |
*/
|
|
370 |
public void move(double x, double y) {
|
|
371 |
gp.getPointCoords()[index*2]+=x;
|
|
372 |
gp.getPointCoords()[index*2+1]+=y;
|
|
373 |
}
|
|
363 |
/**
|
|
364 |
* DOCUMENT ME!
|
|
365 |
*
|
|
366 |
* @param x DOCUMENT ME!
|
|
367 |
* @param y DOCUMENT ME!
|
|
368 |
*
|
|
369 |
* @return DOCUMENT ME!
|
|
370 |
*/
|
|
371 |
public void move(double x, double y) {
|
|
372 |
gp.getPointCoords()[index*2]+=x;
|
|
373 |
gp.getPointCoords()[index*2+1]+=y;
|
|
374 |
}
|
|
374 | 375 |
|
375 |
/**
|
|
376 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
|
377 |
*/
|
|
378 |
public void set(double x, double y) {
|
|
379 |
gp.getPointCoords()[index*2]=x;
|
|
380 |
gp.getPointCoords()[index*2+1]=y;
|
|
381 |
}
|
|
382 |
}
|
|
383 |
/**
|
|
384 |
* DOCUMENT ME!
|
|
385 |
*
|
|
386 |
* @author Vicente Caballero Navarro
|
|
387 |
*/
|
|
388 |
class PointSelHandler extends AbstractHandler implements FinalHandler{
|
|
389 |
/**
|
|
390 |
* Crea un nuevo PointHandler.
|
|
391 |
*
|
|
392 |
* @param x DOCUMENT ME!
|
|
393 |
* @param y DOCUMENT ME!
|
|
394 |
*/
|
|
395 |
public PointSelHandler(int i,double x, double y) {
|
|
396 |
point = new Point2D.Double(x, y);
|
|
397 |
index=i;
|
|
398 |
}
|
|
376 |
/**
|
|
377 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
|
378 |
*/
|
|
379 |
public void set(double x, double y) {
|
|
380 |
gp.getPointCoords()[index*2]=x;
|
|
381 |
gp.getPointCoords()[index*2+1]=y;
|
|
382 |
}
|
|
383 |
}
|
|
384 |
/**
|
|
385 |
* DOCUMENT ME!
|
|
386 |
*
|
|
387 |
* @author Vicente Caballero Navarro
|
|
388 |
*/
|
|
389 |
class PointSelHandler extends AbstractHandler implements FinalHandler{
|
|
390 |
/**
|
|
391 |
* Crea un nuevo PointHandler.
|
|
392 |
*
|
|
393 |
* @param x DOCUMENT ME!
|
|
394 |
* @param y DOCUMENT ME!
|
|
395 |
*/
|
|
396 |
public PointSelHandler(int i,double x, double y) {
|
|
397 |
point = new Point2D.Double(x, y);
|
|
398 |
index=i;
|
|
399 |
}
|
|
399 | 400 |
|
400 |
/**
|
|
401 |
* DOCUMENT ME!
|
|
402 |
*
|
|
403 |
* @param x DOCUMENT ME!
|
|
404 |
* @param y DOCUMENT ME!
|
|
405 |
*
|
|
406 |
* @return DOCUMENT ME!
|
|
407 |
*/
|
|
408 |
public void move(double x, double y) {
|
|
409 |
gp.getPointCoords()[index*2]+=x;
|
|
410 |
gp.getPointCoords()[index*2+1]+=y;
|
|
411 |
}
|
|
401 |
/**
|
|
402 |
* DOCUMENT ME!
|
|
403 |
*
|
|
404 |
* @param x DOCUMENT ME!
|
|
405 |
* @param y DOCUMENT ME!
|
|
406 |
*
|
|
407 |
* @return DOCUMENT ME!
|
|
408 |
*/
|
|
409 |
public void move(double x, double y) {
|
|
410 |
gp.getPointCoords()[index*2]+=x;
|
|
411 |
gp.getPointCoords()[index*2+1]+=y;
|
|
412 |
}
|
|
412 | 413 |
|
413 |
/**
|
|
414 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
|
415 |
*/
|
|
416 |
public void set(double x, double y) {
|
|
417 |
gp.getPointCoords()[index*2]=x;
|
|
418 |
gp.getPointCoords()[index*2+1]=y;
|
|
419 |
}
|
|
420 |
}
|
|
414 |
/**
|
|
415 |
* @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
|
|
416 |
*/
|
|
417 |
public void set(double x, double y) {
|
|
418 |
gp.getPointCoords()[index*2]=x;
|
|
419 |
gp.getPointCoords()[index*2+1]=y;
|
|
420 |
}
|
|
421 |
}
|
|
421 | 422 |
|
422 |
/*
|
|
423 |
* (non-Javadoc)
|
|
424 |
* @see org.gvsig.geometries.iso.GM_Object#coordinateDimension()
|
|
425 |
*/
|
|
426 |
public int getDimension() {
|
|
427 |
return 2;
|
|
428 |
}
|
|
423 |
/*
|
|
424 |
* (non-Javadoc)
|
|
425 |
* @see org.gvsig.geometries.iso.GM_Object#coordinateDimension()
|
|
426 |
*/
|
|
427 |
public int getDimension() {
|
|
428 |
return 2;
|
|
429 |
}
|
|
429 | 430 |
|
430 |
public Envelope getEnvelope() { |
|
431 |
Rectangle2D r=gp.getBounds2D(); |
|
432 |
return new Envelope2D(r.getX(),r.getY(),r.getMaxX(),r.getMaxY()); |
|
433 |
} |
|
431 |
public Envelope getEnvelope() { |
|
432 |
Rectangle2D r=gp.getBounds2D(); |
|
433 |
return new Envelope2D(r.getX(),r.getY(),r.getMaxX(),r.getMaxY()); |
|
434 |
} |
|
435 |
|
|
436 |
public GeneralPathX getGeneralPath() { |
|
437 |
return gp; |
|
438 |
} |
|
439 |
|
|
440 |
public int getNumVertices() { |
|
441 |
return gp.getNumCoords(); |
|
442 |
} |
|
443 |
|
|
444 |
public void addVertex(Point point) { |
|
445 |
gp.lineTo(point.getX(), point.getY()); |
|
446 |
} |
|
447 |
|
|
448 |
public void setVertex(int index, Point p) { |
|
449 |
throw new UnsupportedOperationException("Use setGeneralPathX"); |
|
450 |
} |
|
451 |
|
|
452 |
public Point getVertex(int index) { |
|
453 |
throw new UnsupportedOperationException("Method not implemented"); |
|
454 |
} |
|
455 |
|
|
456 |
public void insertVertex(int index, Point p) { |
|
457 |
throw new UnsupportedOperationException("Method not implemented"); |
|
458 |
} |
|
459 |
|
|
460 |
public void removeVertex(int index) { |
|
461 |
throw new UnsupportedOperationException("Method not implemented"); |
|
462 |
} |
|
463 |
|
|
464 |
public void setCoordinateAt(int index, int dimension, double value) { |
|
465 |
throw new UnsupportedOperationException("Method not implemented"); |
|
466 |
} |
|
467 |
|
|
468 |
public void setGeneralPath(GeneralPathX generalPathX) { |
|
469 |
this.gp = generalPathX; |
|
470 |
} |
|
471 |
|
|
472 |
public void setPoints(Point startPoint, Point endPoint) { |
|
473 |
throw new UnsupportedOperationException("Method not implemented"); |
|
474 |
} |
|
434 | 475 |
} |
Also available in: Unified diff