svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / gml / Polygon.java @ 2312
History | View | Annotate | Download (3.21 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 java.awt.Color; |
27 |
import java.awt.geom.Point2D; |
28 |
|
29 |
import java.awt.Graphics2D; |
30 |
|
31 |
import org.cresques.cts.ICoordTrans; |
32 |
import org.cresques.cts.IProjection; |
33 |
import org.cresques.geo.Polygon2D; |
34 |
import org.cresques.geo.ViewPortData; |
35 |
import org.cresques.px.Extent; |
36 |
|
37 |
/**
|
38 |
* Geometria de tipo Polygon
|
39 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
40 |
*/
|
41 |
|
42 |
public class Polygon extends Geometry { |
43 |
final static Color colorBase = new Color(192, 64, 64); |
44 |
final static Color fColorBase = new Color(192,64,64,0x10);// new Color(255,192,192,64); |
45 |
public static int pointNr = 0; |
46 |
Polygon2D outPol = null;
|
47 |
Polygon2D inPol = null;
|
48 |
boolean outer = true; |
49 |
|
50 |
public Polygon() { |
51 |
super();
|
52 |
outPol = new Polygon2D();
|
53 |
inPol = new Polygon2D();
|
54 |
} |
55 |
|
56 |
public void add(Point2D pt) { |
57 |
pointNr++; |
58 |
if (outer)
|
59 |
outPol.addPoint(pt); |
60 |
else
|
61 |
inPol.addPoint(pt); |
62 |
extent.add(pt); |
63 |
} |
64 |
|
65 |
public Point2D get(int i) { |
66 |
if (outer)
|
67 |
return (Point2D) outPol.get(i); |
68 |
return (Point2D) inPol.get(i); |
69 |
} |
70 |
public void remove(int i) { |
71 |
if (outer)
|
72 |
outPol.remove(i); |
73 |
else
|
74 |
inPol.remove(i); |
75 |
} |
76 |
public int pointNr() { |
77 |
if (outer)
|
78 |
return outPol.size();
|
79 |
return inPol.size();
|
80 |
} |
81 |
|
82 |
public void setOuterBoundary() { outer=true; } |
83 |
public void setInnerBoundary() { outer=false; } |
84 |
|
85 |
private Color fillColor = fColorBase; //new Color(255,222,165,64); |
86 |
private Color color = colorBase; //Color(255,214,132,255); |
87 |
|
88 |
public Color c() {return color;} |
89 |
public Color c(Color color) {this.color = color; return color;} |
90 |
|
91 |
public Color fillColor() {return fillColor;} |
92 |
public Color fillColor(Color c) {fillColor = c; return fillColor;} |
93 |
|
94 |
public IProjection getProjection() { return proj; } |
95 |
public void setProjection(IProjection p) { proj = p; } |
96 |
public void reProject(ICoordTrans rp) { |
97 |
Polygon2D savePol = outPol; |
98 |
|
99 |
outPol = new Polygon2D();
|
100 |
extent = new Extent();
|
101 |
Point2D ptDest = null; |
102 |
for (int i=0; i<savePol.size(); i++) { |
103 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
104 |
ptDest = rp.convert((Point2D) savePol.get(i), ptDest);
|
105 |
outPol.addPoint(ptDest); |
106 |
extent.add(ptDest); |
107 |
} |
108 |
setProjection(rp.getPDest()); |
109 |
} |
110 |
|
111 |
public void draw(Graphics2D g, ViewPortData vp) { |
112 |
// relleno el poligono si es preciso
|
113 |
if (fillColor() != null) { |
114 |
g.setColor(fillColor()); |
115 |
outPol.fill(g, vp); |
116 |
} |
117 |
// pinto el poligono si es preciso
|
118 |
g.setColor(c()); |
119 |
outPol.draw(g, vp); |
120 |
} |
121 |
} |
122 |
|