Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / DefaultStrategy.java @ 1100

History | View | Annotate | Download (7.68 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.operations.strategies;
42

    
43
import com.iver.cit.gvsig.fmap.DriverException;
44
import com.iver.cit.gvsig.fmap.ViewPort;
45
import com.iver.cit.gvsig.fmap.core.IGeometry;
46
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
47
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
48
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
49
import com.iver.cit.gvsig.fmap.layers.FLayer;
50
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
51
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
52
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
53
import com.iver.cit.gvsig.fmap.operations.Cancellable;
54
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
55
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
56

    
57
import org.apache.log4j.Logger;
58

    
59
import org.cresques.cts.ICoordTrans;
60

    
61
import java.awt.Graphics2D;
62
import java.awt.geom.AffineTransform;
63
import java.awt.geom.Point2D;
64
import java.awt.geom.Rectangle2D;
65
import java.awt.image.BufferedImage;
66

    
67
import java.util.BitSet;
68

    
69

    
70
/**
71
 * Implementa la Strategy por defecto. Los m?todos que tendr?n en com?n la
72
 * mayor parte de las estrategias
73
 */
74
public class DefaultStrategy implements Strategy {
75
        private static Logger logger = Logger.getLogger(DefaultStrategy.class.getName());
76
        private FLayer capa = null;
77

    
78
        /**
79
         * Crea un nuevo DefaultStrategy.
80
         *
81
         * @param capa DOCUMENT ME!
82
         */
83
        public DefaultStrategy(FLayer capa) {
84
                this.capa = capa;
85

    
86
                SingleLayer foo = (SingleLayer) capa;
87
                ClassifiableVectorial vectorial = (ClassifiableVectorial) capa;
88
        }
89

    
90
        /**
91
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByRect(java.awt.geom.Rectangle2D)
92
         */
93
        public BitSet queryByRect(Rectangle2D rect) throws DriverException {
94
                QueryByRectVisitor visitor = new QueryByRectVisitor();
95

    
96
                visitor.setRect(rect);
97

    
98
                try {
99
                        process(visitor);
100
                } catch (VisitException e) {
101
                        throw new RuntimeException(
102
                                "QueryByRectVisitor lanza una VisitException?");
103
                }
104

    
105
                return visitor.getBitSet();
106
        }
107

    
108
        /**
109
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.fshape.IGeometry,
110
         *                 int)
111
         */
112
        public BitSet queryByShape(IGeometry g, int relationship)
113
                throws DriverException, VisitException {
114
                QueryByShapeVisitor visitor = new QueryByShapeVisitor();
115
                visitor.setRelationShip(relationship);
116
                visitor.setShape(g);
117
                process(visitor);
118

    
119
                return visitor.getBitSet();
120
        }
121

    
122
        /**
123
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#getSelectionBounds()
124
         */
125
        public Rectangle2D getSelectionBounds() {
126
                return null;
127
        }
128

    
129
        /**
130
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#createIndex()
131
         */
132
        public void createIndex() {
133
        }
134

    
135
        /**
136
         * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
137
         *                 java.awt.Graphics2D, FStyle2D)
138
         */
139
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
140
                Cancellable cancel) throws DriverException {
141
                try {
142
                        VectorialAdapter adapter = ((SingleLayer) capa).getSource();
143
                        ICoordTrans ct = getCapa().getCoordTrans();
144
                        logger.debug("adapter.start()");
145
                        adapter.start();
146

    
147
                        VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver();
148
                        int sc;
149
                        long t1 = System.currentTimeMillis();
150
                        Rectangle2D extent = viewPort.getAdjustedExtent();
151
                        AffineTransform at = viewPort.getAffineTransform();
152

    
153
                        sc = adapter.getShapeCount();
154

    
155
                        for (int i = 0; i < sc; i++) {
156
                                if (cancel.isCanceled()) {
157
                                        break;
158
                                }
159

    
160
                                IGeometry geom = adapter.getShape(i);
161

    
162
                                if (geom == null) {
163
                                        continue;
164
                                }
165

    
166
                                if (ct != null) {
167
                                        geom.reProject(ct);
168
                                }
169

    
170
                                VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) capa).getLegend();
171

    
172
                                if (geom.intersects(extent)) {
173
                                        FSymbol symbol = l.getSymbol(i);
174
                                        geom.draw(g, viewPort, symbol);
175
                                }
176
                        }
177

    
178
                        long t2 = System.currentTimeMillis();
179
                        logger.debug("adapter.stop()");
180
                        adapter.stop();
181

    
182
                        System.out.println(t2 - t1);
183
                } catch (DriverIOException e) {
184
                        throw new DriverException(e);
185
                }
186
        }
187

    
188
        /**
189
         * Devuelve la capa.
190
         *
191
         * @return Returns the capa.
192
         */
193
        public FLayer getCapa() {
194
                return capa;
195
        }
196

    
197
        /**
198
         * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#getFullExtent()
199
         */
200
        public Rectangle2D getFullExtent() throws DriverException {
201
                return null;
202
        }
203

    
204
        /**
205
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
206
         *                 java.util.BitSet)
207
         */
208
        public void process(FeatureVisitor visitor, BitSet subset)
209
                throws DriverException, VisitException {
210
                try {
211
                        logger.debug("visitor.start()");
212

    
213
                        if (visitor.start(capa)) {
214
                                VectorialAdapter va = ((SingleLayer) capa).getSource();
215

    
216
                                for (int i = 0; i < va.getShapeCount(); i++) {
217
                                        if (subset.get(i)) {
218
                                                visitor.visit(va.getShape(i), i);
219
                                        }
220
                                }
221

    
222
                                logger.debug("visitor.stop()");
223
                                visitor.stop(capa);
224
                        }
225
                } catch (DriverIOException e) {
226
                        throw new DriverException(e);
227
                }
228
        }
229

    
230
        /**
231
         * DOCUMENT ME!
232
         *
233
         * @param visitor DOCUMENT ME!
234
         *
235
         * @throws DriverException DOCUMENT ME!
236
         * @throws VisitException
237
         *
238
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
239
         */
240
        public void process(FeatureVisitor visitor)
241
                throws DriverException, VisitException {
242
                try {
243
                        logger.debug("visitor.start()");
244

    
245
                        if (visitor.start(capa)) {
246
                                VectorialAdapter va = ((SingleLayer) capa).getSource();
247

    
248
                                for (int i = 0; i < va.getShapeCount(); i++) {
249
                                        visitor.visit(va.getShape(i), i);
250
                                }
251

    
252
                                logger.debug("visitor.stop()");
253
                                visitor.stop(capa);
254
                        }
255
                } catch (DriverIOException e) {
256
                        throw new DriverException(e);
257
                }
258
        }
259

    
260
        /**
261
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(Point2D,
262
         *                 double)
263
         */
264
        public BitSet queryByPoint(Point2D p, double tolerance)
265
                throws DriverException {
266
                QueryByPointVisitor visitor = new QueryByPointVisitor();
267
                visitor.setLayer(capa);
268
                visitor.setTolerance(tolerance);
269
                visitor.setQueriedPoint(p);
270

    
271
                try {
272
                        process(visitor);
273
                } catch (VisitException e) {
274
                        throw new RuntimeException(
275
                                "QueryByPointVisitor lanza una VisitException?");
276
                }
277

    
278
                return visitor.getBitSet();
279
        }
280

    
281
        /* (non-Javadoc)
282
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
283
         */
284
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel)
285
                throws DriverException {
286
                draw(null, g, viewPort, cancel); // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!!
287
        }
288
}