svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 472
History | View | Annotate | Download (9.18 KB)
1 |
/* Generated by Together */
|
---|---|
2 |
|
3 |
package com.iver.cit.gvsig.fmap.layers; |
4 |
|
5 |
import java.awt.Graphics2D; |
6 |
import java.awt.geom.Point2D; |
7 |
import java.awt.geom.Rectangle2D; |
8 |
import java.awt.image.BufferedImage; |
9 |
import java.util.ArrayList; |
10 |
import java.util.BitSet; |
11 |
import java.util.Iterator; |
12 |
|
13 |
import com.hardcode.driverManager.DriverLoadException; |
14 |
import com.hardcode.gdbms.engine.data.DataSource; |
15 |
import com.hardcode.gdbms.engine.data.DriverException; |
16 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
17 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
18 |
import com.iver.cit.gvsig.fmap.ViewPort; |
19 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
20 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
21 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
22 |
import com.iver.cit.gvsig.fmap.operations.QueriedPoint; |
23 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
24 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
25 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
26 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
27 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
28 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
29 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
30 |
import com.iver.utiles.XMLEntity; |
31 |
|
32 |
public class FLyrVect extends FLyrDefault implements LayerOperations, VectorialOperations, CommonOperations { |
33 |
/** Leyenda de la capa vectorial */
|
34 |
private VectorialLegend legend;
|
35 |
|
36 |
public void addSelectionListener(SelectionListener listener) { |
37 |
selectionSupport.addSelectionListener(listener); |
38 |
} |
39 |
|
40 |
public void removeSelectionListener(SelectionListener listener) { |
41 |
selectionSupport.removeSelectionListener(listener); |
42 |
} |
43 |
|
44 |
/**
|
45 |
* Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de una gran cantidad de eventos. Con el fin de no propagar todos estos eventos, se realiza la propagaci?n de manera manual al final de la "r?faga" de eventos
|
46 |
*/
|
47 |
public void fireSelectionEvents() { |
48 |
selectionSupport.fireSelectionEvents(); |
49 |
} |
50 |
|
51 |
public VectorialAdapter getSource() {
|
52 |
return source;
|
53 |
} |
54 |
|
55 |
public void setSource(VectorialAdapter va) { |
56 |
source = va; |
57 |
} |
58 |
|
59 |
private SelectionSupport selectionSupport = new SelectionSupport(); |
60 |
|
61 |
private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
62 |
|
63 |
/**
|
64 |
* @clientCardinality 0..*
|
65 |
*/
|
66 |
private VectorialAdapter source;
|
67 |
|
68 |
/**
|
69 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
70 |
*/
|
71 |
public Rectangle2D getFullExtent() throws DriverIOException { |
72 |
Rectangle2D rAux;
|
73 |
source.start(); |
74 |
rAux = source.getFullExtent(); |
75 |
source.stop(); |
76 |
return rAux;
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* @throws DriverLoadException
|
81 |
* @throws DriverLoadException
|
82 |
* @throws DriverException
|
83 |
* @throws DriverIOException
|
84 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
85 |
*/
|
86 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverIOException, DriverLoadException, DriverException { |
87 |
Strategy strategy = StrategyManager.getStrategy(this);
|
88 |
|
89 |
strategy.draw(image, g, viewPort, cancel); |
90 |
} |
91 |
|
92 |
/**
|
93 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
|
94 |
*/
|
95 |
public FLyrVect createLabelLayer(int fieldId) { |
96 |
return null; |
97 |
} |
98 |
|
99 |
/**
|
100 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
|
101 |
*/
|
102 |
public void removeLabels() { |
103 |
} |
104 |
|
105 |
/**
|
106 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createIndex()
|
107 |
*/
|
108 |
public void createIndex() { |
109 |
} |
110 |
|
111 |
/**
|
112 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor, com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
113 |
*/
|
114 |
public void process(FeatureVisitor visitor, BitSet subset) { |
115 |
} |
116 |
|
117 |
/**
|
118 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
119 |
*/
|
120 |
public void setSelection(BitSet selection) { |
121 |
selectionSupport.setSelection(selection); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
|
126 |
*/
|
127 |
public boolean isSelected(int index) { |
128 |
return selectionSupport.isSelected(index);
|
129 |
} |
130 |
|
131 |
/**
|
132 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
|
133 |
*/
|
134 |
public BitSet getSelection() { |
135 |
return selectionSupport.getSelection();
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
|
140 |
*/
|
141 |
public void clearSelection() { |
142 |
selectionSupport.clearSelection(); |
143 |
} |
144 |
|
145 |
/**
|
146 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint, double)
|
147 |
*/
|
148 |
public BitSet queryByPoint(Point2D p, double tolerance) { |
149 |
return null; |
150 |
} |
151 |
|
152 |
/**
|
153 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByRect(java.awt.geom.Rectangle2D)
|
154 |
*/
|
155 |
public BitSet queryByRect(Rectangle2D rect) { |
156 |
return null; |
157 |
} |
158 |
|
159 |
/**
|
160 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByShape(com.iver.cit.gvsig.fmap.core.IGeometry, int)
|
161 |
*/
|
162 |
public BitSet queryByShape(IGeometry g, int relationship) { |
163 |
return null; |
164 |
} |
165 |
|
166 |
/**
|
167 |
* @throws DriverIOException
|
168 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#selectByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint, double)
|
169 |
*/
|
170 |
public void selectByPoint(QueriedPoint p, double tolerance) throws DriverIOException { |
171 |
Strategy s = StrategyManager.getStrategy(this);
|
172 |
this.setSelection(s.queryByPoint(p, tolerance));
|
173 |
fireSelectionEvents(); |
174 |
} |
175 |
|
176 |
/**
|
177 |
* @throws DriverIOException
|
178 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#selectByRect(java.awt.geom.Rectangle2D)
|
179 |
*/
|
180 |
public void selectByRect(Rectangle2D rect) throws DriverIOException { |
181 |
Strategy s = StrategyManager.getStrategy(this);
|
182 |
this.setSelection(s.queryByRect(rect));
|
183 |
fireSelectionEvents(); |
184 |
} |
185 |
|
186 |
/**
|
187 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#selectByShape(com.iver.cit.gvsig.fmap.core.IGeometry, int)
|
188 |
*/
|
189 |
public void selectByShape(IGeometry g, int relationship) { |
190 |
fireSelectionEvents(); |
191 |
} |
192 |
|
193 |
/**
|
194 |
* @throws DriverLoadException
|
195 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
196 |
*/
|
197 |
public SelectableDataSource getRecordset() throws DriverLoadException { |
198 |
DataSource ds = source.getRecordset(getName());
|
199 |
SelectableDataSource sds = new SelectableDataSource(ds);
|
200 |
sds.setSelectionSupport(selectionSupport); |
201 |
return sds;
|
202 |
} |
203 |
|
204 |
/**
|
205 |
* @throws DriverLoadException
|
206 |
* @throws DriverException
|
207 |
* @throws DriverLoadException
|
208 |
* @throws FieldNotFoundException
|
209 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int, com.iver.cit.gvsig.fmap.rendering.Legend)
|
210 |
*/
|
211 |
public void setLegend(VectorialLegend r) throws FieldNotFoundException, DriverException, DriverLoadException { |
212 |
legend = r; |
213 |
legend.setDataSource(getRecordset()); |
214 |
|
215 |
} |
216 |
|
217 |
public VectorialLegend getLegend() {
|
218 |
|
219 |
return legend;
|
220 |
} |
221 |
|
222 |
/**
|
223 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getLegendInfo()
|
224 |
*/
|
225 |
public Legend getLegendInfo() {
|
226 |
return (Legend) legend;
|
227 |
} |
228 |
|
229 |
/**
|
230 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getShapeType()
|
231 |
*/
|
232 |
public int getShapeType() throws DriverIOException { |
233 |
return source.getShapeType();
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
238 |
*/
|
239 |
public XMLEntity getXMLEntity() {
|
240 |
BitSet selected = selectionSupport.getSelection();
|
241 |
XMLEntity xml=super.getXMLEntity();
|
242 |
xml.addChild(legend.getXMLEntity()); |
243 |
if (selected!=null){ |
244 |
xml.putProperty("numBitSet",selected.cardinality());
|
245 |
int n=0; |
246 |
for (int i=0;i<selected.length();i++){ |
247 |
if (selected.get(i)){
|
248 |
xml.putProperty(String.valueOf(n),selected.get(i));
|
249 |
n++; |
250 |
} |
251 |
} |
252 |
} |
253 |
if (source instanceof VectorialFileAdapter){ |
254 |
xml.putProperty("file",((VectorialFileAdapter)source).getFile());
|
255 |
}else if (source instanceof VectorialDBAdapter){ |
256 |
|
257 |
}else if (source instanceof WFSAdapter){ |
258 |
|
259 |
} |
260 |
|
261 |
xml.putProperty("driverName",getSource().getDriver().getName());
|
262 |
return xml;
|
263 |
} |
264 |
|
265 |
/**
|
266 |
* @throws ClassNotFoundException
|
267 |
* @throws InstantiationException
|
268 |
* @throws IllegalAccessException
|
269 |
* @throws DriverIOException
|
270 |
* @throws DriverLoadException
|
271 |
* @throws CancelationException
|
272 |
* @throws DifferentVersionException
|
273 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
274 |
*/
|
275 |
public void setXMLEntity(XMLEntity xml) throws ClassNotFoundException, InstantiationException, IllegalAccessException, DifferentVersionException, CancelationException, DriverLoadException, DriverIOException { |
276 |
super.setXMLEntity(xml);
|
277 |
legend=LegendFactory.createFromXML(xml.getChild(0));
|
278 |
int numBitSet=xml.getIntProperty("numBitSet"); |
279 |
if (numBitSet!=0){ |
280 |
BitSet selected = new BitSet(); |
281 |
selected=new BitSet(); |
282 |
for(int i=0;i<numBitSet;i++){ |
283 |
selected.set(xml.getIntProperty(String.valueOf(i)));
|
284 |
} |
285 |
selectionSupport.setSelection(selected); |
286 |
} |
287 |
//TODO source.setDriver(nameDriver);
|
288 |
|
289 |
} |
290 |
public void addLayerListener(LayerListener listener) { |
291 |
layerChangeSupport.addLayerListener(listener); |
292 |
} |
293 |
public void callLegendChanged(LegendChangedEvent e) { |
294 |
layerChangeSupport.callLegendChanged(e); |
295 |
} |
296 |
public void removeLayerListener(LayerListener listener) { |
297 |
layerChangeSupport.removeLayerListener(listener); |
298 |
} |
299 |
} |