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