root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / DefaultStrategy.java @ 251
History | View | Annotate | Download (5.15 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.iver.cit.gvsig.fmap.ViewPort; |
11 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
12 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
13 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
14 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
15 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
16 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
17 |
import com.iver.cit.gvsig.fmap.operations.QueriedPoint; |
18 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
19 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
20 |
|
21 |
|
22 |
/**
|
23 |
* Implementa la Strategy por defecto. Los m?todos que tendr?n en com?n la
|
24 |
* mayor parte de las estrategias
|
25 |
*/
|
26 |
public class DefaultStrategy implements Strategy { |
27 |
private FLyrVect capa = null; |
28 |
|
29 |
/**
|
30 |
* Crea un nuevo DefaultStrategy.
|
31 |
*
|
32 |
* @param capa DOCUMENT ME!
|
33 |
*/
|
34 |
public DefaultStrategy(FLyrVect capa) {
|
35 |
this.capa = capa;
|
36 |
} |
37 |
|
38 |
/**
|
39 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByRect(java.awt.geom.Rectangle2D)
|
40 |
*/
|
41 |
public BitSet queryByRect(Rectangle2D rect) throws DriverIOException{ |
42 |
|
43 |
QueryByRectVisitor visitor=new QueryByRectVisitor();
|
44 |
visitor.setRect(rect); |
45 |
process(visitor); |
46 |
return visitor.getBitSet();
|
47 |
} |
48 |
|
49 |
/**
|
50 |
* @throws DriverIOException
|
51 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.fshape.FGeometry,
|
52 |
* int)
|
53 |
*/
|
54 |
public BitSet queryByShape(FGeometry g, int relationship) throws DriverIOException { |
55 |
QueryByShapeVisitor visitor=new QueryByShapeVisitor();
|
56 |
visitor.setRelationShip(relationship); |
57 |
visitor.setShape(g); |
58 |
process(visitor); |
59 |
return visitor.getBitSet();
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#getSelectionBounds()
|
64 |
*/
|
65 |
public Rectangle2D getSelectionBounds() { |
66 |
return null; |
67 |
} |
68 |
|
69 |
/**
|
70 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#createIndex()
|
71 |
*/
|
72 |
public void createIndex() { |
73 |
} |
74 |
|
75 |
/**
|
76 |
* DOCUMENT ME!
|
77 |
*
|
78 |
* @param image DOCUMENT ME!
|
79 |
* @param g DOCUMENT ME!
|
80 |
* @param viewPort DOCUMENT ME!
|
81 |
*
|
82 |
* @throws DriverIOException
|
83 |
*
|
84 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
|
85 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
86 |
*/
|
87 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) |
88 |
throws DriverIOException {
|
89 |
VectorialAdapter adapter = capa.getSource(); |
90 |
|
91 |
adapter.start(); |
92 |
|
93 |
VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver(); |
94 |
int sc;
|
95 |
long t1 = System.currentTimeMillis(); |
96 |
Rectangle2D extent = viewPort.getAdjustedExtent();
|
97 |
AffineTransform at = viewPort.getAffineTransform();
|
98 |
|
99 |
sc = adapter.getShapeCount(); |
100 |
|
101 |
for (int i = 0; i < sc; i++) { |
102 |
if (cancel.isCanceled()) break; |
103 |
FGeometry geom = adapter.getShape(i); |
104 |
Legend l = capa.getLegend(geom.getType()); |
105 |
|
106 |
if (geom.intersects(extent)) {
|
107 |
FStyle2D symbol = l.getSymbol(null);
|
108 |
geom.draw(g, viewPort, symbol.getStyle2D()); |
109 |
} |
110 |
} |
111 |
|
112 |
long t2 = System.currentTimeMillis(); |
113 |
adapter.stop(); |
114 |
|
115 |
System.out.println(t2 - t1);
|
116 |
} |
117 |
|
118 |
/**
|
119 |
* DOCUMENT ME!
|
120 |
*
|
121 |
* @return Returns the capa.
|
122 |
*/
|
123 |
public FLyrVect getCapa() {
|
124 |
return capa;
|
125 |
} |
126 |
|
127 |
/**
|
128 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#getFullExtent()
|
129 |
*/
|
130 |
public Rectangle2D getFullExtent() throws DriverIOException { |
131 |
return null; |
132 |
} |
133 |
|
134 |
/**
|
135 |
* @throws DriverIOException
|
136 |
* @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)
|
137 |
*/
|
138 |
public void process(FeatureVisitor visitor, BitSet subset) throws DriverIOException { |
139 |
visitor.start(); |
140 |
VectorialAdapter va=capa.getSource(); |
141 |
for (int i=0;i<va.getShapeCount();i++){ |
142 |
if (subset.get(i)){
|
143 |
visitor.visit(va.getShape(i), i); |
144 |
} |
145 |
} |
146 |
visitor.stop(); |
147 |
} |
148 |
/**
|
149 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
150 |
*/
|
151 |
public void process(FeatureVisitor visitor) throws DriverIOException { |
152 |
visitor.start(); |
153 |
VectorialAdapter va=capa.getSource(); |
154 |
for (int i=0;i<va.getShapeCount();i++){ |
155 |
visitor.visit(va.getShape(i), i); |
156 |
} |
157 |
visitor.stop(); |
158 |
} |
159 |
/**
|
160 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint, double)
|
161 |
*/
|
162 |
public BitSet queryByPoint(QueriedPoint p, double tolerance) throws DriverIOException { |
163 |
QueryByPointVisitor visitor=new QueryByPointVisitor();
|
164 |
visitor.setLayer(capa); |
165 |
visitor.setTolerance(tolerance); |
166 |
visitor.setQueriedPoint(p); |
167 |
process(visitor); |
168 |
return visitor.getBitSet();
|
169 |
} |
170 |
|
171 |
/* (non-Javadoc)
|
172 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
173 |
*/
|
174 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverIOException { |
175 |
draw(null, g, viewPort, cancel); // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!! |
176 |
|
177 |
} |
178 |
|
179 |
|
180 |
} |