svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / gml / Polygon.java @ 2
History | View | Annotate | Download (2.19 KB)
1 |
package org.cresques.px.gml; |
---|---|
2 |
/*
|
3 |
* Created on 21-abr-2004
|
4 |
*/
|
5 |
|
6 |
import java.awt.Color; |
7 |
import java.awt.geom.Point2D; |
8 |
|
9 |
import java.awt.Graphics2D; |
10 |
import java.awt.geom.AffineTransform; |
11 |
|
12 |
import org.cresques.geo.Polygon2D; |
13 |
import org.cresques.geo.Projection; |
14 |
import org.cresques.geo.ReProjection; |
15 |
import org.cresques.geo.ViewPort; |
16 |
import org.cresques.px.Extent; |
17 |
|
18 |
/**
|
19 |
* Geometria de tipo Polygon
|
20 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
21 |
*/
|
22 |
|
23 |
public class Polygon extends Geometry { |
24 |
final static Color colorBase = new Color(192, 64, 64); |
25 |
final static Color fColorBase = null; //new Color(192,192,192,32);// new Color(255,192,192,64); |
26 |
public static int pointNr = 0; |
27 |
Polygon2D outPol = null;
|
28 |
Polygon2D inPol = null;
|
29 |
boolean outer = true; |
30 |
|
31 |
public Polygon() { |
32 |
super();
|
33 |
outPol = new Polygon2D();
|
34 |
inPol = new Polygon2D();
|
35 |
} |
36 |
|
37 |
public void add(Point2D pt) { |
38 |
pointNr++; |
39 |
if (outer)
|
40 |
outPol.addPoint(pt); |
41 |
else
|
42 |
inPol.addPoint(pt); |
43 |
extent.add(pt); |
44 |
} |
45 |
public void setOuterBoundary() { outer=true; } |
46 |
public void setInnerBoundary() { outer=false; } |
47 |
|
48 |
private Color fillColor = fColorBase; //new Color(255,222,165,64); |
49 |
private Color color = colorBase; //Color(255,214,132,255); |
50 |
|
51 |
public Color c() {return color;} |
52 |
public Color c(Color color) {this.color = color; return color;} |
53 |
|
54 |
public Color fillColor() {return fillColor;} |
55 |
public Color fillColor(Color c) {fillColor = c; return fillColor;} |
56 |
|
57 |
public Projection getProjection() { return proj; } |
58 |
public void setProjection(Projection p) { proj = p; } |
59 |
public void reProject(ReProjection rp) { |
60 |
Polygon2D savePol = outPol; |
61 |
|
62 |
outPol = new Polygon2D();
|
63 |
extent = new Extent();
|
64 |
Point2D ptDest = null; |
65 |
for (int i=0; i<savePol.size(); i++) { |
66 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
67 |
rp.convert((Point2D) savePol.get(i), ptDest);
|
68 |
outPol.addPoint(ptDest); |
69 |
extent.add(ptDest); |
70 |
} |
71 |
setProjection(rp.getPDest()); |
72 |
} |
73 |
|
74 |
public void draw(Graphics2D g, ViewPort vp) { |
75 |
AffineTransform msave=g.getTransform();
|
76 |
g.setTransform(vp.mat); |
77 |
// relleno el poligono si es preciso
|
78 |
if (fillColor() != null) { |
79 |
g.setColor(fillColor()); |
80 |
outPol.fill(g); |
81 |
} |
82 |
// pinto el poligono si es preciso
|
83 |
g.setColor(c()); |
84 |
outPol.draw(g); |
85 |
g.setTransform(msave); |
86 |
} |
87 |
} |
88 |
|