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