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