Statistics
| Revision:

svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libProjectionCresques / src / org / gvsig / projection / cresques / px / PxObjList.java @ 21932

History | View | Annotate | Download (5.38 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.gvsig.projection.cresques.px;
25

    
26

    
27
import java.awt.Color;
28
import java.awt.Graphics2D;
29
import java.awt.geom.Point2D;
30
import java.util.Iterator;
31
import java.util.Vector;
32

    
33
import org.gvsig.projection.cresques.geo.Projection;
34
import org.gvsig.projection.cresques.geo.ReProjection;
35
import org.gvsig.projection.cts.ICoordTrans;
36
import org.gvsig.projection.cts.IProjection;
37
import org.gvsig.projection.geo.Projected;
38
import org.gvsig.projection.geo.ViewPortData;
39
import org.gvsig.projection.px.Drawable;
40
import org.gvsig.projection.px.Extent;
41
import org.gvsig.projection.px.IObjList;
42
import org.gvsig.projection.px.PxObj;
43

    
44

    
45
public class PxObjList implements Colored, Drawable, IObjList {
46
    IProjection proj = null;
47
    private Color pc = null;
48
    private Color fColor = null;
49
    protected Extent extent = null;
50
    Vector data = null;
51

    
52
    public PxObjList() {
53
        data = new Vector();
54
        extent = new Extent();
55
    }
56

    
57
    public PxObjList(IProjection proj) {
58
        data = new Vector();
59
        this.proj = proj;
60
        extent = new Extent();
61
    }
62

    
63
    public IProjection getProjection() {
64
        return proj;
65
    }
66

    
67
    public void setProjection(IProjection p) {
68
        proj = p;
69
    }
70

    
71
    public void reProject(ICoordTrans rp) {
72
        extent = new Extent();
73

    
74
        Iterator iter = data.iterator();
75
        Projected obj = null;
76

    
77
        while (iter.hasNext()) {
78
            obj = (Projected) iter.next();
79
            obj.reProject(rp);
80
            extent.add(((Extent.Has) obj).getExtent());
81
        }
82

    
83
        setProjection(rp.getPDest());
84
    }
85

    
86
    public Extent getExtent() {
87
        return extent;
88
    }
89

    
90
    public Color c() {
91
        return pc;
92
    }
93

    
94
    public Color c(Color color) {
95
        pc = color;
96

    
97
        return pc;
98
    }
99

    
100
    public void setColor(Color color) {
101
        pc = color;
102
    }
103

    
104
    public Color getColor() {
105
        return pc;
106
    }
107

    
108
    public void setFillColor(Color color) {
109
        fColor = color;
110
    }
111

    
112
    public Color getFillColor() {
113
        return fColor;
114
    }
115

    
116
    public void draw(Graphics2D g, ViewPortData vp) {
117
        System.err.println("draw :" + this + ": " + size() + "objetos.");
118

    
119
        if (pc != null) {
120
            g.setColor(pc);
121
        }
122

    
123
        Iterator iter = data.iterator();
124
        Drawable dwObj = null;
125

    
126
        while (iter.hasNext()) {
127
            dwObj = (Drawable) iter.next();
128

    
129
            //if (dwObj.getClass() == PxContour.class)
130
            //        drawPxContour(g, vp, (PxContour) dwObj);
131
            //else
132

    
133
            /*extent = ((Extent.Has) dwObj).getExtent();
134
            if (vp.getExtent().minX()> extent.maxX()) continue;
135
            if (vp.getExtent().minY()> extent.maxY()) continue;
136
            if (vp.getExtent().maxX()< extent.minX()) continue;
137
            if (vp.getExtent().maxY()< extent.minY()) continue;*/
138
            dwObj.draw(g, vp);
139
        }
140
    }
141

    
142
    public IObjList getAt(Point2D pt) {
143
        PxObjList oList = new PxObjList();
144
        Iterator iter = data.iterator();
145

    
146
        while (iter.hasNext()) {
147
            PxObj o = (PxObj) iter.next();
148

    
149
            if (o.getExtent().isAt(pt)) {
150
                oList.add(o);
151
            }
152
        }
153

    
154
        return oList;
155
    }
156

    
157
    public Iterator iterator() {
158
        return data.iterator();
159
    }
160

    
161
    public int size() {
162
        return data.size();
163
    }
164

    
165
    public void add(Extent.Has obj) {
166
        if (obj != null) {
167
            extent.add(obj.getExtent());
168
            data.add(obj);
169
        }
170
    }
171

    
172
    public void remove(Object obj) {
173
        data.remove(obj);
174
    }
175

    
176
    public void clear() {
177
        extent = new Extent();
178
        data.clear();
179
    }
180

    
181
    /**
182
     * Prueba de reproyecci?n.
183
     *
184
     */
185
    public void drawPxContour(Graphics2D g, ViewPortData vp, PxContour obj) {
186
        IProjection prj = obj.getProjection();
187
        obj.setColor(pc);
188
        obj.setFillColor(fColor);
189

    
190
        if (prj != null) {
191
            if (prj != vp.getProjection()) {
192
                ICoordTrans rp = null;
193

    
194
                if (proj instanceof Projection) {
195
                    rp = new ReProjection(((Projection) proj),
196
                                          ((Projection) vp.getProjection()));
197
                }
198

    
199
                obj.draw(g, vp, rp);
200
            } else {
201
                obj.draw(g, vp);
202
            }
203
        } else {
204
            System.err.println("Proyecci?n nula o inadecuada.");
205
        }
206
    }
207
}