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