Statistics
| Revision:

svn-gvsig-desktop / tags / Root_CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / PxObjList.java @ 1732

History | View | Annotate | Download (3.22 KB)

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