Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / DefaultStrategy.java @ 470

History | View | Annotate | Download (5.43 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 com.hardcode.driverManager.DriverLoadException;
11
import com.hardcode.gdbms.engine.data.DriverException;
12
import com.iver.cit.gvsig.fmap.ViewPort;
13
import com.iver.cit.gvsig.fmap.core.IGeometry;
14
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
15
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
16
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
17
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
18
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
19
import com.iver.cit.gvsig.fmap.operations.Cancellable;
20
import com.iver.cit.gvsig.fmap.operations.QueriedPoint;
21
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
22
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
23

    
24

    
25
/**
26
 * Implementa la Strategy por defecto. Los m?todos que tendr?n en com?n la
27
 * mayor parte de las estrategias
28
 */
29
public class DefaultStrategy implements Strategy {
30
        private FLyrVect capa = null;
31

    
32
        /**
33
         * Crea un nuevo DefaultStrategy.
34
         *
35
         * @param capa DOCUMENT ME!
36
         */
37
        public DefaultStrategy(FLyrVect capa) {
38
                this.capa = capa;
39
        }
40

    
41
        /**
42
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByRect(java.awt.geom.Rectangle2D)
43
         */
44
        public BitSet queryByRect(Rectangle2D rect) throws DriverIOException{
45
                
46
                QueryByRectVisitor visitor=new QueryByRectVisitor();
47
                visitor.setRect(rect);
48
                process(visitor);
49
                return visitor.getBitSet();
50
        }
51

    
52
        /**
53
         * @throws DriverIOException
54
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.fshape.IGeometry,
55
         *                 int)
56
         */
57
        public BitSet queryByShape(IGeometry g, int relationship) throws DriverIOException {
58
                QueryByShapeVisitor visitor=new QueryByShapeVisitor();
59
                visitor.setRelationShip(relationship);
60
                visitor.setShape(g);
61
                process(visitor);
62
                return visitor.getBitSet();
63
        }
64

    
65
        /**
66
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#getSelectionBounds()
67
         */
68
        public Rectangle2D getSelectionBounds() {
69
                return null;
70
        }
71

    
72
        /**
73
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#createIndex()
74
         */
75
        public void createIndex() {
76
        }
77

    
78
        /**
79
         * DOCUMENT ME!
80
         *
81
         * @param image DOCUMENT ME!
82
         * @param g DOCUMENT ME!
83
         * @param viewPort DOCUMENT ME!
84
         *
85
         * @throws DriverIOException
86
         * @throws DriverLoadException
87
         * @throws DriverException
88
         *
89
         * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
90
         *                 java.awt.Graphics2D, FStyle2D)
91
         */
92
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel)
93
                throws DriverIOException, DriverLoadException, DriverException {
94
                VectorialAdapter adapter = capa.getSource();
95

    
96
                adapter.start();
97

    
98
                VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver();
99
                int sc;
100
                long t1 = System.currentTimeMillis();
101
                Rectangle2D extent = viewPort.getAdjustedExtent();
102
                AffineTransform at = viewPort.getAffineTransform();
103

    
104
                sc = adapter.getShapeCount();
105

    
106
                for (int i = 0; i < sc; i++) {
107
                        if (cancel.isCanceled()) break;
108
                        IGeometry geom = adapter.getShape(i);
109
                        if (geom == null) continue;
110
                        VectorialLegend l = capa.getLegend();
111

    
112
                        if (geom.intersects(extent)) {
113
                                FSymbol symbol = l.getSymbol(i);
114
                                geom.draw(g, viewPort, symbol);
115
                        }
116
                }
117

    
118
                long t2 = System.currentTimeMillis();
119
                adapter.stop();
120

    
121
                System.out.println(t2 - t1);
122
        }
123

    
124
        /**
125
         * DOCUMENT ME!
126
         *
127
         * @return Returns the capa.
128
         */
129
        public FLyrVect getCapa() {
130
                return capa;
131
        }
132

    
133
        /**
134
         * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#getFullExtent()
135
         */
136
        public Rectangle2D getFullExtent() throws DriverIOException {
137
                return null;
138
        }
139

    
140
        /**
141
         * @throws DriverIOException
142
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor, com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
143
         */
144
        public void process(FeatureVisitor visitor, BitSet subset) throws DriverIOException {
145
                visitor.start();
146
                VectorialAdapter va=capa.getSource();
147
                for (int i=0;i<va.getShapeCount();i++){
148
                        if (subset.get(i)){
149
                                visitor.visit(va.getShape(i), i);
150
                        }
151
                }
152
                visitor.stop();
153
        }
154
        /**
155
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
156
         */
157
        public void process(FeatureVisitor visitor) throws DriverIOException {
158
                visitor.start();
159
                VectorialAdapter va=capa.getSource();
160
                for (int i=0;i<va.getShapeCount();i++){
161
                        visitor.visit(va.getShape(i), i);
162
                }
163
                visitor.stop();
164
        }
165
        /**
166
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint, double)
167
         */
168
        public BitSet queryByPoint(QueriedPoint p, double tolerance) throws DriverIOException {
169
                QueryByPointVisitor visitor=new QueryByPointVisitor();
170
                visitor.setLayer(capa);
171
                visitor.setTolerance(tolerance);
172
                visitor.setQueriedPoint(p);
173
                process(visitor);
174
                return visitor.getBitSet();
175
        }
176

    
177
        /* (non-Javadoc)
178
         * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
179
         */
180
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverIOException, DriverLoadException, DriverException {
181
                draw(null, g, viewPort, cancel);  // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!!
182
                
183
        }
184

    
185
        
186
}