svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 4256
History | View | Annotate | Download (24.7 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 |
|
49 |
import org.apache.log4j.Logger; |
50 |
import org.cresques.cts.ICoordTrans; |
51 |
|
52 |
import com.hardcode.driverManager.DriverLoadException; |
53 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
54 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
55 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
56 |
import com.iver.cit.gvsig.fmap.DriverException; |
57 |
import com.iver.cit.gvsig.fmap.ViewPort; |
58 |
import com.iver.cit.gvsig.fmap.MapControl.CancelDraw; |
59 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
60 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
61 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
62 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
63 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
64 |
import com.iver.cit.gvsig.fmap.edition.AnnotationEditableAdapter; |
65 |
import com.iver.cit.gvsig.fmap.edition.EditableAdapter; |
66 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
67 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
68 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableDBAdapter; |
69 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
70 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
71 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable; |
72 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData; |
73 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
74 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
75 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
76 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
77 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
78 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
79 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
80 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
81 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
82 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
83 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
84 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
85 |
import com.iver.utiles.IPersistance; |
86 |
import com.iver.utiles.PostProcessSupport; |
87 |
import com.iver.utiles.XMLEntity; |
88 |
import com.vividsolutions.jts.geom.Coordinate; |
89 |
import com.vividsolutions.jts.geom.Envelope; |
90 |
import com.vividsolutions.jts.index.SpatialIndex; |
91 |
import com.vividsolutions.jts.index.quadtree.Quadtree; |
92 |
|
93 |
|
94 |
/**
|
95 |
* Capa b?sica Vectorial.
|
96 |
*
|
97 |
* @author Fernando Gonz?lez Cort?s
|
98 |
*/
|
99 |
|
100 |
//TODO Cuando no sea para pruebas debe no ser public
|
101 |
public class FLyrVect extends FLyrDefault implements Labelable, ClassifiableVectorial, SingleLayer, VectorialData, |
102 |
RandomVectorialData,AlphanumericData { |
103 |
private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
104 |
|
105 |
/** Leyenda de la capa vectorial */
|
106 |
private VectorialLegend legend;
|
107 |
private int typeShape = -1; |
108 |
|
109 |
private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
110 |
private ReadableVectorial source;
|
111 |
//private SelectableDataSource sds;
|
112 |
|
113 |
protected SpatialIndex spatialIndex = null; |
114 |
|
115 |
private boolean bHasJoin = false; |
116 |
|
117 |
/**
|
118 |
* A?ade un SelectionListener a la lista de listeners.
|
119 |
*
|
120 |
* @param listener SelectionListener.
|
121 |
*/
|
122 |
/*public void addSelectionListener(SelectionListener listener) {
|
123 |
try {
|
124 |
getRecordset().addSelectionListener(listener);
|
125 |
} catch (DriverException e) {
|
126 |
// TODO Auto-generated catch block
|
127 |
e.printStackTrace();
|
128 |
}
|
129 |
}
|
130 |
*/
|
131 |
/**
|
132 |
* Borra un selectionListener de la lista de listeners.
|
133 |
*
|
134 |
* @param listener SelectionListener
|
135 |
*/
|
136 |
/*public void removeSelectionListener(SelectionListener listener) {
|
137 |
try {
|
138 |
getRecordset().removeSelectionListener(listener);
|
139 |
} catch (DriverException e) {
|
140 |
// TODO Auto-generated catch block
|
141 |
e.printStackTrace();
|
142 |
}
|
143 |
}
|
144 |
*/
|
145 |
/**
|
146 |
* Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
147 |
* una gran cantidad de eventos. Con el fin de no propagar todos estos
|
148 |
* eventos, se realiza la propagaci?n de manera manual al final de la
|
149 |
* "r?faga" de eventos
|
150 |
*/
|
151 |
/*public void fireSelectionEvents() {
|
152 |
try {
|
153 |
getRecordset().fireSelectionEvents();
|
154 |
} catch (DriverException e) {
|
155 |
// TODO Auto-generated catch block
|
156 |
e.printStackTrace();
|
157 |
}
|
158 |
}
|
159 |
*/
|
160 |
/**
|
161 |
* Devuelve el VectorialAdapater de la capa.
|
162 |
*
|
163 |
* @return VectorialAdapter.
|
164 |
*/
|
165 |
public ReadableVectorial getSource() {
|
166 |
return source;
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* Inserta el VectorialAdapter a la capa.
|
171 |
*
|
172 |
* @param va VectorialAdapter.
|
173 |
*/
|
174 |
public void setSource(ReadableVectorial rv) { |
175 |
source = rv; |
176 |
} |
177 |
|
178 |
/**
|
179 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
180 |
*/
|
181 |
public Rectangle2D getFullExtent() throws DriverException { |
182 |
try {
|
183 |
Rectangle2D rAux;
|
184 |
logger.debug("source.start()");
|
185 |
source.start(); |
186 |
rAux = source.getFullExtent(); |
187 |
logger.debug("source.stop()");
|
188 |
source.stop(); |
189 |
|
190 |
// Si existe reproyecci?n, reproyectar el extent
|
191 |
ICoordTrans ct = getCoordTrans(); |
192 |
|
193 |
if (ct != null) { |
194 |
Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
195 |
Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
196 |
pt1 = ct.convert(pt1, null);
|
197 |
pt2 = ct.convert(pt2, null);
|
198 |
rAux = new Rectangle2D.Double(); |
199 |
rAux.setFrameFromDiagonal(pt1, pt2); |
200 |
} |
201 |
|
202 |
return rAux;
|
203 |
} catch (DriverIOException e) {
|
204 |
throw new DriverException(e); |
205 |
} |
206 |
} |
207 |
|
208 |
/**
|
209 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
210 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
211 |
*/
|
212 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
213 |
Cancellable cancel,double scale) throws DriverException { |
214 |
|
215 |
if (isWithinScale(scale)){
|
216 |
// Las que solo tienen etiquetado sin pintar el shape,
|
217 |
// no pasamos por ellas
|
218 |
boolean bDrawShapes = true; |
219 |
if (legend instanceof SingleSymbolLegend) |
220 |
{ |
221 |
if (legend.getDefaultSymbol().isShapeVisible() == false) |
222 |
bDrawShapes = false;
|
223 |
} |
224 |
if (bDrawShapes)
|
225 |
{ |
226 |
Strategy strategy = StrategyManager.getStrategy(this);
|
227 |
try{
|
228 |
strategy.draw(image, g, viewPort, cancel); |
229 |
}catch (DriverException e) {
|
230 |
this.setVisible(false); |
231 |
this.setActive(false); |
232 |
throw e;
|
233 |
} |
234 |
} |
235 |
|
236 |
if (getVirtualLayers() != null) { |
237 |
getVirtualLayers().draw(image, g, viewPort, cancel,scale); |
238 |
} |
239 |
|
240 |
if (getLayerText() != null) { |
241 |
getLayerText().draw(image, g, viewPort, cancel,scale); |
242 |
} |
243 |
} |
244 |
} |
245 |
|
246 |
/**
|
247 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
248 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
249 |
* com.iver.cit.gvsig.fmap.operations.Cancellable)
|
250 |
*/
|
251 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) |
252 |
throws DriverException {
|
253 |
if (isVisible() && isWithinScale(scale)){
|
254 |
Strategy strategy = StrategyManager.getStrategy(this);
|
255 |
|
256 |
strategy.print(g, viewPort, cancel); |
257 |
|
258 |
if (getLayerText() != null) { |
259 |
getLayerText().draw(null, g, viewPort, cancel,scale);
|
260 |
} |
261 |
} |
262 |
} |
263 |
|
264 |
/**
|
265 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
|
266 |
*/
|
267 |
// public FLayer createLabelLayer(int fieldId) {
|
268 |
public FLayer createLabelLayer(SelectableDataSource ds) {
|
269 |
FLyrText layerText = null;
|
270 |
try {
|
271 |
layerText = new FLyrText();
|
272 |
layerText.setLegend((VectorialLegend) getLegend()); |
273 |
layerText.createLabels(this);
|
274 |
} catch (FieldNotFoundException e1) {
|
275 |
// TODO Auto-generated catch block
|
276 |
e1.printStackTrace(); |
277 |
} catch (DriverException e1) {
|
278 |
// TODO Auto-generated catch block
|
279 |
e1.printStackTrace(); |
280 |
} |
281 |
|
282 |
|
283 |
setLayerText(layerText); |
284 |
layerText.setCoordTrans(getCoordTrans()); |
285 |
return layerText;
|
286 |
} |
287 |
|
288 |
/**
|
289 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
|
290 |
*/
|
291 |
public void removeLabels() { |
292 |
setLayerText(null);
|
293 |
} |
294 |
|
295 |
/* (non-Javadoc)
|
296 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#deleteSpatialIndex()
|
297 |
*/
|
298 |
public void deleteSpatialIndex() |
299 |
{ |
300 |
spatialIndex = null;
|
301 |
} |
302 |
/* (non-Javadoc)
|
303 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
|
304 |
*/
|
305 |
public void createSpatialIndex() { |
306 |
// FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
307 |
// QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
308 |
// para que acepten recorrer sin geometria, solo con rectangulos.
|
309 |
spatialIndex = new Quadtree();
|
310 |
ReadableVectorial va = getSource(); |
311 |
ICoordTrans ct = getCoordTrans(); |
312 |
BoundedShapes shapeBounds = (BoundedShapes) va.getDriver(); |
313 |
try {
|
314 |
va.start(); |
315 |
|
316 |
for (int i=0; i < va.getShapeCount(); i++) |
317 |
{ |
318 |
Rectangle2D r = shapeBounds.getShapeBounds(i);
|
319 |
// TODO: MIRAR COMO SE TRAGAR?A ESTO LO DE LAS REPROYECCIONES
|
320 |
if (ct != null) { |
321 |
r = ct.convert(r); |
322 |
} |
323 |
Coordinate c1 = new Coordinate(r.getMinX(), r.getMinY());
|
324 |
Coordinate c2 = new Coordinate(r.getMaxX(), r.getMaxY());
|
325 |
Envelope env = new Envelope(c1, c2);
|
326 |
spatialIndex.insert(env, new Integer(i)); |
327 |
} // for
|
328 |
va.stop(); |
329 |
} catch (DriverIOException e) {
|
330 |
// TODO Auto-generated catch block
|
331 |
e.printStackTrace(); |
332 |
} catch (IOException e) { |
333 |
// TODO Auto-generated catch block
|
334 |
e.printStackTrace(); |
335 |
} |
336 |
|
337 |
} |
338 |
|
339 |
/**
|
340 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
341 |
* FBitSet)
|
342 |
*/
|
343 |
public void process(FeatureVisitor visitor, FBitSet subset) |
344 |
throws DriverException, VisitException {
|
345 |
Strategy s = StrategyManager.getStrategy(this);
|
346 |
s.process(visitor, subset); |
347 |
} |
348 |
|
349 |
/**
|
350 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
351 |
*/
|
352 |
public void process(FeatureVisitor visitor) |
353 |
throws DriverException, VisitException {
|
354 |
Strategy s = StrategyManager.getStrategy(this);
|
355 |
s.process(visitor); |
356 |
} |
357 |
|
358 |
/**
|
359 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor, Rectangle2D)
|
360 |
*/
|
361 |
public void process(FeatureVisitor visitor, Rectangle2D rect) |
362 |
throws DriverException, VisitException {
|
363 |
Strategy s = StrategyManager.getStrategy(this);
|
364 |
s.process(visitor, rect); |
365 |
} |
366 |
|
367 |
|
368 |
|
369 |
/**
|
370 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
371 |
*/
|
372 |
/*public void setSelection(FBitSet selection) {
|
373 |
try {
|
374 |
getRecordset().setSelection(selection);
|
375 |
} catch (DriverException e) {
|
376 |
// TODO Auto-generated catch block
|
377 |
e.printStackTrace();
|
378 |
}
|
379 |
fireSelectionEvents();
|
380 |
}
|
381 |
*/
|
382 |
/**
|
383 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
|
384 |
*/
|
385 |
/*public boolean isSelected(int index) {
|
386 |
try {
|
387 |
return getRecordset().isSelected(index);
|
388 |
} catch (DriverException e) {
|
389 |
// TODO Auto-generated catch block
|
390 |
e.printStackTrace();
|
391 |
}
|
392 |
return false;
|
393 |
}
|
394 |
*/
|
395 |
/**
|
396 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
|
397 |
*/
|
398 |
/*public FBitSet getSelection() {
|
399 |
try {
|
400 |
return getRecordset().getSelection();
|
401 |
} catch (DriverException e) {
|
402 |
// TODO Auto-generated catch block
|
403 |
e.printStackTrace();
|
404 |
}
|
405 |
return new FBitSet();
|
406 |
}
|
407 |
*/
|
408 |
/**
|
409 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
|
410 |
*/
|
411 |
/*public void clearSelection() {
|
412 |
try {
|
413 |
getRecordset().clearSelection();
|
414 |
} catch (DriverException e) {
|
415 |
// TODO Auto-generated catch block
|
416 |
e.printStackTrace();
|
417 |
}
|
418 |
}*/
|
419 |
|
420 |
/* (non-Javadoc)
|
421 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
|
422 |
*/
|
423 |
public FBitSet queryByRect(Rectangle2D rect) throws DriverException { |
424 |
Strategy s = StrategyManager.getStrategy(this);
|
425 |
|
426 |
return s.queryByRect(rect);
|
427 |
} |
428 |
|
429 |
public FBitSet queryByPoint(Point2D p, double tolerance) throws DriverException |
430 |
{ |
431 |
Strategy s = StrategyManager.getStrategy(this);
|
432 |
return s.queryByPoint(p, tolerance);
|
433 |
} |
434 |
|
435 |
public FBitSet queryByShape(IGeometry g, int relationship) throws DriverException, VisitException |
436 |
{ |
437 |
Strategy s = StrategyManager.getStrategy(this);
|
438 |
return s.queryByShape(g, relationship);
|
439 |
} |
440 |
/**
|
441 |
* @throws DriverException
|
442 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
443 |
*/
|
444 |
/*public SelectableDataSource getRecordset() throws DriverException {
|
445 |
if (sds == null){
|
446 |
try {
|
447 |
DataSource ds = getSource().getRecordset();
|
448 |
|
449 |
if (ds == null) {
|
450 |
return null;
|
451 |
}
|
452 |
|
453 |
sds = new SelectableDataSource(ds);
|
454 |
//sds.setSelectionSupport(selectionSupport);
|
455 |
|
456 |
return sds;
|
457 |
} catch (DriverLoadException e) {
|
458 |
throw new DriverException(e);
|
459 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
460 |
throw new DriverException(e);
|
461 |
}
|
462 |
}
|
463 |
return sds;
|
464 |
}
|
465 |
*/
|
466 |
/**
|
467 |
* Para cuando haces una uni?n, sustituyes el recorset por el nuevo.
|
468 |
* De esta forma, podr?s poner leyendas basadas en el nuevo
|
469 |
* recordset
|
470 |
* @param newSds
|
471 |
* @throws DriverException
|
472 |
* @throws FieldNotFoundException
|
473 |
* @throws FieldNotFoundException
|
474 |
*/
|
475 |
/* public void setRecordset(SelectableDataSource newSds) throws DriverException, FieldNotFoundException
|
476 |
{
|
477 |
sds = newSds;
|
478 |
//sds.setSelectionSupport(selectionSupport);
|
479 |
legend.setDataSource(sds);
|
480 |
logger.debug("Recordset cambiado a " + sds.getName());
|
481 |
}
|
482 |
*/
|
483 |
/**
|
484 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
|
485 |
* com.iver.cit.gvsig.fmap.rendering.Legend)
|
486 |
*/
|
487 |
public void setLegend(VectorialLegend r) |
488 |
throws DriverException, FieldNotFoundException {
|
489 |
VectorialLegend oldLegend = legend; |
490 |
legend = r; |
491 |
|
492 |
try {
|
493 |
legend.setDataSource(getRecordset()); |
494 |
|
495 |
if (legend.getLabelField() != null) { |
496 |
// sds.start();
|
497 |
// int idLabelField = getRecordset().getFieldIndexByName(legend.getLabelField());
|
498 |
createLabelLayer(getSource().getRecordset()); |
499 |
// sds.stop();
|
500 |
} |
501 |
else
|
502 |
removeLabels(); |
503 |
} catch (DriverException e) {
|
504 |
throw new DriverException(e); |
505 |
} catch (FieldNotFoundException e) {
|
506 |
// TODO Auto-generated catch block
|
507 |
e.printStackTrace(); |
508 |
} catch (DriverLoadException e) {
|
509 |
// TODO Auto-generated catch block
|
510 |
e.printStackTrace(); |
511 |
} |
512 |
|
513 |
LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(oldLegend, legend); |
514 |
callLegendChanged(e); |
515 |
} |
516 |
|
517 |
/**
|
518 |
* Devuelve la Leyenda de la capa.
|
519 |
*
|
520 |
* @return Leyenda.
|
521 |
*/
|
522 |
public Legend getLegend() {
|
523 |
return legend;
|
524 |
} |
525 |
|
526 |
/**
|
527 |
* Devuelve el tipo de shape que contiene la capa.
|
528 |
*
|
529 |
* @return tipo de shape.
|
530 |
*
|
531 |
* @throws DriverException
|
532 |
*/
|
533 |
public int getShapeType() throws DriverException { |
534 |
if (typeShape == -1) { |
535 |
try {
|
536 |
logger.debug("source.start()");
|
537 |
getSource().start(); |
538 |
typeShape = getSource().getShapeType(); |
539 |
logger.debug("source.stop()");
|
540 |
getSource().stop(); |
541 |
} catch (DriverIOException e) {
|
542 |
throw new DriverException(e); |
543 |
} |
544 |
} |
545 |
|
546 |
return typeShape;
|
547 |
} |
548 |
|
549 |
/**
|
550 |
* @throws XMLException
|
551 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
552 |
*/
|
553 |
public XMLEntity getXMLEntity() throws XMLException { |
554 |
XMLEntity xml = super.getXMLEntity();
|
555 |
xml.addChild(getLegend().getXMLEntity()); |
556 |
//try {
|
557 |
xml.addChild(getRecordset().getSelectionSupport().getXMLEntity()); |
558 |
|
559 |
//} catch (DriverException e1) {
|
560 |
// TODO Auto-generated catch block
|
561 |
// e1.printStackTrace();
|
562 |
//}
|
563 |
if (getSource() instanceof VectorialEditableAdapter){ |
564 |
setSource(((VectorialEditableAdapter)source).getOriginalAdapter()); |
565 |
} |
566 |
if (getSource() instanceof VectorialFileAdapter) { |
567 |
xml.putProperty("type", "vectorial"); |
568 |
xml.putProperty("file", ((VectorialFileAdapter) getSource()).getFile());
|
569 |
//try {
|
570 |
try {
|
571 |
xml.putProperty("recordset-name", getSource().getRecordset().getName());
|
572 |
} catch (DriverLoadException e) {
|
573 |
// TODO Auto-generated catch block
|
574 |
e.printStackTrace(); |
575 |
} |
576 |
//} catch (DriverException e) {
|
577 |
// throw new XMLException(e);
|
578 |
//}
|
579 |
} else if (source instanceof VectorialDBAdapter) { |
580 |
xml.putProperty("type", "vectorial"); |
581 |
|
582 |
VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) getSource().getDriver(); |
583 |
|
584 |
// Guardamos el nombre del driver para poder recuperarlo
|
585 |
// con el DriverManager de Fernando.
|
586 |
xml.putProperty("db", dbDriver.getName());
|
587 |
//try {
|
588 |
try {
|
589 |
xml.putProperty("recordset-name", getSource().getRecordset().getName());
|
590 |
} catch (DriverLoadException e) {
|
591 |
// TODO Auto-generated catch block
|
592 |
e.printStackTrace(); |
593 |
} |
594 |
//} catch (DriverException e) {
|
595 |
// throw new XMLException(e);
|
596 |
//}
|
597 |
xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos metido la leyenda y el selection support
|
598 |
} else if (source instanceof VectorialAdapter) { |
599 |
// Se supone que hemos hecho algo gen?rico.
|
600 |
xml.putProperty("type", "vectorial"); |
601 |
|
602 |
VectorialDriver driver = (VectorialDriver) getSource().getDriver(); |
603 |
|
604 |
// Guardamos el nombre del driver para poder recuperarlo
|
605 |
// con el DriverManager de Fernando.
|
606 |
xml.putProperty("other", driver.getName());
|
607 |
//try {
|
608 |
try {
|
609 |
xml.putProperty("recordset-name", getSource().getRecordset().getName());
|
610 |
} catch (DriverLoadException e) {
|
611 |
// TODO Auto-generated catch block
|
612 |
e.printStackTrace(); |
613 |
} |
614 |
//} catch (DriverException e) {
|
615 |
// throw new XMLException(e);
|
616 |
//}
|
617 |
if (driver instanceof IPersistance) |
618 |
{ |
619 |
// xml.putProperty("className", driver.getClass().getName());
|
620 |
IPersistance persist = (IPersistance) driver; |
621 |
xml.addChild(persist.getXMLEntity()); // Tercer child. Antes hemos metido la leyenda y el selection support
|
622 |
} |
623 |
} |
624 |
xml.putProperty("driverName", getSource().getDriver().getName());
|
625 |
if (bHasJoin)
|
626 |
xml.putProperty("hasJoin", "true"); |
627 |
|
628 |
|
629 |
return xml;
|
630 |
} |
631 |
|
632 |
/**
|
633 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
634 |
*/
|
635 |
public void setXMLEntity03(XMLEntity xml) |
636 |
throws XMLException {
|
637 |
|
638 |
super.setXMLEntity(xml);
|
639 |
legend = LegendFactory.createFromXML03(xml.getChild(0));
|
640 |
|
641 |
try {
|
642 |
// legend.setDataSource(getRecordset());
|
643 |
setLegend(legend); |
644 |
} catch (FieldNotFoundException e) {
|
645 |
throw new XMLException(e); |
646 |
} catch (DriverException e) {
|
647 |
throw new XMLException(e); |
648 |
} |
649 |
|
650 |
//try {
|
651 |
getRecordset().getSelectionSupport().setXMLEntity03(xml.getChild(1));
|
652 |
//} catch (DriverException e) {
|
653 |
// TODO Auto-generated catch block
|
654 |
// e.printStackTrace();
|
655 |
//}
|
656 |
} |
657 |
|
658 |
/**
|
659 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
660 |
*/
|
661 |
public void setXMLEntity(XMLEntity xml) |
662 |
throws XMLException {
|
663 |
super.setXMLEntity(xml);
|
664 |
|
665 |
VectorialLegend leg = LegendFactory.createFromXML(xml.getChild(0));
|
666 |
getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
667 |
|
668 |
|
669 |
String recordsetName = xml.getStringProperty("recordset-name"); |
670 |
try {
|
671 |
LayerFactory.getDataSourceFactory().changeDataSourceName( |
672 |
getSource().getRecordset().getName(), recordsetName |
673 |
); |
674 |
// Hacemos que el recordset que hemos creado antes (los
|
675 |
// recordset se crean antes que todo) sea el recordset
|
676 |
// de esta capa. Y del que se crea automaticamente
|
677 |
// en el setLegend del createLayer, nos olvidamos
|
678 |
SelectableDataSource sds=new SelectableDataSource(LayerFactory.getDataSourceFactory()
|
679 |
.createRandomDataSource(recordsetName, DataSourceFactory.AUTOMATIC_OPENING)); |
680 |
//sds.setSelectionSupport(selectionSupport);
|
681 |
//((EditableAdapter)getSource()).setRecordSet(sds);
|
682 |
} catch (NoSuchTableException e1) {
|
683 |
throw new XMLException(e1); |
684 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
|
685 |
throw new XMLException(e1); |
686 |
} catch (DriverLoadException e1) {
|
687 |
throw new XMLException(e1); |
688 |
} |
689 |
// Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta el final
|
690 |
// de la lectura del proyecto
|
691 |
if (xml.contains("hasJoin")) |
692 |
{ |
693 |
setIsJoined(true);
|
694 |
PostProcessSupport.addToPostProcess(this,"setLegend", leg, 1); |
695 |
} |
696 |
else
|
697 |
{ |
698 |
try {
|
699 |
// legend.setDataSource(getRecordset());
|
700 |
setLegend(leg); |
701 |
} catch (FieldNotFoundException e) {
|
702 |
throw new XMLException(e); |
703 |
} catch (DriverException e) {
|
704 |
throw new XMLException(e); |
705 |
} |
706 |
} |
707 |
|
708 |
} |
709 |
|
710 |
/**
|
711 |
* A?ade un LegendListener a la lista de Listeners.
|
712 |
*
|
713 |
* @param listener LegendListener.
|
714 |
*/
|
715 |
public void addLegendListener(LegendListener listener) { |
716 |
layerChangeSupport.addLayerListener(listener); |
717 |
} |
718 |
|
719 |
/**
|
720 |
* Llamada al m?todo callLegendChanged de los listener.
|
721 |
*
|
722 |
* @param e Evento.
|
723 |
*/
|
724 |
private void callLegendChanged(LegendChangedEvent e) { |
725 |
layerChangeSupport.callLegendChanged(e); |
726 |
} |
727 |
|
728 |
/**
|
729 |
* Borra un LegendListener de la lista de Listeners
|
730 |
*
|
731 |
* @param listener LegendListener.
|
732 |
*/
|
733 |
public void removeLegendListener(LegendListener listener) { |
734 |
layerChangeSupport.removeLayerListener(listener); |
735 |
} |
736 |
|
737 |
/**
|
738 |
* Sobreimplementaci?n del m?todo toString para que las bases de datos
|
739 |
* identifiquen la capa.
|
740 |
*
|
741 |
* @return DOCUMENT ME!
|
742 |
*/
|
743 |
public String toString() { |
744 |
/*
|
745 |
* Se usa internamente para que la parte de datos
|
746 |
* identifique de forma un?voca las tablas
|
747 |
*/
|
748 |
String ret = super.toString(); |
749 |
|
750 |
return "layer" + ret.substring(ret.indexOf('@') + 1); |
751 |
} |
752 |
|
753 |
public boolean isJoined() { |
754 |
return bHasJoin;
|
755 |
} |
756 |
|
757 |
public void setIsJoined(boolean hasJoin) { |
758 |
bHasJoin = hasJoin; |
759 |
} |
760 |
|
761 |
/**
|
762 |
* @return Returns the spatialIndex.
|
763 |
*/
|
764 |
public SpatialIndex getSpatialIndex() {
|
765 |
return spatialIndex;
|
766 |
} |
767 |
|
768 |
public SelectableDataSource getRecordset() {
|
769 |
try {
|
770 |
return getSource().getRecordset();
|
771 |
} catch (DriverLoadException e) {
|
772 |
// TODO Auto-generated catch block
|
773 |
e.printStackTrace(); |
774 |
} |
775 |
return null; |
776 |
} |
777 |
|
778 |
/* (non-Javadoc)
|
779 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setEditing(boolean)
|
780 |
*/
|
781 |
public void setEditing(boolean b) { |
782 |
super.setEditing(b);
|
783 |
if (b)
|
784 |
{ |
785 |
VectorialEditableAdapter vea = null;
|
786 |
// TODO: Qu? pasa si hay m?s tipos de adapters?
|
787 |
if (getSource() instanceof VectorialDBAdapter) |
788 |
{ |
789 |
vea = new VectorialEditableDBAdapter();
|
790 |
}else if (this instanceof FLyrAnnotation) |
791 |
{ |
792 |
vea = new AnnotationEditableAdapter(((FLyrAnnotation)this).getLabels(),((FLyrAnnotation)this).getMapping()); |
793 |
} |
794 |
else
|
795 |
{ |
796 |
vea = new VectorialEditableAdapter();
|
797 |
} |
798 |
vea.setOriginalVectorialAdapter(getSource()); |
799 |
try{
|
800 |
vea.startEdition(); |
801 |
}catch (EditionException e) {
|
802 |
e.printStackTrace(); |
803 |
} |
804 |
setSource(vea); |
805 |
getRecordset().setSelectionSupport(vea.getOriginalAdapter().getRecordset().getSelectionSupport()); |
806 |
|
807 |
} |
808 |
else
|
809 |
{ |
810 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) getSource(); |
811 |
setSource(vea.getOriginalAdapter()); |
812 |
} |
813 |
callEditionChanged(LayerEvent.createEditionChangedEvent(this, "edition")); |
814 |
|
815 |
} |
816 |
|
817 |
/*public SelectionSupport getSelectionSupport() {
|
818 |
return selectionSupport;
|
819 |
}
|
820 |
|
821 |
public void setSelectionSupport(SelectionSupport selectionSupport) {
|
822 |
this.selectionSupport = selectionSupport;
|
823 |
}*/
|
824 |
} |