svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / FLyrVect.java @ 21369
History | View | Annotate | Download (64 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 org.gvsig.fmap.mapcontext.layers.vectorial; |
42 |
|
43 |
import java.awt.Graphics2D; |
44 |
import java.awt.geom.AffineTransform; |
45 |
import java.awt.geom.Point2D; |
46 |
import java.awt.geom.Rectangle2D; |
47 |
import java.awt.image.BufferedImage; |
48 |
import java.net.URI; |
49 |
import java.util.ArrayList; |
50 |
import java.util.Iterator; |
51 |
|
52 |
import javax.print.attribute.PrintRequestAttributeSet; |
53 |
import javax.print.attribute.standard.PrintQuality; |
54 |
|
55 |
import org.apache.log4j.Logger; |
56 |
import org.cresques.cts.ICoordTrans; |
57 |
import org.gvsig.data.DataStore; |
58 |
import org.gvsig.data.ReadException; |
59 |
import org.gvsig.data.vectorial.Feature; |
60 |
import org.gvsig.data.vectorial.FeatureCollection; |
61 |
import org.gvsig.data.vectorial.FeatureStore; |
62 |
import org.gvsig.data.vectorial.FeatureType; |
63 |
import org.gvsig.data.vectorial.visitor.FeaturesVisitor; |
64 |
import org.gvsig.exceptions.BaseException; |
65 |
import org.gvsig.fmap.geom.Geometry; |
66 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
67 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
68 |
import org.gvsig.fmap.geometry.operation.DrawInts; |
69 |
import org.gvsig.fmap.geometry.operation.DrawOperationContext; |
70 |
import org.gvsig.fmap.mapcontext.MapContext; |
71 |
import org.gvsig.fmap.mapcontext.ViewPort; |
72 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
73 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
74 |
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException; |
75 |
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException; |
76 |
import org.gvsig.fmap.mapcontext.layers.AbstractLinkProperties; |
77 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
78 |
import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
79 |
import org.gvsig.fmap.mapcontext.layers.FLyrVectLinkProperties; |
80 |
import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
81 |
import org.gvsig.fmap.mapcontext.layers.SelectionSupport; |
82 |
import org.gvsig.fmap.mapcontext.layers.SpatialCache; |
83 |
import org.gvsig.fmap.mapcontext.layers.XMLException; |
84 |
import org.gvsig.fmap.mapcontext.layers.operations.AlphanumericData; |
85 |
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial; |
86 |
import org.gvsig.fmap.mapcontext.layers.operations.ILabelable; |
87 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
88 |
import org.gvsig.fmap.mapcontext.layers.operations.VectorialData; |
89 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend; |
90 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
91 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
92 |
import org.gvsig.fmap.mapcontext.rendering.legend.SingleSymbolLegend; |
93 |
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort; |
94 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
95 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
96 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
97 |
import org.gvsig.fmap.mapcontext.rendering.symbols.FSymbol; |
98 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
99 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
100 |
|
101 |
import com.iver.utiles.XMLEntity; |
102 |
import com.iver.utiles.swing.threads.Cancellable; |
103 |
|
104 |
/**
|
105 |
* Capa b?sica Vectorial.
|
106 |
*
|
107 |
* @author Fernando Gonz?lez Cort?s
|
108 |
*/
|
109 |
|
110 |
// TODO Cuando no sea para pruebas debe no ser public
|
111 |
public class FLyrVect extends FLyrDefault implements ILabelable, |
112 |
ClassifiableVectorial, SingleLayer, VectorialData, //RandomVectorialData,
|
113 |
AlphanumericData //, InfoByPoint
|
114 |
{ |
115 |
private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
116 |
|
117 |
/** Leyenda de la capa vectorial */
|
118 |
private IVectorLegend legend;
|
119 |
private int typeShape = -1; |
120 |
// private ReadableVectorial source;
|
121 |
// private SelectableDataSource sds;
|
122 |
private FeatureStore featureStore=null; |
123 |
private SelectionSupport selectionSupport = new SelectionSupport(); |
124 |
private SpatialCache spatialCache = new SpatialCache(); |
125 |
private boolean spatialCacheEnabled = false; |
126 |
|
127 |
/**
|
128 |
* An implementation of gvSIG spatial index
|
129 |
*/
|
130 |
// protected ISpatialIndex spatialIndex = null;
|
131 |
private boolean bHasJoin = false; |
132 |
private XMLEntity orgXMLEntity = null; |
133 |
private XMLEntity loadSelection = null; |
134 |
private IVectorLegend loadLegend = null; |
135 |
|
136 |
//Lo a?ado. Caracter?sticas de HyperEnlace (LINK)
|
137 |
private FLyrVectLinkProperties linkProperties=new FLyrVectLinkProperties(); |
138 |
|
139 |
/**
|
140 |
* Devuelve el VectorialAdapater de la capa.
|
141 |
*
|
142 |
* @return VectorialAdapter.
|
143 |
*/
|
144 |
public DataStore getDataStore() {
|
145 |
if (!this.isAvailable()) return null; |
146 |
return featureStore;
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* If we use a persistent spatial index associated with this layer, and the
|
151 |
* index is not intrisic to the layer (for example spatial databases) this
|
152 |
* method looks for existent spatial index, and loads it.
|
153 |
*
|
154 |
*/
|
155 |
// private void loadSpatialIndex() {
|
156 |
// //FIXME: Al abrir el indice en fichero...
|
157 |
// //?C?mo lo liberamos? un metodo Layer.shutdown()
|
158 |
//
|
159 |
//
|
160 |
// ReadableVectorial source = getSource();
|
161 |
// //REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
|
162 |
// //PUES SON VECTORIALFILEADAPTER
|
163 |
// if (!(source instanceof VectorialFileAdapter)) {
|
164 |
// // we are not interested in db adapters
|
165 |
// return;
|
166 |
// }
|
167 |
// VectorialDriver driver = source.getDriver();
|
168 |
// if (!(driver instanceof BoundedShapes)) {
|
169 |
// // we dont spatially index layers that are not bounded
|
170 |
// return;
|
171 |
// }
|
172 |
// File file = ((VectorialFileAdapter) source).getFile();
|
173 |
// String fileName = file.getAbsolutePath();
|
174 |
// File sptFile = new File(fileName + ".qix");
|
175 |
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
176 |
// // before to exit, look for it in temp path
|
177 |
// String tempPath = System.getProperty("java.io.tmpdir");
|
178 |
// fileName = tempPath + File.separator + sptFile.getName();
|
179 |
// sptFile = new File(fileName);
|
180 |
// // it doesnt exists, must to create
|
181 |
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
182 |
// return;
|
183 |
// }// if
|
184 |
// }// if
|
185 |
//
|
186 |
// try {
|
187 |
// source.start();
|
188 |
// spatialIndex = new QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
|
189 |
// "NM", source.getFullExtent(), source.getShapeCount(), false);
|
190 |
// source.setSpatialIndex(spatialIndex);
|
191 |
// } catch (SpatialIndexException e) {
|
192 |
// spatialIndex = null;
|
193 |
// e.printStackTrace();
|
194 |
// return;
|
195 |
// } catch (ReadDriverException e) {
|
196 |
// spatialIndex = null;
|
197 |
// e.printStackTrace();
|
198 |
// return;
|
199 |
// }
|
200 |
//
|
201 |
// }
|
202 |
|
203 |
/**
|
204 |
* Checks if it has associated an external spatial index
|
205 |
* (an spatial index file).
|
206 |
*
|
207 |
* It looks for it in main file path, or in temp system path.
|
208 |
* If main file is rivers.shp, it looks for a file called
|
209 |
* rivers.shp.qix.
|
210 |
|
211 |
* @return
|
212 |
*/
|
213 |
// public boolean isExternallySpatiallyIndexed() {
|
214 |
// /*
|
215 |
// * FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
|
216 |
// * con el que se trabaje (ahora mismo considera la extension .qix,
|
217 |
// * pero esto depender? del tipo de ?ndice)
|
218 |
// * */
|
219 |
// ReadableVectorial source = getSource();
|
220 |
// if (!(source instanceof VectorialFileAdapter)) {
|
221 |
// // we are not interested in db adapters.
|
222 |
// // think in non spatial dbs, like HSQLDB
|
223 |
// return false;
|
224 |
// }
|
225 |
// File file = ((VectorialFileAdapter) source).getFile();
|
226 |
// String fileName = file.getAbsolutePath();
|
227 |
// File sptFile = new File(fileName + ".qix");
|
228 |
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
229 |
// // before to exit, look for it in temp path
|
230 |
// // it doesnt exists, must to create
|
231 |
// String tempPath = System.getProperty("java.io.tmpdir");
|
232 |
// fileName = tempPath + File.separator + sptFile.getName();
|
233 |
// sptFile = new File(fileName);
|
234 |
// if (!sptFile.exists() || (!(sptFile.length() > 0))) {
|
235 |
// return false;
|
236 |
// }// if
|
237 |
// }// if
|
238 |
// return true;
|
239 |
// }
|
240 |
|
241 |
/**
|
242 |
* Inserta el VectorialAdapter a la capa.
|
243 |
*
|
244 |
* @param va
|
245 |
* VectorialAdapter.
|
246 |
*/
|
247 |
public void setDataStore(DataStore dataStore) { |
248 |
featureStore = (FeatureStore)dataStore; |
249 |
// azabala: we check if this layer could have a file spatial index
|
250 |
// and load it if it exists
|
251 |
// loadSpatialIndex();
|
252 |
} |
253 |
|
254 |
public Rectangle2D getFullExtent() throws ReadException { |
255 |
Rectangle2D rAux=null; |
256 |
// source.start();
|
257 |
// rAux = (Rectangle2D)source.getFullExtent().clone();
|
258 |
// source.stop();
|
259 |
//
|
260 |
//
|
261 |
// // Si existe reproyecci?n, reproyectar el extent
|
262 |
// ICoordTrans ct = getCoordTrans();
|
263 |
//
|
264 |
// if (ct != null) {
|
265 |
// Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY());
|
266 |
// Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY());
|
267 |
// pt1 = ct.convert(pt1, null);
|
268 |
// pt2 = ct.convert(pt2, null);
|
269 |
// rAux = new Rectangle2D.Double();
|
270 |
// rAux.setFrameFromDiagonal(pt1, pt2);
|
271 |
// }
|
272 |
//
|
273 |
// //Esto es para cuando se crea una capa nueva con el fullExtent de ancho y alto 0.
|
274 |
// if (rAux.getWidth()==0 && rAux.getHeight()==0) {
|
275 |
// rAux=new Rectangle2D.Double(0,0,100,100);
|
276 |
// }
|
277 |
|
278 |
return rAux;
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* Draws using IFeatureIterator. This method will replace the old draw(...) one.
|
283 |
* @autor jaume dominguez faus - jaume.dominguez@iver.es
|
284 |
* @param image
|
285 |
* @param g
|
286 |
* @param viewPort
|
287 |
* @param cancel
|
288 |
* @param scale
|
289 |
* @throws ReadDriverException
|
290 |
*/
|
291 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
292 |
Cancellable cancel, double scale) throws ReadException { |
293 |
boolean bDrawShapes = true; |
294 |
if (legend instanceof SingleSymbolLegend) { |
295 |
bDrawShapes = legend.getDefaultSymbol().isShapeVisible(); |
296 |
} |
297 |
Point2D offset = viewPort.getOffset();
|
298 |
double dpi = MapContext.getScreenDPI();
|
299 |
|
300 |
|
301 |
|
302 |
if (bDrawShapes) {
|
303 |
boolean cacheFeatures = isSpatialCacheEnabled();
|
304 |
SpatialCache cache = null;
|
305 |
if (cacheFeatures) {
|
306 |
getSpatialCache().clearAll(); |
307 |
cache = getSpatialCache(); |
308 |
} |
309 |
|
310 |
try {
|
311 |
ArrayList<String> fieldList = new ArrayList<String>(); |
312 |
|
313 |
// fields from legend
|
314 |
String[] aux = null; |
315 |
|
316 |
if (legend instanceof IClassifiedVectorLegend) { |
317 |
aux = ((IClassifiedVectorLegend) legend).getClassifyingFieldNames(); |
318 |
for (int i = 0; i < aux.length; i++) { |
319 |
fieldList.add(aux[i]); |
320 |
} |
321 |
} |
322 |
FeatureStore featureStore=(FeatureStore)getDataStore(); |
323 |
// Get the iterator over the visible features
|
324 |
|
325 |
FeatureCollection featureCollection=null;
|
326 |
featureCollection = (FeatureCollection)featureStore.getDataCollection( |
327 |
fieldList.toArray(new String[fieldList.size()]), |
328 |
null,//filter |
329 |
null);//order |
330 |
Iterator it = featureCollection.iterator();
|
331 |
|
332 |
|
333 |
// viewPort.getAdjustedExtent(),
|
334 |
// fieldList.toArray(new String[fieldList.size()]),
|
335 |
// viewPort.getProjection(),
|
336 |
// true);
|
337 |
|
338 |
ZSort zSort = ((IVectorLegend) getLegend()).getZSort(); |
339 |
|
340 |
boolean bSymbolLevelError = false; |
341 |
|
342 |
// if layer has map levels it will use a ZSort
|
343 |
boolean useZSort = zSort != null && zSort.isUsingZSort(); |
344 |
|
345 |
// -- visual FX stuff
|
346 |
long time = System.currentTimeMillis(); |
347 |
BufferedImage virtualBim;
|
348 |
Graphics2D virtualGraphics;
|
349 |
|
350 |
// render temporary map each screenRefreshRate milliseconds;
|
351 |
int screenRefreshDelay = (int) ((1D/MapContext.getDrawFrameRate())*3*1000); |
352 |
BufferedImage[] imageLevels = null; |
353 |
Graphics2D[] graphics = null; |
354 |
if (useZSort) {
|
355 |
imageLevels = new BufferedImage[zSort.getLevelCount()]; |
356 |
graphics = new Graphics2D[imageLevels.length]; |
357 |
for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) { |
358 |
imageLevels[i] = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); |
359 |
graphics[i] = imageLevels[i].createGraphics(); |
360 |
graphics[i].setTransform(g.getTransform()); |
361 |
graphics[i].setRenderingHints(g.getRenderingHints()); |
362 |
} |
363 |
} |
364 |
// -- end visual FX stuff
|
365 |
|
366 |
|
367 |
// Iteration over each feature
|
368 |
while ( !cancel.isCanceled() && it.hasNext()) {
|
369 |
Feature feat = (Feature)it.next(); |
370 |
Geometry geom = (Geometry)feat.getDefaultGeometry(); |
371 |
|
372 |
if (cacheFeatures) {
|
373 |
if (cache.getMaxFeatures() >= cache.size()) {
|
374 |
// already reprojected
|
375 |
cache.insert(geom.getBounds2D(), geom); |
376 |
} |
377 |
} |
378 |
|
379 |
// retrieve the symbol associated to such feature
|
380 |
ISymbol sym = legend.getSymbolByFeature(feat); |
381 |
|
382 |
if (sym == null) continue; |
383 |
|
384 |
//C?digo para poder acceder a los ?ndices para ver si est? seleccionado un Feature
|
385 |
// ReadableVectorial rv=getSource();
|
386 |
// int selectionIndex=-1;
|
387 |
// if (rv instanceof ISpatialDB){
|
388 |
// selectionIndex=((ISpatialDB)rv).getRowIndexByFID(feat);
|
389 |
// }else{
|
390 |
// selectionIndex=Integer.parseInt(feat.getID());
|
391 |
// }
|
392 |
// if (selectionIndex!=-1) {
|
393 |
// if (selectionSupport.isSelected(selectionIndex)) {
|
394 |
// sym = sym.getSymbolForSelection();
|
395 |
// }
|
396 |
// }
|
397 |
|
398 |
// Check if this symbol is sized with CartographicSupport
|
399 |
CartographicSupport csSym = null;
|
400 |
int symbolType = sym.getSymbolType();
|
401 |
boolean bDrawCartographicSupport = false; |
402 |
|
403 |
if ( symbolType == Geometry.TYPES.POINT
|
404 |
|| symbolType == Geometry.TYPES.CURVE |
405 |
|| sym instanceof CartographicSupport) {
|
406 |
|
407 |
// patch
|
408 |
if (!sym.getClass().equals(FSymbol.class)) {
|
409 |
csSym = (CartographicSupport) sym; |
410 |
bDrawCartographicSupport = (csSym.getUnit() != -1);
|
411 |
} |
412 |
} |
413 |
|
414 |
int x = -1; |
415 |
int y = -1; |
416 |
int[] xyCoords = new int[2]; |
417 |
|
418 |
// Check if size is a pixel
|
419 |
boolean onePoint = bDrawCartographicSupport ?
|
420 |
isOnePoint(g.getTransform(), viewPort, MapContext.getScreenDPI(), csSym, geom, xyCoords) : |
421 |
isOnePoint(g.getTransform(), viewPort, geom, xyCoords); |
422 |
|
423 |
// Avoid out of bounds exceptions
|
424 |
if (onePoint) {
|
425 |
x = xyCoords[0];
|
426 |
y = xyCoords[1];
|
427 |
if (x<0 || y<0 || x>= viewPort.getImageWidth() || y>=viewPort.getImageHeight()) continue; |
428 |
} |
429 |
|
430 |
if (useZSort) {
|
431 |
// Check if this symbol is a multilayer
|
432 |
if (sym instanceof IMultiLayerSymbol) { |
433 |
// if so, treat each of its layers as a single symbol
|
434 |
// in its corresponding map level
|
435 |
IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym; |
436 |
for (int i = 0; !cancel.isCanceled() && i < mlSym.getLayerCount(); i++) { |
437 |
ISymbol mySym = mlSym.getLayer(i); |
438 |
int symbolLevel = zSort.getSymbolLevel(mySym);
|
439 |
|
440 |
if (symbolLevel == -1) { |
441 |
/* an error occured when managing symbol levels
|
442 |
* some of the legend changed events regarding the
|
443 |
* symbols did not finish satisfactory and the legend
|
444 |
* is now inconsistent. For this drawing, it will finish
|
445 |
* as it was at the bottom (level 0) but, when done, the
|
446 |
* ZSort will be reset to avoid app crashes. This is
|
447 |
* a bug that has to be fixed.
|
448 |
*/
|
449 |
bSymbolLevelError = true;
|
450 |
symbolLevel=0;
|
451 |
} |
452 |
|
453 |
if (onePoint) {
|
454 |
if (x<0 || y<0 || x>= imageLevels[symbolLevel].getWidth() || y>=imageLevels[symbolLevel].getHeight()) continue; |
455 |
imageLevels[symbolLevel].setRGB(x, y, mySym.getOnePointRgb()); |
456 |
} else {
|
457 |
if (!bDrawCartographicSupport) {
|
458 |
DrawOperationContext doc=new DrawOperationContext();
|
459 |
doc.setGraphics(graphics[symbolLevel]); |
460 |
doc.setViewPort(viewPort); |
461 |
doc.setSymbol(mySym); |
462 |
doc.setCancellable(cancel); |
463 |
geom.invokeOperation(DrawInts.CODE,doc); |
464 |
} else {
|
465 |
DrawOperationContext doc=new DrawOperationContext();
|
466 |
doc.setGraphics(graphics[symbolLevel]); |
467 |
doc.setViewPort(viewPort); |
468 |
doc.setSymbol(mySym); |
469 |
doc.setCancellable(cancel); |
470 |
doc.setDPI(dpi); |
471 |
geom.invokeOperation(DrawInts.CODE,doc); |
472 |
} |
473 |
} |
474 |
} |
475 |
} else {
|
476 |
// else, just draw the symbol in its level
|
477 |
if (!bDrawCartographicSupport) {
|
478 |
DrawOperationContext doc=new DrawOperationContext();
|
479 |
doc.setGraphics(graphics[zSort.getSymbolLevel(sym)]); |
480 |
doc.setViewPort(viewPort); |
481 |
doc.setSymbol(sym); |
482 |
doc.setCancellable(cancel); |
483 |
geom.invokeOperation(DrawInts.CODE,doc); |
484 |
} else {
|
485 |
DrawOperationContext doc=new DrawOperationContext();
|
486 |
doc.setGraphics(graphics[zSort.getSymbolLevel(sym)]); |
487 |
doc.setViewPort(viewPort); |
488 |
doc.setSymbol((ISymbol)csSym); |
489 |
doc.setCancellable(cancel); |
490 |
doc.setDPI(dpi); |
491 |
geom.invokeOperation(DrawInts.CODE,doc); |
492 |
} |
493 |
} |
494 |
|
495 |
// -- visual FX stuff
|
496 |
// Cuando el offset!=0 se est? dibujando sobre el Layout y por tanto no tiene que ejecutar el siguiente c?digo.
|
497 |
if (offset.getX()==0 && offset.getY()==0) |
498 |
if ((System.currentTimeMillis() - time) > screenRefreshDelay) { |
499 |
virtualBim = new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_INT_ARGB); |
500 |
virtualGraphics = virtualBim.createGraphics(); |
501 |
virtualGraphics.drawImage(image,0,0, null); |
502 |
for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) { |
503 |
virtualGraphics.drawImage(imageLevels[i],0,0, null); |
504 |
} |
505 |
g.clearRect(0, 0, image.getWidth(), image.getHeight()); |
506 |
g.drawImage(virtualBim, 0, 0, null); |
507 |
time = System.currentTimeMillis();
|
508 |
} |
509 |
// -- end visual FX stuff
|
510 |
|
511 |
} else {
|
512 |
// no ZSort, so there is only a map level, symbols are
|
513 |
// just drawn.
|
514 |
if (onePoint) {
|
515 |
if (x<0 || y<0 || x>= image.getWidth() || y>=image.getHeight()) continue; |
516 |
image.setRGB(x, y, sym.getOnePointRgb()); |
517 |
} else {
|
518 |
|
519 |
if (!bDrawCartographicSupport) {
|
520 |
DrawOperationContext doc=new DrawOperationContext();
|
521 |
doc.setGraphics(g); |
522 |
doc.setViewPort(viewPort); |
523 |
doc.setSymbol(sym); |
524 |
doc.setCancellable(cancel); |
525 |
geom.invokeOperation(DrawInts.CODE,doc); |
526 |
} else {
|
527 |
DrawOperationContext doc=new DrawOperationContext();
|
528 |
doc.setGraphics(g); |
529 |
doc.setViewPort(viewPort); |
530 |
doc.setSymbol((ISymbol)csSym); |
531 |
doc.setCancellable(cancel); |
532 |
doc.setDPI(dpi); |
533 |
geom.invokeOperation(DrawInts.CODE,doc); |
534 |
} |
535 |
} |
536 |
} |
537 |
} |
538 |
|
539 |
if (useZSort) {
|
540 |
g.drawImage(image, 0, 0, null); |
541 |
g.translate(offset.getX(), offset.getY()); |
542 |
for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) { |
543 |
g.drawImage(imageLevels[i],0,0, null); |
544 |
imageLevels[i] = null;
|
545 |
graphics[i] = null;
|
546 |
} |
547 |
g.translate(-offset.getX(), -offset.getY()); |
548 |
imageLevels = null;
|
549 |
graphics = null;
|
550 |
} |
551 |
// it.closeIterator();
|
552 |
it=null;
|
553 |
featureCollection.dispose(); |
554 |
|
555 |
if (bSymbolLevelError) {
|
556 |
((IVectorLegend) getLegend()).setZSort(null);
|
557 |
} |
558 |
|
559 |
} catch (ReadException e) {
|
560 |
this.setVisible(false); |
561 |
this.setActive(false); |
562 |
throw e;
|
563 |
} catch (GeometryOperationNotSupportedException e) {
|
564 |
this.setVisible(false); |
565 |
this.setActive(false); |
566 |
throw new ReadException(getName(),e); |
567 |
} catch (GeometryOperationException e) {
|
568 |
this.setVisible(false); |
569 |
this.setActive(false); |
570 |
throw new ReadException(getName(),e); |
571 |
} |
572 |
|
573 |
|
574 |
} |
575 |
} |
576 |
|
577 |
// public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
|
578 |
// Cancellable cancel, double scale) throws ReadException {
|
579 |
//// forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD = true;
|
580 |
// if (!isUseStrategy()) {
|
581 |
// _draw(image, g, viewPort, cancel, scale);
|
582 |
// } else {
|
583 |
//// moved up to FLayers
|
584 |
//// if (isWithinScale(scale)) {
|
585 |
//
|
586 |
//
|
587 |
// // Las que solo tienen etiquetado sin pintar el shape,
|
588 |
// // no pasamos por ellas
|
589 |
// boolean bDrawShapes = true;
|
590 |
// if (legend instanceof SingleSymbolLegend) {
|
591 |
// if (legend.getDefaultSymbol().isShapeVisible() == false)
|
592 |
// bDrawShapes = false;
|
593 |
// }
|
594 |
// if (bDrawShapes) {
|
595 |
// Strategy strategy = StrategyManager.getStrategy(this);
|
596 |
// try {
|
597 |
// prepareDrawing(image, g, viewPort);
|
598 |
// strategy.draw(image, g, viewPort, cancel);
|
599 |
// } catch (ReadDriverException e) {
|
600 |
// this.setVisible(false);
|
601 |
// this.setActive(false);
|
602 |
// throw e;
|
603 |
// }
|
604 |
// }
|
605 |
// if (getVirtualLayers() != null) {
|
606 |
// getVirtualLayers().draw(image, g, viewPort, cancel, scale);
|
607 |
// }
|
608 |
//// }
|
609 |
// }
|
610 |
// }
|
611 |
|
612 |
/**
|
613 |
* Se llama antes de empezar a pintar.
|
614 |
* Es ?til para preparar la cache a emplear, las leyendas, etc.
|
615 |
* @param image
|
616 |
* @param g
|
617 |
* @param viewPort
|
618 |
*/
|
619 |
private void prepareDrawing(BufferedImage image, Graphics2D g, ViewPort viewPort) { |
620 |
|
621 |
} |
622 |
|
623 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
624 |
double scale, PrintRequestAttributeSet properties) throws ReadException { |
625 |
// TEST METHOD
|
626 |
|
627 |
|
628 |
/* SVN */
|
629 |
|
630 |
/* boolean bDrawShapes = true;
|
631 |
if (legend instanceof SingleSymbolLegend) {
|
632 |
bDrawShapes = legend.getDefaultSymbol().isShapeVisible();
|
633 |
}
|
634 |
|
635 |
|
636 |
if (bDrawShapes) {
|
637 |
double dpi = 72;
|
638 |
|
639 |
PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class);
|
640 |
if (resolution.equals(PrintQuality.NORMAL)){
|
641 |
dpi = 300;
|
642 |
} else if (resolution.equals(PrintQuality.HIGH)){
|
643 |
dpi = 600;
|
644 |
} else if (resolution.equals(PrintQuality.DRAFT)){
|
645 |
dpi = 72;
|
646 |
}
|
647 |
|
648 |
|
649 |
try {
|
650 |
prepareDrawing(null, g, viewPort);
|
651 |
ArrayList<String> fieldList = new ArrayList<String>();
|
652 |
String[] aux;
|
653 |
|
654 |
// fields from legend
|
655 |
if (legend instanceof IClassifiedVectorLegend) {
|
656 |
aux = ((IClassifiedVectorLegend) legend).
|
657 |
getClassifyingFieldNames();
|
658 |
for (int i = 0; i < aux.length; i++) {
|
659 |
fieldList.add(aux[i]);
|
660 |
}
|
661 |
}
|
662 |
|
663 |
// fields from labeling
|
664 |
if (isLabeled()) {
|
665 |
aux = getLabelingStrategy().getUsedFields();
|
666 |
for (int i = 0; i < aux.length; i++) {
|
667 |
fieldList.add(aux[i]);
|
668 |
}
|
669 |
}
|
670 |
|
671 |
ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
|
672 |
|
673 |
// if layer has map levels it will use a ZSort
|
674 |
boolean useZSort = zSort != null && zSort.isUsingZSort();
|
675 |
|
676 |
|
677 |
int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1;
|
678 |
for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) {
|
679 |
// Get the iterator over the visible features
|
680 |
IFeatureIterator it = getSource().getFeatureIterator(
|
681 |
viewPort.getAdjustedExtent(),
|
682 |
fieldList.toArray(new String[fieldList.size()]),
|
683 |
viewPort.getProjection(),
|
684 |
true);
|
685 |
|
686 |
// Iteration over each feature
|
687 |
while ( !cancel.isCanceled() && it.hasNext()) {
|
688 |
IFeature feat = it.next();
|
689 |
IGeometry geom = feat.getGeometry();
|
690 |
|
691 |
// retreive the symbol associated to such feature
|
692 |
ISymbol sym = legend.getSymbolByFeature(feat);
|
693 |
|
694 |
if (useZSort) {
|
695 |
// Check if this symbol is a multilayer
|
696 |
if (sym instanceof IMultiLayerSymbol) {
|
697 |
// if so, get the layer corresponding to the current
|
698 |
// level. If none, continue to next iteration
|
699 |
IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
|
700 |
for (int i = 0; i < mlSym.getLayerCount(); i++) {
|
701 |
ISymbol mySym = mlSym.getLayer(i);
|
702 |
if (zSort.getSymbolLevel(mySym) == mapPass) {
|
703 |
sym = mySym;
|
704 |
break;
|
705 |
}
|
706 |
System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")");
|
707 |
}
|
708 |
|
709 |
if (sym == null) {
|
710 |
continue;
|
711 |
}
|
712 |
} else {
|
713 |
// else, just draw the symbol in its level
|
714 |
if (zSort.getSymbolLevel(sym) != mapPass) {
|
715 |
System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")");
|
716 |
continue;
|
717 |
}
|
718 |
}
|
719 |
}
|
720 |
|
721 |
// Check if this symbol is sized with CartographicSupport
|
722 |
CartographicSupport csSym = null;
|
723 |
int symbolType = sym.getSymbolType();
|
724 |
boolean bDrawCartographicSupport = false;
|
725 |
|
726 |
if ( symbolType == FShape.POINT
|
727 |
|| symbolType == FShape.LINE
|
728 |
|| sym instanceof CartographicSupport) {
|
729 |
|
730 |
csSym = (CartographicSupport) sym;
|
731 |
bDrawCartographicSupport = (csSym.getUnit() != -1);
|
732 |
}
|
733 |
|
734 |
System.err.println("passada "+mapPass+" pinte s?mboll "+sym.getDescription());
|
735 |
|
736 |
if (!bDrawCartographicSupport) {
|
737 |
geom.drawInts(g, viewPort, sym, null);
|
738 |
} else {
|
739 |
geom.drawInts(g, viewPort, dpi, (CartographicSupport) csSym);
|
740 |
}
|
741 |
|
742 |
}
|
743 |
it.closeIterator();
|
744 |
}
|
745 |
} catch (ReadDriverException e) {
|
746 |
this.setVisible(false);
|
747 |
this.setActive(false);
|
748 |
throw e;
|
749 |
}
|
750 |
*/
|
751 |
|
752 |
|
753 |
// TEST METHOD
|
754 |
boolean bDrawShapes = true; |
755 |
if (legend instanceof SingleSymbolLegend) { |
756 |
bDrawShapes = legend.getDefaultSymbol().isShapeVisible(); |
757 |
} |
758 |
|
759 |
|
760 |
if (bDrawShapes) {
|
761 |
|
762 |
try {
|
763 |
double dpi = 72; |
764 |
|
765 |
PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class); |
766 |
if (resolution.equals(PrintQuality.NORMAL)){ |
767 |
dpi = 300;
|
768 |
} else if (resolution.equals(PrintQuality.HIGH)){ |
769 |
dpi = 600;
|
770 |
} else if (resolution.equals(PrintQuality.DRAFT)){ |
771 |
dpi = 72;
|
772 |
} |
773 |
ArrayList<String> fieldList = new ArrayList<String>(); |
774 |
String[] aux; |
775 |
|
776 |
// fields from legend
|
777 |
if (legend instanceof IClassifiedVectorLegend) { |
778 |
aux = ((IClassifiedVectorLegend) legend). |
779 |
getClassifyingFieldNames(); |
780 |
for (int i = 0; i < aux.length; i++) { |
781 |
fieldList.add(aux[i]); |
782 |
} |
783 |
} |
784 |
//
|
785 |
// // fields from labeling
|
786 |
// if (isLabeled()) {
|
787 |
// aux = getLabelingStrategy().getUsedFields();
|
788 |
// for (int i = 0; i < aux.length; i++) {
|
789 |
// fieldList.add(aux[i]);
|
790 |
// }
|
791 |
// }
|
792 |
|
793 |
ZSort zSort = ((IVectorLegend) getLegend()).getZSort(); |
794 |
|
795 |
// if layer has map levels it will use a ZSort
|
796 |
boolean useZSort = zSort != null && zSort.isUsingZSort(); |
797 |
|
798 |
|
799 |
int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1; |
800 |
for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) { |
801 |
// Get the iterator over the visible features
|
802 |
FeatureStore featureStore=(FeatureStore)getDataStore(); |
803 |
// Get the iterator over the visible features
|
804 |
FeatureCollection featureCollection=null;
|
805 |
featureCollection= (FeatureCollection) featureStore.getDataCollection( |
806 |
fieldList.toArray(new String[fieldList.size()]), |
807 |
null,//filter |
808 |
null);//order |
809 |
Iterator it = featureCollection.iterator();
|
810 |
// viewPort.getAdjustedExtent(),
|
811 |
// fieldList.toArray(new String[fieldList.size()]),
|
812 |
// viewPort.getProjection(),
|
813 |
// true);
|
814 |
|
815 |
// Iteration over each feature
|
816 |
while ( !cancel.isCanceled() && it.hasNext()) {
|
817 |
Feature feat = (Feature)it.next(); |
818 |
Geometry geom = (Geometry)feat.getDefaultGeometry(); |
819 |
|
820 |
// retreive the symbol associated to such feature
|
821 |
ISymbol sym = legend.getSymbolByFeature(feat); |
822 |
|
823 |
if (useZSort) {
|
824 |
// Check if this symbol is a multilayer
|
825 |
if (sym instanceof IMultiLayerSymbol) { |
826 |
// if so, get the layer corresponding to the current
|
827 |
// level. If none, continue to next iteration
|
828 |
IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym; |
829 |
for (int i = 0; i < mlSym.getLayerCount(); i++) { |
830 |
ISymbol mySym = mlSym.getLayer(i); |
831 |
if (zSort.getSymbolLevel(mySym) == mapPass) {
|
832 |
sym = mySym; |
833 |
break;
|
834 |
} |
835 |
System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")"); |
836 |
} |
837 |
|
838 |
if (sym == null) { |
839 |
continue;
|
840 |
} |
841 |
} else {
|
842 |
// else, just draw the symbol in its level
|
843 |
if (zSort.getSymbolLevel(sym) != mapPass) {
|
844 |
System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")"); |
845 |
continue;
|
846 |
} |
847 |
} |
848 |
} |
849 |
|
850 |
// Check if this symbol is sized with CartographicSupport
|
851 |
CartographicSupport csSym = null;
|
852 |
int symbolType = sym.getSymbolType();
|
853 |
boolean bDrawCartographicSupport = false; |
854 |
|
855 |
if ( symbolType == Geometry.TYPES.POINT
|
856 |
|| symbolType == Geometry.TYPES.CURVE |
857 |
|| sym instanceof CartographicSupport) {
|
858 |
|
859 |
csSym = (CartographicSupport) sym; |
860 |
bDrawCartographicSupport = (csSym.getUnit() != -1);
|
861 |
} |
862 |
|
863 |
System.err.println("passada "+mapPass+" pinte s?mboll "+sym.getDescription()); |
864 |
|
865 |
if (!bDrawCartographicSupport) {
|
866 |
DrawOperationContext doc=new DrawOperationContext();
|
867 |
doc.setGraphics(g); |
868 |
doc.setViewPort(viewPort); |
869 |
doc.setSymbol(sym); |
870 |
doc.setCancellable(cancel); |
871 |
geom.invokeOperation(DrawInts.CODE,doc); |
872 |
} else {
|
873 |
DrawOperationContext doc=new DrawOperationContext();
|
874 |
doc.setGraphics(g); |
875 |
doc.setViewPort(viewPort); |
876 |
doc.setSymbol((ISymbol)csSym); |
877 |
doc.setCancellable(cancel); |
878 |
doc.setDPI(dpi); |
879 |
geom.invokeOperation(DrawInts.CODE,doc); |
880 |
} |
881 |
} |
882 |
// it.closeIterator();
|
883 |
it=null;
|
884 |
featureCollection.dispose(); |
885 |
} |
886 |
} catch (ReadException e) {
|
887 |
this.setVisible(false); |
888 |
this.setActive(false); |
889 |
throw e;
|
890 |
} catch (GeometryOperationNotSupportedException e) {
|
891 |
this.setVisible(false); |
892 |
this.setActive(false); |
893 |
throw new ReadException(getName(),e); |
894 |
} catch (GeometryOperationException e) {
|
895 |
this.setVisible(false); |
896 |
this.setActive(false); |
897 |
throw new ReadException(getName(),e); |
898 |
} |
899 |
} |
900 |
} |
901 |
|
902 |
|
903 |
// public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
|
904 |
// double scale, PrintRequestAttributeSet properties) throws ReadException {
|
905 |
// if (forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD) {
|
906 |
// _print(g, viewPort, cancel, scale, properties);
|
907 |
// } else {
|
908 |
//// moved up to Flayers
|
909 |
//// if (isVisible() && isWithinScale(scale)) {
|
910 |
// Strategy strategy = StrategyManager.getStrategy(this);
|
911 |
//
|
912 |
// strategy.print(g, viewPort, cancel, properties);
|
913 |
// ILabelingStrategy labeling;
|
914 |
// if ( (labeling = getLabelingStrategy() ) != null) {
|
915 |
// // contains labels
|
916 |
// labeling.print(g, viewPort, cancel, properties);
|
917 |
// }
|
918 |
//// }
|
919 |
// }
|
920 |
// }
|
921 |
|
922 |
// public void deleteSpatialIndex() {
|
923 |
// //must we delete possible spatial indexes files?
|
924 |
// spatialIndex = null;
|
925 |
// }
|
926 |
|
927 |
/**
|
928 |
* <p>
|
929 |
* Creates an spatial index associated to this layer.
|
930 |
* The spatial index will used
|
931 |
* the native projection of the layer, so if the layer is reprojected, it will
|
932 |
* be ignored.
|
933 |
* </p>
|
934 |
* @param cancelMonitor instance of CancellableMonitorable that allows
|
935 |
* to monitor progress of spatial index creation, and cancel the process
|
936 |
*/
|
937 |
// public void createSpatialIndex(CancellableMonitorable cancelMonitor){
|
938 |
// // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
939 |
// // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
940 |
// // para que acepten recorrer sin geometria, solo con rectangulos.
|
941 |
//
|
942 |
// //If this vectorial layer is based in a spatial database, the spatial
|
943 |
// //index is already implicit. We only will index file drivers
|
944 |
// ReadableVectorial va = getSource();
|
945 |
// //We must think in non spatial databases, like HSQLDB
|
946 |
// if(!(va instanceof VectorialFileAdapter)){
|
947 |
// return;
|
948 |
// }
|
949 |
// if (!(va.getDriver() instanceof BoundedShapes)) {
|
950 |
// return;
|
951 |
// }
|
952 |
// File file = ((VectorialFileAdapter) va).getFile();
|
953 |
// String fileName = file.getAbsolutePath();
|
954 |
// ISpatialIndex localCopy = null;
|
955 |
// try {
|
956 |
// va.start();
|
957 |
// localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(),
|
958 |
// va.getShapeCount(), true);
|
959 |
//
|
960 |
// } catch (SpatialIndexException e1) {
|
961 |
// // Probably we dont have writing permissions
|
962 |
// String directoryName = System.getProperty("java.io.tmpdir");
|
963 |
// File newFile = new File(directoryName +
|
964 |
// File.separator +
|
965 |
// file.getName());
|
966 |
// String newFileName = newFile.getName();
|
967 |
// try {
|
968 |
// localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(),
|
969 |
// va.getShapeCount(), true);
|
970 |
// } catch (SpatialIndexException e) {
|
971 |
// // if we cant build a file based spatial index, we'll build
|
972 |
// // a pure memory spatial index
|
973 |
// localCopy = new QuadtreeJts();
|
974 |
// } catch (ReadException e) {
|
975 |
// localCopy = new QuadtreeJts();
|
976 |
// }
|
977 |
//
|
978 |
// } catch(Exception e){
|
979 |
// e.printStackTrace();
|
980 |
// }//try
|
981 |
// BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
|
982 |
// try {
|
983 |
// for (int i=0; i < va.getShapeCount(); i++)
|
984 |
// {
|
985 |
// if(cancelMonitor != null){
|
986 |
// if(cancelMonitor.isCanceled())
|
987 |
// return;
|
988 |
// cancelMonitor.reportStep();
|
989 |
// }
|
990 |
// Rectangle2D r = shapeBounds.getShapeBounds(i);
|
991 |
// if(r != null)
|
992 |
// localCopy.insert(r, i);
|
993 |
// } // for
|
994 |
// va.stop();
|
995 |
// if(localCopy instanceof IPersistentSpatialIndex)
|
996 |
// ((IPersistentSpatialIndex) localCopy).flush();
|
997 |
// spatialIndex = localCopy;
|
998 |
// //vectorial adapter needs a reference to the spatial index, to solve
|
999 |
// //request for feature iteration based in spatial queries
|
1000 |
// source.setSpatialIndex(spatialIndex);
|
1001 |
// } catch (ReadException e) {
|
1002 |
// // TODO Auto-generated catch block
|
1003 |
// e.printStackTrace();
|
1004 |
// }
|
1005 |
// }
|
1006 |
|
1007 |
// public void createSpatialIndex() {
|
1008 |
// createSpatialIndex(null);
|
1009 |
// }
|
1010 |
|
1011 |
public void process(FeaturesVisitor visitor, FeatureCollection collection) |
1012 |
throws ReadException {
|
1013 |
try {
|
1014 |
collection.accept(visitor); |
1015 |
} catch (BaseException e) {
|
1016 |
throw new ReadException(getName(),e); |
1017 |
} |
1018 |
// Strategy s = StrategyManager.getStrategy(this);
|
1019 |
// s.process(visitor, subset);
|
1020 |
} |
1021 |
|
1022 |
public void process(FeaturesVisitor visitor) throws ReadException { |
1023 |
FeatureCollection collection=(FeatureCollection)((FeatureStore)getDataStore()).getDataCollection(); |
1024 |
try {
|
1025 |
collection.accept(visitor); |
1026 |
} catch (BaseException e) {
|
1027 |
throw new ReadException(getName(),e); |
1028 |
} |
1029 |
} |
1030 |
|
1031 |
// public void process(FeaturesVisitor visitor, Rectangle2D rect)
|
1032 |
// throws ReadException {
|
1033 |
// Strategy s = StrategyManager.getStrategy(this);
|
1034 |
// s.process(visitor, rect);
|
1035 |
// }
|
1036 |
|
1037 |
// public FBitSet queryByRect(Rectangle2D rect) throws ReadException {
|
1038 |
// Strategy s = StrategyManager.getStrategy(this);
|
1039 |
//
|
1040 |
// return s.queryByRect(rect);
|
1041 |
// }
|
1042 |
|
1043 |
// public FBitSet queryByPoint(Point2D p, double tolerance)
|
1044 |
// throws ReadException {
|
1045 |
// Strategy s = StrategyManager.getStrategy(this);
|
1046 |
// return s.queryByPoint(p, tolerance);
|
1047 |
// }
|
1048 |
|
1049 |
// public FBitSet queryByShape(Geometry g, int relationship)
|
1050 |
// throws ReadException {
|
1051 |
// Strategy s = StrategyManager.getStrategy(this);
|
1052 |
// return s.queryByShape(g, relationship);
|
1053 |
// }
|
1054 |
|
1055 |
// public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws ReadDriverException, VisitorException {
|
1056 |
// Point2D pReal = this.getMapContext().getViewPort().toMapPoint(p);
|
1057 |
// FBitSet bs = queryByPoint(pReal, tolerance);
|
1058 |
// VectorialXMLItem[] item = new VectorialXMLItem[1];
|
1059 |
// item[0] = new VectorialXMLItem(bs, this);
|
1060 |
//
|
1061 |
// return item;
|
1062 |
// }
|
1063 |
|
1064 |
public void setLegend(IVectorLegend r) throws LegendLayerException { |
1065 |
IVectorLegend oldLegend = legend; |
1066 |
legend = r; |
1067 |
try {
|
1068 |
legend.setFeatureStore(getFeatureStore()); |
1069 |
} catch (ReadException e1) {
|
1070 |
throw new LegendLayerException(getName(),e1); |
1071 |
} |
1072 |
LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent( |
1073 |
oldLegend, legend); |
1074 |
callLegendChanged(e); |
1075 |
} |
1076 |
|
1077 |
/**
|
1078 |
* Devuelve la Leyenda de la capa.
|
1079 |
*
|
1080 |
* @return Leyenda.
|
1081 |
*/
|
1082 |
public ILegend getLegend() {
|
1083 |
return legend;
|
1084 |
} |
1085 |
|
1086 |
/**
|
1087 |
* Devuelve el tipo de shape que contiene la capa.
|
1088 |
*
|
1089 |
* @return tipo de shape.
|
1090 |
*
|
1091 |
* @throws DriverException
|
1092 |
*/
|
1093 |
public int getShapeType() throws ReadException { |
1094 |
if (typeShape == -1) { |
1095 |
// getSource().start();
|
1096 |
typeShape = ((FeatureType)((FeatureStore)getDataStore()).getFeatureTypes().get(0)).getGeometryTypes()[0]; |
1097 |
// getSource().stop();
|
1098 |
} |
1099 |
|
1100 |
return typeShape;
|
1101 |
} |
1102 |
|
1103 |
public XMLEntity getXMLEntity() throws XMLException { |
1104 |
// if (!this.isAvailable() && this.orgXMLEntity != null) {
|
1105 |
// return this.orgXMLEntity;
|
1106 |
// }
|
1107 |
// XMLEntity xml = super.getXMLEntity();
|
1108 |
// if (getLegend()!=null)
|
1109 |
// xml.addChild(getLegend().getXMLEntity());
|
1110 |
// try {
|
1111 |
// if (getRecordset()!=null)
|
1112 |
// xml.addChild(getRecordset().getSelectionSupport().getXMLEntity());
|
1113 |
// } catch (ReadException e1) {
|
1114 |
// e1.printStackTrace();
|
1115 |
// throw new XMLException(e1);
|
1116 |
// }
|
1117 |
// // Repongo el mismo ReadableVectorial m?s abajo para cuando se guarda el proyecto.
|
1118 |
// ReadableVectorial rv=getSource();
|
1119 |
// xml.putProperty("type", "vectorial");
|
1120 |
// if (source instanceof VectorialEditableAdapter) {
|
1121 |
// setSource(((VectorialEditableAdapter) source).getOriginalAdapter());
|
1122 |
// }
|
1123 |
// if (source instanceof VectorialFileAdapter) {
|
1124 |
// xml.putProperty("type", "vectorial");
|
1125 |
// xml.putProperty("file", ((VectorialFileAdapter) source)
|
1126 |
// .getFile());
|
1127 |
// try {
|
1128 |
// xml.putProperty("recordset-name", source.getRecordset()
|
1129 |
// .getName());
|
1130 |
// } catch (ReadException e) {
|
1131 |
// throw new XMLException(e);
|
1132 |
// } catch (RuntimeException e) {
|
1133 |
// e.printStackTrace();
|
1134 |
// }
|
1135 |
// } else if (source instanceof VectorialDBAdapter) {
|
1136 |
// xml.putProperty("type", "vectorial");
|
1137 |
//
|
1138 |
// IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) source
|
1139 |
// .getDriver();
|
1140 |
//
|
1141 |
// // Guardamos el nombre del driver para poder recuperarlo
|
1142 |
// // con el DriverManager de Fernando.
|
1143 |
// xml.putProperty("db", dbDriver.getName());
|
1144 |
// try {
|
1145 |
// xml.putProperty("recordset-name", source.getRecordset()
|
1146 |
// .getName());
|
1147 |
// } catch (ReadException e) {
|
1148 |
// throw new XMLException(e);
|
1149 |
// } catch (RuntimeException e) {
|
1150 |
// e.printStackTrace();
|
1151 |
// }
|
1152 |
// xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos
|
1153 |
// // metido la leyenda y el
|
1154 |
// // selection support
|
1155 |
// } else if (source instanceof VectorialAdapter) {
|
1156 |
// // Se supone que hemos hecho algo gen?rico.
|
1157 |
// xml.putProperty("type", "vectorial");
|
1158 |
//
|
1159 |
// VectorialDriver driver = source.getDriver();
|
1160 |
//
|
1161 |
// // Guardamos el nombre del driver para poder recuperarlo
|
1162 |
// // con el DriverManager de Fernando.
|
1163 |
// xml.putProperty("other", driver.getName());
|
1164 |
// // try {
|
1165 |
// try {
|
1166 |
// xml.putProperty("recordset-name", source.getRecordset()
|
1167 |
// .getName());
|
1168 |
// } catch (ReadException e) {
|
1169 |
// throw new XMLException(e);
|
1170 |
// } catch (RuntimeException e) {
|
1171 |
// e.printStackTrace();
|
1172 |
// }
|
1173 |
// if (driver instanceof IPersistence) {
|
1174 |
// // xml.putProperty("className", driver.getClass().getName());
|
1175 |
// IPersistence persist = (IPersistence) driver;
|
1176 |
// xml.addChild(persist.getXMLEntity()); // Tercer child. Antes
|
1177 |
// // hemos metido la
|
1178 |
// // leyenda y el
|
1179 |
// // selection support
|
1180 |
// }
|
1181 |
// }
|
1182 |
// if (rv!=null)
|
1183 |
// setSource(rv);
|
1184 |
// xml.putProperty("driverName", source.getDriver().getName());
|
1185 |
// if (bHasJoin)
|
1186 |
// xml.putProperty("hasJoin", "true");
|
1187 |
//
|
1188 |
// // properties from ILabelable
|
1189 |
// xml.putProperty("isLabeled", isLabeled);
|
1190 |
// if (strategy != null) {
|
1191 |
// XMLEntity strategyXML = strategy.getXMLEntity();
|
1192 |
// strategyXML.putProperty("Strategy", strategy.getClassName());
|
1193 |
// xml.addChild(strategy.getXMLEntity());
|
1194 |
// }
|
1195 |
// xml.addChild(getLinkProperties().getXMLEntity());
|
1196 |
// return xml;
|
1197 |
return null; |
1198 |
} |
1199 |
/*
|
1200 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
1201 |
*/
|
1202 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
1203 |
// try {
|
1204 |
// super.setXMLEntity(xml);
|
1205 |
// XMLEntity legendXML = xml.getChild(0);
|
1206 |
// IVectorLegend leg = LegendFactory.createFromXML(legendXML);
|
1207 |
// /* (jaume) begin patch;
|
1208 |
// * for backward compatibility purposes. Since gvSIG v1.1 labeling is
|
1209 |
// * no longer managed by the Legend but by the ILabelingStrategy. The
|
1210 |
// * following allows restoring older projects' labelings.
|
1211 |
// */
|
1212 |
// if (legendXML.contains("labelFieldName")) {
|
1213 |
// String labelTextField = legendXML.getStringProperty("labelFieldName");
|
1214 |
// if (labelTextField != null) {
|
1215 |
// AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
|
1216 |
// labeling.setLayer(this);
|
1217 |
// labeling.setTextField(legendXML.getStringProperty("labelFieldName"));
|
1218 |
// labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
|
1219 |
// labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
|
1220 |
// this.setLabelingStrategy(labeling);
|
1221 |
// this.setIsLabeled(true);
|
1222 |
// }
|
1223 |
// }
|
1224 |
// /* end patch */
|
1225 |
// try {
|
1226 |
// getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
1227 |
// // JMVIVO: Esto sirve para algo????
|
1228 |
// String recordsetName = xml.getStringProperty("recordset-name");
|
1229 |
//
|
1230 |
// LayerFactory.getDataSourceFactory().changeDataSourceName(
|
1231 |
// getSource().getRecordset().getName(), recordsetName);
|
1232 |
// } catch (NoSuchTableException e1) {
|
1233 |
// this.setAvailable(false);
|
1234 |
// throw new XMLException(e1);
|
1235 |
// } catch (ReadException e1) {
|
1236 |
// this.setAvailable(false);
|
1237 |
// throw new XMLException(e1);
|
1238 |
// }
|
1239 |
// // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
1240 |
// // el final
|
1241 |
// // de la lectura del proyecto
|
1242 |
// if (xml.contains("hasJoin")) {
|
1243 |
// setIsJoined(true);
|
1244 |
// PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1);
|
1245 |
// } else {
|
1246 |
// try {
|
1247 |
// setLegend(leg);
|
1248 |
// } catch (LegendLayerException e) {
|
1249 |
// throw new XMLException(e);
|
1250 |
// }
|
1251 |
// }
|
1252 |
//
|
1253 |
// // set properties for ILabelable
|
1254 |
// XMLEntity labelingXML = xml.firstChild("id", "LabelingStrategy");
|
1255 |
// if (labelingXML!= null) {
|
1256 |
// isLabeled = true;
|
1257 |
// try {
|
1258 |
// this.strategy = LabelingFactory.createStrategyFromXML(labelingXML, this);
|
1259 |
// } catch (NotExistInXMLEntity neXMLEX) {
|
1260 |
// // no strategy was set, just continue;
|
1261 |
// logger.warn("Reached what should be unreachable code");
|
1262 |
// }
|
1263 |
// } else {
|
1264 |
// isLabeled = false;
|
1265 |
// }
|
1266 |
//
|
1267 |
// XMLEntity xmlLinkProperties=xml.firstChild("typeChild","linkProperties");
|
1268 |
// if (xmlLinkProperties != null){
|
1269 |
// getLinkProperties().setXMLEntity(xmlLinkProperties);
|
1270 |
// }
|
1271 |
//
|
1272 |
// } catch (XMLException e) {
|
1273 |
// this.setAvailable(false);
|
1274 |
// this.orgXMLEntity = xml;
|
1275 |
// } catch (Exception e) {
|
1276 |
// e.printStackTrace();
|
1277 |
// this.setAvailable(false);
|
1278 |
// this.orgXMLEntity = xml;
|
1279 |
//
|
1280 |
// }
|
1281 |
//
|
1282 |
|
1283 |
} |
1284 |
|
1285 |
public void setXMLEntityNew(XMLEntity xml) throws XMLException { |
1286 |
// try {
|
1287 |
// super.setXMLEntity(xml);
|
1288 |
//
|
1289 |
// XMLEntity legendXML = xml.getChild(0);
|
1290 |
// IVectorLegend leg = LegendFactory.createFromXML(legendXML);
|
1291 |
// /* (jaume) begin patch;
|
1292 |
// * for backward compatibility purposes. Since gvSIG v1.1 labeling is
|
1293 |
// * no longer managed by the Legend but by the ILabelingStrategy. The
|
1294 |
// * following allows restoring older projects' labelings.
|
1295 |
// */
|
1296 |
// if (legendXML.contains("labelFieldHeight")) {
|
1297 |
// AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
|
1298 |
// labeling.setLayer(this);
|
1299 |
// labeling.setTextField(legendXML.getStringProperty("labelFieldHeight"));
|
1300 |
// labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
|
1301 |
// this.setLabelingStrategy(labeling);
|
1302 |
// this.setIsLabeled(true);
|
1303 |
// }
|
1304 |
// /* end patch */
|
1305 |
// try {
|
1306 |
// getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
1307 |
//
|
1308 |
// this.setLoadSelection(xml.getChild(1));
|
1309 |
// } catch (ReadException e1) {
|
1310 |
// this.setAvailable(false);
|
1311 |
// throw new XMLException(e1);
|
1312 |
// }
|
1313 |
// // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
1314 |
// // el final
|
1315 |
// // de la lectura del proyecto
|
1316 |
// if (xml.contains("hasJoin")) {
|
1317 |
// setIsJoined(true);
|
1318 |
// PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1);
|
1319 |
// } else {
|
1320 |
// this.setLoadLegend(leg);
|
1321 |
// }
|
1322 |
//
|
1323 |
// } catch (XMLException e) {
|
1324 |
// this.setAvailable(false);
|
1325 |
// this.orgXMLEntity = xml;
|
1326 |
// } catch (Exception e) {
|
1327 |
// this.setAvailable(false);
|
1328 |
// this.orgXMLEntity = xml;
|
1329 |
// }
|
1330 |
|
1331 |
|
1332 |
} |
1333 |
|
1334 |
|
1335 |
/**
|
1336 |
* Sobreimplementaci?n del m?todo toString para que las bases de datos
|
1337 |
* identifiquen la capa.
|
1338 |
*
|
1339 |
* @return DOCUMENT ME!
|
1340 |
*/
|
1341 |
public String toString() { |
1342 |
/*
|
1343 |
* Se usa internamente para que la parte de datos identifique de forma
|
1344 |
* un?voca las tablas
|
1345 |
*/
|
1346 |
String ret = super.toString(); |
1347 |
|
1348 |
return "layer" + ret.substring(ret.indexOf('@') + 1); |
1349 |
} |
1350 |
|
1351 |
public boolean isJoined() { |
1352 |
return bHasJoin;
|
1353 |
} |
1354 |
|
1355 |
/**
|
1356 |
* Returns if a layer is spatially indexed
|
1357 |
*
|
1358 |
* @return if this layer has the ability to proces spatial queries without
|
1359 |
* secuential scans.
|
1360 |
*/
|
1361 |
// public boolean isSpatiallyIndexed() {
|
1362 |
// ReadableVectorial source = getSource();
|
1363 |
// if (source instanceof ISpatialDB)
|
1364 |
// return true;
|
1365 |
//
|
1366 |
////FIXME azabala
|
1367 |
///*
|
1368 |
// * Esto es muy dudoso, y puede cambiar.
|
1369 |
// * Estoy diciendo que las que no son fichero o no son
|
1370 |
// * BoundedShapes estan indexadas. Esto es mentira, pero
|
1371 |
// * as? quien pregunte no querr? generar el indice.
|
1372 |
// * Esta por ver si interesa generar el indice para capas
|
1373 |
// * HSQLDB, WFS, etc.
|
1374 |
// */
|
1375 |
// if(!(source instanceof VectorialFileAdapter)){
|
1376 |
// return true;
|
1377 |
// }
|
1378 |
// if (!(source.getDriver() instanceof BoundedShapes)) {
|
1379 |
// return true;
|
1380 |
// }
|
1381 |
//
|
1382 |
// if (getISpatialIndex() != null)
|
1383 |
// return true;
|
1384 |
// return false;
|
1385 |
// }
|
1386 |
|
1387 |
public void setIsJoined(boolean hasJoin) { |
1388 |
bHasJoin = hasJoin; |
1389 |
} |
1390 |
|
1391 |
// /**
|
1392 |
// * @return Returns the spatialIndex.
|
1393 |
// */
|
1394 |
// public ISpatialIndex getISpatialIndex() {
|
1395 |
// return spatialIndex;
|
1396 |
// }
|
1397 |
// /**
|
1398 |
// * Sets the spatial index. This could be useful if, for some
|
1399 |
// * reasons, you want to work with a distinct spatial index
|
1400 |
// * (for example, a spatial index which could makes nearest
|
1401 |
// * neighbour querys)
|
1402 |
// * @param spatialIndex
|
1403 |
// */
|
1404 |
// public void setISpatialIndex(ISpatialIndex spatialIndex){
|
1405 |
// this.spatialIndex = spatialIndex;
|
1406 |
// }
|
1407 |
|
1408 |
// public SelectableDataSource getRecordset() throws ReadException {
|
1409 |
// if (!this.isAvailable()) return null;
|
1410 |
// if (sds == null) {
|
1411 |
//
|
1412 |
// SelectableDataSource ds = source.getRecordset();
|
1413 |
//
|
1414 |
// if (ds == null) {
|
1415 |
// return null;
|
1416 |
// }
|
1417 |
//
|
1418 |
// sds = ds;
|
1419 |
// sds.setSelectionSupport(selectionSupport);
|
1420 |
//
|
1421 |
// }
|
1422 |
// return sds;
|
1423 |
// }
|
1424 |
|
1425 |
public void setEditing(boolean b) throws StartEditionLayerException { |
1426 |
super.setEditing(b);
|
1427 |
try {
|
1428 |
getDataStore().startEditing(); |
1429 |
} catch (ReadException e) {
|
1430 |
throw new StartEditionLayerException(getName(),e); |
1431 |
} |
1432 |
// try {
|
1433 |
// if (b) {
|
1434 |
// VectorialEditableAdapter vea = null;
|
1435 |
// // TODO: Qu? pasa si hay m?s tipos de adapters?
|
1436 |
// // FJP: Se podr?a pasar como argumento el
|
1437 |
// // VectorialEditableAdapter
|
1438 |
// // que se quiera usar para evitar meter c?digo aqu? de este
|
1439 |
// // estilo.
|
1440 |
// if (getSource() instanceof VectorialDBAdapter) {
|
1441 |
// vea = new VectorialEditableDBAdapter();
|
1442 |
// } else if (this instanceof FLyrAnnotation) {
|
1443 |
// vea = new AnnotationEditableAdapter(
|
1444 |
// (FLyrAnnotation) this);
|
1445 |
// } else {
|
1446 |
// vea = new VectorialEditableAdapter();
|
1447 |
// }
|
1448 |
// vea.setOriginalVectorialAdapter(getSource());
|
1449 |
//// azo: implementations of readablevectorial need
|
1450 |
// //references of projection and spatial index
|
1451 |
// vea.setProjection(getProjection());
|
1452 |
// vea.setSpatialIndex(spatialIndex);
|
1453 |
//
|
1454 |
//
|
1455 |
// // /vea.setSpatialIndex(getSpatialIndex());
|
1456 |
// // /vea.setFullExtent(getFullExtent());
|
1457 |
// vea.setCoordTrans(getCoordTrans());
|
1458 |
// vea.startEdition(EditionEvent.GRAPHIC);
|
1459 |
// setSource(vea);
|
1460 |
// getRecordset().setSelectionSupport(
|
1461 |
// vea.getOriginalAdapter().getRecordset()
|
1462 |
// .getSelectionSupport());
|
1463 |
//
|
1464 |
// } else {
|
1465 |
// VectorialEditableAdapter vea = (VectorialEditableAdapter) getSource();
|
1466 |
// setSource(vea.getOriginalAdapter());
|
1467 |
// }
|
1468 |
// // Si tenemos una leyenda, hay que pegarle el cambiazo a su
|
1469 |
// // recordset
|
1470 |
// setRecordset(getSource().getRecordset());
|
1471 |
// if (getLegend() instanceof IVectorLegend) {
|
1472 |
// IVectorLegend ley = (IVectorLegend) getLegend();
|
1473 |
// ley.setDataSource(getSource().getRecordset());
|
1474 |
// // Esto lo pongo para evitar que al dibujar sobre un
|
1475 |
// // dxf, dwg, o dgn no veamos nada. Es debido al checkbox
|
1476 |
// // de la leyenda de textos "dibujar solo textos".
|
1477 |
////jaume
|
1478 |
//// if (!(getSource().getDriver() instanceof IndexedShpDriver)){
|
1479 |
//// FSymbol symbol=new FSymbol(getShapeType());
|
1480 |
//// symbol.setFontSizeInPixels(false);
|
1481 |
//// symbol.setFont(new Font("SansSerif", Font.PLAIN, 9));
|
1482 |
//// Color color=symbol.getColor();
|
1483 |
//// int alpha=symbol.getColor().getAlpha();
|
1484 |
//// if (alpha>250) {
|
1485 |
//// symbol.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),100));
|
1486 |
//// }
|
1487 |
//// ley.setDefaultSymbol(symbol);
|
1488 |
//// }
|
1489 |
////jaume//
|
1490 |
// ley.useDefaultSymbol(true);
|
1491 |
// }
|
1492 |
// } catch (ReadDriverException e) {
|
1493 |
// throw new StartEditionLayerException(getName(),e);
|
1494 |
// } catch (FieldNotFoundException e) {
|
1495 |
// throw new StartEditionLayerException(getName(),e);
|
1496 |
// } catch (StartWriterVisitorException e) {
|
1497 |
// throw new StartEditionLayerException(getName(),e);
|
1498 |
// }
|
1499 |
|
1500 |
setSpatialCacheEnabled(b); |
1501 |
callEditionChanged(LayerEvent |
1502 |
.createEditionChangedEvent(this, "edition")); |
1503 |
|
1504 |
} |
1505 |
|
1506 |
/**
|
1507 |
* Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
1508 |
* forma, podr?s poner leyendas basadas en el nuevo recordset
|
1509 |
*
|
1510 |
* @param newSds
|
1511 |
*/
|
1512 |
// public void setRecordset(SelectableDataSource newSds) {
|
1513 |
// sds = newSds;
|
1514 |
// sds.setSelectionSupport(selectionSupport);
|
1515 |
// }
|
1516 |
|
1517 |
public void clearSpatialCache() |
1518 |
{ |
1519 |
spatialCache.clearAll(); |
1520 |
} |
1521 |
|
1522 |
public boolean isSpatialCacheEnabled() { |
1523 |
return spatialCacheEnabled;
|
1524 |
} |
1525 |
|
1526 |
public void setSpatialCacheEnabled(boolean spatialCacheEnabled) { |
1527 |
this.spatialCacheEnabled = spatialCacheEnabled;
|
1528 |
} |
1529 |
|
1530 |
public SpatialCache getSpatialCache() {
|
1531 |
return spatialCache;
|
1532 |
} |
1533 |
|
1534 |
/**
|
1535 |
* Siempre es un numero mayor de 1000
|
1536 |
* @param maxFeatures
|
1537 |
*/
|
1538 |
public void setMaxFeaturesInEditionCache(int maxFeatures) { |
1539 |
if (maxFeatures > spatialCache.getMaxFeatures())
|
1540 |
spatialCache.setMaxFeatures(maxFeatures); |
1541 |
|
1542 |
} |
1543 |
|
1544 |
/**
|
1545 |
* This method returns a boolean that is used by the FPopMenu
|
1546 |
* to make visible the properties menu or not. It is visible by
|
1547 |
* default, and if a later don't have to show this menu only
|
1548 |
* has to override this method.
|
1549 |
* @return
|
1550 |
* If the properties menu is visible (or not)
|
1551 |
*/
|
1552 |
public boolean isPropertiesMenuVisible(){ |
1553 |
return true; |
1554 |
} |
1555 |
|
1556 |
public void reload() throws ReloadLayerException { |
1557 |
this.setAvailable(true); |
1558 |
super.reload();
|
1559 |
// try {
|
1560 |
// this.source.getDriver().reload();
|
1561 |
// if (this.getLegend() == null) {
|
1562 |
// if (this.getRecordset().getDriver() instanceof WithDefaultLegend) {
|
1563 |
// WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
|
1564 |
// this.setLegend((IVectorLegend) aux.getDefaultLegend());
|
1565 |
// this.setLabelingStrategy(aux.getDefaultLabelingStrategy());
|
1566 |
// } else {
|
1567 |
// this.setLegend(LegendFactory.createSingleSymbolLegend(
|
1568 |
// this.getShapeType()));
|
1569 |
// }
|
1570 |
// }
|
1571 |
//
|
1572 |
// } catch (LegendLayerException e) {
|
1573 |
// this.setAvailable(false);
|
1574 |
// throw new ReloadLayerException(getName(),e);
|
1575 |
// } catch (ReadException e) {
|
1576 |
// this.setAvailable(false);
|
1577 |
// throw new ReloadLayerException(getName(),e);
|
1578 |
// }
|
1579 |
|
1580 |
} |
1581 |
|
1582 |
protected void setLoadSelection(XMLEntity xml) { |
1583 |
this.loadSelection = xml;
|
1584 |
} |
1585 |
|
1586 |
protected void setLoadLegend(IVectorLegend legend) { |
1587 |
this.loadLegend = legend;
|
1588 |
} |
1589 |
|
1590 |
protected void putLoadSelection() throws XMLException { |
1591 |
// if (this.loadSelection == null) return;
|
1592 |
// try {
|
1593 |
// this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection);
|
1594 |
// } catch (ReadDriverException e) {
|
1595 |
// throw new XMLException(e);
|
1596 |
// }
|
1597 |
// this.loadSelection = null;
|
1598 |
|
1599 |
} |
1600 |
protected void putLoadLegend() throws LegendLayerException { |
1601 |
if (this.loadLegend == null) return; |
1602 |
this.setLegend(this.loadLegend); |
1603 |
this.loadLegend = null; |
1604 |
} |
1605 |
|
1606 |
protected void cleanLoadOptions() { |
1607 |
this.loadLegend = null; |
1608 |
this.loadSelection = null; |
1609 |
} |
1610 |
|
1611 |
public boolean isWritable() { |
1612 |
return getDataStore().isEditable();
|
1613 |
// VectorialDriver drv = getSource().getDriver();
|
1614 |
// if (!drv.isWritable())
|
1615 |
// return false;
|
1616 |
// if (drv instanceof IWriteable)
|
1617 |
// {
|
1618 |
// IWriter writer = ((IWriteable)drv).getWriter();
|
1619 |
// if (writer != null)
|
1620 |
// {
|
1621 |
// if (writer instanceof ISpatialWriter)
|
1622 |
// return true;
|
1623 |
// }
|
1624 |
// }
|
1625 |
// return false;
|
1626 |
|
1627 |
} |
1628 |
|
1629 |
public FLayer cloneLayer() throws Exception { |
1630 |
FLyrVect clonedLayer = new FLyrVect();
|
1631 |
clonedLayer.setDataStore(getDataStore()); |
1632 |
if (isJoined()) {
|
1633 |
clonedLayer.setIsJoined(true);
|
1634 |
// clonedLayer.setRecordset(getRecordset());
|
1635 |
} |
1636 |
clonedLayer.setVisible(isVisible()); |
1637 |
// clonedLayer.setISpatialIndex(getISpatialIndex());
|
1638 |
clonedLayer.setName(getName()); |
1639 |
clonedLayer.setCoordTrans(getCoordTrans()); |
1640 |
|
1641 |
clonedLayer.setLegend((IVectorLegend)getLegend().cloneLegend()); |
1642 |
|
1643 |
clonedLayer.setIsLabeled(isLabeled()); |
1644 |
clonedLayer.setLabelingStrategy(getLabelingStrategy()); |
1645 |
|
1646 |
return clonedLayer;
|
1647 |
} |
1648 |
|
1649 |
|
1650 |
private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, double dpi, CartographicSupport csSym, Geometry geom, int[] xyCoords) { |
1651 |
return isOnePoint(graphicsTransform, viewPort, geom, xyCoords) && csSym.getCartographicSize(viewPort, dpi, null) <= 1; |
1652 |
} |
1653 |
|
1654 |
private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, Geometry geom, int[] xyCoords) { |
1655 |
boolean onePoint = false; |
1656 |
int type=geom.getType() % Geometry.TYPES.Z;
|
1657 |
if (type!=Geometry.TYPES.POINT && type!=Geometry.TYPES.MULTIPOINT) {
|
1658 |
|
1659 |
Rectangle2D geomBounds = geom.getBounds2D();
|
1660 |
|
1661 |
ICoordTrans ct = getCoordTrans(); |
1662 |
|
1663 |
if (ct!=null) { |
1664 |
// geomBounds = ct.getInverted().convert(geomBounds);
|
1665 |
geomBounds = ct.convert(geomBounds); |
1666 |
} |
1667 |
|
1668 |
double dist1Pixel = viewPort.getDist1pixel();
|
1669 |
|
1670 |
onePoint = (geomBounds.getWidth() <= dist1Pixel |
1671 |
&& geomBounds.getHeight() <= dist1Pixel); |
1672 |
|
1673 |
if (onePoint) {
|
1674 |
// avoid out of range exceptions
|
1675 |
org.gvsig.fmap.geom.primitive.Point2D p = new org.gvsig.fmap.geom.primitive.Point2D(geomBounds.getMinX(), geomBounds.getMinY());
|
1676 |
p.transform(viewPort.getAffineTransform()); |
1677 |
p.transform(graphicsTransform); |
1678 |
xyCoords[0] = (int) p.getX(); |
1679 |
xyCoords[1] = (int) p.getY(); |
1680 |
|
1681 |
} |
1682 |
|
1683 |
} |
1684 |
return onePoint;
|
1685 |
} |
1686 |
/*
|
1687 |
* jaume. Stuff from ILabeled.
|
1688 |
*/
|
1689 |
private boolean isLabeled; |
1690 |
private ILabelingStrategy strategy;
|
1691 |
|
1692 |
public boolean isLabeled() { |
1693 |
return isLabeled;
|
1694 |
} |
1695 |
|
1696 |
public void setIsLabeled(boolean isLabeled) { |
1697 |
this.isLabeled = isLabeled;
|
1698 |
} |
1699 |
|
1700 |
public ILabelingStrategy getLabelingStrategy() {
|
1701 |
return strategy;
|
1702 |
} |
1703 |
|
1704 |
public void setLabelingStrategy(ILabelingStrategy strategy) { |
1705 |
this.strategy = strategy;
|
1706 |
} |
1707 |
|
1708 |
public void drawLabels(BufferedImage image, Graphics2D g, ViewPort viewPort, |
1709 |
Cancellable cancel, double scale, double dpi) throws ReadException { |
1710 |
if (strategy!=null && isWithinScale(scale)) { |
1711 |
strategy.draw(image, g, viewPort, cancel, dpi); |
1712 |
} |
1713 |
} |
1714 |
|
1715 |
|
1716 |
|
1717 |
//M?todos para el uso de HyperLinks en capas FLyerVect
|
1718 |
|
1719 |
/**
|
1720 |
* Return true, because a Vectorial Layer supports HyperLink
|
1721 |
*/
|
1722 |
public boolean allowLinks() |
1723 |
{ |
1724 |
return true; |
1725 |
} |
1726 |
|
1727 |
/**
|
1728 |
* Returns an instance of AbstractLinkProperties that contains the information
|
1729 |
* of the HyperLink
|
1730 |
* @return Abstra
|
1731 |
*/
|
1732 |
public AbstractLinkProperties getLinkProperties()
|
1733 |
{ |
1734 |
return linkProperties;
|
1735 |
} |
1736 |
|
1737 |
/**
|
1738 |
* Provides an array with URIs. Returns one URI by geometry that includes the point
|
1739 |
* in its own geometry limits with a allowed tolerance.
|
1740 |
* @param layer, the layer
|
1741 |
* @param point, the point to check that is contained or not in the geometries in the layer
|
1742 |
* @param tolerance, the tolerance allowed. Allowed margin of error to detect if the point
|
1743 |
* is contained in some geometries of the layer
|
1744 |
* @return
|
1745 |
* @throws ReadException
|
1746 |
* @throws BehaviorException
|
1747 |
*/
|
1748 |
public URI[] getLink(Point2D point, double tolerance) throws ReadException |
1749 |
{ |
1750 |
//return linkProperties.getLink(this)
|
1751 |
return linkProperties.getLink(this,point,tolerance); |
1752 |
} |
1753 |
// /**
|
1754 |
// * @deprecated Don?t use Strategy, you should be use iterators.
|
1755 |
// */
|
1756 |
// public boolean isUseStrategy() {
|
1757 |
// return useStrategy;
|
1758 |
// }
|
1759 |
// /**
|
1760 |
// * @deprecated Don?t use Strategy, you should be use iterators.
|
1761 |
// */
|
1762 |
// public void setUseStrategy(boolean useStrategy) {
|
1763 |
// this.useStrategy = useStrategy;
|
1764 |
// }
|
1765 |
|
1766 |
public void load() throws LoadLayerException { |
1767 |
super.load();
|
1768 |
// useStrategy=forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD;
|
1769 |
} |
1770 |
|
1771 |
public FeatureStore getFeatureStore() throws ReadException { |
1772 |
return (FeatureStore)getDataStore();
|
1773 |
} |
1774 |
|
1775 |
public FeatureCollection queryByPoint(Point2D mapPoint, double tol) { |
1776 |
// TODO Auto-generated method stub
|
1777 |
return null; |
1778 |
} |
1779 |
|
1780 |
public FeatureCollection queryByShape(Geometry geom) {
|
1781 |
// TODO Auto-generated method stub
|
1782 |
return null; |
1783 |
} |
1784 |
|
1785 |
public FeatureCollection queryByRect(Rectangle2D rect) { |
1786 |
// TODO Auto-generated method stub
|
1787 |
return null; |
1788 |
} |
1789 |
|
1790 |
} |