Statistics
| Revision:

root / org.gvsig.dxf / trunk / org.gvsig.dxf / org.gvsig.dxf.lib / src / main / java / org / gvsig / dxf / px / gml / Polygon.java @ 393

History | View | Annotate | Download (4.28 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 boolean is3D() {
58
        if( this.isEmpty() ) {
59
            return false;
60
        }
61
        Object x = this.get(0);
62
        return x instanceof Point3D;
63
    }
64

    
65
    public void add(Point2D pt) {
66
        pointNr++;
67

    
68
        if (outer) {
69
            outPol.addPoint(pt);
70
        } else {
71
            inPol.addPoint(pt);
72
        }
73

    
74
        extent.add(pt);
75
    }
76

    
77
    public boolean isEmpty() {
78
        if (outer) {
79
            if( !outPol.isEmpty() ) {
80
                return false;
81
            }
82
        }
83
        return inPol.isEmpty();
84
    }
85
    
86
    public Point2D get(int i) {
87
        if (outer) {
88
            return (Point2D) outPol.get(i);
89
        }
90

    
91
        return (Point2D) inPol.get(i);
92
    }
93

    
94
    public void remove(int i) {
95
        if (outer) {
96
            outPol.remove(i);
97
        } else {
98
            inPol.remove(i);
99
        }
100
    }
101

    
102
    public int pointNr() {
103
        if (outer) {
104
            return outPol.size();
105
        }
106

    
107
        return inPol.size();
108
    }
109

    
110
    public void setOuterBoundary() {
111
        outer = true;
112
    }
113

    
114
    public void setInnerBoundary() {
115
        outer = false;
116
    }
117

    
118
    public Color c() {
119
        return color;
120
    }
121

    
122
    public Color c(Color color) {
123
        this.color = color;
124

    
125
        return color;
126
    }
127

    
128
    public Color fillColor() {
129
        return fillColor;
130
    }
131

    
132
    public Color fillColor(Color c) {
133
        fillColor = c;
134

    
135
        return fillColor;
136
    }
137

    
138
    public IProjection getProjection() {
139
        return proj;
140
    }
141

    
142
    public void setProjection(IProjection p) {
143
        proj = p;
144
    }
145

    
146
    public void reProject(ICoordTrans rp) {
147
        Polygon2D savePol = outPol;
148

    
149
        outPol = new Polygon2D();
150
        extent = new Extent();
151

    
152
        Point2D ptDest = null;
153

    
154
        for (int i = 0; i < savePol.size(); i++) {
155
            ptDest = rp.getPDest().createPoint(0.0, 0.0);
156
            ptDest = rp.convert((Point2D) savePol.get(i), ptDest);
157
            outPol.addPoint(ptDest);
158
            extent.add(ptDest);
159
        }
160

    
161
        setProjection(rp.getPDest());
162
    }
163

    
164
    public void draw(Graphics2D g, ViewPortData vp) {
165
        // relleno el poligono si es preciso
166
        if (fillColor() != null) {
167
            g.setColor(fillColor());
168
            outPol.fill(g, vp);
169
        }
170

    
171
        // pinto el poligono si es preciso
172
        g.setColor(c());
173
        outPol.draw(g, vp);
174
    }
175
}