svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 580
History | View | Annotate | Download (10.6 KB)
1 |
/* Generated by Together */
|
---|---|
2 |
package com.iver.cit.gvsig.fmap.layers; |
3 |
|
4 |
import java.awt.Graphics2D; |
5 |
import java.awt.geom.Rectangle2D; |
6 |
import java.awt.image.BufferedImage; |
7 |
import java.util.BitSet; |
8 |
|
9 |
import org.apache.log4j.Logger; |
10 |
|
11 |
import com.hardcode.driverManager.DriverLoadException; |
12 |
import com.hardcode.gdbms.engine.data.DataSource; |
13 |
import com.hardcode.gdbms.engine.data.DriverException; |
14 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
15 |
import com.iver.cit.gvsig.fmap.ViewPort; |
16 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
17 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
18 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
19 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable; |
20 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData; |
21 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
22 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
23 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
24 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
25 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
26 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
27 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
28 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
29 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
30 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
31 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
32 |
import com.iver.utiles.XMLEntity; |
33 |
|
34 |
|
35 |
/**
|
36 |
* DOCUMENT ME!
|
37 |
*
|
38 |
* @author Fernando Gonz?lez Cort?s
|
39 |
*/
|
40 |
class FLyrVect extends FLyrDefault implements Labelable, Selectable, |
41 |
AlphanumericData, ClassifiableVectorial, SingleLayer, VectorialData, RandomVectorialData { |
42 |
private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
43 |
|
44 |
/** Leyenda de la capa vectorial */
|
45 |
private VectorialLegend legend;
|
46 |
private int typeShape = -1; |
47 |
private SelectionSupport selectionSupport = new SelectionSupport(); |
48 |
private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
49 |
private VectorialAdapter source;
|
50 |
private SelectableDataSource sds;
|
51 |
|
52 |
/**
|
53 |
* DOCUMENT ME!
|
54 |
*
|
55 |
* @param listener DOCUMENT ME!
|
56 |
*/
|
57 |
public void addSelectionListener(SelectionListener listener) { |
58 |
selectionSupport.addSelectionListener(listener); |
59 |
} |
60 |
|
61 |
/**
|
62 |
* DOCUMENT ME!
|
63 |
*
|
64 |
* @param listener DOCUMENT ME!
|
65 |
*/
|
66 |
public void removeSelectionListener(SelectionListener listener) { |
67 |
selectionSupport.removeSelectionListener(listener); |
68 |
} |
69 |
|
70 |
/**
|
71 |
* Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
72 |
* una gran cantidad de eventos. Con el fin de no propagar todos estos
|
73 |
* eventos, se realiza la propagaci?n de manera manual al final de la
|
74 |
* "r?faga" de eventos
|
75 |
*/
|
76 |
public void fireSelectionEvents() { |
77 |
selectionSupport.fireSelectionEvents(); |
78 |
} |
79 |
|
80 |
/**
|
81 |
* DOCUMENT ME!
|
82 |
*
|
83 |
* @return DOCUMENT ME!
|
84 |
*/
|
85 |
public VectorialAdapter getSource() {
|
86 |
return source;
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* DOCUMENT ME!
|
91 |
*
|
92 |
* @param va DOCUMENT ME!
|
93 |
*/
|
94 |
public void setSource(VectorialAdapter va) { |
95 |
source = va; |
96 |
} |
97 |
|
98 |
/**
|
99 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
100 |
*/
|
101 |
public Rectangle2D getFullExtent() throws DriverIOException { |
102 |
Rectangle2D rAux;
|
103 |
logger.debug("source.start()");
|
104 |
source.start(); |
105 |
rAux = source.getFullExtent(); |
106 |
logger.debug("source.stop()");
|
107 |
source.stop(); |
108 |
|
109 |
return rAux;
|
110 |
} |
111 |
|
112 |
/**
|
113 |
* DOCUMENT ME!
|
114 |
*
|
115 |
* @param image DOCUMENT ME!
|
116 |
* @param g DOCUMENT ME!
|
117 |
* @param viewPort DOCUMENT ME!
|
118 |
* @param cancel DOCUMENT ME!
|
119 |
*
|
120 |
* @throws DriverIOException
|
121 |
* @throws DriverLoadException
|
122 |
* @throws DriverException
|
123 |
*
|
124 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
125 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
126 |
*/
|
127 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
128 |
Cancellable cancel) |
129 |
throws DriverIOException, DriverLoadException, DriverException {
|
130 |
Strategy strategy = StrategyManager.getStrategy(this);
|
131 |
|
132 |
strategy.draw(image, g, viewPort, cancel); |
133 |
} |
134 |
|
135 |
/**
|
136 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
137 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
138 |
* com.iver.cit.gvsig.fmap.operations.Cancellable)
|
139 |
*/
|
140 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) |
141 |
throws DriverIOException, DriverLoadException, DriverException {
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
|
146 |
*/
|
147 |
public FLayer createLabelLayer(int fieldId) { |
148 |
return null; |
149 |
} |
150 |
|
151 |
/**
|
152 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
|
153 |
*/
|
154 |
public void removeLabels() { |
155 |
} |
156 |
|
157 |
/**
|
158 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createIndex()
|
159 |
*/
|
160 |
public void createIndex() { |
161 |
} |
162 |
|
163 |
/**
|
164 |
* @throws DriverIOException
|
165 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
166 |
* com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
167 |
*/
|
168 |
public void process(FeatureVisitor visitor, BitSet subset) throws DriverIOException { |
169 |
Strategy s = StrategyManager.getStrategy(this);
|
170 |
s.process(visitor, subset); |
171 |
} |
172 |
|
173 |
/**
|
174 |
* @throws DriverIOException
|
175 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
176 |
*/
|
177 |
public void process(FeatureVisitor visitor) throws DriverIOException { |
178 |
Strategy s = StrategyManager.getStrategy(this);
|
179 |
s.process(visitor); |
180 |
} |
181 |
|
182 |
/**
|
183 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
184 |
*/
|
185 |
public void setSelection(BitSet selection) { |
186 |
selectionSupport.setSelection(selection); |
187 |
fireSelectionEvents(); |
188 |
} |
189 |
|
190 |
/**
|
191 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
|
192 |
*/
|
193 |
public boolean isSelected(int index) { |
194 |
return selectionSupport.isSelected(index);
|
195 |
} |
196 |
|
197 |
/**
|
198 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
|
199 |
*/
|
200 |
public BitSet getSelection() { |
201 |
return selectionSupport.getSelection();
|
202 |
} |
203 |
|
204 |
/**
|
205 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
|
206 |
*/
|
207 |
public void clearSelection() { |
208 |
selectionSupport.clearSelection(); |
209 |
} |
210 |
|
211 |
/**
|
212 |
* DOCUMENT ME!
|
213 |
*
|
214 |
* @param rect DOCUMENT ME!
|
215 |
*
|
216 |
* @return DOCUMENT ME!
|
217 |
*
|
218 |
* @throws DriverIOException
|
219 |
*
|
220 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByRect(java.awt.geom.Rectangle2D)
|
221 |
*/
|
222 |
public BitSet queryByRect(Rectangle2D rect) throws DriverIOException { |
223 |
Strategy s = StrategyManager.getStrategy(this);
|
224 |
|
225 |
return s.queryByRect(rect);
|
226 |
} |
227 |
|
228 |
/**
|
229 |
* DOCUMENT ME!
|
230 |
*
|
231 |
* @return DOCUMENT ME!
|
232 |
*
|
233 |
* @throws DriverLoadException
|
234 |
*
|
235 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
236 |
*/
|
237 |
public SelectableDataSource getRecordset() throws DriverLoadException { |
238 |
if (sds == null) { |
239 |
String name = getName();
|
240 |
|
241 |
if (name == null) { |
242 |
return null; |
243 |
} |
244 |
|
245 |
DataSource ds = source.getRecordset(name);
|
246 |
|
247 |
if (ds == null) { |
248 |
return null; |
249 |
} |
250 |
|
251 |
sds = new SelectableDataSource(getName(), ds);
|
252 |
sds.setSelectionSupport(selectionSupport); |
253 |
} |
254 |
|
255 |
return sds;
|
256 |
} |
257 |
|
258 |
/**
|
259 |
* DOCUMENT ME!
|
260 |
*
|
261 |
* @param r DOCUMENT ME!
|
262 |
*
|
263 |
* @throws FieldNotFoundException
|
264 |
* @throws DriverException
|
265 |
* @throws DriverLoadException
|
266 |
*
|
267 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
|
268 |
* com.iver.cit.gvsig.fmap.rendering.Legend)
|
269 |
*/
|
270 |
public void setLegend(VectorialLegend r) |
271 |
throws FieldNotFoundException, DriverException, DriverLoadException {
|
272 |
VectorialLegend oldLegend = legend; |
273 |
legend = r; |
274 |
legend.setDataSource(getRecordset()); |
275 |
|
276 |
LegendChangedEvent e = new LegendChangedEvent(oldLegend, legend);
|
277 |
callLegendChanged(e); |
278 |
} |
279 |
|
280 |
/**
|
281 |
* DOCUMENT ME!
|
282 |
*
|
283 |
* @return DOCUMENT ME!
|
284 |
*/
|
285 |
public Legend getLegend() {
|
286 |
return legend;
|
287 |
} |
288 |
|
289 |
/**
|
290 |
* DOCUMENT ME!
|
291 |
*
|
292 |
* @return DOCUMENT ME!
|
293 |
*
|
294 |
* @throws DriverIOException DOCUMENT ME!
|
295 |
*/
|
296 |
public int getShapeType() throws DriverIOException { |
297 |
if (typeShape == -1) { |
298 |
logger.debug("source.start()");
|
299 |
source.start(); |
300 |
typeShape = source.getShapeType(); |
301 |
logger.debug("source.stop()");
|
302 |
source.stop(); |
303 |
} |
304 |
|
305 |
return typeShape;
|
306 |
} |
307 |
|
308 |
/**
|
309 |
* DOCUMENT ME!
|
310 |
*
|
311 |
* @return DOCUMENT ME!
|
312 |
*
|
313 |
* @throws DriverException
|
314 |
*
|
315 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
316 |
*/
|
317 |
public XMLEntity getXMLEntity() throws DriverException { |
318 |
BitSet selected = selectionSupport.getSelection();
|
319 |
XMLEntity xml = super.getXMLEntity();
|
320 |
xml.addChild(legend.getXMLEntity()); |
321 |
if (selected!=null){ |
322 |
xml.putProperty("numBitSet",selected.cardinality());
|
323 |
int n=0; |
324 |
for (int i=0;i<selected.length();i++){ |
325 |
if (selected.get(i)){
|
326 |
xml.putProperty(String.valueOf(n),i);
|
327 |
n++; |
328 |
} |
329 |
} |
330 |
|
331 |
if (source instanceof VectorialFileAdapter) { |
332 |
xml.putProperty("file", ((VectorialFileAdapter) source).getFile());
|
333 |
} else if (source instanceof VectorialDBAdapter) { |
334 |
} else if (source instanceof WFSAdapter) { |
335 |
} |
336 |
|
337 |
xml.putProperty("driverName", getSource().getDriver().getName());
|
338 |
|
339 |
return xml;
|
340 |
} |
341 |
|
342 |
/**
|
343 |
* DOCUMENT ME!
|
344 |
*
|
345 |
* @param xml DOCUMENT ME!
|
346 |
*
|
347 |
* @throws XMLException
|
348 |
*
|
349 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
350 |
*/
|
351 |
public void setXMLEntity(XMLEntity xml) throws XMLException{ |
352 |
super.setXMLEntity(xml);
|
353 |
legend=LegendFactory.createFromXML(xml.getChild(0));
|
354 |
try{
|
355 |
legend.setDataSource(getRecordset()); |
356 |
}catch(DriverLoadException e){
|
357 |
throw new XMLException(e); |
358 |
} catch (FieldNotFoundException e) {
|
359 |
throw new XMLException(e); |
360 |
} catch (DriverException e) {
|
361 |
throw new XMLException(e); |
362 |
} |
363 |
int numBitSet=xml.getIntProperty("numBitSet"); |
364 |
if (numBitSet!=0){ |
365 |
BitSet selected = new BitSet(); |
366 |
selected=new BitSet(); |
367 |
for(int i=1;i<=numBitSet;i++){ |
368 |
selected.set(xml.getIntProperty(String.valueOf(i)));
|
369 |
} |
370 |
selectionSupport.setSelection(selected); |
371 |
//sds.setSelectionSupport(selectionSupport);
|
372 |
} |
373 |
//TODO source.setDriver(nameDriver);
|
374 |
|
375 |
} |
376 |
|
377 |
/**
|
378 |
* DOCUMENT ME!
|
379 |
*
|
380 |
* @param listener DOCUMENT ME!
|
381 |
*/
|
382 |
public void addLegendListener(LegendListener listener) { |
383 |
layerChangeSupport.addLayerListener(listener); |
384 |
} |
385 |
|
386 |
/**
|
387 |
* DOCUMENT ME!
|
388 |
*
|
389 |
* @param e DOCUMENT ME!
|
390 |
*/
|
391 |
private void callLegendChanged(LegendChangedEvent e) { |
392 |
layerChangeSupport.callLegendChanged(e); |
393 |
} |
394 |
|
395 |
/**
|
396 |
* DOCUMENT ME!
|
397 |
*
|
398 |
* @param listener DOCUMENT ME!
|
399 |
*/
|
400 |
public void removeLegendListener(LegendListener listener) { |
401 |
layerChangeSupport.removeLayerListener(listener); |
402 |
} |
403 |
|
404 |
/**
|
405 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#changeRecordsetName()
|
406 |
*/
|
407 |
public void changeRecordsetName(String newName) throws DriverLoadException { |
408 |
source.changeRecordsetName(newName); |
409 |
} |
410 |
} |