svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 3612
History | View | Annotate | Download (21.9 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.awt.Graphics2D; |
44 |
import java.awt.geom.Point2D; |
45 |
import java.awt.geom.Rectangle2D; |
46 |
import java.awt.image.BufferedImage; |
47 |
import java.io.IOException; |
48 |
import java.util.ArrayList; |
49 |
import java.util.BitSet; |
50 |
|
51 |
import org.apache.log4j.Logger; |
52 |
import org.cresques.cts.ICoordTrans; |
53 |
|
54 |
import com.hardcode.driverManager.Driver; |
55 |
import com.hardcode.driverManager.DriverLoadException; |
56 |
import com.hardcode.gdbms.engine.data.DataSource; |
57 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
58 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
59 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
60 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
61 |
import com.hardcode.gdbms.engine.values.FloatValue; |
62 |
import com.hardcode.gdbms.engine.values.NullValue; |
63 |
import com.hardcode.gdbms.engine.values.NumericValue; |
64 |
import com.hardcode.gdbms.engine.values.Value; |
65 |
import com.iver.cit.gvsig.fmap.DriverException; |
66 |
import com.iver.cit.gvsig.fmap.ViewPort; |
67 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
68 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
69 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
70 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
71 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
72 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
73 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
74 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
75 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
76 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
77 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable; |
78 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData; |
79 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
80 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
81 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
82 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
83 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
84 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
85 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
86 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
87 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
88 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
89 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
90 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
91 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
92 |
import com.iver.utiles.IPersistance; |
93 |
import com.iver.utiles.PostProcessSupport; |
94 |
import com.iver.utiles.XMLEntity; |
95 |
import com.vividsolutions.jts.geom.Coordinate; |
96 |
import com.vividsolutions.jts.geom.Envelope; |
97 |
import com.vividsolutions.jts.index.SpatialIndex; |
98 |
import com.vividsolutions.jts.index.quadtree.Quadtree; |
99 |
import com.vividsolutions.jts.index.strtree.STRtree; |
100 |
|
101 |
|
102 |
/**
|
103 |
* Capa b?sica Vectorial.
|
104 |
*
|
105 |
* @author Fernando Gonz?lez Cort?s
|
106 |
*/
|
107 |
|
108 |
//TODO Cuando no sea para pruebas debe no ser public
|
109 |
public class FLyrVect extends FLyrDefault implements Labelable, Selectable, |
110 |
AlphanumericData, ClassifiableVectorial, SingleLayer, VectorialData, |
111 |
RandomVectorialData { |
112 |
private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
113 |
|
114 |
/** Leyenda de la capa vectorial */
|
115 |
private VectorialLegend legend;
|
116 |
private int typeShape = -1; |
117 |
private SelectionSupport selectionSupport = new SelectionSupport(); |
118 |
private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
119 |
private VectorialAdapter source;
|
120 |
private SelectableDataSource sds;
|
121 |
|
122 |
private SpatialIndex spatialIndex = null; |
123 |
|
124 |
private boolean bHasJoin = false; |
125 |
|
126 |
/**
|
127 |
* A?ade un SelectionListener a la lista de listeners.
|
128 |
*
|
129 |
* @param listener SelectionListener.
|
130 |
*/
|
131 |
public void addSelectionListener(SelectionListener listener) { |
132 |
selectionSupport.addSelectionListener(listener); |
133 |
} |
134 |
|
135 |
/**
|
136 |
* Borra un selectionListener de la lista de listeners.
|
137 |
*
|
138 |
* @param listener SelectionListener
|
139 |
*/
|
140 |
public void removeSelectionListener(SelectionListener listener) { |
141 |
selectionSupport.removeSelectionListener(listener); |
142 |
} |
143 |
|
144 |
/**
|
145 |
* Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
146 |
* una gran cantidad de eventos. Con el fin de no propagar todos estos
|
147 |
* eventos, se realiza la propagaci?n de manera manual al final de la
|
148 |
* "r?faga" de eventos
|
149 |
*/
|
150 |
public void fireSelectionEvents() { |
151 |
selectionSupport.fireSelectionEvents(); |
152 |
} |
153 |
|
154 |
/**
|
155 |
* Devuelve el VectorialAdapater de la capa.
|
156 |
*
|
157 |
* @return VectorialAdapter.
|
158 |
*/
|
159 |
public VectorialAdapter getSource() {
|
160 |
return source;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* Inserta el VectorialAdapter a la capa.
|
165 |
*
|
166 |
* @param va VectorialAdapter.
|
167 |
*/
|
168 |
public void setSource(VectorialAdapter va) { |
169 |
source = va; |
170 |
} |
171 |
|
172 |
/**
|
173 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
174 |
*/
|
175 |
public Rectangle2D getFullExtent() throws DriverException { |
176 |
try {
|
177 |
Rectangle2D rAux;
|
178 |
logger.debug("source.start()");
|
179 |
source.start(); |
180 |
rAux = source.getFullExtent(); |
181 |
logger.debug("source.stop()");
|
182 |
source.stop(); |
183 |
|
184 |
// Si existe reproyecci?n, reproyectar el extent
|
185 |
ICoordTrans ct = getCoordTrans(); |
186 |
|
187 |
if (ct != null) { |
188 |
Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
189 |
Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
190 |
pt1 = ct.convert(pt1, null);
|
191 |
pt2 = ct.convert(pt2, null);
|
192 |
rAux = new Rectangle2D.Double(); |
193 |
rAux.setFrameFromDiagonal(pt1, pt2); |
194 |
} |
195 |
|
196 |
return rAux;
|
197 |
} catch (DriverIOException e) {
|
198 |
throw new DriverException(e); |
199 |
} |
200 |
} |
201 |
|
202 |
/**
|
203 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
204 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
205 |
*/
|
206 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
207 |
Cancellable cancel,double scale) throws DriverException { |
208 |
|
209 |
if (isWithinScale(scale)){
|
210 |
// Las que solo tienen etiquetado sin pintar el shape,
|
211 |
// no pasamos por ellas
|
212 |
boolean bDrawShapes = true; |
213 |
if (legend instanceof SingleSymbolLegend) |
214 |
{ |
215 |
if (legend.getDefaultSymbol().isShapeVisible() == false) |
216 |
bDrawShapes = false;
|
217 |
} |
218 |
if (bDrawShapes)
|
219 |
{ |
220 |
Strategy strategy = StrategyManager.getStrategy(this);
|
221 |
try{
|
222 |
strategy.draw(image, g, viewPort, cancel); |
223 |
}catch (DriverException e) {
|
224 |
this.setVisible(false); |
225 |
this.setActive(false); |
226 |
throw e;
|
227 |
} |
228 |
} |
229 |
|
230 |
if (getVirtualLayers() != null) { |
231 |
getVirtualLayers().draw(image, g, viewPort, cancel,scale); |
232 |
} |
233 |
|
234 |
if (getLayerText() != null) { |
235 |
getLayerText().draw(image, g, viewPort, cancel,scale); |
236 |
} |
237 |
} |
238 |
} |
239 |
|
240 |
/**
|
241 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
242 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
243 |
* com.iver.cit.gvsig.fmap.operations.Cancellable)
|
244 |
*/
|
245 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) |
246 |
throws DriverException {
|
247 |
if (isVisible() && isWithinScale(scale)){
|
248 |
Strategy strategy = StrategyManager.getStrategy(this);
|
249 |
|
250 |
strategy.print(g, viewPort, cancel); |
251 |
|
252 |
if (getLayerText() != null) { |
253 |
getLayerText().draw(null, g, viewPort, cancel,scale);
|
254 |
} |
255 |
} |
256 |
} |
257 |
|
258 |
/**
|
259 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
|
260 |
*/
|
261 |
// public FLayer createLabelLayer(int fieldId) {
|
262 |
public FLayer createLabelLayer(SelectableDataSource ds) {
|
263 |
FLyrText layerText = null;
|
264 |
try {
|
265 |
layerText = new FLyrText();
|
266 |
layerText.setLegend((VectorialLegend) getLegend()); |
267 |
layerText.createLabels(this);
|
268 |
} catch (FieldNotFoundException e1) {
|
269 |
// TODO Auto-generated catch block
|
270 |
e1.printStackTrace(); |
271 |
} catch (DriverException e1) {
|
272 |
// TODO Auto-generated catch block
|
273 |
e1.printStackTrace(); |
274 |
} |
275 |
|
276 |
|
277 |
setLayerText(layerText); |
278 |
layerText.setCoordTrans(getCoordTrans()); |
279 |
return layerText;
|
280 |
} |
281 |
|
282 |
/**
|
283 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
|
284 |
*/
|
285 |
public void removeLabels() { |
286 |
setLayerText(null);
|
287 |
} |
288 |
|
289 |
/* (non-Javadoc)
|
290 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#deleteSpatialIndex()
|
291 |
*/
|
292 |
public void deleteSpatialIndex() |
293 |
{ |
294 |
spatialIndex = null;
|
295 |
} |
296 |
/* (non-Javadoc)
|
297 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
|
298 |
*/
|
299 |
public void createSpatialIndex() { |
300 |
// FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
301 |
// QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
302 |
// para que acepten recorrer sin geometria, solo con rectangulos.
|
303 |
spatialIndex = new Quadtree();
|
304 |
VectorialAdapter va = getSource(); |
305 |
ICoordTrans ct = getCoordTrans(); |
306 |
BoundedShapes shapeBounds = (BoundedShapes) va.getDriver(); |
307 |
try {
|
308 |
va.start(); |
309 |
|
310 |
for (int i=0; i < va.getShapeCount(); i++) |
311 |
{ |
312 |
Rectangle2D r = shapeBounds.getShapeBounds(i);
|
313 |
// TODO: MIRAR COMO SE TRAGAR?A ESTO LO DE LAS REPROYECCIONES
|
314 |
if (ct != null) { |
315 |
r = ct.convert(r); |
316 |
} |
317 |
Coordinate c1 = new Coordinate(r.getMinX(), r.getMinY());
|
318 |
Coordinate c2 = new Coordinate(r.getMaxX(), r.getMaxY());
|
319 |
Envelope env = new Envelope(c1, c2);
|
320 |
spatialIndex.insert(env, new Integer(i)); |
321 |
} // for
|
322 |
va.stop(); |
323 |
} catch (DriverIOException e) {
|
324 |
// TODO Auto-generated catch block
|
325 |
e.printStackTrace(); |
326 |
} catch (IOException e) { |
327 |
// TODO Auto-generated catch block
|
328 |
e.printStackTrace(); |
329 |
} |
330 |
|
331 |
} |
332 |
|
333 |
/**
|
334 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
335 |
* FBitSet)
|
336 |
*/
|
337 |
public void process(FeatureVisitor visitor, FBitSet subset) |
338 |
throws DriverException, VisitException {
|
339 |
Strategy s = StrategyManager.getStrategy(this);
|
340 |
s.process(visitor, subset); |
341 |
} |
342 |
|
343 |
/**
|
344 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
345 |
*/
|
346 |
public void process(FeatureVisitor visitor) |
347 |
throws DriverException, VisitException {
|
348 |
Strategy s = StrategyManager.getStrategy(this);
|
349 |
s.process(visitor); |
350 |
} |
351 |
|
352 |
/**
|
353 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
354 |
*/
|
355 |
public void setSelection(FBitSet selection) { |
356 |
selectionSupport.setSelection(selection); |
357 |
fireSelectionEvents(); |
358 |
} |
359 |
|
360 |
/**
|
361 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
|
362 |
*/
|
363 |
public boolean isSelected(int index) { |
364 |
return selectionSupport.isSelected(index);
|
365 |
} |
366 |
|
367 |
/**
|
368 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
|
369 |
*/
|
370 |
public FBitSet getSelection() {
|
371 |
return selectionSupport.getSelection();
|
372 |
} |
373 |
|
374 |
/**
|
375 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
|
376 |
*/
|
377 |
public void clearSelection() { |
378 |
selectionSupport.clearSelection(); |
379 |
} |
380 |
|
381 |
/* (non-Javadoc)
|
382 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
|
383 |
*/
|
384 |
public FBitSet queryByRect(Rectangle2D rect) throws DriverException { |
385 |
Strategy s = StrategyManager.getStrategy(this);
|
386 |
|
387 |
return s.queryByRect(rect);
|
388 |
} |
389 |
|
390 |
public FBitSet queryByPoint(Point2D p, double tolerance) throws DriverException |
391 |
{ |
392 |
Strategy s = StrategyManager.getStrategy(this);
|
393 |
return s.queryByPoint(p, tolerance);
|
394 |
} |
395 |
|
396 |
public FBitSet queryByShape(IGeometry g, int relationship) throws DriverException, VisitException |
397 |
{ |
398 |
Strategy s = StrategyManager.getStrategy(this);
|
399 |
return s.queryByShape(g, relationship);
|
400 |
} |
401 |
/**
|
402 |
* @throws DriverException
|
403 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
404 |
*/
|
405 |
public SelectableDataSource getRecordset() throws DriverException { |
406 |
if (sds == null){ |
407 |
try {
|
408 |
DataSource ds = getSource().getRecordset();
|
409 |
|
410 |
if (ds == null) { |
411 |
return null; |
412 |
} |
413 |
|
414 |
sds = new SelectableDataSource(ds);
|
415 |
sds.setSelectionSupport(selectionSupport); |
416 |
|
417 |
return sds;
|
418 |
} catch (DriverLoadException e) {
|
419 |
throw new DriverException(e); |
420 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
421 |
throw new DriverException(e); |
422 |
} |
423 |
} |
424 |
return sds;
|
425 |
} |
426 |
|
427 |
/**
|
428 |
* Para cuando haces una uni?n, sustituyes el recorset por el nuevo.
|
429 |
* De esta forma, podr?s poner leyendas basadas en el nuevo
|
430 |
* recordset
|
431 |
* @param newSds
|
432 |
* @throws DriverException
|
433 |
* @throws FieldNotFoundException
|
434 |
* @throws FieldNotFoundException
|
435 |
*/
|
436 |
public void setRecordset(SelectableDataSource newSds) throws DriverException, FieldNotFoundException |
437 |
{ |
438 |
sds = newSds; |
439 |
sds.setSelectionSupport(selectionSupport); |
440 |
legend.setDataSource(sds); |
441 |
logger.debug("Recordset cambiado a " + sds.getName());
|
442 |
} |
443 |
|
444 |
/**
|
445 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
|
446 |
* com.iver.cit.gvsig.fmap.rendering.Legend)
|
447 |
*/
|
448 |
public void setLegend(VectorialLegend r) |
449 |
throws DriverException, FieldNotFoundException {
|
450 |
VectorialLegend oldLegend = legend; |
451 |
legend = r; |
452 |
|
453 |
try {
|
454 |
legend.setDataSource(getRecordset()); |
455 |
|
456 |
if (legend.getLabelField() != null) { |
457 |
// sds.start();
|
458 |
// int idLabelField = getRecordset().getFieldIndexByName(legend.getLabelField());
|
459 |
createLabelLayer(sds); |
460 |
// sds.stop();
|
461 |
} |
462 |
else
|
463 |
removeLabels(); |
464 |
} catch (DriverException e) {
|
465 |
throw new DriverException(e); |
466 |
} catch (FieldNotFoundException e) {
|
467 |
// TODO Auto-generated catch block
|
468 |
e.printStackTrace(); |
469 |
} |
470 |
|
471 |
LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(oldLegend, legend); |
472 |
callLegendChanged(e); |
473 |
} |
474 |
|
475 |
/**
|
476 |
* Devuelve la Leyenda de la capa.
|
477 |
*
|
478 |
* @return Leyenda.
|
479 |
*/
|
480 |
public Legend getLegend() {
|
481 |
return legend;
|
482 |
} |
483 |
|
484 |
/**
|
485 |
* Devuelve el tipo de shape que contiene la capa.
|
486 |
*
|
487 |
* @return tipo de shape.
|
488 |
*
|
489 |
* @throws DriverException
|
490 |
*/
|
491 |
public int getShapeType() throws DriverException { |
492 |
if (typeShape == -1) { |
493 |
try {
|
494 |
logger.debug("source.start()");
|
495 |
source.start(); |
496 |
typeShape = source.getShapeType(); |
497 |
logger.debug("source.stop()");
|
498 |
source.stop(); |
499 |
} catch (DriverIOException e) {
|
500 |
throw new DriverException(e); |
501 |
} |
502 |
} |
503 |
|
504 |
return typeShape;
|
505 |
} |
506 |
|
507 |
/**
|
508 |
* @throws XMLException
|
509 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
510 |
*/
|
511 |
public XMLEntity getXMLEntity() throws XMLException { |
512 |
XMLEntity xml = super.getXMLEntity();
|
513 |
xml.addChild(legend.getXMLEntity()); |
514 |
xml.addChild(selectionSupport.getXMLEntity()); |
515 |
|
516 |
if (source instanceof VectorialFileAdapter) { |
517 |
xml.putProperty("type", "vectorial"); |
518 |
xml.putProperty("file", ((VectorialFileAdapter) source).getFile());
|
519 |
try {
|
520 |
xml.putProperty("recordset-name", getRecordset().getName());
|
521 |
} catch (DriverException e) {
|
522 |
throw new XMLException(e); |
523 |
} |
524 |
} else if (source instanceof VectorialDBAdapter) { |
525 |
xml.putProperty("type", "vectorial"); |
526 |
|
527 |
VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) source.getDriver(); |
528 |
|
529 |
// Guardamos el nombre del driver para poder recuperarlo
|
530 |
// con el DriverManager de Fernando.
|
531 |
xml.putProperty("db", dbDriver.getName());
|
532 |
try {
|
533 |
xml.putProperty("recordset-name", getRecordset().getName());
|
534 |
} catch (DriverException e) {
|
535 |
throw new XMLException(e); |
536 |
} |
537 |
xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos metido la leyenda y el selection support
|
538 |
} else if (source instanceof VectorialAdapter) { |
539 |
// Se supone que hemos hecho algo gen?rico.
|
540 |
xml.putProperty("type", "vectorial"); |
541 |
|
542 |
VectorialDriver driver = (VectorialDriver) source.getDriver(); |
543 |
|
544 |
// Guardamos el nombre del driver para poder recuperarlo
|
545 |
// con el DriverManager de Fernando.
|
546 |
xml.putProperty("other", driver.getName());
|
547 |
try {
|
548 |
xml.putProperty("recordset-name", getRecordset().getName());
|
549 |
} catch (DriverException e) {
|
550 |
throw new XMLException(e); |
551 |
} |
552 |
if (driver instanceof IPersistance) |
553 |
{ |
554 |
// xml.putProperty("className", driver.getClass().getName());
|
555 |
IPersistance persist = (IPersistance) driver; |
556 |
xml.addChild(persist.getXMLEntity()); // Tercer child. Antes hemos metido la leyenda y el selection support
|
557 |
} |
558 |
} |
559 |
xml.putProperty("driverName", getSource().getDriver().getName());
|
560 |
if (bHasJoin)
|
561 |
xml.putProperty("hasJoin", "true"); |
562 |
|
563 |
|
564 |
return xml;
|
565 |
} |
566 |
|
567 |
/**
|
568 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
569 |
*/
|
570 |
public void setXMLEntity03(XMLEntity xml) |
571 |
throws XMLException {
|
572 |
|
573 |
super.setXMLEntity(xml);
|
574 |
legend = LegendFactory.createFromXML03(xml.getChild(0));
|
575 |
|
576 |
try {
|
577 |
// legend.setDataSource(getRecordset());
|
578 |
setLegend(legend); |
579 |
} catch (FieldNotFoundException e) {
|
580 |
throw new XMLException(e); |
581 |
} catch (DriverException e) {
|
582 |
throw new XMLException(e); |
583 |
} |
584 |
|
585 |
selectionSupport.setXMLEntity03(xml.getChild(1));
|
586 |
} |
587 |
|
588 |
/**
|
589 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
590 |
*/
|
591 |
public void setXMLEntity(XMLEntity xml) |
592 |
throws XMLException {
|
593 |
super.setXMLEntity(xml);
|
594 |
|
595 |
legend = LegendFactory.createFromXML(xml.getChild(0));
|
596 |
selectionSupport.setXMLEntity(xml.getChild(1));
|
597 |
|
598 |
String recordsetName = xml.getStringProperty("recordset-name"); |
599 |
try {
|
600 |
LayerFactory.getDataSourceFactory().changeDataSourceName( |
601 |
getRecordset().getName(), recordsetName |
602 |
); |
603 |
// Hacemos que el recordset que hemos creado antes (los
|
604 |
// recordset se crean antes que todo) sea el recordset
|
605 |
// de esta capa. Y del que se crea automaticamente
|
606 |
// en el setLegend del createLayer, nos olvidamos
|
607 |
setRecordset(new SelectableDataSource(LayerFactory.getDataSourceFactory()
|
608 |
.createRandomDataSource(recordsetName, DataSourceFactory.AUTOMATIC_OPENING))); |
609 |
} catch (NoSuchTableException e1) {
|
610 |
throw new XMLException(e1); |
611 |
} catch (DriverException e1) {
|
612 |
throw new XMLException(e1); |
613 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
|
614 |
throw new XMLException(e1); |
615 |
} catch (DriverLoadException e1) {
|
616 |
throw new XMLException(e1); |
617 |
} catch (FieldNotFoundException e) {
|
618 |
e.printStackTrace(); |
619 |
throw new XMLException(e); |
620 |
} |
621 |
// Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta el final
|
622 |
// de la lectura del proyecto
|
623 |
if (xml.contains("hasJoin")) |
624 |
{ |
625 |
setIsJoined(true);
|
626 |
PostProcessSupport.addToPostProcess(this,"setLegend", legend, 1); |
627 |
} |
628 |
else
|
629 |
{ |
630 |
try {
|
631 |
// legend.setDataSource(getRecordset());
|
632 |
setLegend(legend); |
633 |
} catch (FieldNotFoundException e) {
|
634 |
throw new XMLException(e); |
635 |
} catch (DriverException e) {
|
636 |
throw new XMLException(e); |
637 |
} |
638 |
} |
639 |
|
640 |
} |
641 |
|
642 |
/**
|
643 |
* A?ade un LegendListener a la lista de Listeners.
|
644 |
*
|
645 |
* @param listener LegendListener.
|
646 |
*/
|
647 |
public void addLegendListener(LegendListener listener) { |
648 |
layerChangeSupport.addLayerListener(listener); |
649 |
} |
650 |
|
651 |
/**
|
652 |
* Llamada al m?todo callLegendChanged de los listener.
|
653 |
*
|
654 |
* @param e Evento.
|
655 |
*/
|
656 |
private void callLegendChanged(LegendChangedEvent e) { |
657 |
layerChangeSupport.callLegendChanged(e); |
658 |
} |
659 |
|
660 |
/**
|
661 |
* Borra un LegendListener de la lista de Listeners
|
662 |
*
|
663 |
* @param listener LegendListener.
|
664 |
*/
|
665 |
public void removeLegendListener(LegendListener listener) { |
666 |
layerChangeSupport.removeLayerListener(listener); |
667 |
} |
668 |
|
669 |
/**
|
670 |
* Sobreimplementaci?n del m?todo toString para que las bases de datos
|
671 |
* identifiquen la capa.
|
672 |
*
|
673 |
* @return DOCUMENT ME!
|
674 |
*/
|
675 |
public String toString() { |
676 |
/*
|
677 |
* Se usa internamente para que la parte de datos
|
678 |
* identifique de forma un?voca las tablas
|
679 |
*/
|
680 |
String ret = super.toString(); |
681 |
|
682 |
return "layer" + ret.substring(ret.indexOf('@') + 1); |
683 |
} |
684 |
|
685 |
public boolean isJoined() { |
686 |
return bHasJoin;
|
687 |
} |
688 |
|
689 |
public void setIsJoined(boolean hasJoin) { |
690 |
bHasJoin = hasJoin; |
691 |
} |
692 |
|
693 |
/**
|
694 |
* @return Returns the spatialIndex.
|
695 |
*/
|
696 |
public SpatialIndex getSpatialIndex() {
|
697 |
return spatialIndex;
|
698 |
} |
699 |
|
700 |
public SelectionSupport getSelectionSupport() {
|
701 |
return selectionSupport;
|
702 |
} |
703 |
|
704 |
public void setSelectionSupport(SelectionSupport selectionSupport) { |
705 |
this.selectionSupport = selectionSupport;
|
706 |
} |
707 |
} |