svn-gvsig-desktop / tags / v1_1_Build_1003 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 12271
History | View | Annotate | Download (43.7 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.awt.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.MapControl; |
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.IVectorialDatabaseDriver; |
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.setCoordTrans(getCoordTrans()); |
412 |
layerText.setLegend((VectorialLegend) getLegend()); |
413 |
layerText.createLabels(this);
|
414 |
} catch (FieldNotFoundException e1) {
|
415 |
// TODO Auto-generated catch block
|
416 |
e1.printStackTrace(); |
417 |
} catch (DriverException e1) {
|
418 |
// TODO Auto-generated catch block
|
419 |
e1.printStackTrace(); |
420 |
} |
421 |
|
422 |
setLayerText(layerText); |
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 |
if (getLegend()!=null) |
738 |
xml.addChild(getLegend().getXMLEntity()); |
739 |
try {
|
740 |
if (getRecordset()!=null) |
741 |
xml.addChild(getRecordset().getSelectionSupport().getXMLEntity()); |
742 |
} catch (DriverException e1) {
|
743 |
e1.printStackTrace(); |
744 |
throw new XMLException(e1); |
745 |
} |
746 |
//Repongo el mismo ReadableVectorial m?s abajo para cuando se guarda el proyecto.
|
747 |
ReadableVectorial rv=getSource(); |
748 |
xml.putProperty("type", "vectorial"); |
749 |
if (source instanceof VectorialEditableAdapter) { |
750 |
setSource(((VectorialEditableAdapter) source) |
751 |
.getOriginalAdapter()); |
752 |
} |
753 |
if (source instanceof VectorialFileAdapter) { |
754 |
xml.putProperty("file", ((VectorialFileAdapter) source)
|
755 |
.getFile()); |
756 |
try {
|
757 |
xml.putProperty("recordset-name", source
|
758 |
.getRecordset().getName()); |
759 |
} catch (DriverLoadException e) {
|
760 |
e.printStackTrace(); |
761 |
} catch (RuntimeException e) { |
762 |
e.printStackTrace(); |
763 |
} |
764 |
} else if (source instanceof VectorialDBAdapter) { |
765 |
IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) source |
766 |
.getDriver(); |
767 |
|
768 |
// Guardamos el nombre del driver para poder recuperarlo
|
769 |
// con el DriverManager de Fernando.
|
770 |
xml.putProperty("db", dbDriver.getName());
|
771 |
try {
|
772 |
xml.putProperty("recordset-name", source
|
773 |
.getRecordset().getName()); |
774 |
} catch (DriverLoadException e) {
|
775 |
e.printStackTrace(); |
776 |
} catch (RuntimeException e) { |
777 |
e.printStackTrace(); |
778 |
} |
779 |
if (dbDriver!=null) |
780 |
xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes
|
781 |
// hemos
|
782 |
// metido la leyenda y el
|
783 |
// selection support
|
784 |
} else if (source instanceof VectorialAdapter) { |
785 |
VectorialDriver driver = (VectorialDriver) source.getDriver(); |
786 |
|
787 |
// Guardamos el nombre del driver para poder recuperarlo
|
788 |
// con el DriverManager de Fernando.
|
789 |
xml.putProperty("other", driver.getName());
|
790 |
try {
|
791 |
xml.putProperty("recordset-name", source
|
792 |
.getRecordset().getName()); |
793 |
} catch (DriverLoadException e) {
|
794 |
e.printStackTrace(); |
795 |
} catch (RuntimeException e) { |
796 |
e.printStackTrace(); |
797 |
} |
798 |
if (driver instanceof IPersistance) { |
799 |
// xml.putProperty("className",
|
800 |
// driver.getClass().getName());
|
801 |
IPersistance persist = (IPersistance) driver; |
802 |
xml.addChild(persist.getXMLEntity()); // Tercer child.
|
803 |
// Antes
|
804 |
// hemos metido la
|
805 |
// leyenda y el
|
806 |
// selection support
|
807 |
} |
808 |
} |
809 |
if (rv!=null) |
810 |
setSource(rv); |
811 |
xml.putProperty("driverName", source.getDriver().getName());
|
812 |
|
813 |
if (bHasJoin)
|
814 |
xml.putProperty("hasJoin", "true"); |
815 |
|
816 |
return xml;
|
817 |
} |
818 |
|
819 |
/**
|
820 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
821 |
*/
|
822 |
public void setXMLEntity03(XMLEntity xml) throws XMLException { |
823 |
|
824 |
super.setXMLEntity(xml);
|
825 |
legend = LegendFactory.createFromXML03(xml.getChild(0));
|
826 |
|
827 |
try {
|
828 |
// legend.setDataSource(getRecordset());
|
829 |
setLegend(legend); |
830 |
} catch (FieldNotFoundException e) {
|
831 |
throw new XMLException(e); |
832 |
} catch (DriverException e) {
|
833 |
throw new XMLException(e); |
834 |
} |
835 |
|
836 |
try {
|
837 |
getRecordset().getSelectionSupport() |
838 |
.setXMLEntity03(xml.getChild(1));
|
839 |
} catch (DriverException e) {
|
840 |
e.printStackTrace(); |
841 |
} |
842 |
} |
843 |
|
844 |
/**
|
845 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
846 |
*/
|
847 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
848 |
try {
|
849 |
super.setXMLEntity(xml);
|
850 |
|
851 |
VectorialLegend leg = LegendFactory.createFromXML(xml.getChild(0));
|
852 |
try {
|
853 |
getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
854 |
/* JMVIVO
|
855 |
this.setLoadSelection(xml.getChild(1));
|
856 |
*/
|
857 |
// JMVIVO: Esto sirve para algo????
|
858 |
String recordsetName = xml.getStringProperty("recordset-name"); |
859 |
|
860 |
LayerFactory.getDataSourceFactory().changeDataSourceName( |
861 |
getSource().getRecordset().getName(), recordsetName); |
862 |
// Hacemos que el recordset que hemos creado antes (los
|
863 |
// recordset se crean antes que todo) sea el recordset
|
864 |
// de esta capa. Y del que se crea automaticamente
|
865 |
// en el setLegend del createLayer, nos olvidamos
|
866 |
// CHEMA: AUTOMATIC DATA SOURCE
|
867 |
/*
|
868 |
SelectableDataSource sds = new SelectableDataSource(LayerFactory
|
869 |
.getDataSourceFactory().createRandomDataSource(
|
870 |
recordsetName, DataSourceFactory.MANUAL_OPENING));
|
871 |
*/
|
872 |
SelectableDataSource sds = new SelectableDataSource(LayerFactory
|
873 |
.getDataSourceFactory().createRandomDataSource( |
874 |
recordsetName, DataSourceFactory.AUTOMATIC_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 |
//CHEMA
|
1166 |
vea.start(); |
1167 |
//CHEMA
|
1168 |
vea.startEdition(EditionEvent.GRAPHIC); |
1169 |
setSource(vea); |
1170 |
getRecordset().setSelectionSupport( |
1171 |
vea.getOriginalAdapter().getRecordset() |
1172 |
.getSelectionSupport()); |
1173 |
|
1174 |
} else {
|
1175 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) getSource(); |
1176 |
//CHEMA
|
1177 |
vea.stop(); |
1178 |
//CHEMA
|
1179 |
setSource(vea.getOriginalAdapter()); |
1180 |
} |
1181 |
// Si tenemos una leyenda, hay que pegarle el cambiazo a su
|
1182 |
// recordset
|
1183 |
setRecordset(getSource().getRecordset()); |
1184 |
if (getLegend() instanceof VectorialLegend) { |
1185 |
VectorialLegend ley = (VectorialLegend) getLegend(); |
1186 |
ley.setDataSource(getSource().getRecordset()); |
1187 |
// Esto lo pongo para evitar que al dibujar sobre un
|
1188 |
// dxf, dwg, o dgn no veamos nada. Es debido al checkbox
|
1189 |
// de la leyenda de textos "dibujar solo textos".
|
1190 |
if (!(getSource().getDriver() instanceof IndexedShpDriver)){ |
1191 |
if (ley.getDefaultSymbol()==null){ |
1192 |
FSymbol symbol=new FSymbol(getShapeType());
|
1193 |
symbol.setFontSizeInPixels(false);
|
1194 |
symbol.setFont(new Font("SansSerif", Font.PLAIN, 9)); |
1195 |
// Color color=symbol.getColor();
|
1196 |
// int alpha=symbol.getColor().getAlpha();
|
1197 |
// if (alpha>250) {
|
1198 |
// symbol.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),100));
|
1199 |
// }
|
1200 |
ley.setDefaultSymbol(symbol); |
1201 |
// }
|
1202 |
} |
1203 |
ley.useDefaultSymbol(true);
|
1204 |
} |
1205 |
} |
1206 |
} catch (DriverLoadException e) {
|
1207 |
e.printStackTrace(); |
1208 |
throw new EditionException(e); |
1209 |
} catch (DriverException e) {
|
1210 |
e.printStackTrace(); |
1211 |
throw new EditionException(e); |
1212 |
} catch (FieldNotFoundException e) {
|
1213 |
e.printStackTrace(); |
1214 |
throw new EditionException(e); |
1215 |
//CHEMA
|
1216 |
} catch (DriverIOException e) {
|
1217 |
e.printStackTrace(); |
1218 |
throw new EditionException(e); |
1219 |
//CHEMA
|
1220 |
} |
1221 |
|
1222 |
setSpatialCacheEnabled(b); |
1223 |
callEditionChanged(LayerEvent |
1224 |
.createEditionChangedEvent(this, "edition")); |
1225 |
|
1226 |
} |
1227 |
|
1228 |
/**
|
1229 |
* Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
1230 |
* forma, podr?s poner leyendas basadas en el nuevo recordset
|
1231 |
*
|
1232 |
* @param newSds
|
1233 |
*/
|
1234 |
public void setRecordset(SelectableDataSource newSds) { |
1235 |
sds = newSds; |
1236 |
sds.setSelectionSupport(selectionSupport); |
1237 |
} |
1238 |
/*
|
1239 |
* public SelectionSupport getSelectionSupport() { return selectionSupport; }
|
1240 |
*
|
1241 |
* public void setSelectionSupport(SelectionSupport selectionSupport) {
|
1242 |
* this.selectionSupport = selectionSupport; }
|
1243 |
*/
|
1244 |
|
1245 |
// public SpatialCache createSpatialCache() {
|
1246 |
// spatialCache = new SpatialCache();
|
1247 |
// return spatialCache;
|
1248 |
// }
|
1249 |
public void clearSpatialCache() |
1250 |
{ |
1251 |
spatialCache.clearAll(); |
1252 |
} |
1253 |
|
1254 |
// public void setSpatialCache(SpatialCache spatialCache) {
|
1255 |
// this.spatialCache = spatialCache;
|
1256 |
// }
|
1257 |
|
1258 |
public boolean isSpatialCacheEnabled() { |
1259 |
return spatialCacheEnabled;
|
1260 |
} |
1261 |
|
1262 |
public void setSpatialCacheEnabled(boolean spatialCacheEnabled) { |
1263 |
this.spatialCacheEnabled = spatialCacheEnabled;
|
1264 |
} |
1265 |
|
1266 |
public SpatialCache getSpatialCache() {
|
1267 |
return spatialCache;
|
1268 |
} |
1269 |
|
1270 |
/**
|
1271 |
* Siempre es un numero mayor de 1000
|
1272 |
* @param maxFeatures
|
1273 |
*/
|
1274 |
public void setMaxFeaturesInEditionCache(int maxFeatures) { |
1275 |
if (maxFeatures > spatialCache.maxFeatures)
|
1276 |
spatialCache.setMaxFeatures(maxFeatures); |
1277 |
|
1278 |
} |
1279 |
|
1280 |
/**
|
1281 |
* This method returns a boolean that is used by the FPopMenu
|
1282 |
* to make visible the properties menu or not. It is visible by
|
1283 |
* default, and if a later don't have to show this menu only
|
1284 |
* has to override this method.
|
1285 |
* @return
|
1286 |
* If the properties menu is visible (or not)
|
1287 |
*/
|
1288 |
public boolean isPropertiesMenuVisible(){ |
1289 |
return true; |
1290 |
} |
1291 |
|
1292 |
public void reload() throws DriverIOException { |
1293 |
super.reload();
|
1294 |
try {
|
1295 |
this.source.getDriver().reload();
|
1296 |
//this.getRecordset().reload();
|
1297 |
if (this.getLegend() == null) { |
1298 |
if (this.getRecordset().getDriver() instanceof WithDefaultLegend) { |
1299 |
WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
1300 |
this.setLegend((VectorialLegend) aux.getDefaultLegend());
|
1301 |
} else {
|
1302 |
this.setLegend(LegendFactory.createSingleSymbolLegend(
|
1303 |
this.getShapeType()));
|
1304 |
} |
1305 |
} |
1306 |
|
1307 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
1308 |
this.setAvailable(false); |
1309 |
throw new DriverIOException(e); |
1310 |
} catch (IOException e) { |
1311 |
this.setAvailable(false); |
1312 |
throw new DriverIOException(e); |
1313 |
} catch (DriverException e) {
|
1314 |
this.setAvailable(false); |
1315 |
throw new DriverIOException(e); |
1316 |
} catch (Exception e) { |
1317 |
this.setAvailable(false); |
1318 |
throw new DriverIOException(e); |
1319 |
} |
1320 |
|
1321 |
} |
1322 |
|
1323 |
protected void setLoadSelection(XMLEntity xml) { |
1324 |
this.loadSelection = xml;
|
1325 |
} |
1326 |
|
1327 |
protected void setLoadLegend(VectorialLegend legend) { |
1328 |
this.loadLegend = legend;
|
1329 |
} |
1330 |
|
1331 |
protected void putLoadSelection() throws XMLException { |
1332 |
if (this.loadSelection == null) return; |
1333 |
try {
|
1334 |
this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection); |
1335 |
} catch (DriverException e) {
|
1336 |
throw new XMLException(e); |
1337 |
} |
1338 |
this.loadSelection = null; |
1339 |
|
1340 |
} |
1341 |
protected void putLoadLegend() throws FieldNotFoundException, DriverException { |
1342 |
if (this.loadLegend == null) return; |
1343 |
|
1344 |
this.setLegend(this.loadLegend); |
1345 |
|
1346 |
this.loadLegend = null; |
1347 |
|
1348 |
} |
1349 |
|
1350 |
protected void cleanLoadOptions() { |
1351 |
this.loadLegend = null; |
1352 |
this.loadSelection = null; |
1353 |
} |
1354 |
|
1355 |
public boolean isWritable() { |
1356 |
VectorialDriver drv = getSource().getDriver(); |
1357 |
if (!drv.isWritable())
|
1358 |
return false; |
1359 |
// VectorialEditableAdapter vea = (VectorialEditableAdapter) lyrVect
|
1360 |
// .getSource();
|
1361 |
if (drv instanceof IWriteable) |
1362 |
{ |
1363 |
IWriter writer = ((IWriteable)drv).getWriter(); |
1364 |
if (writer != null) |
1365 |
{ |
1366 |
if (writer instanceof ISpatialWriter) |
1367 |
return true; |
1368 |
} |
1369 |
} |
1370 |
return false; |
1371 |
|
1372 |
} |
1373 |
|
1374 |
public void beforePrinting(PrintRequestAttributeSet properties) { |
1375 |
VectorialLegend vl=(VectorialLegend)getLegend(); |
1376 |
if (vl instanceof ClassifiedLegendInfo) { |
1377 |
ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) vl; |
1378 |
ISymbol[] symbols=clsfLegend.getSymbols();
|
1379 |
for (int i=0;i<symbols.length;i++) { |
1380 |
symbols[i].setPrintingProperties(properties); |
1381 |
} |
1382 |
} |
1383 |
if (vl.getDefaultSymbol()!=null) { |
1384 |
vl.getDefaultSymbol().setPrintingProperties(properties); |
1385 |
} |
1386 |
} |
1387 |
|
1388 |
public void afterPrinting() { |
1389 |
VectorialLegend vl=(VectorialLegend)getLegend(); |
1390 |
if (vl instanceof ClassifiedLegendInfo) { |
1391 |
ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) vl; |
1392 |
ISymbol[] symbols=clsfLegend.getSymbols();
|
1393 |
for (int i=0;i<symbols.length;i++) { |
1394 |
symbols[i].setPrintingProperties(null);
|
1395 |
} |
1396 |
} |
1397 |
if (vl.getDefaultSymbol()!=null) { |
1398 |
vl.getDefaultSymbol().setPrintingProperties(null);
|
1399 |
} |
1400 |
|
1401 |
} |
1402 |
|
1403 |
public FLayer cloneLayer() throws Exception { |
1404 |
FLyrVect clonedLayer = new FLyrVect();
|
1405 |
clonedLayer.setSource(getSource()); |
1406 |
clonedLayer.setVisible(isVisible()); |
1407 |
clonedLayer.setISpatialIndex(getISpatialIndex()); |
1408 |
clonedLayer.setName(getName()); |
1409 |
clonedLayer.setCoordTrans(getCoordTrans()); |
1410 |
|
1411 |
if (legend.getLabelField() != null) // Hay etiquetas |
1412 |
{ |
1413 |
FLyrText lyrText = getLayerText(); |
1414 |
String antLabelField = legend.getLabelField();
|
1415 |
VectorialLegend clonedLegend = (VectorialLegend) legend.cloneLegend(); |
1416 |
clonedLegend.setLabelField(null);
|
1417 |
clonedLayer.setLegend(clonedLegend); |
1418 |
clonedLayer.setLayerText(lyrText); |
1419 |
clonedLegend.setLabelField(antLabelField); |
1420 |
|
1421 |
} |
1422 |
else
|
1423 |
clonedLayer.setLegend((VectorialLegend)getLegend()); |
1424 |
return clonedLayer;
|
1425 |
} |
1426 |
|
1427 |
/**
|
1428 |
* This method tells the driver that the layer is going to be removed
|
1429 |
* from the view, if it is a VectorialDatabaseDriver, because those
|
1430 |
* drivers can have problems if that event is not notified.
|
1431 |
* This overwrites FLyrDefault.removingThisLayer().
|
1432 |
*/
|
1433 |
public void removingThisLayer() { |
1434 |
if (sds==null) |
1435 |
return;
|
1436 |
Driver drv = sds.getDriver();
|
1437 |
if (drv != null) { |
1438 |
if (drv instanceof IVectorialDatabaseDriver) { |
1439 |
((IVectorialDatabaseDriver) drv).remove(); |
1440 |
} |
1441 |
} else {
|
1442 |
logger.warn("Unable to send removing event to driver (driver is null)");
|
1443 |
} |
1444 |
|
1445 |
} |
1446 |
|
1447 |
/**
|
1448 |
* Devuelve true en el caso de que el tipo de capa sea reproyectable.
|
1449 |
*/
|
1450 |
public boolean isReprojectable() { |
1451 |
return true; |
1452 |
} |
1453 |
|
1454 |
/**
|
1455 |
* Reproyecta una capa. Cada tipo de capa reimplementa este m?todo realizando las operaciones
|
1456 |
* que le son necesarias.
|
1457 |
*/
|
1458 |
public boolean reProject(MapControl mapC) { |
1459 |
ViewPort vPort = mapC.getViewPort(); |
1460 |
ICoordTrans ct = this.getProjection().getCT(vPort.getProjection());
|
1461 |
this.setCoordTrans(ct);
|
1462 |
|
1463 |
System.err.println("coordTrans = " + this.getProjection().getAbrev() + " " |
1464 |
+ vPort.getProjection().getAbrev()); |
1465 |
|
1466 |
return true; |
1467 |
} |
1468 |
} |