svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / PxObjList.java @ 47
History | View | Annotate | Download (3.1 KB)
1 |
package org.cresques.px; |
---|---|
2 |
|
3 |
import java.util.Vector; |
4 |
import java.util.Iterator; |
5 |
|
6 |
import java.awt.Color; |
7 |
import java.awt.Graphics2D; |
8 |
|
9 |
import java.awt.geom.Point2D; |
10 |
|
11 |
import org.cresques.geo.Projected; |
12 |
import org.cresques.geo.Projection; |
13 |
import org.cresques.geo.ReProjection; |
14 |
import org.cresques.geo.ViewPort; |
15 |
|
16 |
public class PxObjList implements Colored, Drawable, Projected, Extent.Has { |
17 |
Projection proj = null;
|
18 |
private Color pc = null; |
19 |
private Color fColor = null; |
20 |
protected Extent extent = null; |
21 |
Vector data = null; |
22 |
|
23 |
public PxObjList() {
|
24 |
data = new Vector(); |
25 |
extent = new Extent();
|
26 |
} |
27 |
public PxObjList(Projection proj) {
|
28 |
data = new Vector(); |
29 |
this.proj = proj;
|
30 |
extent = new Extent();
|
31 |
} |
32 |
|
33 |
public Projection getProjection() { return proj; } |
34 |
public void setProjection(Projection p) { proj = p; } |
35 |
public void reProject(ReProjection rp) { |
36 |
extent = new Extent();
|
37 |
Iterator iter = data.iterator();
|
38 |
Projected obj = null;
|
39 |
while (iter.hasNext()) {
|
40 |
obj = (Projected) iter.next(); |
41 |
obj.reProject(rp); |
42 |
extent.add(((Extent.Has) obj).getExtent()); |
43 |
} |
44 |
setProjection(rp.getPDest()); |
45 |
} |
46 |
|
47 |
public Extent getExtent() { return extent; } |
48 |
|
49 |
public Color c() {return pc;} |
50 |
public Color c(Color color) {pc = color; return pc;} |
51 |
|
52 |
public void setColor(Color color) {pc = color;} |
53 |
public Color getColor() { return pc; } |
54 |
|
55 |
public void setFillColor(Color color) {fColor = color;} |
56 |
public Color getFillColor() { return fColor; } |
57 |
|
58 |
public void draw(Graphics2D g, ViewPort vp) { |
59 |
System.err.println("draw :"+this+": "+size()+ "objetos."); |
60 |
if (pc != null) g.setColor(pc); |
61 |
Iterator iter = data.iterator();
|
62 |
Drawable dwObj = null;
|
63 |
while (iter.hasNext()) {
|
64 |
dwObj = (Drawable) iter.next(); |
65 |
//if (dwObj.getClass() == PxContour.class)
|
66 |
// drawPxContour(g, vp, (PxContour) dwObj);
|
67 |
//else
|
68 |
/*extent = ((Extent.Has) dwObj).getExtent();
|
69 |
if (vp.getExtent().minX()> extent.maxX()) continue;
|
70 |
if (vp.getExtent().minY()> extent.maxY()) continue;
|
71 |
if (vp.getExtent().maxX()< extent.minX()) continue;
|
72 |
if (vp.getExtent().maxY()< extent.minY()) continue;*/
|
73 |
dwObj.draw(g, vp); |
74 |
} |
75 |
} |
76 |
|
77 |
public PxObjList getAt(Point2D pt) { |
78 |
PxObjList oList = new PxObjList();
|
79 |
Iterator iter = data.iterator();
|
80 |
while (iter.hasNext()) {
|
81 |
PxObj o = (PxObj) iter.next(); |
82 |
if (o.getExtent().isAt(pt)) oList.add(o);
|
83 |
} |
84 |
return oList;
|
85 |
} |
86 |
|
87 |
public Iterator iterator() { return data.iterator(); } |
88 |
public int size() { return data.size(); } |
89 |
|
90 |
public void add(PxObj obj) { |
91 |
if (obj != null) { |
92 |
extent.add(obj.extent); |
93 |
data.add(obj); |
94 |
} |
95 |
} |
96 |
|
97 |
public void add(PxObjList obj) { |
98 |
extent.add(obj.extent); |
99 |
data.add(obj); |
100 |
} |
101 |
|
102 |
public void clear() { |
103 |
extent = new Extent();
|
104 |
data.clear(); |
105 |
} |
106 |
/**
|
107 |
* Prueba de reproyecci?n.
|
108 |
*
|
109 |
*/
|
110 |
public void drawPxContour(Graphics2D g, ViewPort vp, PxContour obj) { |
111 |
Projection prj = obj.getProjection(); |
112 |
obj.setColor(pc); |
113 |
obj.setFillColor(fColor); |
114 |
if (prj != null) { |
115 |
if (prj != vp.getProjection()) {
|
116 |
ReProjection rp = new ReProjection(obj.getProjection(), vp.getProjection());
|
117 |
obj.draw(g, vp, rp); |
118 |
} else {
|
119 |
obj.draw(g, vp); |
120 |
} |
121 |
} else
|
122 |
System.err.println("Proyecci?n nula o inadecuada."); |
123 |
} |
124 |
} |