Statistics
| Revision:

root / branches / FMap_piloto_CAD_Layout_version / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FGeometryCollection.java @ 1762

History | View | Annotate | Download (7.46 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.core;
42

    
43
import com.iver.cit.gvsig.fmap.ViewPort;
44
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
45
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
46
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
47

    
48
import com.vividsolutions.jts.geom.Geometry;
49

    
50
import org.cresques.cts.ICoordTrans;
51

    
52
import java.awt.Graphics2D;
53
import java.awt.geom.AffineTransform;
54
import java.awt.geom.Point2D;
55
import java.awt.geom.Rectangle2D;
56
import java.util.ArrayList;
57

    
58

    
59
/**
60
 * Colecci?n de Geometr?as.
61
 *
62
 * @author Vicente Caballero Navarro
63
 */
64
public class FGeometryCollection implements IGeometry {
65
        private ArrayList geometries = new ArrayList();
66
        private FSymbol symbol;
67
        /**
68
         * Crea un nuevo FGeometryCollection.
69
         *
70
         * @param geoms vector de geometr?as.
71
         */
72
        public FGeometryCollection(IGeometry[] geoms) {
73
                for (int i = 0; i < geoms.length; i++) {
74
                        geometries.add(geoms[i]);
75
                }
76
        }
77
        
78
        public void addGeometry(IGeometry g){
79
                geometries.add(g);
80
        }
81

    
82
        /**
83
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D,
84
         *                 com.iver.cit.gvsig.fmap.ViewPort, FStyle2D)
85
         */
86
        public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) {
87
                for (int i = 0; i < geometries.size(); i++)
88
                        ((IGeometry)geometries.get(i)).draw(g, vp, symbol);
89
        }
90

    
91
        /**
92
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
93
         */
94
        public FLabel[] createLabels(int position, boolean duplicates) {
95
                return null;
96
        }
97

    
98
        /**
99
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
100
         */
101
        public boolean intersects(Rectangle2D r) {
102
            boolean resul = false;
103
                for (int i = 0; i < geometries.size(); i++)
104
                {
105
                        resul = ((IGeometry)geometries.get(i)).intersects(r);
106
                        if (resul) break;
107
                }
108
                
109
                return resul;
110
        }
111

    
112
        /**
113
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
114
         */
115
        public Rectangle2D getBounds2D() {
116
                Rectangle2D rAux = null;
117

    
118
                for (int i = 0; i < geometries.size(); i++)
119
                        if (rAux==null){
120
                                rAux=((IGeometry)geometries.get(i)).getBounds2D();
121
                        }else{
122
                                rAux.add(((IGeometry)geometries.get(i)).getBounds2D());
123
                        }
124
                return rAux;
125
        }
126

    
127
        /**
128
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
129
         */
130
        public int getGeometryType() {
131
                /*int ret = 0;
132

133
                for (int i = 0; i < geometries.length; i++) {
134
                        ret = ret | geometries[i].getGeometryType();
135
                }
136

137
                return ret;
138
                */
139
                return FShape.POLYLINE;
140
        }
141

    
142
        /* (non-Javadoc)
143
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.core.v02.FSymbol)
144
         */
145
        public void draw(Graphics2D g, ViewPort vp, FSymbol symbol) {
146
                for (int i = 0; i < geometries.size(); i++)
147
                        ((IGeometry)geometries.get(i)).draw(g, vp, symbol);
148
        }
149

    
150
        /* (non-Javadoc)
151
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
152
         */
153
        public IGeometry cloneGeometry() {
154
                IGeometry[] newGeometries = new IGeometry[geometries.size()];
155

    
156
                for (int i = 0; i < geometries.size(); i++)
157
                        newGeometries[i] = ((IGeometry)geometries.get(i)).cloneGeometry();
158

    
159
                return new FGeometryCollection(newGeometries);
160
        }
161

    
162
        /* (non-Javadoc)
163
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
164
         */
165
        public Geometry toJTSGeometry() {
166
                // TODO Auto-generated method stub
167
                return null;
168
        }
169

    
170
        /* (non-Javadoc)
171
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
172
         */
173
        public void reProject(ICoordTrans ct) {
174
                for (int i = 0; i < geometries.size(); i++)
175
                        ((IGeometry)geometries.get(i)).reProject(ct);
176
        }
177

    
178
        /**
179
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
180
         */
181
        public GeneralPathXIterator getGeneralPathXIterator() {
182
                //TODO no esta implementado.
183
                return null;
184
        }
185

    
186
    /* (non-Javadoc)
187
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
188
     */
189
    public boolean fastIntersects(double x, double y, double w, double h) {
190
            boolean resul = false;
191
                for (int i = 0; i < geometries.size(); i++)
192
                {
193
                        resul = ((IGeometry)geometries.get(i)).fastIntersects(x,y,w,h);
194
                        if (resul) break;
195
                }                
196
                return resul;
197
    }
198

    
199
        /**
200
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#move(double, double)
201
         */
202
        public void move(double x, double y) {
203
                for (int i = 0; i < geometries.size(); i++){
204
                        ((IGeometry)geometries.get(i)).move(x,y);
205
                }
206
        }
207

    
208
        /**
209
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#rotate(double, double, double)
210
         */
211
        public void rotate(double r, double x, double y) {
212
                for (int i = 0; i < geometries.size(); i++){
213
                        ((IGeometry)geometries.get(i)).rotate(r,x,y);
214
                }
215
        }
216

    
217
        /**
218
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getHandlers()
219
         */
220
        public Handler[] getHandlers(int type) {
221
                ArrayList handlers=new ArrayList();
222
                for (int i = 0; i < geometries.size(); i++){
223
                        Handler[] handAux=((IGeometry)geometries.get(i)).getHandlers(type);
224
                        for (int j=0;j<handAux.length;j++){
225
                                handlers.add(handAux[j]);
226
                        }
227
                }
228
                return (Handler[])handlers.toArray(new Handler[0]);
229
                
230
        }
231

    
232
        /**
233
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#scale(java.awt.geom.Point2D, double, double)
234
         */
235
        public void scale(Point2D point, double x, double y) {
236
                for (int i = 0; i < geometries.size(); i++){
237
                        ((IGeometry)geometries.get(i)).scale(point,x,y);
238
                }
239
        }
240

    
241
        /**
242
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getShapes()
243
         */
244
        public FShape[] getShapes() {
245
                ArrayList shapes=new ArrayList();
246
                for (int i= 0;i<geometries.size();i++){
247
                        FShape[] s=((IGeometry)geometries.get(i)).getShapes();
248
                        for (int j=0;j<s.length;j++){
249
                                shapes.add(s[j]);
250
                        }
251
                }
252
                return (FShape[])shapes.toArray(new FShape[0]);
253
        }
254
        public IGeometry[] getGeometries(){
255
                return (IGeometry[])geometries.toArray(new IGeometry[0]).clone();
256
        }
257

    
258
        /**
259
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, java.awt.geom.AffineTransform, com.iver.cit.gvsig.fmap.core.v02.FSymbol)
260
         */
261
        public void draw(Graphics2D g, AffineTransform at, FSymbol symbol) {
262
                for (int i = 0; i < geometries.size(); i++)
263
                        ((IGeometry)geometries.get(i)).draw(g, at, symbol);
264
        }
265

    
266
        /**
267
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getSymbol()
268
         */
269
        public FSymbol getSymbol() {
270
                if (!geometries.isEmpty())return (FSymbol)((IGeometry)geometries.get(0)).getSymbol();
271
                return symbol;
272
        }
273

    
274
        /**
275
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#setSymbol(com.iver.cit.gvsig.fmap.core.v02.FSymbol)
276
         */
277
        public void setSymbol(FSymbol s) {
278
                symbol=s;
279
        }
280
}