svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / PxObjList.java @ 2312
History | View | Annotate | Download (4.1 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 java.util.Vector; |
27 |
import java.util.Iterator; |
28 |
|
29 |
import java.awt.Color; |
30 |
import java.awt.Graphics2D; |
31 |
|
32 |
import java.awt.geom.Point2D; |
33 |
|
34 |
import org.cresques.cts.ICoordTrans; |
35 |
import org.cresques.cts.IProjection; |
36 |
import org.cresques.geo.Projected; |
37 |
import org.cresques.geo.Projection; |
38 |
import org.cresques.geo.ReProjection; |
39 |
import org.cresques.geo.ViewPortData; |
40 |
|
41 |
public class PxObjList implements Colored, Drawable, IObjList { |
42 |
IProjection proj = null;
|
43 |
private Color pc = null; |
44 |
private Color fColor = null; |
45 |
protected Extent extent = null; |
46 |
Vector data = null; |
47 |
|
48 |
public PxObjList() {
|
49 |
data = new Vector(); |
50 |
extent = new Extent();
|
51 |
} |
52 |
public PxObjList(IProjection proj) {
|
53 |
data = new Vector(); |
54 |
this.proj = proj;
|
55 |
extent = new Extent();
|
56 |
} |
57 |
|
58 |
public IProjection getProjection() { return proj; } |
59 |
public void setProjection(IProjection p) { proj = p; } |
60 |
public void reProject(ICoordTrans rp) { |
61 |
extent = new Extent();
|
62 |
Iterator iter = data.iterator();
|
63 |
Projected obj = null;
|
64 |
while (iter.hasNext()) {
|
65 |
obj = (Projected) iter.next(); |
66 |
obj.reProject(rp); |
67 |
extent.add(((Extent.Has) obj).getExtent()); |
68 |
} |
69 |
setProjection(rp.getPDest()); |
70 |
} |
71 |
|
72 |
public Extent getExtent() { return extent; } |
73 |
|
74 |
public Color c() {return pc;} |
75 |
public Color c(Color color) {pc = color; return pc;} |
76 |
|
77 |
public void setColor(Color color) {pc = color;} |
78 |
public Color getColor() { return pc; } |
79 |
|
80 |
public void setFillColor(Color color) {fColor = color;} |
81 |
public Color getFillColor() { return fColor; } |
82 |
|
83 |
public void draw(Graphics2D g, ViewPortData vp) { |
84 |
System.err.println("draw :"+this+": "+size()+ "objetos."); |
85 |
if (pc != null) g.setColor(pc); |
86 |
Iterator iter = data.iterator();
|
87 |
Drawable dwObj = null;
|
88 |
while (iter.hasNext()) {
|
89 |
dwObj = (Drawable) iter.next(); |
90 |
//if (dwObj.getClass() == PxContour.class)
|
91 |
// drawPxContour(g, vp, (PxContour) dwObj);
|
92 |
//else
|
93 |
/*extent = ((Extent.Has) dwObj).getExtent();
|
94 |
if (vp.getExtent().minX()> extent.maxX()) continue;
|
95 |
if (vp.getExtent().minY()> extent.maxY()) continue;
|
96 |
if (vp.getExtent().maxX()< extent.minX()) continue;
|
97 |
if (vp.getExtent().maxY()< extent.minY()) continue;*/
|
98 |
dwObj.draw(g, vp); |
99 |
} |
100 |
} |
101 |
|
102 |
public IObjList getAt(Point2D pt) { |
103 |
PxObjList oList = new PxObjList();
|
104 |
Iterator iter = data.iterator();
|
105 |
while (iter.hasNext()) {
|
106 |
PxObj o = (PxObj) iter.next(); |
107 |
if (o.getExtent().isAt(pt)) oList.add(o);
|
108 |
} |
109 |
return oList;
|
110 |
} |
111 |
|
112 |
public Iterator iterator() { return data.iterator(); } |
113 |
public int size() { return data.size(); } |
114 |
|
115 |
public void add(Extent.Has obj) { |
116 |
if (obj != null) { |
117 |
extent.add(obj.getExtent()); |
118 |
data.add(obj); |
119 |
} |
120 |
} |
121 |
|
122 |
public void remove(Object obj) { |
123 |
data.remove(obj); |
124 |
} |
125 |
|
126 |
public void clear() { |
127 |
extent = new Extent();
|
128 |
data.clear(); |
129 |
} |
130 |
/**
|
131 |
* Prueba de reproyecci?n.
|
132 |
*
|
133 |
*/
|
134 |
public void drawPxContour(Graphics2D g, ViewPortData vp, PxContour obj) { |
135 |
IProjection prj = obj.getProjection(); |
136 |
obj.setColor(pc); |
137 |
obj.setFillColor(fColor); |
138 |
if (prj != null) { |
139 |
if (prj != vp.getProjection()) {
|
140 |
ICoordTrans rp = null;
|
141 |
if (proj instanceof Projection) |
142 |
rp = new ReProjection(((Projection) proj), ((Projection) vp.getProjection()));
|
143 |
obj.draw(g, vp, rp); |
144 |
} else {
|
145 |
obj.draw(g, vp); |
146 |
} |
147 |
} else
|
148 |
System.err.println("Proyecci?n nula o inadecuada."); |
149 |
} |
150 |
} |