Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / gml / Polygon.java @ 46

History | View | Annotate | Download (2.39 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 = new Color(192,64,64,0x10);// 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
        
46
        public Point2D get(int i) {
47
                if (outer)
48
                        return (Point2D) outPol.get(i);
49
                return (Point2D) inPol.get(i);
50
        }
51
        public void remove(int i) {
52
                if (outer)
53
                        outPol.remove(i);
54
                else
55
                        inPol.remove(i);
56
        }
57
        public int pointNr() {
58
                if (outer)
59
                        return outPol.size();
60
                return inPol.size();
61
        }
62
        
63
        public void setOuterBoundary() { outer=true; }
64
        public void setInnerBoundary() { outer=false; }
65
        
66
        private Color fillColor = fColorBase; //new Color(255,222,165,64);
67
        private Color color = colorBase; //Color(255,214,132,255);
68
        
69
        public Color c() {return color;}
70
        public Color c(Color color) {this.color = color; return color;}
71

    
72
        public Color fillColor() {return fillColor;}
73
        public Color fillColor(Color c) {fillColor = c; return fillColor;}
74

    
75
        public Projection getProjection() { return proj; }
76
        public void setProjection(Projection p) { proj = p; }
77
        public void reProject(ReProjection rp) {
78
                Polygon2D savePol = outPol;
79

    
80
                outPol = new Polygon2D();
81
                extent = new Extent();
82
                Point2D ptDest = null;
83
                for (int i=0; i<savePol.size(); i++) {
84
                        ptDest = rp.getPDest().createPoint(0.0,0.0);
85
                        rp.convert((Point2D) savePol.get(i), ptDest);
86
                        outPol.addPoint(ptDest);
87
                        extent.add(ptDest);
88
                }
89
                setProjection(rp.getPDest());
90
        }
91
        
92
        public void draw(Graphics2D g, ViewPort vp) {
93
                // relleno el poligono si es preciso
94
                if (fillColor() != null) {
95
                        g.setColor(fillColor());
96
                        outPol.fill(g, vp);
97
                }
98
                // pinto el poligono si es preciso
99
                g.setColor(c());
100
                outPol.draw(g, vp);
101
        }
102
}
103