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