svn-gvsig-desktop / tags / v1_0_2_RELEASE / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 11432
History | View | Annotate | Download (43.1 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.Font; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.Point; |
46 |
import java.awt.geom.Point2D; |
47 |
import java.awt.geom.Rectangle2D; |
48 |
import java.awt.image.BufferedImage; |
49 |
import java.io.File; |
50 |
import java.io.IOException; |
51 |
|
52 |
import javax.print.attribute.PrintRequestAttributeSet; |
53 |
|
54 |
import org.apache.log4j.Logger; |
55 |
import org.cresques.cts.ICoordTrans; |
56 |
|
57 |
import com.hardcode.driverManager.Driver; |
58 |
import com.hardcode.driverManager.DriverLoadException; |
59 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
60 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
61 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
62 |
import com.iver.cit.gvsig.fmap.DriverException; |
63 |
import com.iver.cit.gvsig.fmap.DriverNotLoadedExceptionType; |
64 |
import com.iver.cit.gvsig.fmap.ViewPort; |
65 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
66 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
67 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
68 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
69 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
70 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
71 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
72 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
73 |
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
74 |
import com.iver.cit.gvsig.fmap.edition.AnnotationEditableAdapter; |
75 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
76 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
77 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
78 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
79 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
80 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
81 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableDBAdapter; |
82 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
83 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
84 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
85 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable; |
86 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData; |
87 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
88 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
89 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialXMLItem; |
90 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
91 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
92 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
93 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
94 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
95 |
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo; |
96 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
97 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
98 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
99 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
100 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
101 |
import com.iver.cit.gvsig.fmap.spatialindex.IPersistentSpatialIndex; |
102 |
import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex; |
103 |
import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeGt2; |
104 |
import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeJts; |
105 |
import com.iver.cit.gvsig.fmap.spatialindex.SpatialIndexException; |
106 |
import com.iver.utiles.FileUtils; |
107 |
import com.iver.utiles.IPersistance; |
108 |
import com.iver.utiles.PostProcessSupport; |
109 |
import com.iver.utiles.XMLEntity; |
110 |
import com.iver.utiles.swing.threads.Cancellable; |
111 |
import com.iver.utiles.swing.threads.CancellableMonitorable; |
112 |
|
113 |
/**
|
114 |
* Capa b?sica Vectorial.
|
115 |
*
|
116 |
* @author Fernando Gonz?lez Cort?s
|
117 |
*/
|
118 |
|
119 |
// TODO Cuando no sea para pruebas debe no ser public
|
120 |
public class FLyrVect extends FLyrDefault implements Labelable, |
121 |
ClassifiableVectorial, SingleLayer, VectorialData, RandomVectorialData, |
122 |
AlphanumericData, InfoByPoint { |
123 |
private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
124 |
|
125 |
/** Leyenda de la capa vectorial */
|
126 |
private VectorialLegend legend;
|
127 |
|
128 |
private int typeShape = -1; |
129 |
|
130 |
private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
131 |
|
132 |
private ReadableVectorial source;
|
133 |
|
134 |
private SelectableDataSource sds;
|
135 |
|
136 |
private SelectionSupport selectionSupport = new SelectionSupport(); |
137 |
|
138 |
private SpatialCache spatialCache = new SpatialCache(); |
139 |
private boolean spatialCacheEnabled = false; |
140 |
|
141 |
// protected SpatialIndex spatialIndex = null;
|
142 |
/**
|
143 |
* An implementation of gvSIG spatial index
|
144 |
*/
|
145 |
protected ISpatialIndex spatialIndex = null; |
146 |
|
147 |
private boolean bHasJoin = false; |
148 |
|
149 |
private XMLEntity orgXMLEntity = null; |
150 |
|
151 |
private XMLEntity loadSelection = null; |
152 |
private VectorialLegend loadLegend = null; |
153 |
|
154 |
|
155 |
/**
|
156 |
* A?ade un SelectionListener a la lista de listeners.
|
157 |
*
|
158 |
* @param listener
|
159 |
* SelectionListener.
|
160 |
*/
|
161 |
/*
|
162 |
* public void addSelectionListener(SelectionListener listener) { try {
|
163 |
* getRecordset().addSelectionListener(listener); } catch (DriverException
|
164 |
* e) { // TODO Auto-generated catch block e.printStackTrace(); } }
|
165 |
*/
|
166 |
/**
|
167 |
* Borra un selectionListener de la lista de listeners.
|
168 |
*
|
169 |
* @param listener
|
170 |
* SelectionListener
|
171 |
*/
|
172 |
/*
|
173 |
* public void removeSelectionListener(SelectionListener listener) { try {
|
174 |
* getRecordset().removeSelectionListener(listener); } catch
|
175 |
* (DriverException e) { // TODO Auto-generated catch block
|
176 |
* e.printStackTrace(); } }
|
177 |
*/
|
178 |
/**
|
179 |
* Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
180 |
* una gran cantidad de eventos. Con el fin de no propagar todos estos
|
181 |
* eventos, se realiza la propagaci?n de manera manual al final de la
|
182 |
* "r?faga" de eventos
|
183 |
*/
|
184 |
/*
|
185 |
* public void fireSelectionEvents() { try {
|
186 |
* getRecordset().fireSelectionEvents(); } catch (DriverException e) { //
|
187 |
* TODO Auto-generated catch block e.printStackTrace(); } }
|
188 |
*/
|
189 |
/**
|
190 |
* Devuelve el VectorialAdapater de la capa.
|
191 |
*
|
192 |
* @return VectorialAdapter.
|
193 |
*/
|
194 |
public ReadableVectorial getSource() {
|
195 |
if (!this.isAvailable()) return null; |
196 |
return source;
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* If we use a persistent spatial index associated with this layer, and the
|
201 |
* index is not intrisic to the layer (for example spatial databases) this
|
202 |
* method looks for existent spatial index, and loads it.
|
203 |
*
|
204 |
*/
|
205 |
private void loadSpatialIndex() { |
206 |
//FIXME: Al abrir el indice en fichero...
|
207 |
//?C?mo lo liberamos? un metodo Layer.shutdown()
|
208 |
|
209 |
|
210 |
ReadableVectorial source = getSource(); |
211 |
//REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
|
212 |
//PUES SON VECTORIALFILEADAPTER
|
213 |
if (!(source instanceof VectorialFileAdapter)) { |
214 |
// we are not interested in db adapters
|
215 |
return;
|
216 |
} |
217 |
VectorialDriver driver = source.getDriver(); |
218 |
if (!(driver instanceof BoundedShapes)) { |
219 |
// we dont spatially index layers that are not bounded
|
220 |
return;
|
221 |
} |
222 |
File file = ((VectorialFileAdapter) source).getFile();
|
223 |
String fileName = file.getAbsolutePath();
|
224 |
File sptFile = new File(fileName + ".qix"); |
225 |
if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
226 |
// before to exit, look for it in temp path
|
227 |
String tempPath = System.getProperty("java.io.tmpdir"); |
228 |
fileName = tempPath + File.separator + sptFile.getName();
|
229 |
sptFile = new File(fileName); |
230 |
// it doesnt exists, must to create
|
231 |
if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
232 |
return;
|
233 |
}// if
|
234 |
}// if
|
235 |
|
236 |
try {
|
237 |
source.start(); |
238 |
spatialIndex = new QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
|
239 |
"NM", source.getFullExtent(), source.getShapeCount(), false); |
240 |
} catch (SpatialIndexException e) {
|
241 |
spatialIndex = null;
|
242 |
e.printStackTrace(); |
243 |
return;
|
244 |
} catch (DriverIOException e) {
|
245 |
// TODO Auto-generated catch block
|
246 |
e.printStackTrace(); |
247 |
} |
248 |
|
249 |
} |
250 |
|
251 |
/**
|
252 |
* Checks if it has associated an external spatial index
|
253 |
* (an spatial index file).
|
254 |
*
|
255 |
* It looks for it in main file path, or in temp system path.
|
256 |
* If main file is rivers.shp, it looks for a file called
|
257 |
* rivers.shp.qix.
|
258 |
|
259 |
* @return
|
260 |
*/
|
261 |
public boolean isExternallySpatiallyIndexed() { |
262 |
/*
|
263 |
* FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
|
264 |
* con el que se trabaje (ahora mismo considera la extension .qix,
|
265 |
* pero esto depender? del tipo de ?ndice)
|
266 |
* */
|
267 |
ReadableVectorial source = getSource(); |
268 |
if (!(source instanceof VectorialFileAdapter)) { |
269 |
// we are not interested in db adapters.
|
270 |
// think in non spatial dbs, like HSQLDB
|
271 |
return false; |
272 |
} |
273 |
File file = ((VectorialFileAdapter) source).getFile();
|
274 |
String fileName = file.getAbsolutePath();
|
275 |
File sptFile = new File(fileName + ".qix"); |
276 |
if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
277 |
// before to exit, look for it in temp path
|
278 |
// it doesnt exists, must to create
|
279 |
String tempPath = System.getProperty("java.io.tmpdir"); |
280 |
fileName = tempPath + File.separator + sptFile.getName();
|
281 |
sptFile = new File(fileName); |
282 |
if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
283 |
return false; |
284 |
}// if
|
285 |
}// if
|
286 |
return true; |
287 |
} |
288 |
|
289 |
/**
|
290 |
* Inserta el VectorialAdapter a la capa.
|
291 |
*
|
292 |
* @param va
|
293 |
* VectorialAdapter.
|
294 |
*/
|
295 |
public void setSource(ReadableVectorial rv) { |
296 |
source = rv; |
297 |
// azabala: we check if this layer could have a file spatial index
|
298 |
// and load it if it exists
|
299 |
loadSpatialIndex(); |
300 |
} |
301 |
|
302 |
/**
|
303 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
304 |
*/
|
305 |
public Rectangle2D getFullExtent() throws DriverException { |
306 |
try {
|
307 |
Rectangle2D rAux;
|
308 |
// logger.debug(getName() + "_source.start()");
|
309 |
source.start(); |
310 |
rAux = (Rectangle2D)source.getFullExtent().clone();
|
311 |
// logger.debug(getName() + "_source.stop()");
|
312 |
source.stop(); |
313 |
|
314 |
// Si existe reproyecci?n, reproyectar el extent
|
315 |
ICoordTrans ct = getCoordTrans(); |
316 |
|
317 |
if (ct != null) { |
318 |
Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
319 |
Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
320 |
pt1 = ct.convert(pt1, null);
|
321 |
pt2 = ct.convert(pt2, null);
|
322 |
rAux = new Rectangle2D.Double(); |
323 |
rAux.setFrameFromDiagonal(pt1, pt2); |
324 |
} |
325 |
|
326 |
//Esto es para cuando se crea una capa nueva con el fullExtent de ancho y alto 0.
|
327 |
if (rAux.getWidth()==0 && rAux.getHeight()==0) { |
328 |
rAux=new Rectangle2D.Double(0,0,100,100); |
329 |
} |
330 |
|
331 |
return rAux;
|
332 |
} catch (DriverIOException e) {
|
333 |
throw new DriverException(e); |
334 |
} |
335 |
} |
336 |
|
337 |
/**
|
338 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
339 |
* java.awt.Graphics2D, ISymbol)
|
340 |
*/
|
341 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
342 |
Cancellable cancel, double scale) throws DriverException { |
343 |
|
344 |
if (isWithinScale(scale)) {
|
345 |
// Las que solo tienen etiquetado sin pintar el shape,
|
346 |
// no pasamos por ellas
|
347 |
boolean bDrawShapes = true; |
348 |
if (legend instanceof SingleSymbolLegend) { |
349 |
if (legend.getDefaultSymbol().isShapeVisible() == false) |
350 |
bDrawShapes = false;
|
351 |
} |
352 |
if (bDrawShapes) {
|
353 |
Strategy strategy = StrategyManager.getStrategy(this);
|
354 |
try {
|
355 |
prepareDrawing(image, g, viewPort); |
356 |
strategy.draw(image, g, viewPort, cancel); |
357 |
} catch (DriverException e) {
|
358 |
this.setVisible(false); |
359 |
this.setActive(false); |
360 |
throw e;
|
361 |
} |
362 |
} |
363 |
if (getVirtualLayers() != null) { |
364 |
getVirtualLayers().draw(image, g, viewPort, cancel, scale); |
365 |
} |
366 |
|
367 |
if (getLayerText() != null) { |
368 |
getLayerText().draw(image, g, viewPort, cancel, scale); |
369 |
} |
370 |
} |
371 |
} |
372 |
|
373 |
/**
|
374 |
* Se llama antes de empezar a pintar.
|
375 |
* Es ?til para preparar la cache a emplear, las leyendas, etc.
|
376 |
* @param image
|
377 |
* @param g
|
378 |
* @param viewPort
|
379 |
*/
|
380 |
private void prepareDrawing(BufferedImage image, Graphics2D g, ViewPort viewPort) { |
381 |
|
382 |
} |
383 |
|
384 |
/**
|
385 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
386 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
387 |
* com.iver.utiles.swing.threads.Cancellable)
|
388 |
*/
|
389 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
390 |
double scale, PrintRequestAttributeSet properties) throws DriverException { |
391 |
if (isVisible() && isWithinScale(scale)) {
|
392 |
Strategy strategy = StrategyManager.getStrategy(this);
|
393 |
|
394 |
strategy.print(g, viewPort, cancel, properties); |
395 |
|
396 |
if (getLayerText() != null) { |
397 |
getLayerText().draw(null, g, viewPort, cancel, scale);
|
398 |
} |
399 |
} |
400 |
} |
401 |
|
402 |
/**
|
403 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
|
404 |
*/
|
405 |
// public FLayer createLabelLayer(int fieldId) {
|
406 |
public FLayer createLabelLayer(SelectableDataSource ds) {
|
407 |
FLyrText layerText = null;
|
408 |
try {
|
409 |
layerText = new FLyrText();
|
410 |
layerText.setCoordTrans(getCoordTrans()); |
411 |
layerText.setLegend((VectorialLegend) getLegend()); |
412 |
layerText.createLabels(this);
|
413 |
} catch (FieldNotFoundException e1) {
|
414 |
// TODO Auto-generated catch block
|
415 |
e1.printStackTrace(); |
416 |
} catch (DriverException e1) {
|
417 |
// TODO Auto-generated catch block
|
418 |
e1.printStackTrace(); |
419 |
} |
420 |
|
421 |
setLayerText(layerText); |
422 |
return layerText;
|
423 |
} |
424 |
|
425 |
/**
|
426 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
|
427 |
*/
|
428 |
public void removeLabels() { |
429 |
setLayerText(null);
|
430 |
} |
431 |
|
432 |
/*
|
433 |
* (non-Javadoc)
|
434 |
*
|
435 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#deleteSpatialIndex()
|
436 |
*/
|
437 |
public void deleteSpatialIndex() { |
438 |
//must we delete possible spatial indexes files?
|
439 |
spatialIndex = null;
|
440 |
} |
441 |
|
442 |
|
443 |
|
444 |
/**
|
445 |
* <p>
|
446 |
* Creates an spatial index associated to this layer.
|
447 |
* The spatial index will used
|
448 |
* the native projection of the layer, so if the layer is reprojected, it will
|
449 |
* be ignored.
|
450 |
* </p>
|
451 |
* @param cancelMonitor instance of CancellableMonitorable that allows
|
452 |
* to monitor progress of spatial index creation, and cancel the process
|
453 |
*/
|
454 |
public void createSpatialIndex(CancellableMonitorable cancelMonitor){ |
455 |
// FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
456 |
// QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
457 |
// para que acepten recorrer sin geometria, solo con rectangulos.
|
458 |
|
459 |
//If this vectorial layer is based in a spatial database, the spatial
|
460 |
//index is already implicit. We only will index file drivers
|
461 |
ReadableVectorial va = getSource(); |
462 |
//We must think in non spatial databases, like HSQLDB
|
463 |
if(!(va instanceof VectorialFileAdapter)){ |
464 |
return;
|
465 |
} |
466 |
if (!(va.getDriver() instanceof BoundedShapes)) { |
467 |
return;
|
468 |
} |
469 |
File file = ((VectorialFileAdapter) va).getFile();
|
470 |
String fileName = file.getAbsolutePath();
|
471 |
ISpatialIndex localCopy = null;
|
472 |
try {
|
473 |
va.start(); |
474 |
localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(), |
475 |
va.getShapeCount(), true);
|
476 |
|
477 |
} catch (SpatialIndexException e1) {
|
478 |
// Probably we dont have writing permissions
|
479 |
String directoryName = System.getProperty("java.io.tmpdir"); |
480 |
File newFile = new File(directoryName + |
481 |
File.separator +
|
482 |
file.getName()); |
483 |
String newFileName = newFile.getName();
|
484 |
try {
|
485 |
localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(), |
486 |
va.getShapeCount(), true);
|
487 |
} catch (SpatialIndexException e) {
|
488 |
// if we cant build a file based spatial index, we'll build
|
489 |
// a pure memory spatial index
|
490 |
localCopy = new QuadtreeJts();
|
491 |
} catch (DriverIOException e) {
|
492 |
// TODO Auto-generated catch block
|
493 |
e.printStackTrace(); |
494 |
} |
495 |
|
496 |
}catch(Exception e){ |
497 |
e.printStackTrace(); |
498 |
}//try
|
499 |
BoundedShapes shapeBounds = (BoundedShapes) va.getDriver(); |
500 |
try {
|
501 |
for (int i=0; i < va.getShapeCount(); i++) |
502 |
{ |
503 |
if(cancelMonitor != null){ |
504 |
if(cancelMonitor.isCanceled())
|
505 |
return;
|
506 |
cancelMonitor.reportStep(); |
507 |
} |
508 |
Rectangle2D r = shapeBounds.getShapeBounds(i);
|
509 |
if(r != null) |
510 |
localCopy.insert(r, i); |
511 |
} // for
|
512 |
va.stop(); |
513 |
if(localCopy instanceof IPersistentSpatialIndex) |
514 |
((IPersistentSpatialIndex) localCopy).flush(); |
515 |
spatialIndex = localCopy; |
516 |
} catch (DriverIOException e) {
|
517 |
// TODO Auto-generated catch block
|
518 |
e.printStackTrace(); |
519 |
} catch (IOException e) { |
520 |
// TODO Auto-generated catch block
|
521 |
e.printStackTrace(); |
522 |
} |
523 |
} |
524 |
|
525 |
/**
|
526 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
|
527 |
*/
|
528 |
public void createSpatialIndex() { |
529 |
createSpatialIndex(null);
|
530 |
} |
531 |
|
532 |
/**
|
533 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
534 |
* FBitSet)
|
535 |
*/
|
536 |
public void process(FeatureVisitor visitor, FBitSet subset) |
537 |
throws DriverException, VisitException {
|
538 |
Strategy s = StrategyManager.getStrategy(this);
|
539 |
s.process(visitor, subset); |
540 |
} |
541 |
|
542 |
/**
|
543 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
544 |
*/
|
545 |
public void process(FeatureVisitor visitor) throws DriverException, |
546 |
VisitException { |
547 |
Strategy s = StrategyManager.getStrategy(this);
|
548 |
s.process(visitor); |
549 |
} |
550 |
|
551 |
/**
|
552 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
553 |
* Rectangle2D)
|
554 |
*/
|
555 |
public void process(FeatureVisitor visitor, Rectangle2D rect) |
556 |
throws DriverException, VisitException {
|
557 |
Strategy s = StrategyManager.getStrategy(this);
|
558 |
s.process(visitor, rect); |
559 |
} |
560 |
|
561 |
/**
|
562 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
563 |
*/
|
564 |
/*
|
565 |
* public void setSelection(FBitSet selection) { try {
|
566 |
* getRecordset().setSelection(selection); } catch (DriverException e) { //
|
567 |
* TODO Auto-generated catch block e.printStackTrace(); }
|
568 |
* fireSelectionEvents(); }
|
569 |
*/
|
570 |
/**
|
571 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
|
572 |
*/
|
573 |
/*
|
574 |
* public boolean isSelected(int index) { try { return
|
575 |
* getRecordset().isSelected(index); } catch (DriverException e) { // TODO
|
576 |
* Auto-generated catch block e.printStackTrace(); } return false; }
|
577 |
*/
|
578 |
/**
|
579 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
|
580 |
*/
|
581 |
/*
|
582 |
* public FBitSet getSelection() { try { return
|
583 |
* getRecordset().getSelection(); } catch (DriverException e) { // TODO
|
584 |
* Auto-generated catch block e.printStackTrace(); } return new FBitSet(); }
|
585 |
*/
|
586 |
/**
|
587 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
|
588 |
*/
|
589 |
/*
|
590 |
* public void clearSelection() { try { getRecordset().clearSelection(); }
|
591 |
* catch (DriverException e) { // TODO Auto-generated catch block
|
592 |
* e.printStackTrace(); } }
|
593 |
*/
|
594 |
|
595 |
/*
|
596 |
* (non-Javadoc)
|
597 |
*
|
598 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
|
599 |
*/
|
600 |
public FBitSet queryByRect(Rectangle2D rect) throws DriverException { |
601 |
Strategy s = StrategyManager.getStrategy(this);
|
602 |
|
603 |
return s.queryByRect(rect);
|
604 |
} |
605 |
|
606 |
public FBitSet queryByPoint(Point2D p, double tolerance) |
607 |
throws DriverException {
|
608 |
Strategy s = StrategyManager.getStrategy(this);
|
609 |
return s.queryByPoint(p, tolerance);
|
610 |
} |
611 |
|
612 |
public FBitSet queryByShape(IGeometry g, int relationship) |
613 |
throws DriverException, VisitException {
|
614 |
Strategy s = StrategyManager.getStrategy(this);
|
615 |
return s.queryByShape(g, relationship);
|
616 |
} |
617 |
|
618 |
public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws DriverException { |
619 |
Point2D pReal = this.getMapContext().getViewPort().toMapPoint(p); |
620 |
FBitSet bs = queryByPoint(pReal, tolerance); |
621 |
VectorialXMLItem[] item = new VectorialXMLItem[1]; |
622 |
item[0] = new VectorialXMLItem(bs, this); |
623 |
|
624 |
return item;
|
625 |
} |
626 |
|
627 |
/**
|
628 |
* @throws DriverException
|
629 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
630 |
*/
|
631 |
/*
|
632 |
* public SelectableDataSource getRecordset() throws DriverException { if
|
633 |
* (sds == null){ try { DataSource ds = getSource().getRecordset();
|
634 |
*
|
635 |
* if (ds == null) { return null; }
|
636 |
*
|
637 |
* sds = new SelectableDataSource(ds);
|
638 |
* //sds.setSelectionSupport(selectionSupport);
|
639 |
*
|
640 |
* return sds; } catch (DriverLoadException e) { throw new
|
641 |
* DriverException(e); } catch
|
642 |
* (com.hardcode.gdbms.engine.data.driver.DriverException e) { throw new
|
643 |
* DriverException(e); } } return sds; }
|
644 |
*/
|
645 |
/**
|
646 |
* Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
647 |
* forma, podr?s poner leyendas basadas en el nuevo recordset
|
648 |
*
|
649 |
* @param newSds
|
650 |
* @throws DriverException
|
651 |
* @throws FieldNotFoundException
|
652 |
* @throws FieldNotFoundException
|
653 |
*/
|
654 |
/*
|
655 |
* public void setRecordset(SelectableDataSource newSds) throws
|
656 |
* DriverException, FieldNotFoundException { sds = newSds;
|
657 |
* //sds.setSelectionSupport(selectionSupport); legend.setDataSource(sds);
|
658 |
* logger.debug("Recordset cambiado a " + sds.getName()); }
|
659 |
*/
|
660 |
/**
|
661 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
|
662 |
* com.iver.cit.gvsig.fmap.rendering.Legend)
|
663 |
*/
|
664 |
public void setLegend(VectorialLegend r) throws DriverException, |
665 |
FieldNotFoundException { |
666 |
VectorialLegend oldLegend = legend; |
667 |
legend = r; |
668 |
|
669 |
try {
|
670 |
legend.setDataSource(getRecordset()); |
671 |
|
672 |
if (legend.getLabelField() != null) { |
673 |
// sds.start();
|
674 |
// int idLabelField =
|
675 |
// getRecordset().getFieldIndexByName(legend.getLabelField());
|
676 |
createLabelLayer(getSource().getRecordset()); |
677 |
// sds.stop();
|
678 |
} else
|
679 |
removeLabels(); |
680 |
} catch (DriverException e) {
|
681 |
throw new DriverException(e); |
682 |
} catch (FieldNotFoundException e) {
|
683 |
// TODO Auto-generated catch block
|
684 |
e.printStackTrace(); |
685 |
} catch (DriverLoadException e) {
|
686 |
// TODO Auto-generated catch block
|
687 |
e.printStackTrace(); |
688 |
} |
689 |
|
690 |
LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent( |
691 |
oldLegend, legend); |
692 |
callLegendChanged(e); |
693 |
} |
694 |
|
695 |
/**
|
696 |
* Devuelve la Leyenda de la capa.
|
697 |
*
|
698 |
* @return Leyenda.
|
699 |
*/
|
700 |
public Legend getLegend() {
|
701 |
return legend;
|
702 |
} |
703 |
|
704 |
/**
|
705 |
* Devuelve el tipo de shape que contiene la capa.
|
706 |
*
|
707 |
* @return tipo de shape.
|
708 |
*
|
709 |
* @throws DriverException
|
710 |
*/
|
711 |
public int getShapeType() throws DriverException { |
712 |
if (typeShape == -1) { |
713 |
try {
|
714 |
// logger.debug("source.start()");
|
715 |
getSource().start(); |
716 |
typeShape = getSource().getShapeType(); |
717 |
// logger.debug("source.stop()");
|
718 |
getSource().stop(); |
719 |
} catch (DriverIOException e) {
|
720 |
throw new DriverException(e); |
721 |
} |
722 |
} |
723 |
|
724 |
return typeShape;
|
725 |
} |
726 |
|
727 |
/**
|
728 |
* @throws XMLException
|
729 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
730 |
*/
|
731 |
public XMLEntity getXMLEntity() throws XMLException { |
732 |
if (!this.isAvailable() && this.orgXMLEntity != null) { |
733 |
return this.orgXMLEntity; |
734 |
} |
735 |
XMLEntity xml = super.getXMLEntity();
|
736 |
if (getLegend()!=null) |
737 |
xml.addChild(getLegend().getXMLEntity()); |
738 |
try {
|
739 |
if (getRecordset()!=null) |
740 |
xml.addChild(getRecordset().getSelectionSupport().getXMLEntity()); |
741 |
} catch (DriverException e1) {
|
742 |
e1.printStackTrace(); |
743 |
throw new XMLException(e1); |
744 |
} |
745 |
//Repongo el mismo ReadableVectorial m?s abajo para cuando se guarda el proyecto.
|
746 |
ReadableVectorial rv=getSource(); |
747 |
xml.putProperty("type", "vectorial"); |
748 |
if (source instanceof VectorialEditableAdapter) { |
749 |
setSource(((VectorialEditableAdapter) source) |
750 |
.getOriginalAdapter()); |
751 |
} |
752 |
if (source instanceof VectorialFileAdapter) { |
753 |
xml.putProperty("file", ((VectorialFileAdapter) source)
|
754 |
.getFile()); |
755 |
try {
|
756 |
xml.putProperty("recordset-name", source
|
757 |
.getRecordset().getName()); |
758 |
} catch (DriverLoadException e) {
|
759 |
e.printStackTrace(); |
760 |
} catch (RuntimeException e) { |
761 |
e.printStackTrace(); |
762 |
} |
763 |
} else if (source instanceof VectorialDBAdapter) { |
764 |
VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) source |
765 |
.getDriver(); |
766 |
|
767 |
// Guardamos el nombre del driver para poder recuperarlo
|
768 |
// con el DriverManager de Fernando.
|
769 |
xml.putProperty("db", dbDriver.getName());
|
770 |
try {
|
771 |
xml.putProperty("recordset-name", source
|
772 |
.getRecordset().getName()); |
773 |
} catch (DriverLoadException e) {
|
774 |
e.printStackTrace(); |
775 |
} catch (RuntimeException e) { |
776 |
e.printStackTrace(); |
777 |
} |
778 |
if (dbDriver!=null) |
779 |
xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes
|
780 |
// hemos
|
781 |
// metido la leyenda y el
|
782 |
// selection support
|
783 |
} else if (source instanceof VectorialAdapter) { |
784 |
VectorialDriver driver = (VectorialDriver) source.getDriver(); |
785 |
|
786 |
// Guardamos el nombre del driver para poder recuperarlo
|
787 |
// con el DriverManager de Fernando.
|
788 |
xml.putProperty("other", driver.getName());
|
789 |
try {
|
790 |
xml.putProperty("recordset-name", source
|
791 |
.getRecordset().getName()); |
792 |
} catch (DriverLoadException e) {
|
793 |
e.printStackTrace(); |
794 |
} catch (RuntimeException e) { |
795 |
e.printStackTrace(); |
796 |
} |
797 |
if (driver instanceof IPersistance) { |
798 |
// xml.putProperty("className",
|
799 |
// driver.getClass().getName());
|
800 |
IPersistance persist = (IPersistance) driver; |
801 |
xml.addChild(persist.getXMLEntity()); // Tercer child.
|
802 |
// Antes
|
803 |
// hemos metido la
|
804 |
// leyenda y el
|
805 |
// selection support
|
806 |
} |
807 |
} |
808 |
if (rv!=null) |
809 |
setSource(rv); |
810 |
xml.putProperty("driverName", source.getDriver().getName());
|
811 |
|
812 |
if (bHasJoin)
|
813 |
xml.putProperty("hasJoin", "true"); |
814 |
|
815 |
return xml;
|
816 |
} |
817 |
|
818 |
/**
|
819 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
820 |
*/
|
821 |
public void setXMLEntity03(XMLEntity xml) throws XMLException { |
822 |
|
823 |
super.setXMLEntity(xml);
|
824 |
legend = LegendFactory.createFromXML03(xml.getChild(0));
|
825 |
|
826 |
try {
|
827 |
// legend.setDataSource(getRecordset());
|
828 |
setLegend(legend); |
829 |
} catch (FieldNotFoundException e) {
|
830 |
throw new XMLException(e); |
831 |
} catch (DriverException e) {
|
832 |
throw new XMLException(e); |
833 |
} |
834 |
|
835 |
try {
|
836 |
getRecordset().getSelectionSupport() |
837 |
.setXMLEntity03(xml.getChild(1));
|
838 |
} catch (DriverException e) {
|
839 |
e.printStackTrace(); |
840 |
} |
841 |
} |
842 |
|
843 |
/**
|
844 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
845 |
*/
|
846 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
847 |
try {
|
848 |
super.setXMLEntity(xml);
|
849 |
|
850 |
VectorialLegend leg = LegendFactory.createFromXML(xml.getChild(0));
|
851 |
try {
|
852 |
getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
853 |
/* JMVIVO
|
854 |
this.setLoadSelection(xml.getChild(1));
|
855 |
*/
|
856 |
// JMVIVO: Esto sirve para algo????
|
857 |
String recordsetName = xml.getStringProperty("recordset-name"); |
858 |
|
859 |
LayerFactory.getDataSourceFactory().changeDataSourceName( |
860 |
getSource().getRecordset().getName(), recordsetName); |
861 |
// Hacemos que el recordset que hemos creado antes (los
|
862 |
// recordset se crean antes que todo) sea el recordset
|
863 |
// de esta capa. Y del que se crea automaticamente
|
864 |
// en el setLegend del createLayer, nos olvidamos
|
865 |
// CHEMA: AUTOMATIC DATA SOURCE
|
866 |
/*
|
867 |
SelectableDataSource sds = new SelectableDataSource(LayerFactory
|
868 |
.getDataSourceFactory().createRandomDataSource(
|
869 |
recordsetName, DataSourceFactory.MANUAL_OPENING));
|
870 |
*/
|
871 |
SelectableDataSource sds = new SelectableDataSource(LayerFactory
|
872 |
.getDataSourceFactory().createRandomDataSource( |
873 |
recordsetName, DataSourceFactory.AUTOMATIC_OPENING)); |
874 |
// sds.setSelectionSupport(selectionSupport);
|
875 |
// ((EditableAdapter)getSource()).setRecordSet(sds);
|
876 |
} catch (NoSuchTableException e1) {
|
877 |
this.setAvailable(false); |
878 |
throw new XMLException(e1); |
879 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
|
880 |
this.setAvailable(false); |
881 |
throw new XMLException(e1); |
882 |
} catch (DriverLoadException e1) {
|
883 |
this.setAvailable(false); |
884 |
throw new XMLException(e1); |
885 |
} catch (DriverException e1) {
|
886 |
this.setAvailable(false); |
887 |
throw new XMLException(e1); |
888 |
} |
889 |
// Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
890 |
// el final
|
891 |
// de la lectura del proyecto
|
892 |
if (xml.contains("hasJoin")) { |
893 |
setIsJoined(true);
|
894 |
PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1); |
895 |
} else {
|
896 |
/*
|
897 |
JMVIVO
|
898 |
this.setLoadLegend(leg);
|
899 |
*/
|
900 |
try {
|
901 |
// legend.setDataSource(getRecordset());
|
902 |
setLegend(leg); |
903 |
} catch (FieldNotFoundException e) {
|
904 |
throw new XMLException(e); |
905 |
} catch (DriverException e) {
|
906 |
throw new XMLException(e); |
907 |
} |
908 |
} |
909 |
|
910 |
} catch (XMLException e) {
|
911 |
this.setAvailable(false); |
912 |
this.orgXMLEntity = xml;
|
913 |
//throw e;
|
914 |
} catch (Exception e) { |
915 |
this.setAvailable(false); |
916 |
this.orgXMLEntity = xml;
|
917 |
//throw new XMLException(e);
|
918 |
} |
919 |
|
920 |
|
921 |
} |
922 |
|
923 |
public void setXMLEntityNew(XMLEntity xml) throws XMLException { |
924 |
try {
|
925 |
super.setXMLEntity(xml);
|
926 |
|
927 |
VectorialLegend leg = LegendFactory.createFromXML(xml.getChild(0));
|
928 |
try {
|
929 |
getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
930 |
|
931 |
this.setLoadSelection(xml.getChild(1)); |
932 |
/*
|
933 |
// JMVIVO: Esto sirve para algo????
|
934 |
String recordsetName = xml.getStringProperty("recordset-name");
|
935 |
|
936 |
LayerFactory.getDataSourceFactory().changeDataSourceName(
|
937 |
getSource().getRecordset().getName(), recordsetName);
|
938 |
// Hacemos que el recordset que hemos creado antes (los
|
939 |
// recordset se crean antes que todo) sea el recordset
|
940 |
// de esta capa. Y del que se crea automaticamente
|
941 |
// en el setLegend del createLayer, nos olvidamos
|
942 |
SelectableDataSource sds = new SelectableDataSource(LayerFactory
|
943 |
.getDataSourceFactory().createRandomDataSource(
|
944 |
recordsetName, DataSourceFactory.AUTOMATIC_OPENING));
|
945 |
// sds.setSelectionSupport(selectionSupport);
|
946 |
// ((EditableAdapter)getSource()).setRecordSet(sds);
|
947 |
|
948 |
|
949 |
} catch (NoSuchTableException e1) {
|
950 |
this.setAvailable(false);
|
951 |
throw new XMLException(e1);
|
952 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
|
953 |
this.setAvailable(false);
|
954 |
throw new XMLException(e1);
|
955 |
*/
|
956 |
} catch (DriverLoadException e1) {
|
957 |
this.setAvailable(false); |
958 |
throw new XMLException(e1); |
959 |
} catch (DriverException e1) {
|
960 |
this.setAvailable(false); |
961 |
throw new XMLException(e1); |
962 |
} |
963 |
// Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
964 |
// el final
|
965 |
// de la lectura del proyecto
|
966 |
if (xml.contains("hasJoin")) { |
967 |
setIsJoined(true);
|
968 |
PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1); |
969 |
} else {
|
970 |
|
971 |
|
972 |
this.setLoadLegend(leg);
|
973 |
/*
|
974 |
try {
|
975 |
// legend.setDataSource(getRecordset());
|
976 |
setLegend(leg);
|
977 |
} catch (FieldNotFoundException e) {
|
978 |
throw new XMLException(e);
|
979 |
} catch (DriverException e) {
|
980 |
throw new XMLException(e);
|
981 |
}
|
982 |
*/
|
983 |
} |
984 |
|
985 |
} catch (XMLException e) {
|
986 |
this.setAvailable(false); |
987 |
this.orgXMLEntity = xml;
|
988 |
//throw e;
|
989 |
} catch (Exception e) { |
990 |
this.setAvailable(false); |
991 |
this.orgXMLEntity = xml;
|
992 |
//throw new XMLException(e);
|
993 |
} |
994 |
|
995 |
|
996 |
} |
997 |
|
998 |
|
999 |
|
1000 |
/**
|
1001 |
* A?ade un LegendListener a la lista de Listeners.
|
1002 |
*
|
1003 |
* @param listener
|
1004 |
* LegendListener.
|
1005 |
*/
|
1006 |
public void addLegendListener(LegendListener listener) { |
1007 |
layerChangeSupport.addLayerListener(listener); |
1008 |
} |
1009 |
|
1010 |
/**
|
1011 |
* Llamada al m?todo callLegendChanged de los listener.
|
1012 |
*
|
1013 |
* @param e
|
1014 |
* Evento.
|
1015 |
*/
|
1016 |
private void callLegendChanged(LegendChangedEvent e) { |
1017 |
layerChangeSupport.callLegendChanged(e); |
1018 |
} |
1019 |
|
1020 |
/**
|
1021 |
* Borra un LegendListener de la lista de Listeners
|
1022 |
*
|
1023 |
* @param listener
|
1024 |
* LegendListener.
|
1025 |
*/
|
1026 |
public void removeLegendListener(LegendListener listener) { |
1027 |
layerChangeSupport.removeLayerListener(listener); |
1028 |
} |
1029 |
|
1030 |
/**
|
1031 |
* Sobreimplementaci?n del m?todo toString para que las bases de datos
|
1032 |
* identifiquen la capa.
|
1033 |
*
|
1034 |
* @return DOCUMENT ME!
|
1035 |
*/
|
1036 |
public String toString() { |
1037 |
/*
|
1038 |
* Se usa internamente para que la parte de datos identifique de forma
|
1039 |
* un?voca las tablas
|
1040 |
*/
|
1041 |
String ret = super.toString(); |
1042 |
|
1043 |
return "layer" + ret.substring(ret.indexOf('@') + 1); |
1044 |
} |
1045 |
|
1046 |
public boolean isJoined() { |
1047 |
return bHasJoin;
|
1048 |
} |
1049 |
|
1050 |
/**
|
1051 |
* Returns if a layer is spatially indexed
|
1052 |
*
|
1053 |
* @return if this layer has the ability to proces spatial queries without
|
1054 |
* secuential scans.
|
1055 |
*/
|
1056 |
public boolean isSpatiallyIndexed() { |
1057 |
ReadableVectorial source = getSource(); |
1058 |
if (source instanceof ISpatialDB) |
1059 |
return true; |
1060 |
|
1061 |
//FIXME azabala
|
1062 |
/*
|
1063 |
* Esto es muy dudoso, y puede cambiar.
|
1064 |
* Estoy diciendo que las que no son fichero o no son
|
1065 |
* BoundedShapes estan indexadas. Esto es mentira, pero
|
1066 |
* as? quien pregunte no querr? generar el indice.
|
1067 |
* Esta por ver si interesa generar el indice para capas
|
1068 |
* HSQLDB, WFS, etc.
|
1069 |
*/
|
1070 |
if(!(source instanceof VectorialFileAdapter)){ |
1071 |
return true; |
1072 |
} |
1073 |
if (!(source.getDriver() instanceof BoundedShapes)) { |
1074 |
return true; |
1075 |
} |
1076 |
|
1077 |
if (getISpatialIndex() != null) |
1078 |
return true; |
1079 |
return false; |
1080 |
} |
1081 |
|
1082 |
public void setIsJoined(boolean hasJoin) { |
1083 |
bHasJoin = hasJoin; |
1084 |
} |
1085 |
|
1086 |
/**
|
1087 |
* @return Returns the spatialIndex.
|
1088 |
*/
|
1089 |
public ISpatialIndex getISpatialIndex() {
|
1090 |
return spatialIndex;
|
1091 |
} |
1092 |
/**
|
1093 |
* Sets the spatial index. This could be useful if, for some
|
1094 |
* reasons, you want to work with a distinct spatial index
|
1095 |
* (for example, a spatial index which could makes nearest
|
1096 |
* neighbour querys)
|
1097 |
* @param spatialIndex
|
1098 |
*/
|
1099 |
public void setISpatialIndex(ISpatialIndex spatialIndex){ |
1100 |
this.spatialIndex = spatialIndex;
|
1101 |
} |
1102 |
|
1103 |
|
1104 |
/*
|
1105 |
* public SelectableDataSource getRecordset() { try { return
|
1106 |
* getSource().getRecordset(); } catch (DriverLoadException e) { // TODO
|
1107 |
* Auto-generated catch block e.printStackTrace(); } return null; }
|
1108 |
*/
|
1109 |
|
1110 |
/**
|
1111 |
* @throws DriverException
|
1112 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
1113 |
*/
|
1114 |
public SelectableDataSource getRecordset() throws DriverException { |
1115 |
if (!this.isAvailable()) return null; |
1116 |
if (sds == null) { |
1117 |
try {
|
1118 |
SelectableDataSource ds = source.getRecordset(); |
1119 |
|
1120 |
if (ds == null) { |
1121 |
return null; |
1122 |
} |
1123 |
|
1124 |
sds = ds; |
1125 |
sds.setSelectionSupport(selectionSupport); |
1126 |
|
1127 |
} catch (DriverLoadException e) {
|
1128 |
DriverNotLoadedExceptionType exceptionType = |
1129 |
new DriverNotLoadedExceptionType();
|
1130 |
exceptionType.setDriverName(source.getDriver().getName()); |
1131 |
throw new DriverException(e, exceptionType); |
1132 |
} |
1133 |
} |
1134 |
return sds;
|
1135 |
} |
1136 |
|
1137 |
/*
|
1138 |
* (non-Javadoc)
|
1139 |
*
|
1140 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setEditing(boolean)
|
1141 |
*/
|
1142 |
public void setEditing(boolean b) throws EditionException { |
1143 |
super.setEditing(b);
|
1144 |
try {
|
1145 |
if (b) {
|
1146 |
VectorialEditableAdapter vea = null;
|
1147 |
// TODO: Qu? pasa si hay m?s tipos de adapters?
|
1148 |
// FJP: Se podr?a pasar como argumento el
|
1149 |
// VectorialEditableAdapter
|
1150 |
// que se quiera usar para evitar meter c?digo aqu? de este
|
1151 |
// estilo.
|
1152 |
if (getSource() instanceof VectorialDBAdapter) { |
1153 |
vea = new VectorialEditableDBAdapter();
|
1154 |
} else if (this instanceof FLyrAnnotation) { |
1155 |
vea = new AnnotationEditableAdapter(
|
1156 |
(FLyrAnnotation) this);
|
1157 |
} else {
|
1158 |
vea = new VectorialEditableAdapter();
|
1159 |
} |
1160 |
vea.setOriginalVectorialAdapter(getSource()); |
1161 |
|
1162 |
// /vea.setSpatialIndex(getSpatialIndex());
|
1163 |
// /vea.setFullExtent(getFullExtent());
|
1164 |
//CHEMA
|
1165 |
vea.start(); |
1166 |
//CHEMA
|
1167 |
vea.startEdition(EditionEvent.GRAPHIC); |
1168 |
setSource(vea); |
1169 |
getRecordset().setSelectionSupport( |
1170 |
vea.getOriginalAdapter().getRecordset() |
1171 |
.getSelectionSupport()); |
1172 |
|
1173 |
} else {
|
1174 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) getSource(); |
1175 |
//CHEMA
|
1176 |
vea.stop(); |
1177 |
//CHEMA
|
1178 |
setSource(vea.getOriginalAdapter()); |
1179 |
} |
1180 |
// Si tenemos una leyenda, hay que pegarle el cambiazo a su
|
1181 |
// recordset
|
1182 |
setRecordset(getSource().getRecordset()); |
1183 |
if (getLegend() instanceof VectorialLegend) { |
1184 |
VectorialLegend ley = (VectorialLegend) getLegend(); |
1185 |
ley.setDataSource(getSource().getRecordset()); |
1186 |
// Esto lo pongo para evitar que al dibujar sobre un
|
1187 |
// dxf, dwg, o dgn no veamos nada. Es debido al checkbox
|
1188 |
// de la leyenda de textos "dibujar solo textos".
|
1189 |
if (!(getSource().getDriver() instanceof IndexedShpDriver)){ |
1190 |
if (ley.getDefaultSymbol()==null){ |
1191 |
FSymbol symbol=new FSymbol(getShapeType());
|
1192 |
symbol.setFontSizeInPixels(false);
|
1193 |
symbol.setFont(new Font("SansSerif", Font.PLAIN, 9)); |
1194 |
// Color color=symbol.getColor();
|
1195 |
// int alpha=symbol.getColor().getAlpha();
|
1196 |
// if (alpha>250) {
|
1197 |
// symbol.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),100));
|
1198 |
// }
|
1199 |
ley.setDefaultSymbol(symbol); |
1200 |
} |
1201 |
} |
1202 |
ley.useDefaultSymbol(true);
|
1203 |
} |
1204 |
} catch (DriverLoadException e) {
|
1205 |
e.printStackTrace(); |
1206 |
throw new EditionException(e); |
1207 |
} catch (DriverException e) {
|
1208 |
e.printStackTrace(); |
1209 |
throw new EditionException(e); |
1210 |
} catch (FieldNotFoundException e) {
|
1211 |
e.printStackTrace(); |
1212 |
throw new EditionException(e); |
1213 |
//CHEMA
|
1214 |
} catch (DriverIOException e) {
|
1215 |
e.printStackTrace(); |
1216 |
throw new EditionException(e); |
1217 |
//CHEMA
|
1218 |
} |
1219 |
|
1220 |
setSpatialCacheEnabled(b); |
1221 |
callEditionChanged(LayerEvent |
1222 |
.createEditionChangedEvent(this, "edition")); |
1223 |
|
1224 |
} |
1225 |
|
1226 |
/**
|
1227 |
* Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
1228 |
* forma, podr?s poner leyendas basadas en el nuevo recordset
|
1229 |
*
|
1230 |
* @param newSds
|
1231 |
*/
|
1232 |
public void setRecordset(SelectableDataSource newSds) { |
1233 |
sds = newSds; |
1234 |
sds.setSelectionSupport(selectionSupport); |
1235 |
} |
1236 |
/*
|
1237 |
* public SelectionSupport getSelectionSupport() { return selectionSupport; }
|
1238 |
*
|
1239 |
* public void setSelectionSupport(SelectionSupport selectionSupport) {
|
1240 |
* this.selectionSupport = selectionSupport; }
|
1241 |
*/
|
1242 |
|
1243 |
// public SpatialCache createSpatialCache() {
|
1244 |
// spatialCache = new SpatialCache();
|
1245 |
// return spatialCache;
|
1246 |
// }
|
1247 |
public void clearSpatialCache() |
1248 |
{ |
1249 |
spatialCache.clearAll(); |
1250 |
} |
1251 |
|
1252 |
// public void setSpatialCache(SpatialCache spatialCache) {
|
1253 |
// this.spatialCache = spatialCache;
|
1254 |
// }
|
1255 |
|
1256 |
public boolean isSpatialCacheEnabled() { |
1257 |
return spatialCacheEnabled;
|
1258 |
} |
1259 |
|
1260 |
public void setSpatialCacheEnabled(boolean spatialCacheEnabled) { |
1261 |
this.spatialCacheEnabled = spatialCacheEnabled;
|
1262 |
} |
1263 |
|
1264 |
public SpatialCache getSpatialCache() {
|
1265 |
return spatialCache;
|
1266 |
} |
1267 |
|
1268 |
/**
|
1269 |
* Siempre es un numero mayor de 1000
|
1270 |
* @param maxFeatures
|
1271 |
*/
|
1272 |
public void setMaxFeaturesInEditionCache(int maxFeatures) { |
1273 |
if (maxFeatures > spatialCache.maxFeatures)
|
1274 |
spatialCache.setMaxFeatures(maxFeatures); |
1275 |
|
1276 |
} |
1277 |
|
1278 |
/**
|
1279 |
* This method returns a boolean that is used by the FPopMenu
|
1280 |
* to make visible the properties menu or not. It is visible by
|
1281 |
* default, and if a later don't have to show this menu only
|
1282 |
* has to override this method.
|
1283 |
* @return
|
1284 |
* If the properties menu is visible (or not)
|
1285 |
*/
|
1286 |
public boolean isPropertiesMenuVisible(){ |
1287 |
return true; |
1288 |
} |
1289 |
|
1290 |
public void reload() throws DriverIOException { |
1291 |
super.reload();
|
1292 |
try {
|
1293 |
this.source.getDriver().reload();
|
1294 |
//this.getRecordset().reload();
|
1295 |
if (this.getLegend() == null) { |
1296 |
if (this.getRecordset().getDriver() instanceof WithDefaultLegend) { |
1297 |
WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
1298 |
this.setLegend((VectorialLegend) aux.getDefaultLegend());
|
1299 |
} else {
|
1300 |
this.setLegend(LegendFactory.createSingleSymbolLegend(
|
1301 |
this.getShapeType()));
|
1302 |
} |
1303 |
} |
1304 |
|
1305 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
1306 |
this.setAvailable(false); |
1307 |
throw new DriverIOException(e); |
1308 |
} catch (IOException e) { |
1309 |
this.setAvailable(false); |
1310 |
throw new DriverIOException(e); |
1311 |
} catch (DriverException e) {
|
1312 |
this.setAvailable(false); |
1313 |
throw new DriverIOException(e); |
1314 |
} catch (Exception e) { |
1315 |
this.setAvailable(false); |
1316 |
throw new DriverIOException(e); |
1317 |
} |
1318 |
|
1319 |
} |
1320 |
|
1321 |
protected void setLoadSelection(XMLEntity xml) { |
1322 |
this.loadSelection = xml;
|
1323 |
} |
1324 |
|
1325 |
protected void setLoadLegend(VectorialLegend legend) { |
1326 |
this.loadLegend = legend;
|
1327 |
} |
1328 |
|
1329 |
protected void putLoadSelection() throws XMLException { |
1330 |
if (this.loadSelection == null) return; |
1331 |
try {
|
1332 |
this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection); |
1333 |
} catch (DriverException e) {
|
1334 |
throw new XMLException(e); |
1335 |
} |
1336 |
this.loadSelection = null; |
1337 |
|
1338 |
} |
1339 |
protected void putLoadLegend() throws FieldNotFoundException, DriverException { |
1340 |
if (this.loadLegend == null) return; |
1341 |
|
1342 |
this.setLegend(this.loadLegend); |
1343 |
|
1344 |
this.loadLegend = null; |
1345 |
|
1346 |
} |
1347 |
|
1348 |
protected void cleanLoadOptions() { |
1349 |
this.loadLegend = null; |
1350 |
this.loadSelection = null; |
1351 |
} |
1352 |
|
1353 |
public boolean isWritable() { |
1354 |
VectorialDriver drv = getSource().getDriver(); |
1355 |
if (!drv.isWritable())
|
1356 |
return false; |
1357 |
// VectorialEditableAdapter vea = (VectorialEditableAdapter) lyrVect
|
1358 |
// .getSource();
|
1359 |
if (drv instanceof IWriteable) |
1360 |
{ |
1361 |
IWriter writer = ((IWriteable)drv).getWriter(); |
1362 |
if (writer != null) |
1363 |
{ |
1364 |
if (writer instanceof ISpatialWriter) |
1365 |
return true; |
1366 |
} |
1367 |
} |
1368 |
return false; |
1369 |
|
1370 |
} |
1371 |
|
1372 |
public void beforePrinting(PrintRequestAttributeSet properties) { |
1373 |
VectorialLegend vl=(VectorialLegend)getLegend(); |
1374 |
if (vl instanceof ClassifiedLegendInfo) { |
1375 |
ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) vl; |
1376 |
ISymbol[] symbols=clsfLegend.getSymbols();
|
1377 |
for (int i=0;i<symbols.length;i++) { |
1378 |
symbols[i].setPrintingProperties(properties); |
1379 |
} |
1380 |
} |
1381 |
if (vl.getDefaultSymbol()!=null) { |
1382 |
vl.getDefaultSymbol().setPrintingProperties(properties); |
1383 |
} |
1384 |
} |
1385 |
|
1386 |
public void afterPrinting() { |
1387 |
VectorialLegend vl=(VectorialLegend)getLegend(); |
1388 |
if (vl instanceof ClassifiedLegendInfo) { |
1389 |
ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) vl; |
1390 |
ISymbol[] symbols=clsfLegend.getSymbols();
|
1391 |
for (int i=0;i<symbols.length;i++) { |
1392 |
symbols[i].setPrintingProperties(null);
|
1393 |
} |
1394 |
} |
1395 |
if (vl.getDefaultSymbol()!=null) { |
1396 |
vl.getDefaultSymbol().setPrintingProperties(null);
|
1397 |
} |
1398 |
|
1399 |
} |
1400 |
|
1401 |
public FLayer cloneLayer() throws Exception { |
1402 |
FLyrVect clonedLayer = new FLyrVect();
|
1403 |
clonedLayer.setSource(getSource()); |
1404 |
clonedLayer.setVisible(isVisible()); |
1405 |
clonedLayer.setISpatialIndex(getISpatialIndex()); |
1406 |
clonedLayer.setName(getName()); |
1407 |
clonedLayer.setCoordTrans(getCoordTrans()); |
1408 |
|
1409 |
if (legend.getLabelField() != null) // Hay etiquetas |
1410 |
{ |
1411 |
FLyrText lyrText = getLayerText(); |
1412 |
String antLabelField = legend.getLabelField();
|
1413 |
VectorialLegend clonedLegend = (VectorialLegend) legend.cloneLegend(); |
1414 |
clonedLegend.setLabelField(null);
|
1415 |
clonedLayer.setLegend(clonedLegend); |
1416 |
clonedLayer.setLayerText(lyrText); |
1417 |
clonedLegend.setLabelField(antLabelField); |
1418 |
|
1419 |
} |
1420 |
else
|
1421 |
clonedLayer.setLegend((VectorialLegend)getLegend()); |
1422 |
return clonedLayer;
|
1423 |
} |
1424 |
|
1425 |
/**
|
1426 |
* This method tells the driver that the layer is going to be removed
|
1427 |
* from the view, if it is a VectorialDatabaseDriver, because those
|
1428 |
* drivers can have problems if that event is not notified.
|
1429 |
* This overwrites FLyrDefault.removingThisLayer().
|
1430 |
*/
|
1431 |
public void removingThisLayer() { |
1432 |
if (sds==null) |
1433 |
return;
|
1434 |
Driver drv = sds.getDriver();
|
1435 |
if (drv != null) { |
1436 |
if (drv instanceof VectorialDatabaseDriver) { |
1437 |
((VectorialDatabaseDriver) drv).remove(); |
1438 |
} |
1439 |
} else {
|
1440 |
logger.warn("Unable to send removing event to driver (driver is null)");
|
1441 |
} |
1442 |
|
1443 |
} |
1444 |
|
1445 |
} |