root / trunk / libraries / libCq_CMS_praster / src / org / cresques / px / gml / Polygon.java @ 8026
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.cresques.px.gml; |
25 |
|
26 |
import org.cresques.cts.ICoordTrans; |
27 |
import org.cresques.cts.IProjection; |
28 |
|
29 |
import org.cresques.geo.Polygon2D; |
30 |
import org.cresques.geo.ViewPortData; |
31 |
|
32 |
import org.cresques.px.Extent; |
33 |
|
34 |
import java.awt.Color; |
35 |
import java.awt.Graphics2D; |
36 |
import java.awt.geom.Point2D; |
37 |
|
38 |
|
39 |
/**
|
40 |
* Geometria de tipo Polygon
|
41 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
42 |
*/
|
43 |
public class Polygon extends Geometry { |
44 |
final static Color colorBase = new Color(192, 64, 64); |
45 |
final static Color fColorBase = new Color(192, 64, 64, 0x10); // new Color(255,192,192,64); |
46 |
public static int pointNr = 0; |
47 |
Polygon2D outPol = null;
|
48 |
Polygon2D inPol = null;
|
49 |
boolean outer = true; |
50 |
private Color fillColor = fColorBase; //new Color(255,222,165,64); |
51 |
private Color color = colorBase; //Color(255,214,132,255); |
52 |
|
53 |
public Polygon() { |
54 |
super();
|
55 |
outPol = new Polygon2D();
|
56 |
inPol = new Polygon2D();
|
57 |
} |
58 |
|
59 |
public void add(Point2D pt) { |
60 |
pointNr++; |
61 |
|
62 |
if (outer) {
|
63 |
outPol.addPoint(pt); |
64 |
} else {
|
65 |
inPol.addPoint(pt); |
66 |
} |
67 |
|
68 |
extent.add(pt); |
69 |
} |
70 |
|
71 |
public Point2D get(int i) { |
72 |
if (outer) {
|
73 |
return (Point2D) outPol.get(i); |
74 |
} |
75 |
|
76 |
return (Point2D) inPol.get(i); |
77 |
} |
78 |
|
79 |
public void remove(int i) { |
80 |
if (outer) {
|
81 |
outPol.remove(i); |
82 |
} else {
|
83 |
inPol.remove(i); |
84 |
} |
85 |
} |
86 |
|
87 |
public int pointNr() { |
88 |
if (outer) {
|
89 |
return outPol.size();
|
90 |
} |
91 |
|
92 |
return inPol.size();
|
93 |
} |
94 |
|
95 |
public void setOuterBoundary() { |
96 |
outer = true;
|
97 |
} |
98 |
|
99 |
public void setInnerBoundary() { |
100 |
outer = false;
|
101 |
} |
102 |
|
103 |
public Color c() { |
104 |
return color;
|
105 |
} |
106 |
|
107 |
public Color c(Color color) { |
108 |
this.color = color;
|
109 |
|
110 |
return color;
|
111 |
} |
112 |
|
113 |
public Color fillColor() { |
114 |
return fillColor;
|
115 |
} |
116 |
|
117 |
public Color fillColor(Color c) { |
118 |
fillColor = c; |
119 |
|
120 |
return fillColor;
|
121 |
} |
122 |
|
123 |
public IProjection getProjection() {
|
124 |
return proj;
|
125 |
} |
126 |
|
127 |
public void setProjection(IProjection p) { |
128 |
proj = p; |
129 |
} |
130 |
|
131 |
public void reProject(ICoordTrans rp) { |
132 |
Polygon2D savePol = outPol; |
133 |
|
134 |
outPol = new Polygon2D();
|
135 |
extent = new Extent();
|
136 |
|
137 |
Point2D ptDest = null; |
138 |
|
139 |
for (int i = 0; i < savePol.size(); i++) { |
140 |
ptDest = rp.getPDest().createPoint(0.0, 0.0); |
141 |
ptDest = rp.convert((Point2D) savePol.get(i), ptDest);
|
142 |
outPol.addPoint(ptDest); |
143 |
extent.add(ptDest); |
144 |
} |
145 |
|
146 |
setProjection(rp.getPDest()); |
147 |
} |
148 |
|
149 |
public void draw(Graphics2D g, ViewPortData vp) { |
150 |
// relleno el poligono si es preciso
|
151 |
if (fillColor() != null) { |
152 |
g.setColor(fillColor()); |
153 |
outPol.fill(g, vp); |
154 |
} |
155 |
|
156 |
// pinto el poligono si es preciso
|
157 |
g.setColor(c()); |
158 |
outPol.draw(g, vp); |
159 |
} |
160 |
} |