root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 11971
History | View | Annotate | Download (40 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 |
|
332 |
ZSort zSort = ((IVectorialLegend) getLegend()).getZSort(); |
333 |
if (zSort != null && zSort.isUsingZSort()) { |
334 |
|
335 |
|
336 |
|
337 |
|
338 |
BufferedImage[] imageLevels = new BufferedImage[zSort.getLevelCount()+1]; |
339 |
Graphics2D[] graphics = new Graphics2D[imageLevels.length]; |
340 |
for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) { |
341 |
imageLevels[i] = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); |
342 |
graphics[i] = imageLevels[i].createGraphics(); |
343 |
} |
344 |
|
345 |
// -- visual FX stuff
|
346 |
int screenRefreshRate = 1000; // render temporary map each screenRefreshRate milliseconds; |
347 |
long time = System.currentTimeMillis(); |
348 |
|
349 |
BufferedImage virtualBim;
|
350 |
Graphics2D virtualGraphics;
|
351 |
// -- end visual FX stuff
|
352 |
|
353 |
while ( !cancel.isCanceled() && it.hasNext()) {
|
354 |
|
355 |
IFeature feat = it.next(); |
356 |
IGeometry geom = feat.getGeometry(); |
357 |
|
358 |
ISymbol sym = legend.getSymbolByFeature(feat); |
359 |
if (sym instanceof IMultiLayerSymbol) { |
360 |
IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym; |
361 |
for (int i = 0; i < mlSym.getLayerCount(); i++) { |
362 |
ISymbol mySym = mlSym.getLayer(i); |
363 |
geom.drawInts(graphics[zSort.getSymbolLevel(mySym)], viewPort, mySym); |
364 |
} |
365 |
} else {
|
366 |
geom.drawInts(graphics[zSort.getSymbolLevel(sym)], viewPort, sym); |
367 |
} |
368 |
|
369 |
// -- visual FX stuff
|
370 |
if ((System.currentTimeMillis() - time) > screenRefreshRate) { |
371 |
time = System.currentTimeMillis();
|
372 |
virtualBim = new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_INT_ARGB); |
373 |
virtualGraphics = virtualBim.createGraphics(); |
374 |
virtualGraphics.drawImage(image,0,0,null); |
375 |
for (int i = 0; i < imageLevels.length; i++) { |
376 |
virtualGraphics.drawImage(imageLevels[i],0,0, null); |
377 |
} |
378 |
g.clearRect(0, 0, image.getWidth(), image.getHeight()); |
379 |
g.drawImage(virtualBim, 0, 0, null); |
380 |
} |
381 |
// -- end visual FX stuff
|
382 |
|
383 |
} |
384 |
g.drawImage(image, 0, 0, null); |
385 |
for (int i = 0; i < imageLevels.length; i++) { |
386 |
g.drawImage(imageLevels[i],0,0, null); |
387 |
imageLevels[i] = null;
|
388 |
graphics[i] = null;
|
389 |
} |
390 |
imageLevels = null;
|
391 |
graphics = null;
|
392 |
} else {
|
393 |
|
394 |
while ( !cancel.isCanceled() && it.hasNext() ) {
|
395 |
IFeature feat = it.next(); |
396 |
ISymbol sym = legend.getSymbolByFeature(feat); |
397 |
IGeometry geom = feat.getGeometry(); |
398 |
geom.drawInts(g, viewPort, sym); |
399 |
} |
400 |
} |
401 |
} catch (ReadDriverException e) {
|
402 |
this.setVisible(false); |
403 |
this.setActive(false); |
404 |
throw e;
|
405 |
} catch (ExpansionFileReadException e) {
|
406 |
this.setVisible(false); |
407 |
this.setActive(false); |
408 |
// throw new DriverException(e);
|
409 |
// TODO throw a correct exception (??? ReadDriverException ???)
|
410 |
e.printStackTrace(); |
411 |
} |
412 |
} |
413 |
if (getVirtualLayers() != null) { |
414 |
getVirtualLayers().draw(image, g, viewPort, cancel, scale); |
415 |
} |
416 |
} |
417 |
} |
418 |
|
419 |
public void _draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
420 |
Cancellable cancel, double scale) throws ReadDriverException { |
421 |
|
422 |
if (isWithinScale(scale)) {
|
423 |
|
424 |
|
425 |
// Las que solo tienen etiquetado sin pintar el shape,
|
426 |
// no pasamos por ellas
|
427 |
boolean bDrawShapes = true; |
428 |
if (legend instanceof SingleSymbolLegend) { |
429 |
if (legend.getDefaultSymbol().isShapeVisible() == false) |
430 |
bDrawShapes = false;
|
431 |
} |
432 |
if (bDrawShapes) {
|
433 |
Strategy strategy = StrategyManager.getStrategy(this);
|
434 |
try {
|
435 |
prepareDrawing(image, g, viewPort); |
436 |
strategy.draw(image, g, viewPort, cancel); |
437 |
} catch (ReadDriverException e) {
|
438 |
this.setVisible(false); |
439 |
this.setActive(false); |
440 |
throw e;
|
441 |
} |
442 |
} |
443 |
if (getVirtualLayers() != null) { |
444 |
getVirtualLayers().draw(image, g, viewPort, cancel, scale); |
445 |
} |
446 |
} |
447 |
} |
448 |
|
449 |
/**
|
450 |
* Se llama antes de empezar a pintar.
|
451 |
* Es ?til para preparar la cache a emplear, las leyendas, etc.
|
452 |
* @param image
|
453 |
* @param g
|
454 |
* @param viewPort
|
455 |
*/
|
456 |
private void prepareDrawing(BufferedImage image, Graphics2D g, ViewPort viewPort) { |
457 |
|
458 |
} |
459 |
|
460 |
public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
461 |
double scale, PrintRequestAttributeSet properties) throws ReadDriverException { |
462 |
// TEST METHOD
|
463 |
draw(null, g, viewPort, cancel, scale);
|
464 |
} |
465 |
|
466 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
467 |
double scale, PrintRequestAttributeSet properties) throws ReadDriverException { |
468 |
if (isVisible() && isWithinScale(scale)) {
|
469 |
Strategy strategy = StrategyManager.getStrategy(this);
|
470 |
|
471 |
strategy.print(g, viewPort, cancel, properties); |
472 |
ILabelingStrategy labeling; |
473 |
if ( (labeling = getLabelingStrategy() ) != null) { |
474 |
// contains labels
|
475 |
labeling.print(g, viewPort, cancel, properties); |
476 |
} |
477 |
} |
478 |
} |
479 |
|
480 |
|
481 |
public void deleteSpatialIndex() { |
482 |
//must we delete possible spatial indexes files?
|
483 |
spatialIndex = null;
|
484 |
} |
485 |
|
486 |
|
487 |
|
488 |
/**
|
489 |
* <p>
|
490 |
* Creates an spatial index associated to this layer.
|
491 |
* The spatial index will used
|
492 |
* the native projection of the layer, so if the layer is reprojected, it will
|
493 |
* be ignored.
|
494 |
* </p>
|
495 |
* @param cancelMonitor instance of CancellableMonitorable that allows
|
496 |
* to monitor progress of spatial index creation, and cancel the process
|
497 |
*/
|
498 |
public void createSpatialIndex(CancellableMonitorable cancelMonitor){ |
499 |
// FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
500 |
// QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
501 |
// para que acepten recorrer sin geometria, solo con rectangulos.
|
502 |
|
503 |
//If this vectorial layer is based in a spatial database, the spatial
|
504 |
//index is already implicit. We only will index file drivers
|
505 |
ReadableVectorial va = getSource(); |
506 |
//We must think in non spatial databases, like HSQLDB
|
507 |
if(!(va instanceof VectorialFileAdapter)){ |
508 |
return;
|
509 |
} |
510 |
if (!(va.getDriver() instanceof BoundedShapes)) { |
511 |
return;
|
512 |
} |
513 |
File file = ((VectorialFileAdapter) va).getFile();
|
514 |
String fileName = file.getAbsolutePath();
|
515 |
ISpatialIndex localCopy = null;
|
516 |
try {
|
517 |
va.start(); |
518 |
localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(), |
519 |
va.getShapeCount(), true);
|
520 |
|
521 |
} catch (SpatialIndexException e1) {
|
522 |
// Probably we dont have writing permissions
|
523 |
String directoryName = System.getProperty("java.io.tmpdir"); |
524 |
File newFile = new File(directoryName + |
525 |
File.separator +
|
526 |
file.getName()); |
527 |
String newFileName = newFile.getName();
|
528 |
try {
|
529 |
localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(), |
530 |
va.getShapeCount(), true);
|
531 |
} catch (SpatialIndexException e) {
|
532 |
// if we cant build a file based spatial index, we'll build
|
533 |
// a pure memory spatial index
|
534 |
localCopy = new QuadtreeJts();
|
535 |
} catch (ReadDriverException e) {
|
536 |
localCopy = new QuadtreeJts();
|
537 |
} catch (ExpansionFileReadException e) {
|
538 |
localCopy = new QuadtreeJts();
|
539 |
} |
540 |
|
541 |
}catch(Exception e){ |
542 |
e.printStackTrace(); |
543 |
}//try
|
544 |
BoundedShapes shapeBounds = (BoundedShapes) va.getDriver(); |
545 |
try {
|
546 |
for (int i=0; i < va.getShapeCount(); i++) |
547 |
{ |
548 |
if(cancelMonitor != null){ |
549 |
if(cancelMonitor.isCanceled())
|
550 |
return;
|
551 |
cancelMonitor.reportStep(); |
552 |
} |
553 |
Rectangle2D r = shapeBounds.getShapeBounds(i);
|
554 |
if(r != null) |
555 |
localCopy.insert(r, i); |
556 |
} // for
|
557 |
va.stop(); |
558 |
if(localCopy instanceof IPersistentSpatialIndex) |
559 |
((IPersistentSpatialIndex) localCopy).flush(); |
560 |
spatialIndex = localCopy; |
561 |
//vectorial adapter needs a reference to the spatial index, to solve
|
562 |
//request for feature iteration based in spatial queries
|
563 |
source.setSpatialIndex(spatialIndex); |
564 |
} catch (ReadDriverException e) {
|
565 |
// TODO Auto-generated catch block
|
566 |
e.printStackTrace(); |
567 |
} catch (ExpansionFileReadException e) {
|
568 |
// TODO Auto-generated catch block
|
569 |
e.printStackTrace(); |
570 |
} |
571 |
} |
572 |
|
573 |
public void createSpatialIndex() { |
574 |
createSpatialIndex(null);
|
575 |
} |
576 |
|
577 |
public void process(FeatureVisitor visitor, FBitSet subset) |
578 |
throws ReadDriverException, ExpansionFileReadException, VisitorException {
|
579 |
Strategy s = StrategyManager.getStrategy(this);
|
580 |
s.process(visitor, subset); |
581 |
} |
582 |
|
583 |
public void process(FeatureVisitor visitor) throws ReadDriverException, VisitorException { |
584 |
Strategy s = StrategyManager.getStrategy(this);
|
585 |
s.process(visitor); |
586 |
} |
587 |
|
588 |
public void process(FeatureVisitor visitor, Rectangle2D rect) |
589 |
throws ReadDriverException, ExpansionFileReadException, VisitorException {
|
590 |
Strategy s = StrategyManager.getStrategy(this);
|
591 |
s.process(visitor, rect); |
592 |
} |
593 |
|
594 |
public FBitSet queryByRect(Rectangle2D rect) throws ReadDriverException, VisitorException { |
595 |
Strategy s = StrategyManager.getStrategy(this);
|
596 |
|
597 |
return s.queryByRect(rect);
|
598 |
} |
599 |
|
600 |
public FBitSet queryByPoint(Point2D p, double tolerance) |
601 |
throws ReadDriverException, VisitorException {
|
602 |
Strategy s = StrategyManager.getStrategy(this);
|
603 |
return s.queryByPoint(p, tolerance);
|
604 |
} |
605 |
|
606 |
public FBitSet queryByShape(IGeometry g, int relationship) |
607 |
throws ReadDriverException, VisitorException {
|
608 |
Strategy s = StrategyManager.getStrategy(this);
|
609 |
return s.queryByShape(g, relationship);
|
610 |
} |
611 |
|
612 |
public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws ReadDriverException, VisitorException { |
613 |
Point2D pReal = this.getMapContext().getViewPort().toMapPoint(p); |
614 |
FBitSet bs = queryByPoint(pReal, tolerance); |
615 |
VectorialXMLItem[] item = new VectorialXMLItem[1]; |
616 |
item[0] = new VectorialXMLItem(bs, this); |
617 |
|
618 |
return item;
|
619 |
} |
620 |
|
621 |
public void setLegend(IVectorialLegend r) throws LegendLayerException { |
622 |
IVectorialLegend oldLegend = legend; |
623 |
legend = r; |
624 |
try {
|
625 |
legend.setDataSource(getRecordset()); |
626 |
} catch (FieldNotFoundException e1) {
|
627 |
throw new LegendLayerException(getName(),e1); |
628 |
} catch (ReadDriverException e1) {
|
629 |
throw new LegendLayerException(getName(),e1); |
630 |
} |
631 |
LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent( |
632 |
oldLegend, legend); |
633 |
callLegendChanged(e); |
634 |
} |
635 |
|
636 |
/**
|
637 |
* Devuelve la Leyenda de la capa.
|
638 |
*
|
639 |
* @return Leyenda.
|
640 |
*/
|
641 |
public ILegend getLegend() {
|
642 |
return legend;
|
643 |
} |
644 |
|
645 |
/**
|
646 |
* Devuelve el tipo de shape que contiene la capa.
|
647 |
*
|
648 |
* @return tipo de shape.
|
649 |
*
|
650 |
* @throws DriverException
|
651 |
*/
|
652 |
public int getShapeType() throws ReadDriverException { |
653 |
if (typeShape == -1) { |
654 |
getSource().start(); |
655 |
typeShape = getSource().getShapeType(); |
656 |
getSource().stop(); |
657 |
} |
658 |
|
659 |
return typeShape;
|
660 |
} |
661 |
|
662 |
public XMLEntity getXMLEntity() throws XMLException { |
663 |
if (!this.isAvailable() && this.orgXMLEntity != null) { |
664 |
return this.orgXMLEntity; |
665 |
} |
666 |
XMLEntity xml = super.getXMLEntity();
|
667 |
if (getLegend()!=null) |
668 |
xml.addChild(getLegend().getXMLEntity()); |
669 |
try {
|
670 |
if (getRecordset()!=null) |
671 |
xml.addChild(getRecordset().getSelectionSupport().getXMLEntity()); |
672 |
} catch (ReadDriverException e1) {
|
673 |
e1.printStackTrace(); |
674 |
throw new XMLException(e1); |
675 |
} |
676 |
// Repongo el mismo ReadableVectorial m?s abajo para cuando se guarda el proyecto.
|
677 |
ReadableVectorial rv=getSource(); |
678 |
xml.putProperty("type", "vectorial"); |
679 |
if (source instanceof VectorialEditableAdapter) { |
680 |
setSource(((VectorialEditableAdapter) source).getOriginalAdapter()); |
681 |
} |
682 |
if (source instanceof VectorialFileAdapter) { |
683 |
xml.putProperty("type", "vectorial"); |
684 |
xml.putProperty("file", ((VectorialFileAdapter) source)
|
685 |
.getFile()); |
686 |
try {
|
687 |
xml.putProperty("recordset-name", source.getRecordset()
|
688 |
.getName()); |
689 |
} catch (ReadDriverException e) {
|
690 |
throw new XMLException(e); |
691 |
} catch (RuntimeException e) { |
692 |
e.printStackTrace(); |
693 |
} |
694 |
} else if (source instanceof VectorialDBAdapter) { |
695 |
xml.putProperty("type", "vectorial"); |
696 |
|
697 |
IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) source |
698 |
.getDriver(); |
699 |
|
700 |
// Guardamos el nombre del driver para poder recuperarlo
|
701 |
// con el DriverManager de Fernando.
|
702 |
xml.putProperty("db", dbDriver.getName());
|
703 |
try {
|
704 |
xml.putProperty("recordset-name", source.getRecordset()
|
705 |
.getName()); |
706 |
} catch (ReadDriverException e) {
|
707 |
throw new XMLException(e); |
708 |
} catch (RuntimeException e) { |
709 |
e.printStackTrace(); |
710 |
} |
711 |
xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos
|
712 |
// metido la leyenda y el
|
713 |
// selection support
|
714 |
} else if (source instanceof VectorialAdapter) { |
715 |
// Se supone que hemos hecho algo gen?rico.
|
716 |
xml.putProperty("type", "vectorial"); |
717 |
|
718 |
VectorialDriver driver = source.getDriver(); |
719 |
|
720 |
// Guardamos el nombre del driver para poder recuperarlo
|
721 |
// con el DriverManager de Fernando.
|
722 |
xml.putProperty("other", driver.getName());
|
723 |
// try {
|
724 |
try {
|
725 |
xml.putProperty("recordset-name", source.getRecordset()
|
726 |
.getName()); |
727 |
} catch (ReadDriverException e) {
|
728 |
throw new XMLException(e); |
729 |
} catch (RuntimeException e) { |
730 |
e.printStackTrace(); |
731 |
} |
732 |
if (driver instanceof IPersistance) { |
733 |
// xml.putProperty("className", driver.getClass().getName());
|
734 |
IPersistance persist = (IPersistance) driver; |
735 |
xml.addChild(persist.getXMLEntity()); // Tercer child. Antes
|
736 |
// hemos metido la
|
737 |
// leyenda y el
|
738 |
// selection support
|
739 |
} |
740 |
} |
741 |
if (rv!=null) |
742 |
setSource(rv); |
743 |
xml.putProperty("driverName", source.getDriver().getName());
|
744 |
if (bHasJoin)
|
745 |
xml.putProperty("hasJoin", "true"); |
746 |
|
747 |
// properties from ILabelable
|
748 |
xml.putProperty("isLabeled", isLabeled);
|
749 |
if (strategy != null) { |
750 |
XMLEntity strategyXML = strategy.getXMLEntity(); |
751 |
strategyXML.putProperty("Strategy", strategy.getClassName());
|
752 |
xml.addChild(strategy.getXMLEntity()); |
753 |
} |
754 |
return xml;
|
755 |
} |
756 |
|
757 |
/**
|
758 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
759 |
*/
|
760 |
public void setXMLEntity03(XMLEntity xml) throws XMLException { |
761 |
|
762 |
super.setXMLEntity(xml);
|
763 |
legend = LegendFactory.createFromXML03(xml.getChild(0));
|
764 |
|
765 |
try {
|
766 |
setLegend(legend); |
767 |
} catch (LegendLayerException e) {
|
768 |
throw new XMLException(e); |
769 |
} |
770 |
|
771 |
try {
|
772 |
getRecordset().getSelectionSupport() |
773 |
.setXMLEntity03(xml.getChild(1));
|
774 |
} catch (ReadDriverException e) {
|
775 |
e.printStackTrace(); |
776 |
} |
777 |
} |
778 |
|
779 |
/*
|
780 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
781 |
*/
|
782 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
783 |
try {
|
784 |
super.setXMLEntity(xml);
|
785 |
XMLEntity legendXML = xml.getChild(0);
|
786 |
IVectorialLegend leg = LegendFactory.createFromXML(legendXML); |
787 |
/* (jaume) begin patch;
|
788 |
* for backward compatibility purposes. Since gvSIG v1.1 labeling is
|
789 |
* no longer managed by the Legend but by the ILabelingStrategy. The
|
790 |
* following allows restoring older projects' labelings.
|
791 |
*/
|
792 |
if (legendXML.contains("labelFieldName")) { |
793 |
String labelTextField = legendXML.getStringProperty("labelFieldName"); |
794 |
if (labelTextField != null) { |
795 |
AttrInTableLabeling labeling = new AttrInTableLabeling();
|
796 |
labeling.setLayer(this);
|
797 |
labeling.setTextField(legendXML.getStringProperty("labelFieldName"));
|
798 |
labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
|
799 |
labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
|
800 |
this.setLabelingStrategy(labeling);
|
801 |
this.setIsLabeled(true); |
802 |
} |
803 |
} |
804 |
/* end patch */
|
805 |
try {
|
806 |
getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
807 |
// JMVIVO: Esto sirve para algo????
|
808 |
String recordsetName = xml.getStringProperty("recordset-name"); |
809 |
|
810 |
LayerFactory.getDataSourceFactory().changeDataSourceName( |
811 |
getSource().getRecordset().getName(), recordsetName); |
812 |
} catch (NoSuchTableException e1) {
|
813 |
this.setAvailable(false); |
814 |
throw new XMLException(e1); |
815 |
} catch (ReadDriverException e1) {
|
816 |
this.setAvailable(false); |
817 |
throw new XMLException(e1); |
818 |
} |
819 |
// Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
820 |
// el final
|
821 |
// de la lectura del proyecto
|
822 |
if (xml.contains("hasJoin")) { |
823 |
setIsJoined(true);
|
824 |
PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1); |
825 |
} else {
|
826 |
try {
|
827 |
|
828 |
setLegend(leg); |
829 |
} catch (LegendLayerException e) {
|
830 |
throw new XMLException(e); |
831 |
} |
832 |
} |
833 |
|
834 |
// set properties for ILabelable
|
835 |
for (int i = 0; i < xml.getChildrenCount(); i++) { |
836 |
try {
|
837 |
if (xml.getChild(i).contains("Strategy")) { |
838 |
XMLEntity xmlStrategy = xml.getChild(i); |
839 |
this.strategy = LabelingFactory.createStrategyFromXML(xmlStrategy.getChild(0)); |
840 |
} |
841 |
} catch (NotExistInXMLEntity neXMLEX) {
|
842 |
// no strategy was set, just continue;
|
843 |
logger.warn("Reached what should be unreachable code");
|
844 |
} |
845 |
} |
846 |
} catch (XMLException e) {
|
847 |
this.setAvailable(false); |
848 |
this.orgXMLEntity = xml;
|
849 |
} catch (Exception e) { |
850 |
e.printStackTrace(); |
851 |
this.setAvailable(false); |
852 |
this.orgXMLEntity = xml;
|
853 |
|
854 |
} |
855 |
|
856 |
|
857 |
} |
858 |
|
859 |
public void setXMLEntityNew(XMLEntity xml) throws XMLException { |
860 |
try {
|
861 |
super.setXMLEntity(xml);
|
862 |
|
863 |
XMLEntity legendXML = xml.getChild(0);
|
864 |
IVectorialLegend leg = LegendFactory.createFromXML(legendXML); |
865 |
/* (jaume) begin patch;
|
866 |
* for backward compatibility purposes. Since gvSIG v1.1 labeling is
|
867 |
* no longer managed by the Legend but by the ILabelingStrategy. The
|
868 |
* following allows restoring older projects' labelings.
|
869 |
*/
|
870 |
if (legendXML.contains("labelFieldHeight")) { |
871 |
AttrInTableLabeling labeling = new AttrInTableLabeling();
|
872 |
labeling.setLayer(this);
|
873 |
labeling.setTextField(legendXML.getStringProperty("labelFieldHeight"));
|
874 |
labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
|
875 |
this.setLabelingStrategy(labeling);
|
876 |
this.setIsLabeled(true); |
877 |
} |
878 |
/* end patch */
|
879 |
try {
|
880 |
getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
881 |
|
882 |
this.setLoadSelection(xml.getChild(1)); |
883 |
} catch (ReadDriverException e1) {
|
884 |
this.setAvailable(false); |
885 |
throw new XMLException(e1); |
886 |
} |
887 |
// Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
888 |
// el final
|
889 |
// de la lectura del proyecto
|
890 |
if (xml.contains("hasJoin")) { |
891 |
setIsJoined(true);
|
892 |
PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1); |
893 |
} else {
|
894 |
this.setLoadLegend(leg);
|
895 |
} |
896 |
|
897 |
} catch (XMLException e) {
|
898 |
this.setAvailable(false); |
899 |
this.orgXMLEntity = xml;
|
900 |
} catch (Exception e) { |
901 |
this.setAvailable(false); |
902 |
this.orgXMLEntity = xml;
|
903 |
} |
904 |
|
905 |
|
906 |
} |
907 |
|
908 |
/**
|
909 |
* A?ade un LegendListener a la lista de Listeners.
|
910 |
*
|
911 |
* @param listener
|
912 |
* LegendListener.
|
913 |
*/
|
914 |
public void addLegendListener(LegendListener listener) { |
915 |
layerChangeSupport.addLayerListener(listener); |
916 |
} |
917 |
|
918 |
/**
|
919 |
* Llamada al m?todo callLegendChanged de los listener.
|
920 |
*
|
921 |
* @param e
|
922 |
* Evento.
|
923 |
*/
|
924 |
private void callLegendChanged(LegendChangedEvent e) { |
925 |
layerChangeSupport.callLegendChanged(e); |
926 |
} |
927 |
|
928 |
/**
|
929 |
* Borra un LegendListener de la lista de Listeners
|
930 |
*
|
931 |
* @param listener
|
932 |
* LegendListener.
|
933 |
*/
|
934 |
public void removeLegendListener(LegendListener listener) { |
935 |
layerChangeSupport.removeLayerListener(listener); |
936 |
} |
937 |
|
938 |
/**
|
939 |
* Sobreimplementaci?n del m?todo toString para que las bases de datos
|
940 |
* identifiquen la capa.
|
941 |
*
|
942 |
* @return DOCUMENT ME!
|
943 |
*/
|
944 |
public String toString() { |
945 |
/*
|
946 |
* Se usa internamente para que la parte de datos identifique de forma
|
947 |
* un?voca las tablas
|
948 |
*/
|
949 |
String ret = super.toString(); |
950 |
|
951 |
return "layer" + ret.substring(ret.indexOf('@') + 1); |
952 |
} |
953 |
|
954 |
public boolean isJoined() { |
955 |
return bHasJoin;
|
956 |
} |
957 |
|
958 |
/**
|
959 |
* Returns if a layer is spatially indexed
|
960 |
*
|
961 |
* @return if this layer has the ability to proces spatial queries without
|
962 |
* secuential scans.
|
963 |
*/
|
964 |
public boolean isSpatiallyIndexed() { |
965 |
ReadableVectorial source = getSource(); |
966 |
if (source instanceof ISpatialDB) |
967 |
return true; |
968 |
|
969 |
//FIXME azabala
|
970 |
/*
|
971 |
* Esto es muy dudoso, y puede cambiar.
|
972 |
* Estoy diciendo que las que no son fichero o no son
|
973 |
* BoundedShapes estan indexadas. Esto es mentira, pero
|
974 |
* as? quien pregunte no querr? generar el indice.
|
975 |
* Esta por ver si interesa generar el indice para capas
|
976 |
* HSQLDB, WFS, etc.
|
977 |
*/
|
978 |
if(!(source instanceof VectorialFileAdapter)){ |
979 |
return true; |
980 |
} |
981 |
if (!(source.getDriver() instanceof BoundedShapes)) { |
982 |
return true; |
983 |
} |
984 |
|
985 |
if (getISpatialIndex() != null) |
986 |
return true; |
987 |
return false; |
988 |
} |
989 |
|
990 |
public void setIsJoined(boolean hasJoin) { |
991 |
bHasJoin = hasJoin; |
992 |
} |
993 |
|
994 |
/**
|
995 |
* @return Returns the spatialIndex.
|
996 |
*/
|
997 |
public ISpatialIndex getISpatialIndex() {
|
998 |
return spatialIndex;
|
999 |
} |
1000 |
/**
|
1001 |
* Sets the spatial index. This could be useful if, for some
|
1002 |
* reasons, you want to work with a distinct spatial index
|
1003 |
* (for example, a spatial index which could makes nearest
|
1004 |
* neighbour querys)
|
1005 |
* @param spatialIndex
|
1006 |
*/
|
1007 |
public void setISpatialIndex(ISpatialIndex spatialIndex){ |
1008 |
this.spatialIndex = spatialIndex;
|
1009 |
} |
1010 |
|
1011 |
public SelectableDataSource getRecordset() throws ReadDriverException { |
1012 |
if (!this.isAvailable()) return null; |
1013 |
if (sds == null) { |
1014 |
|
1015 |
SelectableDataSource ds = source.getRecordset(); |
1016 |
|
1017 |
if (ds == null) { |
1018 |
return null; |
1019 |
} |
1020 |
|
1021 |
sds = ds; |
1022 |
sds.setSelectionSupport(selectionSupport); |
1023 |
|
1024 |
} |
1025 |
return sds;
|
1026 |
} |
1027 |
|
1028 |
public void setEditing(boolean b) throws StartEditionLayerException { |
1029 |
super.setEditing(b);
|
1030 |
try {
|
1031 |
if (b) {
|
1032 |
VectorialEditableAdapter vea = null;
|
1033 |
// TODO: Qu? pasa si hay m?s tipos de adapters?
|
1034 |
// FJP: Se podr?a pasar como argumento el
|
1035 |
// VectorialEditableAdapter
|
1036 |
// que se quiera usar para evitar meter c?digo aqu? de este
|
1037 |
// estilo.
|
1038 |
if (getSource() instanceof VectorialDBAdapter) { |
1039 |
vea = new VectorialEditableDBAdapter();
|
1040 |
} else if (this instanceof FLyrAnnotation) { |
1041 |
vea = new AnnotationEditableAdapter(
|
1042 |
(FLyrAnnotation) this);
|
1043 |
} else {
|
1044 |
vea = new VectorialEditableAdapter();
|
1045 |
} |
1046 |
vea.setOriginalVectorialAdapter(getSource()); |
1047 |
// azo: implementations of readablevectorial need
|
1048 |
//references of projection and spatial index
|
1049 |
vea.setProjection(getProjection()); |
1050 |
vea.setSpatialIndex(spatialIndex); |
1051 |
|
1052 |
|
1053 |
// /vea.setSpatialIndex(getSpatialIndex());
|
1054 |
// /vea.setFullExtent(getFullExtent());
|
1055 |
vea.startEdition(EditionEvent.GRAPHIC); |
1056 |
setSource(vea); |
1057 |
getRecordset().setSelectionSupport( |
1058 |
vea.getOriginalAdapter().getRecordset() |
1059 |
.getSelectionSupport()); |
1060 |
|
1061 |
} else {
|
1062 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) getSource(); |
1063 |
setSource(vea.getOriginalAdapter()); |
1064 |
} |
1065 |
// Si tenemos una leyenda, hay que pegarle el cambiazo a su
|
1066 |
// recordset
|
1067 |
setRecordset(getSource().getRecordset()); |
1068 |
if (getLegend() instanceof IVectorialLegend) { |
1069 |
IVectorialLegend ley = (IVectorialLegend) getLegend(); |
1070 |
ley.setDataSource(getSource().getRecordset()); |
1071 |
// Esto lo pongo para evitar que al dibujar sobre un
|
1072 |
// dxf, dwg, o dgn no veamos nada. Es debido al checkbox
|
1073 |
// de la leyenda de textos "dibujar solo textos".
|
1074 |
//jaume
|
1075 |
// if (!(getSource().getDriver() instanceof IndexedShpDriver)){
|
1076 |
// FSymbol symbol=new FSymbol(getShapeType());
|
1077 |
// symbol.setFontSizeInPixels(false);
|
1078 |
// symbol.setFont(new Font("SansSerif", Font.PLAIN, 9));
|
1079 |
// Color color=symbol.getColor();
|
1080 |
// int alpha=symbol.getColor().getAlpha();
|
1081 |
// if (alpha>250) {
|
1082 |
// symbol.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),100));
|
1083 |
// }
|
1084 |
// ley.setDefaultSymbol(symbol);
|
1085 |
// }
|
1086 |
//jaume//
|
1087 |
ley.useDefaultSymbol(true);
|
1088 |
} |
1089 |
} catch (ReadDriverException e) {
|
1090 |
throw new StartEditionLayerException(getName(),e); |
1091 |
} catch (FieldNotFoundException e) {
|
1092 |
throw new StartEditionLayerException(getName(),e); |
1093 |
} catch (StartWriterVisitorException e) {
|
1094 |
throw new StartEditionLayerException(getName(),e); |
1095 |
} |
1096 |
|
1097 |
setSpatialCacheEnabled(b); |
1098 |
callEditionChanged(LayerEvent |
1099 |
.createEditionChangedEvent(this, "edition")); |
1100 |
|
1101 |
} |
1102 |
|
1103 |
/**
|
1104 |
* Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
1105 |
* forma, podr?s poner leyendas basadas en el nuevo recordset
|
1106 |
*
|
1107 |
* @param newSds
|
1108 |
*/
|
1109 |
public void setRecordset(SelectableDataSource newSds) { |
1110 |
sds = newSds; |
1111 |
sds.setSelectionSupport(selectionSupport); |
1112 |
} |
1113 |
|
1114 |
public void clearSpatialCache() |
1115 |
{ |
1116 |
spatialCache.clearAll(); |
1117 |
} |
1118 |
|
1119 |
public boolean isSpatialCacheEnabled() { |
1120 |
return spatialCacheEnabled;
|
1121 |
} |
1122 |
|
1123 |
public void setSpatialCacheEnabled(boolean spatialCacheEnabled) { |
1124 |
this.spatialCacheEnabled = spatialCacheEnabled;
|
1125 |
} |
1126 |
|
1127 |
public SpatialCache getSpatialCache() {
|
1128 |
return spatialCache;
|
1129 |
} |
1130 |
|
1131 |
/**
|
1132 |
* Siempre es un numero mayor de 1000
|
1133 |
* @param maxFeatures
|
1134 |
*/
|
1135 |
public void setMaxFeaturesInEditionCache(int maxFeatures) { |
1136 |
if (maxFeatures > spatialCache.maxFeatures)
|
1137 |
spatialCache.setMaxFeatures(maxFeatures); |
1138 |
|
1139 |
} |
1140 |
|
1141 |
/**
|
1142 |
* This method returns a boolean that is used by the FPopMenu
|
1143 |
* to make visible the properties menu or not. It is visible by
|
1144 |
* default, and if a later don't have to show this menu only
|
1145 |
* has to override this method.
|
1146 |
* @return
|
1147 |
* If the properties menu is visible (or not)
|
1148 |
*/
|
1149 |
public boolean isPropertiesMenuVisible(){ |
1150 |
return true; |
1151 |
} |
1152 |
|
1153 |
public void reload() throws ReloadLayerException { |
1154 |
this.setAvailable(true); |
1155 |
super.reload();
|
1156 |
try {
|
1157 |
this.source.getDriver().reload();
|
1158 |
if (this.getLegend() == null) { |
1159 |
if (this.getRecordset().getDriver() instanceof WithDefaultLegend) { |
1160 |
WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
1161 |
this.setLegend((IVectorialLegend) aux.getDefaultLegend());
|
1162 |
this.setLabelingStrategy(aux.getDefaultLabelingStrategy());
|
1163 |
} else {
|
1164 |
this.setLegend(LegendFactory.createSingleSymbolLegend(
|
1165 |
this.getShapeType()));
|
1166 |
} |
1167 |
} |
1168 |
|
1169 |
} catch (LegendLayerException e) {
|
1170 |
this.setAvailable(false); |
1171 |
throw new ReloadLayerException(getName(),e); |
1172 |
} catch (ReadDriverException e) {
|
1173 |
this.setAvailable(false); |
1174 |
throw new ReloadLayerException(getName(),e); |
1175 |
} |
1176 |
|
1177 |
} |
1178 |
|
1179 |
protected void setLoadSelection(XMLEntity xml) { |
1180 |
this.loadSelection = xml;
|
1181 |
} |
1182 |
|
1183 |
protected void setLoadLegend(IVectorialLegend legend) { |
1184 |
this.loadLegend = legend;
|
1185 |
} |
1186 |
|
1187 |
protected void putLoadSelection() throws XMLException { |
1188 |
if (this.loadSelection == null) return; |
1189 |
try {
|
1190 |
this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection); |
1191 |
} catch (ReadDriverException e) {
|
1192 |
throw new XMLException(e); |
1193 |
} |
1194 |
this.loadSelection = null; |
1195 |
|
1196 |
} |
1197 |
protected void putLoadLegend() throws LegendLayerException { |
1198 |
if (this.loadLegend == null) return; |
1199 |
this.setLegend(this.loadLegend); |
1200 |
this.loadLegend = null; |
1201 |
} |
1202 |
|
1203 |
protected void cleanLoadOptions() { |
1204 |
this.loadLegend = null; |
1205 |
this.loadSelection = null; |
1206 |
} |
1207 |
|
1208 |
public boolean isWritable() { |
1209 |
VectorialDriver drv = getSource().getDriver(); |
1210 |
if (!drv.isWritable())
|
1211 |
return false; |
1212 |
if (drv instanceof IWriteable) |
1213 |
{ |
1214 |
IWriter writer = ((IWriteable)drv).getWriter(); |
1215 |
if (writer != null) |
1216 |
{ |
1217 |
if (writer instanceof ISpatialWriter) |
1218 |
return true; |
1219 |
} |
1220 |
} |
1221 |
return false; |
1222 |
|
1223 |
} |
1224 |
|
1225 |
// public void beforePrinting(PrintRequestAttributeSet properties) {
|
1226 |
// VectorialLegend vl=(VectorialLegend)getLegend();
|
1227 |
// if (vl instanceof ClassifiedLegendInfo) {
|
1228 |
// ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) vl;
|
1229 |
// IPrintable[] symbols=clsfLegend.getSymbols();
|
1230 |
// for (int i=0;i<symbols.length;i++) {
|
1231 |
// symbols[i].setPrintingProperties(properties);
|
1232 |
// }
|
1233 |
// }
|
1234 |
// if (vl.getDefaultSymbol()!=null) {
|
1235 |
// ((IPrintable)vl.getDefaultSymbol()).setPrintingProperties(properties);
|
1236 |
// }
|
1237 |
// }
|
1238 |
//
|
1239 |
// public void afterPrinting() {
|
1240 |
// VectorialLegend vl=(VectorialLegend)getLegend();
|
1241 |
// if (vl instanceof ClassifiedLegendInfo) {
|
1242 |
// ClassifiedLegendInfo clsfLegend = (ClassifiedLegendInfo) vl;
|
1243 |
// IPrintable[] symbols=clsfLegend.getSymbols();
|
1244 |
// for (int i=0;i<symbols.length;i++) {
|
1245 |
// symbols[i].setPrintingProperties(null);
|
1246 |
// }
|
1247 |
// }
|
1248 |
// if (vl.getDefaultSymbol()!=null) {
|
1249 |
// ((IPrintable)vl.getDefaultSymbol()).setPrintingProperties(null);
|
1250 |
// }
|
1251 |
//
|
1252 |
// }
|
1253 |
|
1254 |
public FLayer cloneLayer() throws Exception { |
1255 |
FLyrVect clonedLayer = new FLyrVect();
|
1256 |
clonedLayer.setSource(getSource()); |
1257 |
clonedLayer.setVisible(isVisible()); |
1258 |
clonedLayer.setISpatialIndex(getISpatialIndex()); |
1259 |
clonedLayer.setName(getName()); |
1260 |
clonedLayer.setCoordTrans(getCoordTrans()); |
1261 |
|
1262 |
clonedLayer.setLegend((IVectorialLegend)getLegend()); |
1263 |
|
1264 |
clonedLayer.setIsLabeled(isLabeled()); |
1265 |
clonedLayer.setLabelingStrategy(getLabelingStrategy()); |
1266 |
|
1267 |
return clonedLayer;
|
1268 |
} |
1269 |
|
1270 |
/*
|
1271 |
* jaume. Stuff from ILabeled.
|
1272 |
*/
|
1273 |
private boolean isLabeled; |
1274 |
private ILabelingStrategy strategy;
|
1275 |
|
1276 |
public boolean isLabeled() { |
1277 |
return isLabeled;
|
1278 |
} |
1279 |
|
1280 |
public void setIsLabeled(boolean isLabeled) { |
1281 |
this.isLabeled = isLabeled;
|
1282 |
} |
1283 |
|
1284 |
public ILabelingStrategy getLabelingStrategy() {
|
1285 |
return strategy;
|
1286 |
} |
1287 |
|
1288 |
public void setLabelingStrategy(ILabelingStrategy strategy) { |
1289 |
this.strategy = strategy;
|
1290 |
} |
1291 |
|
1292 |
public void drawLabels(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws ReadDriverException { |
1293 |
if (isWithinScale(scale)) {
|
1294 |
strategy.draw(image, g, viewPort, cancel); |
1295 |
} |
1296 |
} |
1297 |
|
1298 |
} |