svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 12043
History | View | Annotate | Download (40.1 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.awt.Graphics2D; |
44 |
import java.awt.Point; |
45 |
import java.awt.geom.Point2D; |
46 |
import java.awt.geom.Rectangle2D; |
47 |
import java.awt.image.BufferedImage; |
48 |
import java.io.File; |
49 |
import java.util.ArrayList; |
50 |
|
51 |
import javax.print.attribute.PrintRequestAttributeSet; |
52 |
|
53 |
import org.apache.log4j.Logger; |
54 |
import org.cresques.cts.ICoordTrans; |
55 |
|
56 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
57 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
58 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
59 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
60 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
61 |
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
62 |
import com.iver.cit.gvsig.exceptions.layers.ReloadLayerException; |
63 |
import com.iver.cit.gvsig.exceptions.layers.StartEditionLayerException; |
64 |
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException; |
65 |
import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
66 |
import com.iver.cit.gvsig.fmap.ViewPort; |
67 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
68 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
69 |
import com.iver.cit.gvsig.fmap.core.ILabelable; |
70 |
import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol; |
71 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
72 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
73 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
74 |
import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver; |
75 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
76 |
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend; |
77 |
import com.iver.cit.gvsig.fmap.edition.AnnotationEditableAdapter; |
78 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
79 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
80 |
import com.iver.cit.gvsig.fmap.edition.IWriteable; |
81 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
82 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
83 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableDBAdapter; |
84 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
85 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
86 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
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.rendering.ILegend; |
96 |
import com.iver.cit.gvsig.fmap.rendering.IVectorialLegend; |
97 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
98 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
99 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
100 |
import com.iver.cit.gvsig.fmap.rendering.ZSort; |
101 |
import com.iver.cit.gvsig.fmap.rendering.styling.AttrInTableLabeling; |
102 |
import com.iver.cit.gvsig.fmap.rendering.styling.ILabelingStrategy; |
103 |
import com.iver.cit.gvsig.fmap.rendering.styling.LabelingFactory; |
104 |
import com.iver.cit.gvsig.fmap.spatialindex.IPersistentSpatialIndex; |
105 |
import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex; |
106 |
import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeGt2; |
107 |
import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeJts; |
108 |
import com.iver.cit.gvsig.fmap.spatialindex.SpatialIndexException; |
109 |
import com.iver.utiles.FileUtils; |
110 |
import com.iver.utiles.IPersistance; |
111 |
import com.iver.utiles.NotExistInXMLEntity; |
112 |
import com.iver.utiles.PostProcessSupport; |
113 |
import com.iver.utiles.XMLEntity; |
114 |
import com.iver.utiles.swing.threads.Cancellable; |
115 |
import com.iver.utiles.swing.threads.CancellableMonitorable; |
116 |
|
117 |
/**
|
118 |
* Capa b?sica Vectorial.
|
119 |
*
|
120 |
* @author Fernando Gonz?lez Cort?s
|
121 |
*/
|
122 |
|
123 |
// TODO Cuando no sea para pruebas debe no ser public
|
124 |
public class FLyrVect extends FLyrDefault implements ILabelable, |
125 |
ClassifiableVectorial, SingleLayer, VectorialData, RandomVectorialData, |
126 |
AlphanumericData, InfoByPoint { |
127 |
private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
128 |
|
129 |
/** Leyenda de la capa vectorial */
|
130 |
private IVectorialLegend legend;
|
131 |
private int typeShape = -1; |
132 |
private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
133 |
private ReadableVectorial source;
|
134 |
private SelectableDataSource sds;
|
135 |
private SelectionSupport selectionSupport = new SelectionSupport(); |
136 |
private SpatialCache spatialCache = new SpatialCache(); |
137 |
private boolean spatialCacheEnabled = false; |
138 |
|
139 |
/**
|
140 |
* An implementation of gvSIG spatial index
|
141 |
*/
|
142 |
protected ISpatialIndex spatialIndex = null; |
143 |
private boolean bHasJoin = false; |
144 |
private XMLEntity orgXMLEntity = null; |
145 |
private XMLEntity loadSelection = null; |
146 |
private IVectorialLegend loadLegend = null; |
147 |
|
148 |
/**
|
149 |
* Devuelve el VectorialAdapater de la capa.
|
150 |
*
|
151 |
* @return VectorialAdapter.
|
152 |
*/
|
153 |
public ReadableVectorial getSource() {
|
154 |
if (!this.isAvailable()) return null; |
155 |
return source;
|
156 |
} |
157 |
|
158 |
/**
|
159 |
* If we use a persistent spatial index associated with this layer, and the
|
160 |
* index is not intrisic to the layer (for example spatial databases) this
|
161 |
* method looks for existent spatial index, and loads it.
|
162 |
*
|
163 |
*/
|
164 |
private void loadSpatialIndex() { |
165 |
//FIXME: Al abrir el indice en fichero...
|
166 |
//?C?mo lo liberamos? un metodo Layer.shutdown()
|
167 |
|
168 |
|
169 |
ReadableVectorial source = getSource(); |
170 |
//REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
|
171 |
//PUES SON VECTORIALFILEADAPTER
|
172 |
if (!(source instanceof VectorialFileAdapter)) { |
173 |
// we are not interested in db adapters
|
174 |
return;
|
175 |
} |
176 |
VectorialDriver driver = source.getDriver(); |
177 |
if (!(driver instanceof BoundedShapes)) { |
178 |
// we dont spatially index layers that are not bounded
|
179 |
return;
|
180 |
} |
181 |
File file = ((VectorialFileAdapter) source).getFile();
|
182 |
String fileName = file.getAbsolutePath();
|
183 |
File sptFile = new File(fileName + ".qix"); |
184 |
if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
185 |
// before to exit, look for it in temp path
|
186 |
String tempPath = System.getProperty("java.io.tmpdir"); |
187 |
fileName = tempPath + File.separator + sptFile.getName();
|
188 |
sptFile = new File(fileName); |
189 |
// it doesnt exists, must to create
|
190 |
if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
191 |
return;
|
192 |
}// if
|
193 |
}// if
|
194 |
|
195 |
try {
|
196 |
source.start(); |
197 |
spatialIndex = new QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
|
198 |
"NM", source.getFullExtent(), source.getShapeCount(), false); |
199 |
source.setSpatialIndex(spatialIndex); |
200 |
} catch (SpatialIndexException e) {
|
201 |
spatialIndex = null;
|
202 |
e.printStackTrace(); |
203 |
return;
|
204 |
} catch (ReadDriverException e) {
|
205 |
spatialIndex = null;
|
206 |
e.printStackTrace(); |
207 |
return;
|
208 |
} catch (ExpansionFileReadException e) {
|
209 |
spatialIndex = null;
|
210 |
e.printStackTrace(); |
211 |
return;
|
212 |
} |
213 |
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* Checks if it has associated an external spatial index
|
218 |
* (an spatial index file).
|
219 |
*
|
220 |
* It looks for it in main file path, or in temp system path.
|
221 |
* If main file is rivers.shp, it looks for a file called
|
222 |
* rivers.shp.qix.
|
223 |
|
224 |
* @return
|
225 |
*/
|
226 |
public boolean isExternallySpatiallyIndexed() { |
227 |
/*
|
228 |
* FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
|
229 |
* con el que se trabaje (ahora mismo considera la extension .qix,
|
230 |
* pero esto depender? del tipo de ?ndice)
|
231 |
* */
|
232 |
ReadableVectorial source = getSource(); |
233 |
if (!(source instanceof VectorialFileAdapter)) { |
234 |
// we are not interested in db adapters.
|
235 |
// think in non spatial dbs, like HSQLDB
|
236 |
return false; |
237 |
} |
238 |
File file = ((VectorialFileAdapter) source).getFile();
|
239 |
String fileName = file.getAbsolutePath();
|
240 |
File sptFile = new File(fileName + ".qix"); |
241 |
if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
242 |
// before to exit, look for it in temp path
|
243 |
// it doesnt exists, must to create
|
244 |
String tempPath = System.getProperty("java.io.tmpdir"); |
245 |
fileName = tempPath + File.separator + sptFile.getName();
|
246 |
sptFile = new File(fileName); |
247 |
if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
248 |
return false; |
249 |
}// if
|
250 |
}// if
|
251 |
return true; |
252 |
} |
253 |
|
254 |
/**
|
255 |
* Inserta el VectorialAdapter a la capa.
|
256 |
*
|
257 |
* @param va
|
258 |
* VectorialAdapter.
|
259 |
*/
|
260 |
public void setSource(ReadableVectorial rv) { |
261 |
source = rv; |
262 |
// azabala: we check if this layer could have a file spatial index
|
263 |
// and load it if it exists
|
264 |
loadSpatialIndex(); |
265 |
} |
266 |
|
267 |
public Rectangle2D getFullExtent() throws ReadDriverException, ExpansionFileReadException { |
268 |
Rectangle2D rAux;
|
269 |
source.start(); |
270 |
rAux = (Rectangle2D)source.getFullExtent().clone();
|
271 |
source.stop(); |
272 |
|
273 |
// Si existe reproyecci?n, reproyectar el extent
|
274 |
ICoordTrans ct = getCoordTrans(); |
275 |
|
276 |
if (ct != null) { |
277 |
Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
278 |
Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
279 |
pt1 = ct.convert(pt1, null);
|
280 |
pt2 = ct.convert(pt2, null);
|
281 |
rAux = new Rectangle2D.Double(); |
282 |
rAux.setFrameFromDiagonal(pt1, pt2); |
283 |
} |
284 |
|
285 |
//Esto es para cuando se crea una capa nueva con el fullExtent de ancho y alto 0.
|
286 |
if (rAux.getWidth()==0 && rAux.getHeight()==0) { |
287 |
rAux=new Rectangle2D.Double(0,0,100,100); |
288 |
} |
289 |
|
290 |
return rAux;
|
291 |
} |
292 |
|
293 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
294 |
Cancellable cancel, double scale) throws ReadDriverException { |
295 |
// FEATURE ITERATORS (TEST METHOD)
|
296 |
if (isWithinScale(scale)) {
|
297 |
// Las que solo tienen etiquetado sin pintar el shape,
|
298 |
// no pasamos por ellas
|
299 |
|
300 |
|
301 |
|
302 |
boolean bDrawShapes = true; |
303 |
if (legend instanceof SingleSymbolLegend) { |
304 |
if (legend.getDefaultSymbol().isShapeVisible() == false) |
305 |
bDrawShapes = false;
|
306 |
} |
307 |
if (bDrawShapes) {
|
308 |
try {
|
309 |
prepareDrawing(image, g, viewPort); |
310 |
ArrayList fieldList = new ArrayList(); |
311 |
|
312 |
// fields from legend
|
313 |
String[] aux = legend.getUsedFields(); |
314 |
for (int i = 0; i < aux.length; i++) { |
315 |
fieldList.add(aux[i]); |
316 |
} |
317 |
|
318 |
// fields from labeling
|
319 |
if (isLabeled()) {
|
320 |
aux = getLabelingStrategy().getUsedFields(); |
321 |
for (int i = 0; i < aux.length; i++) { |
322 |
fieldList.add(aux[i]); |
323 |
} |
324 |
} |
325 |
|
326 |
IFeatureIterator it = getSource().getFeatureIterator( |
327 |
viewPort.getAdjustedExtent(), |
328 |
//(String[]) fieldList.toArray(new String[fieldList.size()]),
|
329 |
null,
|
330 |
getProjection(), true);
|
331 |
ZSort zSort = ((IVectorialLegend) getLegend()).getZSort(); |
332 |
if (zSort != null && zSort.isUsingZSort()) { |
333 |
|
334 |
|
335 |
|
336 |
|
337 |
BufferedImage[] imageLevels = new BufferedImage[zSort.getLevelCount()+1]; |
338 |
Graphics2D[] graphics = new Graphics2D[imageLevels.length]; |
339 |
for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) { |
340 |
imageLevels[i] = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); |
341 |
graphics[i] = imageLevels[i].createGraphics(); |
342 |
} |
343 |
|
344 |
// -- visual FX stuff
|
345 |
int screenRefreshRate = 1000; // render temporary map each screenRefreshRate milliseconds; |
346 |
long time = System.currentTimeMillis(); |
347 |
|
348 |
BufferedImage virtualBim;
|
349 |
Graphics2D virtualGraphics;
|
350 |
// -- end visual FX stuff
|
351 |
|
352 |
while ( !cancel.isCanceled() && it.hasNext()) {
|
353 |
|
354 |
IFeature feat = it.next(); |
355 |
IGeometry geom = feat.getGeometry(); |
356 |
|
357 |
ISymbol sym = legend.getSymbolByFeature(feat); |
358 |
if (sym instanceof IMultiLayerSymbol) { |
359 |
IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym; |
360 |
for (int i = 0; i < mlSym.getLayerCount(); i++) { |
361 |
ISymbol mySym = mlSym.getLayer(i); |
362 |
geom.drawInts(graphics[zSort.getSymbolLevel(mySym)], viewPort, mySym); |
363 |
} |
364 |
} else {
|
365 |
geom.drawInts(graphics[zSort.getSymbolLevel(sym)], viewPort, sym); |
366 |
} |
367 |
|
368 |
// -- visual FX stuff
|
369 |
if ((System.currentTimeMillis() - time) > screenRefreshRate) { |
370 |
time = System.currentTimeMillis();
|
371 |
virtualBim = new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_INT_ARGB); |
372 |
virtualGraphics = virtualBim.createGraphics(); |
373 |
virtualGraphics.drawImage(image,0,0,null); |
374 |
for (int i = 0; i < imageLevels.length; i++) { |
375 |
virtualGraphics.drawImage(imageLevels[i],0,0, null); |
376 |
} |
377 |
g.clearRect(0, 0, image.getWidth(), image.getHeight()); |
378 |
g.drawImage(virtualBim, 0, 0, null); |
379 |
} |
380 |
// -- end visual FX stuff
|
381 |
|
382 |
} |
383 |
g.drawImage(image, 0, 0, null); |
384 |
for (int i = 0; i < imageLevels.length; i++) { |
385 |
g.drawImage(imageLevels[i],0,0, null); |
386 |
imageLevels[i] = null;
|
387 |
graphics[i] = null;
|
388 |
} |
389 |
imageLevels = null;
|
390 |
graphics = null;
|
391 |
} else {
|
392 |
int i =0 ; |
393 |
while ( !cancel.isCanceled() && it.hasNext() ) {
|
394 |
|
395 |
IFeature feat = it.next(); |
396 |
ISymbol sym = legend.getSymbolByFeature(feat); |
397 |
IGeometry geom = feat.getGeometry(); |
398 |
geom.drawInts(g, viewPort, sym); |
399 |
i++; |
400 |
} |
401 |
} |
402 |
} catch (ReadDriverException e) {
|
403 |
this.setVisible(false); |
404 |
this.setActive(false); |
405 |
throw e;
|
406 |
} catch (ExpansionFileReadException e) {
|
407 |
this.setVisible(false); |
408 |
this.setActive(false); |
409 |
// throw new DriverException(e);
|
410 |
// TODO throw a correct exception (??? ReadDriverException ???)
|
411 |
e.printStackTrace(); |
412 |
} |
413 |
} |
414 |
if (getVirtualLayers() != null) { |
415 |
getVirtualLayers().draw(image, g, viewPort, cancel, scale); |
416 |
} |
417 |
} |
418 |
} |
419 |
|
420 |
public void _draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
421 |
Cancellable cancel, double scale) throws ReadDriverException { |
422 |
|
423 |
if (isWithinScale(scale)) {
|
424 |
|
425 |
|
426 |
// Las que solo tienen etiquetado sin pintar el shape,
|
427 |
// no pasamos por ellas
|
428 |
boolean bDrawShapes = true; |
429 |
if (legend instanceof SingleSymbolLegend) { |
430 |
if (legend.getDefaultSymbol().isShapeVisible() == false) |
431 |
bDrawShapes = false;
|
432 |
} |
433 |
if (bDrawShapes) {
|
434 |
Strategy strategy = StrategyManager.getStrategy(this);
|
435 |
try {
|
436 |
prepareDrawing(image, g, viewPort); |
437 |
strategy.draw(image, g, viewPort, cancel); |
438 |
} catch (ReadDriverException e) {
|
439 |
this.setVisible(false); |
440 |
this.setActive(false); |
441 |
throw e;
|
442 |
} |
443 |
} |
444 |
if (getVirtualLayers() != null) { |
445 |
getVirtualLayers().draw(image, g, viewPort, cancel, scale); |
446 |
} |
447 |
} |
448 |
} |
449 |
|
450 |
/**
|
451 |
* Se llama antes de empezar a pintar.
|
452 |
* Es ?til para preparar la cache a emplear, las leyendas, etc.
|
453 |
* @param image
|
454 |
* @param g
|
455 |
* @param viewPort
|
456 |
*/
|
457 |
private void prepareDrawing(BufferedImage image, Graphics2D g, ViewPort viewPort) { |
458 |
|
459 |
} |
460 |
|
461 |
public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
462 |
double scale, PrintRequestAttributeSet properties) throws ReadDriverException { |
463 |
// TEST METHOD
|
464 |
draw(null, g, viewPort, cancel, scale);
|
465 |
} |
466 |
|
467 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
468 |
double scale, PrintRequestAttributeSet properties) throws ReadDriverException { |
469 |
if (isVisible() && isWithinScale(scale)) {
|
470 |
Strategy strategy = StrategyManager.getStrategy(this);
|
471 |
|
472 |
strategy.print(g, viewPort, cancel, properties); |
473 |
ILabelingStrategy labeling; |
474 |
if ( (labeling = getLabelingStrategy() ) != null) { |
475 |
// contains labels
|
476 |
labeling.print(g, viewPort, cancel, properties); |
477 |
} |
478 |
} |
479 |
} |
480 |
|
481 |
|
482 |
public void deleteSpatialIndex() { |
483 |
//must we delete possible spatial indexes files?
|
484 |
spatialIndex = null;
|
485 |
} |
486 |
|
487 |
|
488 |
|
489 |
/**
|
490 |
* <p>
|
491 |
* Creates an spatial index associated to this layer.
|
492 |
* The spatial index will used
|
493 |
* the native projection of the layer, so if the layer is reprojected, it will
|
494 |
* be ignored.
|
495 |
* </p>
|
496 |
* @param cancelMonitor instance of CancellableMonitorable that allows
|
497 |
* to monitor progress of spatial index creation, and cancel the process
|
498 |
*/
|
499 |
public void createSpatialIndex(CancellableMonitorable cancelMonitor){ |
500 |
// FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
501 |
// QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
502 |
// para que acepten recorrer sin geometria, solo con rectangulos.
|
503 |
|
504 |
//If this vectorial layer is based in a spatial database, the spatial
|
505 |
//index is already implicit. We only will index file drivers
|
506 |
ReadableVectorial va = getSource(); |
507 |
//We must think in non spatial databases, like HSQLDB
|
508 |
if(!(va instanceof VectorialFileAdapter)){ |
509 |
return;
|
510 |
} |
511 |
if (!(va.getDriver() instanceof BoundedShapes)) { |
512 |
return;
|
513 |
} |
514 |
File file = ((VectorialFileAdapter) va).getFile();
|
515 |
String fileName = file.getAbsolutePath();
|
516 |
ISpatialIndex localCopy = null;
|
517 |
try {
|
518 |
va.start(); |
519 |
localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(), |
520 |
va.getShapeCount(), true);
|
521 |
|
522 |
} catch (SpatialIndexException e1) {
|
523 |
// Probably we dont have writing permissions
|
524 |
String directoryName = System.getProperty("java.io.tmpdir"); |
525 |
File newFile = new File(directoryName + |
526 |
File.separator +
|
527 |
file.getName()); |
528 |
String newFileName = newFile.getName();
|
529 |
try {
|
530 |
localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(), |
531 |
va.getShapeCount(), true);
|
532 |
} catch (SpatialIndexException e) {
|
533 |
// if we cant build a file based spatial index, we'll build
|
534 |
// a pure memory spatial index
|
535 |
localCopy = new QuadtreeJts();
|
536 |
} catch (ReadDriverException e) {
|
537 |
localCopy = new QuadtreeJts();
|
538 |
} catch (ExpansionFileReadException e) {
|
539 |
localCopy = new QuadtreeJts();
|
540 |
} |
541 |
|
542 |
}catch(Exception e){ |
543 |
e.printStackTrace(); |
544 |
}//try
|
545 |
BoundedShapes shapeBounds = (BoundedShapes) va.getDriver(); |
546 |
try {
|
547 |
for (int i=0; i < va.getShapeCount(); i++) |
548 |
{ |
549 |
if(cancelMonitor != null){ |
550 |
if(cancelMonitor.isCanceled())
|
551 |
return;
|
552 |
cancelMonitor.reportStep(); |
553 |
} |
554 |
Rectangle2D r = shapeBounds.getShapeBounds(i);
|
555 |
if(r != null) |
556 |
localCopy.insert(r, i); |
557 |
} // for
|
558 |
va.stop(); |
559 |
if(localCopy instanceof IPersistentSpatialIndex) |
560 |
((IPersistentSpatialIndex) localCopy).flush(); |
561 |
spatialIndex = localCopy; |
562 |
//vectorial adapter needs a reference to the spatial index, to solve
|
563 |
//request for feature iteration based in spatial queries
|
564 |
source.setSpatialIndex(spatialIndex); |
565 |
} catch (ReadDriverException e) {
|
566 |
// TODO Auto-generated catch block
|
567 |
e.printStackTrace(); |
568 |
} catch (ExpansionFileReadException e) {
|
569 |
// TODO Auto-generated catch block
|
570 |
e.printStackTrace(); |
571 |
} |
572 |
} |
573 |
|
574 |
public void createSpatialIndex() { |
575 |
createSpatialIndex(null);
|
576 |
} |
577 |
|
578 |
public void process(FeatureVisitor visitor, FBitSet subset) |
579 |
throws ReadDriverException, ExpansionFileReadException, VisitorException {
|
580 |
Strategy s = StrategyManager.getStrategy(this);
|
581 |
s.process(visitor, subset); |
582 |
} |
583 |
|
584 |
public void process(FeatureVisitor visitor) throws ReadDriverException, VisitorException { |
585 |
Strategy s = StrategyManager.getStrategy(this);
|
586 |
s.process(visitor); |
587 |
} |
588 |
|
589 |
public void process(FeatureVisitor visitor, Rectangle2D rect) |
590 |
throws ReadDriverException, ExpansionFileReadException, VisitorException {
|
591 |
Strategy s = StrategyManager.getStrategy(this);
|
592 |
s.process(visitor, rect); |
593 |
} |
594 |
|
595 |
public FBitSet queryByRect(Rectangle2D rect) throws ReadDriverException, VisitorException { |
596 |
Strategy s = StrategyManager.getStrategy(this);
|
597 |
|
598 |
return s.queryByRect(rect);
|
599 |
} |
600 |
|
601 |
public FBitSet queryByPoint(Point2D p, double tolerance) |
602 |
throws ReadDriverException, VisitorException {
|
603 |
Strategy s = StrategyManager.getStrategy(this);
|
604 |
return s.queryByPoint(p, tolerance);
|
605 |
} |
606 |
|
607 |
public FBitSet queryByShape(IGeometry g, int relationship) |
608 |
throws ReadDriverException, VisitorException {
|
609 |
Strategy s = StrategyManager.getStrategy(this);
|
610 |
return s.queryByShape(g, relationship);
|
611 |
} |
612 |
|
613 |
public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws ReadDriverException, VisitorException { |
614 |
Point2D pReal = this.getMapContext().getViewPort().toMapPoint(p); |
615 |
FBitSet bs = queryByPoint(pReal, tolerance); |
616 |
VectorialXMLItem[] item = new VectorialXMLItem[1]; |
617 |
item[0] = new VectorialXMLItem(bs, this); |
618 |
|
619 |
return item;
|
620 |
} |
621 |
|
622 |
public void setLegend(IVectorialLegend r) throws LegendLayerException { |
623 |
IVectorialLegend oldLegend = legend; |
624 |
legend = r; |
625 |
try {
|
626 |
legend.setDataSource(getRecordset()); |
627 |
} catch (FieldNotFoundException e1) {
|
628 |
throw new LegendLayerException(getName(),e1); |
629 |
} catch (ReadDriverException e1) {
|
630 |
throw new LegendLayerException(getName(),e1); |
631 |
} |
632 |
LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent( |
633 |
oldLegend, legend); |
634 |
callLegendChanged(e); |
635 |
} |
636 |
|
637 |
/**
|
638 |
* Devuelve la Leyenda de la capa.
|
639 |
*
|
640 |
* @return Leyenda.
|
641 |
*/
|
642 |
public ILegend getLegend() {
|
643 |
return legend;
|
644 |
} |
645 |
|
646 |
/**
|
647 |
* Devuelve el tipo de shape que contiene la capa.
|
648 |
*
|
649 |
* @return tipo de shape.
|
650 |
*
|
651 |
* @throws DriverException
|
652 |
*/
|
653 |
public int getShapeType() throws ReadDriverException { |
654 |
if (typeShape == -1) { |
655 |
getSource().start(); |
656 |
typeShape = getSource().getShapeType(); |
657 |
getSource().stop(); |
658 |
} |
659 |
|
660 |
return typeShape;
|
661 |
} |
662 |
|
663 |
public XMLEntity getXMLEntity() throws XMLException { |
664 |
if (!this.isAvailable() && this.orgXMLEntity != null) { |
665 |
return this.orgXMLEntity; |
666 |
} |
667 |
XMLEntity xml = super.getXMLEntity();
|
668 |
if (getLegend()!=null) |
669 |
xml.addChild(getLegend().getXMLEntity()); |
670 |
try {
|
671 |
if (getRecordset()!=null) |
672 |
xml.addChild(getRecordset().getSelectionSupport().getXMLEntity()); |
673 |
} catch (ReadDriverException e1) {
|
674 |
e1.printStackTrace(); |
675 |
throw new XMLException(e1); |
676 |
} |
677 |
// Repongo el mismo ReadableVectorial m?s abajo para cuando se guarda el proyecto.
|
678 |
ReadableVectorial rv=getSource(); |
679 |
xml.putProperty("type", "vectorial"); |
680 |
if (source instanceof VectorialEditableAdapter) { |
681 |
setSource(((VectorialEditableAdapter) source).getOriginalAdapter()); |
682 |
} |
683 |
if (source instanceof VectorialFileAdapter) { |
684 |
xml.putProperty("type", "vectorial"); |
685 |
xml.putProperty("file", ((VectorialFileAdapter) source)
|
686 |
.getFile()); |
687 |
try {
|
688 |
xml.putProperty("recordset-name", source.getRecordset()
|
689 |
.getName()); |
690 |
} catch (ReadDriverException e) {
|
691 |
throw new XMLException(e); |
692 |
} catch (RuntimeException e) { |
693 |
e.printStackTrace(); |
694 |
} |
695 |
} else if (source instanceof VectorialDBAdapter) { |
696 |
xml.putProperty("type", "vectorial"); |
697 |
|
698 |
IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) source |
699 |
.getDriver(); |
700 |
|
701 |
// Guardamos el nombre del driver para poder recuperarlo
|
702 |
// con el DriverManager de Fernando.
|
703 |
xml.putProperty("db", dbDriver.getName());
|
704 |
try {
|
705 |
xml.putProperty("recordset-name", source.getRecordset()
|
706 |
.getName()); |
707 |
} catch (ReadDriverException e) {
|
708 |
throw new XMLException(e); |
709 |
} catch (RuntimeException e) { |
710 |
e.printStackTrace(); |
711 |
} |
712 |
xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos
|
713 |
// metido la leyenda y el
|
714 |
// selection support
|
715 |
} else if (source instanceof VectorialAdapter) { |
716 |
// Se supone que hemos hecho algo gen?rico.
|
717 |
xml.putProperty("type", "vectorial"); |
718 |
|
719 |
VectorialDriver driver = source.getDriver(); |
720 |
|
721 |
// Guardamos el nombre del driver para poder recuperarlo
|
722 |
// con el DriverManager de Fernando.
|
723 |
xml.putProperty("other", driver.getName());
|
724 |
// try {
|
725 |
try {
|
726 |
xml.putProperty("recordset-name", source.getRecordset()
|
727 |
.getName()); |
728 |
} catch (ReadDriverException e) {
|
729 |
throw new XMLException(e); |
730 |
} catch (RuntimeException e) { |
731 |
e.printStackTrace(); |
732 |
} |
733 |
if (driver instanceof IPersistance) { |
734 |
// xml.putProperty("className", driver.getClass().getName());
|
735 |
IPersistance persist = (IPersistance) driver; |
736 |
xml.addChild(persist.getXMLEntity()); // Tercer child. Antes
|
737 |
// hemos metido la
|
738 |
// leyenda y el
|
739 |
// selection support
|
740 |
} |
741 |
} |
742 |
if (rv!=null) |
743 |
setSource(rv); |
744 |
xml.putProperty("driverName", source.getDriver().getName());
|
745 |
if (bHasJoin)
|
746 |
xml.putProperty("hasJoin", "true"); |
747 |
|
748 |
// properties from ILabelable
|
749 |
xml.putProperty("isLabeled", isLabeled);
|
750 |
if (strategy != null) { |
751 |
XMLEntity strategyXML = strategy.getXMLEntity(); |
752 |
strategyXML.putProperty("Strategy", strategy.getClassName());
|
753 |
xml.addChild(strategy.getXMLEntity()); |
754 |
} |
755 |
return xml;
|
756 |
} |
757 |
|
758 |
/**
|
759 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
760 |
*/
|
761 |
public void setXMLEntity03(XMLEntity xml) throws XMLException { |
762 |
|
763 |
super.setXMLEntity(xml);
|
764 |
legend = LegendFactory.createFromXML03(xml.getChild(0));
|
765 |
|
766 |
try {
|
767 |
setLegend(legend); |
768 |
} catch (LegendLayerException e) {
|
769 |
throw new XMLException(e); |
770 |
} |
771 |
|
772 |
try {
|
773 |
getRecordset().getSelectionSupport() |
774 |
.setXMLEntity03(xml.getChild(1));
|
775 |
} catch (ReadDriverException e) {
|
776 |
e.printStackTrace(); |
777 |
} |
778 |
} |
779 |
|
780 |
/*
|
781 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
782 |
*/
|
783 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
784 |
try {
|
785 |
super.setXMLEntity(xml);
|
786 |
XMLEntity legendXML = xml.getChild(0);
|
787 |
IVectorialLegend leg = LegendFactory.createFromXML(legendXML); |
788 |
/* (jaume) begin patch;
|
789 |
* for backward compatibility purposes. Since gvSIG v1.1 labeling is
|
790 |
* no longer managed by the Legend but by the ILabelingStrategy. The
|
791 |
* following allows restoring older projects' labelings.
|
792 |
*/
|
793 |
if (legendXML.contains("labelFieldName")) { |
794 |
String labelTextField = legendXML.getStringProperty("labelFieldName"); |
795 |
if (labelTextField != null) { |
796 |
AttrInTableLabeling labeling = new AttrInTableLabeling();
|
797 |
labeling.setLayer(this);
|
798 |
labeling.setTextField(legendXML.getStringProperty("labelFieldName"));
|
799 |
labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
|
800 |
labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
|
801 |
this.setLabelingStrategy(labeling);
|
802 |
this.setIsLabeled(true); |
803 |
} |
804 |
} |
805 |
/* end patch */
|
806 |
try {
|
807 |
getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
808 |
// JMVIVO: Esto sirve para algo????
|
809 |
String recordsetName = xml.getStringProperty("recordset-name"); |
810 |
|
811 |
LayerFactory.getDataSourceFactory().changeDataSourceName( |
812 |
getSource().getRecordset().getName(), recordsetName); |
813 |
} catch (NoSuchTableException e1) {
|
814 |
this.setAvailable(false); |
815 |
throw new XMLException(e1); |
816 |
} catch (ReadDriverException e1) {
|
817 |
this.setAvailable(false); |
818 |
throw new XMLException(e1); |
819 |
} |
820 |
// Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
821 |
// el final
|
822 |
// de la lectura del proyecto
|
823 |
if (xml.contains("hasJoin")) { |
824 |
setIsJoined(true);
|
825 |
PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1); |
826 |
} else {
|
827 |
try {
|
828 |
|
829 |
setLegend(leg); |
830 |
} catch (LegendLayerException e) {
|
831 |
throw new XMLException(e); |
832 |
} |
833 |
} |
834 |
|
835 |
// set properties for ILabelable
|
836 |
for (int i = 0; i < xml.getChildrenCount(); i++) { |
837 |
try {
|
838 |
if (xml.getChild(i).contains("Strategy")) { |
839 |
XMLEntity xmlStrategy = xml.getChild(i); |
840 |
this.strategy = LabelingFactory.createStrategyFromXML(xmlStrategy.getChild(0)); |
841 |
} |
842 |
} catch (NotExistInXMLEntity neXMLEX) {
|
843 |
// no strategy was set, just continue;
|
844 |
logger.warn("Reached what should be unreachable code");
|
845 |
} |
846 |
} |
847 |
} catch (XMLException e) {
|
848 |
this.setAvailable(false); |
849 |
this.orgXMLEntity = xml;
|
850 |
} catch (Exception e) { |
851 |
e.printStackTrace(); |
852 |
this.setAvailable(false); |
853 |
this.orgXMLEntity = xml;
|
854 |
|
855 |
} |
856 |
|
857 |
|
858 |
} |
859 |
|
860 |
public void setXMLEntityNew(XMLEntity xml) throws XMLException { |
861 |
try {
|
862 |
super.setXMLEntity(xml);
|
863 |
|
864 |
XMLEntity legendXML = xml.getChild(0);
|
865 |
IVectorialLegend leg = LegendFactory.createFromXML(legendXML); |
866 |
/* (jaume) begin patch;
|
867 |
* for backward compatibility purposes. Since gvSIG v1.1 labeling is
|
868 |
* no longer managed by the Legend but by the ILabelingStrategy. The
|
869 |
* following allows restoring older projects' labelings.
|
870 |
*/
|
871 |
if (legendXML.contains("labelFieldHeight")) { |
872 |
AttrInTableLabeling labeling = new AttrInTableLabeling();
|
873 |
labeling.setLayer(this);
|
874 |
labeling.setTextField(legendXML.getStringProperty("labelFieldHeight"));
|
875 |
labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
|
876 |
this.setLabelingStrategy(labeling);
|
877 |
this.setIsLabeled(true); |
878 |
} |
879 |
/* end patch */
|
880 |
try {
|
881 |
getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
882 |
|
883 |
this.setLoadSelection(xml.getChild(1)); |
884 |
} catch (ReadDriverException e1) {
|
885 |
this.setAvailable(false); |
886 |
throw new XMLException(e1); |
887 |
} |
888 |
// Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
889 |
// el final
|
890 |
// de la lectura del proyecto
|
891 |
if (xml.contains("hasJoin")) { |
892 |
setIsJoined(true);
|
893 |
PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1); |
894 |
} else {
|
895 |
this.setLoadLegend(leg);
|
896 |
} |
897 |
|
898 |
} catch (XMLException e) {
|
899 |
this.setAvailable(false); |
900 |
this.orgXMLEntity = xml;
|
901 |
} catch (Exception e) { |
902 |
this.setAvailable(false); |
903 |
this.orgXMLEntity = xml;
|
904 |
} |
905 |
|
906 |
|
907 |
} |
908 |
|
909 |
/**
|
910 |
* A?ade un LegendListener a la lista de Listeners.
|
911 |
*
|
912 |
* @param listener
|
913 |
* LegendListener.
|
914 |
*/
|
915 |
public void addLegendListener(LegendListener listener) { |
916 |
layerChangeSupport.addLayerListener(listener); |
917 |
} |
918 |
|
919 |
/**
|
920 |
* Llamada al m?todo callLegendChanged de los listener.
|
921 |
*
|
922 |
* @param e
|
923 |
* Evento.
|
924 |
*/
|
925 |
private void callLegendChanged(LegendChangedEvent e) { |
926 |
layerChangeSupport.callLegendChanged(e); |
927 |
} |
928 |
|
929 |
/**
|
930 |
* Borra un LegendListener de la lista de Listeners
|
931 |
*
|
932 |
* @param listener
|
933 |
* LegendListener.
|
934 |
*/
|
935 |
public void removeLegendListener(LegendListener listener) { |
936 |
layerChangeSupport.removeLayerListener(listener); |
937 |
} |
938 |
|
939 |
/**
|
940 |
* Sobreimplementaci?n del m?todo toString para que las bases de datos
|
941 |
* identifiquen la capa.
|
942 |
*
|
943 |
* @return DOCUMENT ME!
|
944 |
*/
|
945 |
public String toString() { |
946 |
/*
|
947 |
* Se usa internamente para que la parte de datos identifique de forma
|
948 |
* un?voca las tablas
|
949 |
*/
|
950 |
String ret = super.toString(); |
951 |
|
952 |
return "layer" + ret.substring(ret.indexOf('@') + 1); |
953 |
} |
954 |
|
955 |
public boolean isJoined() { |
956 |
return bHasJoin;
|
957 |
} |
958 |
|
959 |
/**
|
960 |
* Returns if a layer is spatially indexed
|
961 |
*
|
962 |
* @return if this layer has the ability to proces spatial queries without
|
963 |
* secuential scans.
|
964 |
*/
|
965 |
public boolean isSpatiallyIndexed() { |
966 |
ReadableVectorial source = getSource(); |
967 |
if (source instanceof ISpatialDB) |
968 |
return true; |
969 |
|
970 |
//FIXME azabala
|
971 |
/*
|
972 |
* Esto es muy dudoso, y puede cambiar.
|
973 |
* Estoy diciendo que las que no son fichero o no son
|
974 |
* BoundedShapes estan indexadas. Esto es mentira, pero
|
975 |
* as? quien pregunte no querr? generar el indice.
|
976 |
* Esta por ver si interesa generar el indice para capas
|
977 |
* HSQLDB, WFS, etc.
|
978 |
*/
|
979 |
if(!(source instanceof VectorialFileAdapter)){ |
980 |
return true; |
981 |
} |
982 |
if (!(source.getDriver() instanceof BoundedShapes)) { |
983 |
return true; |
984 |
} |
985 |
|
986 |
if (getISpatialIndex() != null) |
987 |
return true; |
988 |
return false; |
989 |
} |
990 |
|
991 |
public void setIsJoined(boolean hasJoin) { |
992 |
bHasJoin = hasJoin; |
993 |
} |
994 |
|
995 |
/**
|
996 |
* @return Returns the spatialIndex.
|
997 |
*/
|
998 |
public ISpatialIndex getISpatialIndex() {
|
999 |
return spatialIndex;
|
1000 |
} |
1001 |
/**
|
1002 |
* Sets the spatial index. This could be useful if, for some
|
1003 |
* reasons, you want to work with a distinct spatial index
|
1004 |
* (for example, a spatial index which could makes nearest
|
1005 |
* neighbour querys)
|
1006 |
* @param spatialIndex
|
1007 |
*/
|
1008 |
public void setISpatialIndex(ISpatialIndex spatialIndex){ |
1009 |
this.spatialIndex = spatialIndex;
|
1010 |
} |
1011 |
|
1012 |
public SelectableDataSource getRecordset() throws ReadDriverException { |
1013 |
if (!this.isAvailable()) return null; |
1014 |
if (sds == null) { |
1015 |
|
1016 |
SelectableDataSource ds = source.getRecordset(); |
1017 |
|
1018 |
if (ds == null) { |
1019 |
return null; |
1020 |
} |
1021 |
|
1022 |
sds = ds; |
1023 |
sds.setSelectionSupport(selectionSupport); |
1024 |
|
1025 |
} |
1026 |
return sds;
|
1027 |
} |
1028 |
|
1029 |
public void setEditing(boolean b) throws StartEditionLayerException { |
1030 |
super.setEditing(b);
|
1031 |
try {
|
1032 |
if (b) {
|
1033 |
VectorialEditableAdapter vea = null;
|
1034 |
// TODO: Qu? pasa si hay m?s tipos de adapters?
|
1035 |
// FJP: Se podr?a pasar como argumento el
|
1036 |
// VectorialEditableAdapter
|
1037 |
// que se quiera usar para evitar meter c?digo aqu? de este
|
1038 |
// estilo.
|
1039 |
if (getSource() instanceof VectorialDBAdapter) { |
1040 |
vea = new VectorialEditableDBAdapter();
|
1041 |
} else if (this instanceof FLyrAnnotation) { |
1042 |
vea = new AnnotationEditableAdapter(
|
1043 |
(FLyrAnnotation) this);
|
1044 |
} else {
|
1045 |
vea = new VectorialEditableAdapter();
|
1046 |
} |
1047 |
vea.setOriginalVectorialAdapter(getSource()); |
1048 |
// azo: implementations of readablevectorial need
|
1049 |
//references of projection and spatial index
|
1050 |
vea.setProjection(getProjection()); |
1051 |
vea.setSpatialIndex(spatialIndex); |
1052 |
|
1053 |
|
1054 |
// /vea.setSpatialIndex(getSpatialIndex());
|
1055 |
// /vea.setFullExtent(getFullExtent());
|
1056 |
vea.startEdition(EditionEvent.GRAPHIC); |
1057 |
setSource(vea); |
1058 |
getRecordset().setSelectionSupport( |
1059 |
vea.getOriginalAdapter().getRecordset() |
1060 |
.getSelectionSupport()); |
1061 |
|
1062 |
} else {
|
1063 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) getSource(); |
1064 |
setSource(vea.getOriginalAdapter()); |
1065 |
} |
1066 |
// Si tenemos una leyenda, hay que pegarle el cambiazo a su
|
1067 |
// recordset
|
1068 |
setRecordset(getSource().getRecordset()); |
1069 |
if (getLegend() instanceof IVectorialLegend) { |
1070 |
IVectorialLegend ley = (IVectorialLegend) getLegend(); |
1071 |
ley.setDataSource(getSource().getRecordset()); |
1072 |
// Esto lo pongo para evitar que al dibujar sobre un
|
1073 |
// dxf, dwg, o dgn no veamos nada. Es debido al checkbox
|
1074 |
// de la leyenda de textos "dibujar solo textos".
|
1075 |
//jaume
|
1076 |
// if (!(getSource().getDriver() instanceof IndexedShpDriver)){
|
1077 |
// FSymbol symbol=new FSymbol(getShapeType());
|
1078 |
// symbol.setFontSizeInPixels(false);
|
1079 |
// symbol.setFont(new Font("SansSerif", Font.PLAIN, 9));
|
1080 |
// Color color=symbol.getColor();
|
1081 |
// int alpha=symbol.getColor().getAlpha();
|
1082 |
// if (alpha>250) {
|
1083 |
// symbol.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),100));
|
1084 |
// }
|
1085 |
// ley.setDefaultSymbol(symbol);
|
1086 |
// }
|
1087 |
//jaume//
|
1088 |
ley.useDefaultSymbol(true);
|
1089 |
} |
1090 |
} catch (ReadDriverException e) {
|
1091 |
throw new StartEditionLayerException(getName(),e); |
1092 |
} catch (FieldNotFoundException e) {
|
1093 |
throw new StartEditionLayerException(getName(),e); |
1094 |
} catch (StartWriterVisitorException e) {
|
1095 |
throw new StartEditionLayerException(getName(),e); |
1096 |
} |
1097 |
|
1098 |
setSpatialCacheEnabled(b); |
1099 |
callEditionChanged(LayerEvent |
1100 |
.createEditionChangedEvent(this, "edition")); |
1101 |
|
1102 |
} |
1103 |
|
1104 |
/**
|
1105 |
* Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
1106 |
* forma, podr?s poner leyendas basadas en el nuevo recordset
|
1107 |
*
|
1108 |
* @param newSds
|
1109 |
*/
|
1110 |
public void setRecordset(SelectableDataSource newSds) { |
1111 |
sds = newSds; |
1112 |
sds.setSelectionSupport(selectionSupport); |
1113 |
} |
1114 |
|
1115 |
public void clearSpatialCache() |
1116 |
{ |
1117 |
spatialCache.clearAll(); |
1118 |
} |
1119 |
|
1120 |
public boolean isSpatialCacheEnabled() { |
1121 |
return spatialCacheEnabled;
|
1122 |
} |
1123 |
|
1124 |
public void setSpatialCacheEnabled(boolean spatialCacheEnabled) { |
1125 |
this.spatialCacheEnabled = spatialCacheEnabled;
|
1126 |
} |
1127 |
|
1128 |
public SpatialCache getSpatialCache() {
|
1129 |
return spatialCache;
|
1130 |
} |
1131 |
|
1132 |
/**
|
1133 |
* Siempre es un numero mayor de 1000
|
1134 |
* @param maxFeatures
|
1135 |
*/
|
1136 |
public void setMaxFeaturesInEditionCache(int maxFeatures) { |
1137 |
if (maxFeatures > spatialCache.maxFeatures)
|
1138 |
spatialCache.setMaxFeatures(maxFeatures); |
1139 |
|
1140 |
} |
1141 |
|
1142 |
/**
|
1143 |
* This method returns a boolean that is used by the FPopMenu
|
1144 |
* to make visible the properties menu or not. It is visible by
|
1145 |
* default, and if a later don't have to show this menu only
|
1146 |
* has to override this method.
|
1147 |
* @return
|
1148 |
* If the properties menu is visible (or not)
|
1149 |
*/
|
1150 |
public boolean isPropertiesMenuVisible(){ |
1151 |
return true; |
1152 |
} |
1153 |
|
1154 |
public void reload() throws ReloadLayerException { |
1155 |
this.setAvailable(true); |
1156 |
super.reload();
|
1157 |
try {
|
1158 |
this.source.getDriver().reload();
|
1159 |
if (this.getLegend() == null) { |
1160 |
if (this.getRecordset().getDriver() instanceof WithDefaultLegend) { |
1161 |
WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
1162 |
this.setLegend((IVectorialLegend) aux.getDefaultLegend());
|
1163 |
this.setLabelingStrategy(aux.getDefaultLabelingStrategy());
|
1164 |
} else {
|
1165 |
this.setLegend(LegendFactory.createSingleSymbolLegend(
|
1166 |
this.getShapeType()));
|
1167 |
} |
1168 |
} |
1169 |
|
1170 |
} catch (LegendLayerException e) {
|
1171 |
this.setAvailable(false); |
1172 |
throw new ReloadLayerException(getName(),e); |
1173 |
} catch (ReadDriverException e) {
|
1174 |
this.setAvailable(false); |
1175 |
throw new ReloadLayerException(getName(),e); |
1176 |
} |
1177 |
|
1178 |
} |
1179 |
|
1180 |
protected void setLoadSelection(XMLEntity xml) { |
1181 |
this.loadSelection = xml;
|
1182 |
} |
1183 |
|
1184 |
protected void setLoadLegend(IVectorialLegend legend) { |
1185 |
this.loadLegend = legend;
|
1186 |
} |
1187 |
|
1188 |
protected void putLoadSelection() throws XMLException { |
1189 |
if (this.loadSelection == null) return; |
1190 |
try {
|
1191 |
this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection); |
1192 |
} catch (ReadDriverException e) {
|
1193 |
throw new XMLException(e); |
1194 |
} |
1195 |
this.loadSelection = null; |
1196 |
|
1197 |
} |
1198 |
protected void putLoadLegend() throws LegendLayerException { |
1199 |
if (this.loadLegend == null) return; |
1200 |
this.setLegend(this.loadLegend); |
1201 |
this.loadLegend = null; |
1202 |
} |
1203 |
|
1204 |
protected void cleanLoadOptions() { |
1205 |
this.loadLegend = null; |
1206 |
this.loadSelection = null; |
1207 |
} |
1208 |
|
1209 |
public boolean isWritable() { |
1210 |
VectorialDriver drv = getSource().getDriver(); |
1211 |
if (!drv.isWritable())
|
1212 |
return false; |
1213 |
if (drv instanceof IWriteable) |
1214 |
{ |
1215 |
IWriter writer = ((IWriteable)drv).getWriter(); |
1216 |
if (writer != null) |
1217 |
{ |
1218 |
if (writer instanceof ISpatialWriter) |
1219 |
return true; |
1220 |
} |
1221 |
} |
1222 |
return false; |
1223 |
|
1224 |
} |
1225 |
|
1226 |
// public void beforePrinting(PrintRequestAttributeSet properties) {
|
1227 |
// VectorialLegend vl=(VectorialLegend)getLegend();
|
1228 |
// if (vl instanceof ClassifiedLegendInfo) {
|
1229 |
// ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) vl;
|
1230 |
// IPrintable[] symbols=clsfLegend.getSymbols();
|
1231 |
// for (int i=0;i<symbols.length;i++) {
|
1232 |
// symbols[i].setPrintingProperties(properties);
|
1233 |
// }
|
1234 |
// }
|
1235 |
// if (vl.getDefaultSymbol()!=null) {
|
1236 |
// ((IPrintable)vl.getDefaultSymbol()).setPrintingProperties(properties);
|
1237 |
// }
|
1238 |
// }
|
1239 |
//
|
1240 |
// public void afterPrinting() {
|
1241 |
// VectorialLegend vl=(VectorialLegend)getLegend();
|
1242 |
// if (vl instanceof ClassifiedLegendInfo) {
|
1243 |
// ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) vl;
|
1244 |
// IPrintable[] symbols=clsfLegend.getSymbols();
|
1245 |
// for (int i=0;i<symbols.length;i++) {
|
1246 |
// symbols[i].setPrintingProperties(null);
|
1247 |
// }
|
1248 |
// }
|
1249 |
// if (vl.getDefaultSymbol()!=null) {
|
1250 |
// ((IPrintable)vl.getDefaultSymbol()).setPrintingProperties(null);
|
1251 |
// }
|
1252 |
//
|
1253 |
// }
|
1254 |
|
1255 |
public FLayer cloneLayer() throws Exception { |
1256 |
FLyrVect clonedLayer = new FLyrVect();
|
1257 |
clonedLayer.setSource(getSource()); |
1258 |
clonedLayer.setVisible(isVisible()); |
1259 |
clonedLayer.setISpatialIndex(getISpatialIndex()); |
1260 |
clonedLayer.setName(getName()); |
1261 |
clonedLayer.setCoordTrans(getCoordTrans()); |
1262 |
|
1263 |
clonedLayer.setLegend((IVectorialLegend)getLegend()); |
1264 |
|
1265 |
clonedLayer.setIsLabeled(isLabeled()); |
1266 |
clonedLayer.setLabelingStrategy(getLabelingStrategy()); |
1267 |
|
1268 |
return clonedLayer;
|
1269 |
} |
1270 |
|
1271 |
/*
|
1272 |
* jaume. Stuff from ILabeled.
|
1273 |
*/
|
1274 |
private boolean isLabeled; |
1275 |
private ILabelingStrategy strategy;
|
1276 |
|
1277 |
public boolean isLabeled() { |
1278 |
return isLabeled;
|
1279 |
} |
1280 |
|
1281 |
public void setIsLabeled(boolean isLabeled) { |
1282 |
this.isLabeled = isLabeled;
|
1283 |
} |
1284 |
|
1285 |
public ILabelingStrategy getLabelingStrategy() {
|
1286 |
return strategy;
|
1287 |
} |
1288 |
|
1289 |
public void setLabelingStrategy(ILabelingStrategy strategy) { |
1290 |
this.strategy = strategy;
|
1291 |
} |
1292 |
|
1293 |
public void drawLabels(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws ReadDriverException { |
1294 |
if (isWithinScale(scale)) {
|
1295 |
strategy.draw(image, g, viewPort, cancel); |
1296 |
} |
1297 |
} |
1298 |
|
1299 |
} |