Statistics
| Revision:

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

History | View | Annotate | Download (6.72 KB)

1
/* Generated by Together */
2
package com.iver.cit.gvsig.fmap.operations.strategies;
3

    
4
import java.awt.Graphics2D;
5
import java.awt.geom.AffineTransform;
6
import java.awt.geom.Rectangle2D;
7
import java.awt.image.BufferedImage;
8
import java.util.BitSet;
9

    
10
import org.apache.log4j.Logger;
11
import org.cresques.cts.ICoordTrans;
12

    
13
import com.hardcode.driverManager.DriverLoadException;
14
import com.iver.cit.gvsig.fmap.DriverException;
15
import com.iver.cit.gvsig.fmap.ViewPort;
16
import com.iver.cit.gvsig.fmap.core.IGeometry;
17
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
18
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
19
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
20
import com.iver.cit.gvsig.fmap.layers.FLayer;
21
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
22
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
23
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
24
import com.iver.cit.gvsig.fmap.operations.Cancellable;
25
import com.iver.cit.gvsig.fmap.operations.QueriedPoint;
26
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
27
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
28

    
29

    
30
/**
31
 * Implementa la Strategy por defecto. Los m?todos que tendr?n en com?n la
32
 * mayor parte de las estrategias
33
 */
34
public class DefaultStrategy implements Strategy {
35
        private static Logger logger = Logger.getLogger(DefaultStrategy.class.getName());
36
        private FLayer capa = null;
37

    
38
        /**
39
         * Crea un nuevo DefaultStrategy.
40
         *
41
         * @param capa DOCUMENT ME!
42
         */
43
        public DefaultStrategy(FLayer capa) {
44
                this.capa = capa;
45
                SingleLayer foo = (SingleLayer) capa;
46
                ClassifiableVectorial vectorial = (ClassifiableVectorial) capa;                
47
        }
48

    
49
        /**
50
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByRect(java.awt.geom.Rectangle2D)
51
         */
52
        public BitSet queryByRect(Rectangle2D rect) throws DriverException {
53
                QueryByRectVisitor visitor = new QueryByRectVisitor();
54
                visitor.setRect(rect);
55
                process(visitor);
56

    
57
                return visitor.getBitSet();
58
        }
59

    
60
        /**
61
         * DOCUMENT ME!
62
         *
63
         * @param g DOCUMENT ME!
64
         * @param relationship DOCUMENT ME!
65
         *
66
         * @return DOCUMENT ME!
67
         *
68
         * @throws DriverIOException
69
         *
70
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.fshape.IGeometry,
71
         *                 int)
72
         */
73
        public BitSet queryByShape(IGeometry g, int relationship)
74
                throws DriverException {
75
                QueryByShapeVisitor visitor = new QueryByShapeVisitor();
76
                visitor.setRelationShip(relationship);
77
                visitor.setShape(g);
78
                process(visitor);
79

    
80
                return visitor.getBitSet();
81
        }
82

    
83
        /**
84
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#getSelectionBounds()
85
         */
86
        public Rectangle2D getSelectionBounds() {
87
                return null;
88
        }
89

    
90
        /**
91
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#createIndex()
92
         */
93
        public void createIndex() {
94
        }
95

    
96
        /**
97
         * DOCUMENT ME!
98
         *
99
         * @param image DOCUMENT ME!
100
         * @param g DOCUMENT ME!
101
         * @param viewPort DOCUMENT ME!
102
         * @param cancel DOCUMENT ME!
103
         *
104
         * @throws DriverIOException
105
         * @throws DriverLoadException
106
         * @throws DriverException
107
         *
108
         * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
109
         *                 java.awt.Graphics2D, FStyle2D)
110
         */
111
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
112
                Cancellable cancel)
113
                throws DriverException {
114
                try{
115
                VectorialAdapter adapter = ((SingleLayer) capa).getSource();
116
                ICoordTrans ct = getCapa().getCoordTrans();
117
                logger.debug("adapter.start()");
118
                adapter.start();
119

    
120
                VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver();
121
                int sc;
122
                long t1 = System.currentTimeMillis();
123
                Rectangle2D extent = viewPort.getAdjustedExtent();
124
                AffineTransform at = viewPort.getAffineTransform();
125

    
126
                sc = adapter.getShapeCount();
127

    
128
                for (int i = 0; i < sc; i++) {
129
                        if (cancel.isCanceled()) {
130
                                break;
131
                        }
132

    
133
                        IGeometry geom = adapter.getShape(i);
134

    
135
                        if (geom == null) {
136
                                continue;
137
                        }
138
                if (ct != null)
139
                {
140
                        geom.reProject(ct);
141
                }
142

    
143
                        VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) capa).getLegend();
144

    
145
                        if (geom.intersects(extent)) {
146
                                FSymbol symbol = l.getSymbol(i);
147
                                geom.draw(g, viewPort, symbol);
148
                        }
149
                }
150

    
151
                long t2 = System.currentTimeMillis();
152
                logger.debug("adapter.stop()");
153
                adapter.stop();
154

    
155
                System.out.println(t2 - t1);
156
                
157
                }catch(DriverIOException e){
158
                        throw new DriverException(e);
159
                }
160
        }
161

    
162
        /**
163
         * DOCUMENT ME!
164
         *
165
         * @return Returns the capa.
166
         */
167
        public FLayer getCapa() {
168
                return capa;
169
        }
170

    
171
        /**
172
         * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#getFullExtent()
173
         */
174
        public Rectangle2D getFullExtent() throws DriverException {
175
                return null;
176
        }
177

    
178
        /**
179
         * DOCUMENT ME!
180
         *
181
         * @param visitor DOCUMENT ME!
182
         * @param subset DOCUMENT ME!
183
         *
184
         * @throws DriverIOException
185
         *
186
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
187
         *                 com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
188
         */
189
        public void process(FeatureVisitor visitor, BitSet subset)
190
                throws DriverException {
191
                try{
192
                logger.debug("visitor.start()");
193

    
194
                if (visitor.start(capa)) {
195
                        VectorialAdapter va = ((SingleLayer) capa).getSource();
196

    
197
                        for (int i = 0; i < va.getShapeCount(); i++) {
198
                                if (subset.get(i)) {
199
                                        visitor.visit(va.getShape(i), i);
200
                                }
201
                        }
202

    
203
                        logger.debug("visitor.stop()");
204
                        visitor.stop(capa);
205
                }
206
        }catch(DriverIOException e){
207
                throw new DriverException(e);
208
        }
209
        }
210

    
211
        /**
212
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
213
         */
214
        public void process(FeatureVisitor visitor) throws DriverException {
215
                try{
216
                logger.debug("visitor.start()");
217

    
218
                if (visitor.start(capa)) {
219
                        VectorialAdapter va = ((SingleLayer) capa).getSource();
220

    
221
                        for (int i = 0; i < va.getShapeCount(); i++) {
222
                                visitor.visit(va.getShape(i), i);
223
                        }
224

    
225
                        logger.debug("visitor.stop()");
226
                        visitor.stop(capa);
227
                }
228
                }catch(DriverIOException e){
229
                        throw new DriverException(e);
230
                }
231
        }
232

    
233
        /**
234
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint,
235
         *                 double)
236
         */
237
        public BitSet queryByPoint(QueriedPoint p, double tolerance)
238
                throws DriverException {
239
                QueryByPointVisitor visitor = new QueryByPointVisitor();
240
                visitor.setLayer(capa);
241
                visitor.setTolerance(tolerance);
242
                visitor.setQueriedPoint(p);
243
                process(visitor);
244

    
245
                return visitor.getBitSet();
246
        }
247

    
248
        /* (non-Javadoc)
249
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
250
         */
251
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel)
252
                throws DriverException {
253
                draw(null, g, viewPort, cancel); // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!!
254
        }
255
}