root / trunk / libraries / libCq_CMS_praster / src / org / cresques / px / PxObjList.java @ 8026
History | View | Annotate | Download (4.94 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; |
25 |
|
26 |
import org.cresques.cts.ICoordTrans; |
27 |
import org.cresques.cts.IProjection; |
28 |
|
29 |
import org.cresques.geo.Projected; |
30 |
import org.cresques.geo.Projection; |
31 |
import org.cresques.geo.ReProjection; |
32 |
import org.cresques.geo.ViewPortData; |
33 |
|
34 |
import java.awt.Color; |
35 |
import java.awt.Graphics2D; |
36 |
import java.awt.geom.Point2D; |
37 |
|
38 |
import java.util.Iterator; |
39 |
import java.util.Vector; |
40 |
|
41 |
|
42 |
public class PxObjList implements Colored, Drawable, IObjList { |
43 |
IProjection proj = null;
|
44 |
private Color pc = null; |
45 |
private Color fColor = null; |
46 |
protected Extent extent = null; |
47 |
Vector data = null; |
48 |
|
49 |
public PxObjList() {
|
50 |
data = new Vector(); |
51 |
extent = new Extent();
|
52 |
} |
53 |
|
54 |
public PxObjList(IProjection proj) {
|
55 |
data = new Vector(); |
56 |
this.proj = proj;
|
57 |
extent = new Extent();
|
58 |
} |
59 |
|
60 |
public IProjection getProjection() {
|
61 |
return proj;
|
62 |
} |
63 |
|
64 |
public void setProjection(IProjection p) { |
65 |
proj = p; |
66 |
} |
67 |
|
68 |
public void reProject(ICoordTrans rp) { |
69 |
extent = new Extent();
|
70 |
|
71 |
Iterator iter = data.iterator();
|
72 |
Projected obj = null;
|
73 |
|
74 |
while (iter.hasNext()) {
|
75 |
obj = (Projected) iter.next(); |
76 |
obj.reProject(rp); |
77 |
extent.add(((Extent.Has) obj).getExtent()); |
78 |
} |
79 |
|
80 |
setProjection(rp.getPDest()); |
81 |
} |
82 |
|
83 |
public Extent getExtent() {
|
84 |
return extent;
|
85 |
} |
86 |
|
87 |
public Color c() { |
88 |
return pc;
|
89 |
} |
90 |
|
91 |
public Color c(Color color) { |
92 |
pc = color; |
93 |
|
94 |
return pc;
|
95 |
} |
96 |
|
97 |
public void setColor(Color color) { |
98 |
pc = color; |
99 |
} |
100 |
|
101 |
public Color getColor() { |
102 |
return pc;
|
103 |
} |
104 |
|
105 |
public void setFillColor(Color color) { |
106 |
fColor = color; |
107 |
} |
108 |
|
109 |
public Color getFillColor() { |
110 |
return fColor;
|
111 |
} |
112 |
|
113 |
public void draw(Graphics2D g, ViewPortData vp) { |
114 |
System.err.println("draw :" + this + ": " + size() + "objetos."); |
115 |
|
116 |
if (pc != null) { |
117 |
g.setColor(pc); |
118 |
} |
119 |
|
120 |
Iterator iter = data.iterator();
|
121 |
Drawable dwObj = null;
|
122 |
|
123 |
while (iter.hasNext()) {
|
124 |
dwObj = (Drawable) iter.next(); |
125 |
|
126 |
//if (dwObj.getClass() == PxContour.class)
|
127 |
// drawPxContour(g, vp, (PxContour) dwObj);
|
128 |
//else
|
129 |
|
130 |
/*extent = ((Extent.Has) dwObj).getExtent();
|
131 |
if (vp.getExtent().minX()> extent.maxX()) continue;
|
132 |
if (vp.getExtent().minY()> extent.maxY()) continue;
|
133 |
if (vp.getExtent().maxX()< extent.minX()) continue;
|
134 |
if (vp.getExtent().maxY()< extent.minY()) continue;*/
|
135 |
dwObj.draw(g, vp); |
136 |
} |
137 |
} |
138 |
|
139 |
public IObjList getAt(Point2D pt) { |
140 |
PxObjList oList = new PxObjList();
|
141 |
Iterator iter = data.iterator();
|
142 |
|
143 |
while (iter.hasNext()) {
|
144 |
PxObj o = (PxObj) iter.next(); |
145 |
|
146 |
if (o.getExtent().isAt(pt)) {
|
147 |
oList.add(o); |
148 |
} |
149 |
} |
150 |
|
151 |
return oList;
|
152 |
} |
153 |
|
154 |
public Iterator iterator() { |
155 |
return data.iterator();
|
156 |
} |
157 |
|
158 |
public int size() { |
159 |
return data.size();
|
160 |
} |
161 |
|
162 |
public void add(Extent.Has obj) { |
163 |
if (obj != null) { |
164 |
extent.add(obj.getExtent()); |
165 |
data.add(obj); |
166 |
} |
167 |
} |
168 |
|
169 |
public void remove(Object obj) { |
170 |
data.remove(obj); |
171 |
} |
172 |
|
173 |
public void clear() { |
174 |
extent = new Extent();
|
175 |
data.clear(); |
176 |
} |
177 |
|
178 |
/**
|
179 |
* Prueba de reproyecci?n.
|
180 |
*
|
181 |
*/
|
182 |
public void drawPxContour(Graphics2D g, ViewPortData vp, PxContour obj) { |
183 |
IProjection prj = obj.getProjection(); |
184 |
obj.setColor(pc); |
185 |
obj.setFillColor(fColor); |
186 |
|
187 |
if (prj != null) { |
188 |
if (prj != vp.getProjection()) {
|
189 |
ICoordTrans rp = null;
|
190 |
|
191 |
if (proj instanceof Projection) { |
192 |
rp = new ReProjection(((Projection) proj),
|
193 |
((Projection) vp.getProjection())); |
194 |
} |
195 |
|
196 |
obj.draw(g, vp, rp); |
197 |
} else {
|
198 |
obj.draw(g, vp); |
199 |
} |
200 |
} else {
|
201 |
System.err.println("Proyecci?n nula o inadecuada."); |
202 |
} |
203 |
} |
204 |
} |