Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libDXF / src / org / gvsig / dxf / px / gml / Polygon.java @ 29630

History | View | Annotate | Download (3.75 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.gvsig.dxf.px.gml;
25

    
26
import java.awt.Color;
27
import java.awt.Graphics2D;
28
import java.awt.geom.Point2D;
29

    
30
import org.cresques.cts.ICoordTrans;
31
import org.cresques.cts.IProjection;
32
import org.cresques.geo.ViewPortData;
33
import org.cresques.px.Extent;
34
import org.gvsig.dxf.geo.Polygon2D;
35

    
36

    
37
/**
38
 * Geometria de tipo Polygon
39
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
40
 */
41
public class Polygon extends Geometry {
42
    final static Color colorBase = new Color(192, 64, 64);
43
    final static Color fColorBase = new Color(192, 64, 64, 0x10); // new Color(255,192,192,64);
44
    public static int pointNr = 0;
45
    Polygon2D outPol = null;
46
    Polygon2D inPol = null;
47
    boolean outer = true;
48
    private Color fillColor = fColorBase; //new Color(255,222,165,64);
49
    private Color color = colorBase; //Color(255,214,132,255);
50

    
51
    public Polygon() {
52
        super();
53
        outPol = new Polygon2D();
54
        inPol = new Polygon2D();
55
    }
56

    
57
    public void add(Point2D pt) {
58
        pointNr++;
59

    
60
        if (outer) {
61
            outPol.addPoint(pt);
62
        } else {
63
            inPol.addPoint(pt);
64
        }
65

    
66
        extent.add(pt);
67
    }
68

    
69
    public Point2D get(int i) {
70
        if (outer) {
71
            return (Point2D) outPol.get(i);
72
        }
73

    
74
        return (Point2D) inPol.get(i);
75
    }
76

    
77
    public void remove(int i) {
78
        if (outer) {
79
            outPol.remove(i);
80
        } else {
81
            inPol.remove(i);
82
        }
83
    }
84

    
85
    public int pointNr() {
86
        if (outer) {
87
            return outPol.size();
88
        }
89

    
90
        return inPol.size();
91
    }
92

    
93
    public void setOuterBoundary() {
94
        outer = true;
95
    }
96

    
97
    public void setInnerBoundary() {
98
        outer = false;
99
    }
100

    
101
    public Color c() {
102
        return color;
103
    }
104

    
105
    public Color c(Color color) {
106
        this.color = color;
107

    
108
        return color;
109
    }
110

    
111
    public Color fillColor() {
112
        return fillColor;
113
    }
114

    
115
    public Color fillColor(Color c) {
116
        fillColor = c;
117

    
118
        return fillColor;
119
    }
120

    
121
    public IProjection getProjection() {
122
        return proj;
123
    }
124

    
125
    public void setProjection(IProjection p) {
126
        proj = p;
127
    }
128

    
129
    public void reProject(ICoordTrans rp) {
130
        Polygon2D savePol = outPol;
131

    
132
        outPol = new Polygon2D();
133
        extent = new Extent();
134

    
135
        Point2D ptDest = null;
136

    
137
        for (int i = 0; i < savePol.size(); i++) {
138
            ptDest = rp.getPDest().createPoint(0.0, 0.0);
139
            ptDest = rp.convert((Point2D) savePol.get(i), ptDest);
140
            outPol.addPoint(ptDest);
141
            extent.add(ptDest);
142
        }
143

    
144
        setProjection(rp.getPDest());
145
    }
146

    
147
    public void draw(Graphics2D g, ViewPortData vp) {
148
        // relleno el poligono si es preciso
149
        if (fillColor() != null) {
150
            g.setColor(fillColor());
151
            outPol.fill(g, vp);
152
        }
153

    
154
        // pinto el poligono si es preciso
155
        g.setColor(c());
156
        outPol.draw(g, vp);
157
    }
158
}