svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 6216
History | View | Annotate | Download (34.5 KB)
1 | 1100 | fjp | /* 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 | 214 | fernando | package com.iver.cit.gvsig.fmap.layers; |
42 | |||
43 | 1828 | fernando | import java.awt.Graphics2D; |
44 | 5048 | ldiaz | import java.awt.Point; |
45 | 1828 | fernando | import java.awt.geom.Point2D; |
46 | import java.awt.geom.Rectangle2D; |
||
47 | import java.awt.image.BufferedImage; |
||
48 | 4977 | azabala | import java.io.File; |
49 | 2978 | fjp | import java.io.IOException; |
50 | 1828 | fernando | |
51 | import org.apache.log4j.Logger; |
||
52 | import org.cresques.cts.ICoordTrans; |
||
53 | |||
54 | 408 | fernando | import com.hardcode.driverManager.DriverLoadException; |
55 | 2694 | fjp | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
56 | 1828 | fernando | import com.hardcode.gdbms.engine.data.NoSuchTableException; |
57 | 470 | fjp | import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
58 | 652 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
59 | 214 | fernando | import com.iver.cit.gvsig.fmap.ViewPort; |
60 | 757 | fjp | import com.iver.cit.gvsig.fmap.core.IGeometry; |
61 | 5152 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
62 | 2978 | fjp | import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
63 | 214 | fernando | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
64 | 2778 | fjp | import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver; |
65 | 3301 | fjp | import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
66 | 5390 | caballero | import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
67 | 4256 | caballero | import com.iver.cit.gvsig.fmap.edition.AnnotationEditableAdapter; |
68 | 5184 | caballero | import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
69 | 4147 | fjp | import com.iver.cit.gvsig.fmap.edition.EditionException; |
70 | 3981 | caballero | import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
71 | 4159 | fjp | import com.iver.cit.gvsig.fmap.edition.VectorialEditableDBAdapter; |
72 | 562 | fernando | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
73 | import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
||
74 | 5048 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
75 | 562 | fernando | import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable; |
76 | import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData; |
||
77 | 5690 | fjp | import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
78 | 562 | fernando | import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
79 | import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
||
80 | 5057 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialXMLItem; |
81 | 5201 | ldiaz | import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
82 | 214 | fernando | import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
83 | 231 | fernando | import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
84 | import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
||
85 | 926 | fernando | import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
86 | 461 | fernando | import com.iver.cit.gvsig.fmap.rendering.Legend; |
87 | import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
||
88 | 214 | fernando | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
89 | 3035 | fjp | import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
90 | 321 | fernando | import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
91 | 4977 | azabala | import com.iver.cit.gvsig.fmap.spatialindex.IPersistentSpatialIndex; |
92 | import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex; |
||
93 | 5414 | azabala | import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeGt2; |
94 | 4977 | azabala | import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeJts; |
95 | 5414 | azabala | import com.iver.cit.gvsig.fmap.spatialindex.RTreeJsi; |
96 | 4977 | azabala | import com.iver.cit.gvsig.fmap.spatialindex.RTreeSptLib; |
97 | import com.iver.cit.gvsig.fmap.spatialindex.SpatialIndexException; |
||
98 | import com.iver.utiles.FileUtils; |
||
99 | 3301 | fjp | import com.iver.utiles.IPersistance; |
100 | 2672 | fjp | import com.iver.utiles.PostProcessSupport; |
101 | 415 | fernando | import com.iver.utiles.XMLEntity; |
102 | 5317 | fjp | import com.iver.utiles.swing.threads.Cancellable; |
103 | import com.iver.utiles.swing.threads.CancellableMonitorable; |
||
104 | 214 | fernando | |
105 | 562 | fernando | /**
|
106 | 1034 | vcaballero | * Capa b?sica Vectorial.
|
107 | 5184 | caballero | *
|
108 | 562 | fernando | * @author Fernando Gonz?lez Cort?s
|
109 | */
|
||
110 | 885 | fjp | |
111 | 5152 | fjp | // TODO Cuando no sea para pruebas debe no ser public
|
112 | public class FLyrVect extends FLyrDefault implements Labelable, |
||
113 | ClassifiableVectorial, SingleLayer, VectorialData, RandomVectorialData, |
||
114 | AlphanumericData, InfoByPoint { |
||
115 | 526 | vcaballero | private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
116 | 562 | fernando | |
117 | 526 | vcaballero | /** Leyenda de la capa vectorial */
|
118 | 562 | fernando | private VectorialLegend legend;
|
119 | 5152 | fjp | |
120 | 562 | fernando | private int typeShape = -1; |
121 | 3963 | caballero | |
122 | 562 | fernando | private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
123 | 5152 | fjp | |
124 | 3940 | caballero | private ReadableVectorial source;
|
125 | 5152 | fjp | |
126 | 4455 | fjp | private SelectableDataSource sds;
|
127 | 5152 | fjp | |
128 | 4455 | fjp | private SelectionSupport selectionSupport = new SelectionSupport(); |
129 | 5390 | caballero | |
130 | 5813 | fjp | private SpatialCache spatialCache = new SpatialCache(); |
131 | 5574 | fjp | private boolean spatialCacheEnabled = false; |
132 | 3940 | caballero | |
133 | 5152 | fjp | // protected SpatialIndex spatialIndex = null;
|
134 | 4977 | azabala | /**
|
135 | * An implementation of gvSIG spatial index
|
||
136 | */
|
||
137 | 5152 | fjp | protected ISpatialIndex spatialIndex = null; |
138 | 5115 | caballero | |
139 | 5152 | fjp | private boolean bHasJoin = false; |
140 | 461 | fernando | |
141 | 562 | fernando | /**
|
142 | 1034 | vcaballero | * A?ade un SelectionListener a la lista de listeners.
|
143 | 5184 | caballero | *
|
144 | 5152 | fjp | * @param listener
|
145 | * SelectionListener.
|
||
146 | 562 | fernando | */
|
147 | 5152 | fjp | /*
|
148 | * public void addSelectionListener(SelectionListener listener) { try {
|
||
149 | * getRecordset().addSelectionListener(listener); } catch (DriverException
|
||
150 | * e) { // TODO Auto-generated catch block e.printStackTrace(); } }
|
||
151 | */
|
||
152 | 562 | fernando | /**
|
153 | 1034 | vcaballero | * Borra un selectionListener de la lista de listeners.
|
154 | 5184 | caballero | *
|
155 | 5152 | fjp | * @param listener
|
156 | * SelectionListener
|
||
157 | 562 | fernando | */
|
158 | 5152 | fjp | /*
|
159 | * public void removeSelectionListener(SelectionListener listener) { try {
|
||
160 | * getRecordset().removeSelectionListener(listener); } catch
|
||
161 | * (DriverException e) { // TODO Auto-generated catch block
|
||
162 | * e.printStackTrace(); } }
|
||
163 | */
|
||
164 | 562 | fernando | /**
|
165 | * Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
||
166 | * una gran cantidad de eventos. Con el fin de no propagar todos estos
|
||
167 | * eventos, se realiza la propagaci?n de manera manual al final de la
|
||
168 | * "r?faga" de eventos
|
||
169 | */
|
||
170 | 5152 | fjp | /*
|
171 | * public void fireSelectionEvents() { try {
|
||
172 | * getRecordset().fireSelectionEvents(); } catch (DriverException e) { //
|
||
173 | * TODO Auto-generated catch block e.printStackTrace(); } }
|
||
174 | */
|
||
175 | 562 | fernando | /**
|
176 | 1034 | vcaballero | * Devuelve el VectorialAdapater de la capa.
|
177 | 5184 | caballero | *
|
178 | 1034 | vcaballero | * @return VectorialAdapter.
|
179 | 562 | fernando | */
|
180 | 3940 | caballero | public ReadableVectorial getSource() {
|
181 | 562 | fernando | return source;
|
182 | } |
||
183 | 5115 | caballero | |
184 | 4977 | azabala | /**
|
185 | 5152 | fjp | * If we use a persistent spatial index associated with this layer, and the
|
186 | * index is not intrisic to the layer (for example spatial databases) this
|
||
187 | * method looks for existent spatial index, and loads it.
|
||
188 | 5184 | caballero | *
|
189 | 4977 | azabala | */
|
190 | 5152 | fjp | private void loadSpatialIndex() { |
191 | 5414 | azabala | //FIXME: Al abrir el indice en fichero...
|
192 | //?C?mo lo liberamos? un metodo Layer.shutdown()
|
||
193 | 5484 | caballero | |
194 | |||
195 | 4977 | azabala | ReadableVectorial source = getSource(); |
196 | 5414 | azabala | //REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
|
197 | //PUES SON VECTORIALFILEADAPTER
|
||
198 | 5152 | fjp | if (!(source instanceof VectorialFileAdapter)) { |
199 | // we are not interested in db adapters
|
||
200 | 4977 | azabala | return;
|
201 | } |
||
202 | VectorialDriver driver = source.getDriver(); |
||
203 | 5152 | fjp | if (!(driver instanceof BoundedShapes)) { |
204 | // we dont spatially index layers that are not bounded
|
||
205 | 4977 | azabala | return;
|
206 | } |
||
207 | 5152 | fjp | File file = ((VectorialFileAdapter) source).getFile();
|
208 | 5414 | azabala | String fileName = file.getAbsolutePath();
|
209 | File sptFile = new File(fileName + ".qix"); |
||
210 | 5152 | fjp | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
211 | // before to exit, look for it in temp path
|
||
212 | 4977 | azabala | String tempPath = System.getProperty("java.io.tmpdir"); |
213 | fileName = tempPath + File.separator + sptFile.getName();
|
||
214 | sptFile = new File(fileName); |
||
215 | 5152 | fjp | // it doesnt exists, must to create
|
216 | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
||
217 | 4977 | azabala | return;
|
218 | 5152 | fjp | }// if
|
219 | }// if
|
||
220 | 5484 | caballero | |
221 | 4977 | azabala | try {
|
222 | 5414 | azabala | source.start(); |
223 | spatialIndex = new QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
|
||
224 | "NM", source.getFullExtent(), source.getShapeCount(), false); |
||
225 | 4977 | azabala | } catch (SpatialIndexException e) {
|
226 | spatialIndex = null;
|
||
227 | e.printStackTrace(); |
||
228 | return;
|
||
229 | 5414 | azabala | } catch (DriverIOException e) {
|
230 | // TODO Auto-generated catch block
|
||
231 | e.printStackTrace(); |
||
232 | 5484 | caballero | } |
233 | |||
234 | 4977 | azabala | } |
235 | 5115 | caballero | |
236 | 4977 | azabala | /**
|
237 | * Checks if it has associated an external spatial index
|
||
238 | 5414 | azabala | * (an spatial index file).
|
239 | 5484 | caballero | *
|
240 | 5414 | azabala | * It looks for it in main file path, or in temp system path.
|
241 | * If main file is rivers.shp, it looks for a file called
|
||
242 | * rivers.shp.qix.
|
||
243 | 5484 | caballero | |
244 | 4977 | azabala | * @return
|
245 | */
|
||
246 | 5152 | fjp | public boolean isExternallySpatiallyIndexed() { |
247 | 5414 | azabala | /*
|
248 | * FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
|
||
249 | * con el que se trabaje (ahora mismo considera la extension .qix,
|
||
250 | * pero esto depender? del tipo de ?ndice)
|
||
251 | * */
|
||
252 | 4977 | azabala | ReadableVectorial source = getSource(); |
253 | 5152 | fjp | if (!(source instanceof VectorialFileAdapter)) { |
254 | 5414 | azabala | // we are not interested in db adapters.
|
255 | // think in non spatial dbs, like HSQLDB
|
||
256 | 4977 | azabala | return false; |
257 | } |
||
258 | 5152 | fjp | File file = ((VectorialFileAdapter) source).getFile();
|
259 | 5414 | azabala | String fileName = file.getAbsolutePath();
|
260 | File sptFile = new File(fileName + ".qix"); |
||
261 | 5152 | fjp | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
262 | // before to exit, look for it in temp path
|
||
263 | // it doesnt exists, must to create
|
||
264 | 4977 | azabala | String tempPath = System.getProperty("java.io.tmpdir"); |
265 | fileName = tempPath + File.separator + sptFile.getName();
|
||
266 | sptFile = new File(fileName); |
||
267 | 5152 | fjp | if (!sptFile.exists() || (!(sptFile.length() > 0))) { |
268 | 4977 | azabala | return false; |
269 | 5152 | fjp | }// if
|
270 | }// if
|
||
271 | 4977 | azabala | return true; |
272 | } |
||
273 | 472 | fernando | |
274 | 562 | fernando | /**
|
275 | 1034 | vcaballero | * Inserta el VectorialAdapter a la capa.
|
276 | 5184 | caballero | *
|
277 | 5152 | fjp | * @param va
|
278 | * VectorialAdapter.
|
||
279 | 562 | fernando | */
|
280 | 3940 | caballero | public void setSource(ReadableVectorial rv) { |
281 | source = rv; |
||
282 | 5152 | fjp | // azabala: we check if this layer could have a file spatial index
|
283 | 5414 | azabala | // and load it if it exists
|
284 | 4977 | azabala | loadSpatialIndex(); |
285 | 562 | fernando | } |
286 | 214 | fernando | |
287 | /**
|
||
288 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
289 | 214 | fernando | */
|
290 | 652 | fernando | public Rectangle2D getFullExtent() throws DriverException { |
291 | 885 | fjp | try {
|
292 | 652 | fernando | Rectangle2D rAux;
|
293 | 5401 | fjp | logger.debug(getName() + "_source.start()");
|
294 | 652 | fernando | source.start(); |
295 | rAux = source.getFullExtent(); |
||
296 | 5401 | fjp | logger.debug(getName() + "_source.stop()");
|
297 | 652 | fernando | source.stop(); |
298 | 885 | fjp | |
299 | // Si existe reproyecci?n, reproyectar el extent
|
||
300 | ICoordTrans ct = getCoordTrans(); |
||
301 | |||
302 | if (ct != null) { |
||
303 | Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
||
304 | Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
||
305 | pt1 = ct.convert(pt1, null);
|
||
306 | pt2 = ct.convert(pt2, null);
|
||
307 | rAux = new Rectangle2D.Double(); |
||
308 | rAux.setFrameFromDiagonal(pt1, pt2); |
||
309 | } |
||
310 | |||
311 | 652 | fernando | return rAux;
|
312 | 885 | fjp | } catch (DriverIOException e) {
|
313 | 652 | fernando | throw new DriverException(e); |
314 | } |
||
315 | 214 | fernando | } |
316 | |||
317 | /**
|
||
318 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
319 | 5152 | fjp | * java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
320 | 214 | fernando | */
|
321 | 562 | fernando | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
322 | 5152 | fjp | Cancellable cancel, double scale) throws DriverException { |
323 | 5923 | fjp | |
324 | 5152 | fjp | if (isWithinScale(scale)) {
|
325 | // Las que solo tienen etiquetado sin pintar el shape,
|
||
326 | // no pasamos por ellas
|
||
327 | boolean bDrawShapes = true; |
||
328 | if (legend instanceof SingleSymbolLegend) { |
||
329 | if (legend.getDefaultSymbol().isShapeVisible() == false) |
||
330 | bDrawShapes = false;
|
||
331 | } |
||
332 | if (bDrawShapes) {
|
||
333 | Strategy strategy = StrategyManager.getStrategy(this);
|
||
334 | try {
|
||
335 | 5813 | fjp | prepareDrawing(image, g, viewPort); |
336 | 5152 | fjp | strategy.draw(image, g, viewPort, cancel); |
337 | } catch (DriverException e) {
|
||
338 | 3462 | caballero | this.setVisible(false); |
339 | this.setActive(false); |
||
340 | throw e;
|
||
341 | } |
||
342 | 5152 | fjp | } |
343 | if (getVirtualLayers() != null) { |
||
344 | getVirtualLayers().draw(image, g, viewPort, cancel, scale); |
||
345 | } |
||
346 | 3940 | caballero | |
347 | 5152 | fjp | if (getLayerText() != null) { |
348 | getLayerText().draw(image, g, viewPort, cancel, scale); |
||
349 | } |
||
350 | 885 | fjp | } |
351 | 214 | fernando | } |
352 | |||
353 | /**
|
||
354 | 5813 | fjp | * Se llama antes de empezar a pintar.
|
355 | * Es ?til para preparar la cache a emplear, las leyendas, etc.
|
||
356 | * @param image
|
||
357 | * @param g
|
||
358 | * @param viewPort
|
||
359 | */
|
||
360 | private void prepareDrawing(BufferedImage image, Graphics2D g, ViewPort viewPort) { |
||
361 | |||
362 | } |
||
363 | |||
364 | /**
|
||
365 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
366 | 5152 | fjp | * com.iver.cit.gvsig.fmap.ViewPort,
|
367 | 5317 | fjp | * com.iver.utiles.swing.threads.Cancellable)
|
368 | 562 | fernando | */
|
369 | 5152 | fjp | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
370 | double scale) throws DriverException { |
||
371 | if (isVisible() && isWithinScale(scale)) {
|
||
372 | Strategy strategy = StrategyManager.getStrategy(this);
|
||
373 | 650 | vcaballero | |
374 | 5152 | fjp | strategy.print(g, viewPort, cancel); |
375 | 757 | fjp | |
376 | 5152 | fjp | if (getLayerText() != null) { |
377 | getLayerText().draw(null, g, viewPort, cancel, scale);
|
||
378 | } |
||
379 | 885 | fjp | } |
380 | 562 | fernando | } |
381 | |||
382 | /**
|
||
383 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
|
384 | 214 | fernando | */
|
385 | 2629 | fjp | // public FLayer createLabelLayer(int fieldId) {
|
386 | 5152 | fjp | public FLayer createLabelLayer(SelectableDataSource ds) {
|
387 | 3247 | fjp | FLyrText layerText = null;
|
388 | 5152 | fjp | try {
|
389 | layerText = new FLyrText();
|
||
390 | 763 | fjp | layerText.setLegend((VectorialLegend) getLegend()); |
391 | 5152 | fjp | layerText.createLabels(this);
|
392 | 763 | fjp | } catch (FieldNotFoundException e1) {
|
393 | // TODO Auto-generated catch block
|
||
394 | e1.printStackTrace(); |
||
395 | } catch (DriverException e1) {
|
||
396 | // TODO Auto-generated catch block
|
||
397 | e1.printStackTrace(); |
||
398 | 5152 | fjp | } |
399 | 885 | fjp | |
400 | 757 | fjp | setLayerText(layerText); |
401 | 3438 | caballero | layerText.setCoordTrans(getCoordTrans()); |
402 | 757 | fjp | return layerText;
|
403 | 214 | fernando | } |
404 | |||
405 | /**
|
||
406 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
|
407 | 214 | fernando | */
|
408 | 228 | fernando | public void removeLabels() { |
409 | 757 | fjp | setLayerText(null);
|
410 | 214 | fernando | } |
411 | |||
412 | 5152 | fjp | /*
|
413 | * (non-Javadoc)
|
||
414 | 5184 | caballero | *
|
415 | 5152 | fjp | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#deleteSpatialIndex()
|
416 | */
|
||
417 | public void deleteSpatialIndex() { |
||
418 | 5414 | azabala | //must we delete possible spatial indexes files?
|
419 | 5152 | fjp | spatialIndex = null;
|
420 | } |
||
421 | 5484 | caballero | |
422 | |||
423 | |||
424 | 5414 | azabala | /**
|
425 | * <p>
|
||
426 | * Creates an spatial index associated to this layer.
|
||
427 | * The spatial index will used
|
||
428 | * the native projection of the layer, so if the layer is reprojected, it will
|
||
429 | * be ignored.
|
||
430 | * </p>
|
||
431 | * @param cancelMonitor instance of CancellableMonitorable that allows
|
||
432 | * to monitor progress of spatial index creation, and cancel the process
|
||
433 | 5484 | caballero | */
|
434 | 5414 | azabala | public void createSpatialIndex(CancellableMonitorable cancelMonitor){ |
435 | // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
||
436 | // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
||
437 | // para que acepten recorrer sin geometria, solo con rectangulos.
|
||
438 | 5484 | caballero | |
439 | 5414 | azabala | //If this vectorial layer is based in a spatial database, the spatial
|
440 | 5484 | caballero | //index is already implicit. We only will index file drivers
|
441 | 5414 | azabala | ReadableVectorial va = getSource(); |
442 | //We must think in non spatial databases, like HSQLDB
|
||
443 | if(!(va instanceof VectorialFileAdapter)){ |
||
444 | 4977 | azabala | return;
|
445 | } |
||
446 | 5152 | fjp | if (!(va.getDriver() instanceof BoundedShapes)) { |
447 | 4977 | azabala | return;
|
448 | } |
||
449 | 5152 | fjp | File file = ((VectorialFileAdapter) va).getFile();
|
450 | 5414 | azabala | String fileName = file.getAbsolutePath();
|
451 | ISpatialIndex localCopy = null;
|
||
452 | 5152 | fjp | try {
|
453 | 5414 | azabala | va.start(); |
454 | localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(), |
||
455 | va.getShapeCount(), true);
|
||
456 | 5484 | caballero | |
457 | 4977 | azabala | } catch (SpatialIndexException e1) {
|
458 | 5152 | fjp | // Probably we dont have writing permissions
|
459 | 4977 | azabala | String directoryName = System.getProperty("java.io.tmpdir"); |
460 | 5484 | caballero | File newFile = new File(directoryName + |
461 | File.separator +
|
||
462 | 5414 | azabala | file.getName()); |
463 | 4977 | azabala | String newFileName = newFile.getName();
|
464 | try {
|
||
465 | 5414 | azabala | localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(), |
466 | va.getShapeCount(), true);
|
||
467 | 4977 | azabala | } catch (SpatialIndexException e) {
|
468 | 5414 | azabala | // if we cant build a file based spatial index, we'll build
|
469 | // a pure memory spatial index
|
||
470 | localCopy = new QuadtreeJts();
|
||
471 | } catch (DriverIOException e) {
|
||
472 | // TODO Auto-generated catch block
|
||
473 | e.printStackTrace(); |
||
474 | 4977 | azabala | } |
475 | 5115 | caballero | |
476 | 5414 | azabala | }catch(Exception e){ |
477 | 5152 | fjp | e.printStackTrace(); |
478 | 5414 | azabala | }//try
|
479 | BoundedShapes shapeBounds = (BoundedShapes) va.getDriver(); |
||
480 | try {
|
||
481 | for (int i=0; i < va.getShapeCount(); i++) |
||
482 | { |
||
483 | if(cancelMonitor != null){ |
||
484 | if(cancelMonitor.isCanceled())
|
||
485 | return;
|
||
486 | cancelMonitor.reportStep(); |
||
487 | } |
||
488 | Rectangle2D r = shapeBounds.getShapeBounds(i);
|
||
489 | 5916 | azabala | if(r != null) |
490 | localCopy.insert(r, i); |
||
491 | 5414 | azabala | } // for
|
492 | va.stop(); |
||
493 | if(localCopy instanceof IPersistentSpatialIndex) |
||
494 | ((IPersistentSpatialIndex) localCopy).flush(); |
||
495 | spatialIndex = localCopy; |
||
496 | } catch (DriverIOException e) {
|
||
497 | // TODO Auto-generated catch block
|
||
498 | e.printStackTrace(); |
||
499 | } catch (IOException e) { |
||
500 | // TODO Auto-generated catch block
|
||
501 | e.printStackTrace(); |
||
502 | } |
||
503 | } |
||
504 | 5484 | caballero | |
505 | 5414 | azabala | /**
|
506 | 4977 | azabala | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
|
507 | */
|
||
508 | public void createSpatialIndex() { |
||
509 | createSpatialIndex(null);
|
||
510 | 214 | fernando | } |
511 | |||
512 | /**
|
||
513 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
514 | 5152 | fjp | * FBitSet)
|
515 | 214 | fernando | */
|
516 | 2969 | fjp | public void process(FeatureVisitor visitor, FBitSet subset) |
517 | 5152 | fjp | throws DriverException, VisitException {
|
518 | 562 | fernando | Strategy s = StrategyManager.getStrategy(this);
|
519 | s.process(visitor, subset); |
||
520 | 228 | fernando | } |
521 | |||
522 | /**
|
||
523 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
524 | */
|
||
525 | 5152 | fjp | public void process(FeatureVisitor visitor) throws DriverException, |
526 | VisitException { |
||
527 | 562 | fernando | Strategy s = StrategyManager.getStrategy(this);
|
528 | s.process(visitor); |
||
529 | } |
||
530 | 4223 | caballero | |
531 | 4200 | azabala | /**
|
532 | 5152 | fjp | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
533 | * Rectangle2D)
|
||
534 | 4200 | azabala | */
|
535 | public void process(FeatureVisitor visitor, Rectangle2D rect) |
||
536 | 5152 | fjp | throws DriverException, VisitException {
|
537 | 4200 | azabala | Strategy s = StrategyManager.getStrategy(this);
|
538 | s.process(visitor, rect); |
||
539 | } |
||
540 | 562 | fernando | |
541 | /**
|
||
542 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
543 | */
|
||
544 | 5152 | fjp | /*
|
545 | * public void setSelection(FBitSet selection) { try {
|
||
546 | * getRecordset().setSelection(selection); } catch (DriverException e) { //
|
||
547 | * TODO Auto-generated catch block e.printStackTrace(); }
|
||
548 | * fireSelectionEvents(); }
|
||
549 | */
|
||
550 | 228 | fernando | /**
|
551 | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
|
||
552 | */
|
||
553 | 5152 | fjp | /*
|
554 | * public boolean isSelected(int index) { try { return
|
||
555 | * getRecordset().isSelected(index); } catch (DriverException e) { // TODO
|
||
556 | * Auto-generated catch block e.printStackTrace(); } return false; }
|
||
557 | */
|
||
558 | 228 | fernando | /**
|
559 | 456 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
|
560 | */
|
||
561 | 5152 | fjp | /*
|
562 | * public FBitSet getSelection() { try { return
|
||
563 | * getRecordset().getSelection(); } catch (DriverException e) { // TODO
|
||
564 | * Auto-generated catch block e.printStackTrace(); } return new FBitSet(); }
|
||
565 | */
|
||
566 | 456 | fernando | /**
|
567 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
|
568 | */
|
||
569 | 5152 | fjp | /*
|
570 | * public void clearSelection() { try { getRecordset().clearSelection(); }
|
||
571 | * catch (DriverException e) { // TODO Auto-generated catch block
|
||
572 | * e.printStackTrace(); } }
|
||
573 | */
|
||
574 | 228 | fernando | |
575 | 5152 | fjp | /*
|
576 | * (non-Javadoc)
|
||
577 | 5184 | caballero | *
|
578 | 2978 | fjp | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
|
579 | 214 | fernando | */
|
580 | 2978 | fjp | public FBitSet queryByRect(Rectangle2D rect) throws DriverException { |
581 | 488 | vcaballero | Strategy s = StrategyManager.getStrategy(this);
|
582 | 562 | fernando | |
583 | 488 | vcaballero | return s.queryByRect(rect);
|
584 | 214 | fernando | } |
585 | |||
586 | 5152 | fjp | public FBitSet queryByPoint(Point2D p, double tolerance) |
587 | throws DriverException {
|
||
588 | Strategy s = StrategyManager.getStrategy(this);
|
||
589 | return s.queryByPoint(p, tolerance);
|
||
590 | } |
||
591 | 3940 | caballero | |
592 | 5152 | fjp | public FBitSet queryByShape(IGeometry g, int relationship) |
593 | throws DriverException, VisitException {
|
||
594 | Strategy s = StrategyManager.getStrategy(this);
|
||
595 | return s.queryByShape(g, relationship);
|
||
596 | } |
||
597 | 5048 | ldiaz | |
598 | 5152 | fjp | public XMLItem[] getInfo(Point p, double tolerance) throws DriverException { |
599 | 5057 | ldiaz | Point2D pReal = this.getFMap().getViewPort().toMapPoint(p); |
600 | 5152 | fjp | FBitSet bs = queryByPoint(pReal, tolerance); |
601 | VectorialXMLItem[] item = new VectorialXMLItem[1]; |
||
602 | item[0] = new VectorialXMLItem(bs, this); |
||
603 | 5115 | caballero | |
604 | 5152 | fjp | return item;
|
605 | } |
||
606 | |||
607 | 214 | fernando | /**
|
608 | 1828 | fernando | * @throws DriverException
|
609 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
610 | */
|
||
611 | 5152 | fjp | /*
|
612 | * public SelectableDataSource getRecordset() throws DriverException { if
|
||
613 | * (sds == null){ try { DataSource ds = getSource().getRecordset();
|
||
614 | 5184 | caballero | *
|
615 | 5152 | fjp | * if (ds == null) { return null; }
|
616 | 5184 | caballero | *
|
617 | 5152 | fjp | * sds = new SelectableDataSource(ds);
|
618 | * //sds.setSelectionSupport(selectionSupport);
|
||
619 | 5184 | caballero | *
|
620 | 5152 | fjp | * return sds; } catch (DriverLoadException e) { throw new
|
621 | * DriverException(e); } catch
|
||
622 | * (com.hardcode.gdbms.engine.data.driver.DriverException e) { throw new
|
||
623 | * DriverException(e); } } return sds; }
|
||
624 | */
|
||
625 | 214 | fernando | /**
|
626 | 5152 | fjp | * Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
627 | * forma, podr?s poner leyendas basadas en el nuevo recordset
|
||
628 | 5184 | caballero | *
|
629 | 5152 | fjp | * @param newSds
|
630 | * @throws DriverException
|
||
631 | * @throws FieldNotFoundException
|
||
632 | * @throws FieldNotFoundException
|
||
633 | */
|
||
634 | /*
|
||
635 | * public void setRecordset(SelectableDataSource newSds) throws
|
||
636 | * DriverException, FieldNotFoundException { sds = newSds;
|
||
637 | * //sds.setSelectionSupport(selectionSupport); legend.setDataSource(sds);
|
||
638 | * logger.debug("Recordset cambiado a " + sds.getName()); }
|
||
639 | */
|
||
640 | /**
|
||
641 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
|
642 | 5152 | fjp | * com.iver.cit.gvsig.fmap.rendering.Legend)
|
643 | 214 | fernando | */
|
644 | 5152 | fjp | public void setLegend(VectorialLegend r) throws DriverException, |
645 | FieldNotFoundException { |
||
646 | 486 | fjp | VectorialLegend oldLegend = legend; |
647 | 264 | fernando | legend = r; |
648 | 885 | fjp | |
649 | try {
|
||
650 | 652 | fernando | legend.setDataSource(getRecordset()); |
651 | 885 | fjp | |
652 | if (legend.getLabelField() != null) { |
||
653 | 5152 | fjp | // sds.start();
|
654 | // int idLabelField =
|
||
655 | // getRecordset().getFieldIndexByName(legend.getLabelField());
|
||
656 | 3963 | caballero | createLabelLayer(getSource().getRecordset()); |
657 | 2629 | fjp | // sds.stop();
|
658 | 5152 | fjp | } else
|
659 | removeLabels(); |
||
660 | 885 | fjp | } catch (DriverException e) {
|
661 | 652 | fernando | throw new DriverException(e); |
662 | 757 | fjp | } catch (FieldNotFoundException e) {
|
663 | // TODO Auto-generated catch block
|
||
664 | e.printStackTrace(); |
||
665 | 5152 | fjp | } catch (DriverLoadException e) {
|
666 | 3963 | caballero | // TODO Auto-generated catch block
|
667 | e.printStackTrace(); |
||
668 | } |
||
669 | 562 | fernando | |
670 | 5152 | fjp | LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent( |
671 | oldLegend, legend); |
||
672 | 486 | fjp | callLegendChanged(e); |
673 | 214 | fernando | } |
674 | 303 | fernando | |
675 | 321 | fernando | /**
|
676 | 1034 | vcaballero | * Devuelve la Leyenda de la capa.
|
677 | 5184 | caballero | *
|
678 | 1034 | vcaballero | * @return Leyenda.
|
679 | 321 | fernando | */
|
680 | 562 | fernando | public Legend getLegend() {
|
681 | return legend;
|
||
682 | 321 | fernando | } |
683 | 373 | fernando | |
684 | /**
|
||
685 | 1034 | vcaballero | * Devuelve el tipo de shape que contiene la capa.
|
686 | 5184 | caballero | *
|
687 | 1034 | vcaballero | * @return tipo de shape.
|
688 | 5184 | caballero | *
|
689 | 1034 | vcaballero | * @throws DriverException
|
690 | 373 | fernando | */
|
691 | 652 | fernando | public int getShapeType() throws DriverException { |
692 | 562 | fernando | if (typeShape == -1) { |
693 | 885 | fjp | try {
|
694 | 652 | fernando | logger.debug("source.start()");
|
695 | 4213 | caballero | getSource().start(); |
696 | typeShape = getSource().getShapeType(); |
||
697 | 652 | fernando | logger.debug("source.stop()");
|
698 | 4213 | caballero | getSource().stop(); |
699 | 885 | fjp | } catch (DriverIOException e) {
|
700 | 652 | fernando | throw new DriverException(e); |
701 | } |
||
702 | 526 | vcaballero | } |
703 | 562 | fernando | |
704 | 526 | vcaballero | return typeShape;
|
705 | 373 | fernando | } |
706 | 435 | vcaballero | |
707 | /**
|
||
708 | 1828 | fernando | * @throws XMLException
|
709 | 435 | vcaballero | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
710 | */
|
||
711 | 1828 | fernando | public XMLEntity getXMLEntity() throws XMLException { |
712 | 562 | fernando | XMLEntity xml = super.getXMLEntity();
|
713 | 5152 | fjp | xml.addChild(getLegend().getXMLEntity()); |
714 | try {
|
||
715 | 3963 | caballero | xml.addChild(getRecordset().getSelectionSupport().getXMLEntity()); |
716 | 562 | fernando | |
717 | 4455 | fjp | } catch (DriverException e1) {
|
718 | e1.printStackTrace(); |
||
719 | throw new XMLException(e1); |
||
720 | } |
||
721 | 5484 | caballero | //Repongo el mismo ReadableVectorial m?s abajo para cuando se guarda el proyecto.
|
722 | ReadableVectorial rv=getSource(); |
||
723 | 5152 | fjp | if (getSource() instanceof VectorialEditableAdapter) { |
724 | setSource(((VectorialEditableAdapter) source).getOriginalAdapter()); |
||
725 | 3981 | caballero | } |
726 | 4213 | caballero | if (getSource() instanceof VectorialFileAdapter) { |
727 | 1828 | fernando | xml.putProperty("type", "vectorial"); |
728 | 5152 | fjp | xml.putProperty("file", ((VectorialFileAdapter) getSource())
|
729 | .getFile()); |
||
730 | // try {
|
||
731 | try {
|
||
732 | xml.putProperty("recordset-name", getSource().getRecordset()
|
||
733 | .getName()); |
||
734 | } catch (DriverLoadException e) {
|
||
735 | // TODO Auto-generated catch block
|
||
736 | e.printStackTrace(); |
||
737 | } |
||
738 | // } catch (DriverException e) {
|
||
739 | // throw new XMLException(e);
|
||
740 | // }
|
||
741 | 562 | fernando | } else if (source instanceof VectorialDBAdapter) { |
742 | 5152 | fjp | xml.putProperty("type", "vectorial"); |
743 | 3940 | caballero | |
744 | 5152 | fjp | VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) getSource() |
745 | .getDriver(); |
||
746 | 3940 | caballero | |
747 | 5152 | fjp | // Guardamos el nombre del driver para poder recuperarlo
|
748 | // con el DriverManager de Fernando.
|
||
749 | xml.putProperty("db", dbDriver.getName());
|
||
750 | // try {
|
||
751 | try {
|
||
752 | xml.putProperty("recordset-name", getSource().getRecordset()
|
||
753 | .getName()); |
||
754 | } catch (DriverLoadException e) {
|
||
755 | // TODO Auto-generated catch block
|
||
756 | e.printStackTrace(); |
||
757 | } |
||
758 | // } catch (DriverException e) {
|
||
759 | // throw new XMLException(e);
|
||
760 | // }
|
||
761 | xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos
|
||
762 | // metido la leyenda y el
|
||
763 | // selection support
|
||
764 | } else if (source instanceof VectorialAdapter) { |
||
765 | // Se supone que hemos hecho algo gen?rico.
|
||
766 | xml.putProperty("type", "vectorial"); |
||
767 | 3940 | caballero | |
768 | 5152 | fjp | VectorialDriver driver = (VectorialDriver) getSource().getDriver(); |
769 | 3940 | caballero | |
770 | 5152 | fjp | // Guardamos el nombre del driver para poder recuperarlo
|
771 | // con el DriverManager de Fernando.
|
||
772 | xml.putProperty("other", driver.getName());
|
||
773 | // try {
|
||
774 | try {
|
||
775 | xml.putProperty("recordset-name", getSource().getRecordset()
|
||
776 | .getName()); |
||
777 | } catch (DriverLoadException e) {
|
||
778 | // TODO Auto-generated catch block
|
||
779 | e.printStackTrace(); |
||
780 | } |
||
781 | // } catch (DriverException e) {
|
||
782 | // throw new XMLException(e);
|
||
783 | // }
|
||
784 | if (driver instanceof IPersistance) { |
||
785 | // xml.putProperty("className", driver.getClass().getName());
|
||
786 | IPersistance persist = (IPersistance) driver; |
||
787 | xml.addChild(persist.getXMLEntity()); // Tercer child. Antes
|
||
788 | // hemos metido la
|
||
789 | // leyenda y el
|
||
790 | // selection support
|
||
791 | } |
||
792 | 3940 | caballero | } |
793 | 5484 | caballero | setSource(rv); |
794 | 562 | fernando | xml.putProperty("driverName", getSource().getDriver().getName());
|
795 | 5152 | fjp | if (bHasJoin)
|
796 | xml.putProperty("hasJoin", "true"); |
||
797 | 3940 | caballero | |
798 | 435 | vcaballero | return xml;
|
799 | } |
||
800 | |||
801 | /**
|
||
802 | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
803 | */
|
||
804 | 5152 | fjp | public void setXMLEntity03(XMLEntity xml) throws XMLException { |
805 | 3940 | caballero | |
806 | 2183 | fernando | super.setXMLEntity(xml);
|
807 | legend = LegendFactory.createFromXML03(xml.getChild(0));
|
||
808 | |||
809 | try {
|
||
810 | // legend.setDataSource(getRecordset());
|
||
811 | setLegend(legend); |
||
812 | } catch (FieldNotFoundException e) {
|
||
813 | throw new XMLException(e); |
||
814 | } catch (DriverException e) {
|
||
815 | throw new XMLException(e); |
||
816 | 3940 | caballero | } |
817 | 2183 | fernando | |
818 | 4455 | fjp | try {
|
819 | 5152 | fjp | getRecordset().getSelectionSupport() |
820 | .setXMLEntity03(xml.getChild(1));
|
||
821 | 4455 | fjp | } catch (DriverException e) {
|
822 | e.printStackTrace(); |
||
823 | } |
||
824 | 2183 | fernando | } |
825 | |||
826 | /**
|
||
827 | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
828 | */
|
||
829 | 5152 | fjp | public void setXMLEntity(XMLEntity xml) throws XMLException { |
830 | super.setXMLEntity(xml);
|
||
831 | 3940 | caballero | |
832 | 4213 | caballero | VectorialLegend leg = LegendFactory.createFromXML(xml.getChild(0));
|
833 | 4455 | fjp | try {
|
834 | getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
|
||
835 | String recordsetName = xml.getStringProperty("recordset-name"); |
||
836 | 885 | fjp | |
837 | 1828 | fernando | LayerFactory.getDataSourceFactory().changeDataSourceName( |
838 | 5152 | fjp | getSource().getRecordset().getName(), recordsetName); |
839 | // Hacemos que el recordset que hemos creado antes (los
|
||
840 | // recordset se crean antes que todo) sea el recordset
|
||
841 | // de esta capa. Y del que se crea automaticamente
|
||
842 | // en el setLegend del createLayer, nos olvidamos
|
||
843 | SelectableDataSource sds = new SelectableDataSource(LayerFactory
|
||
844 | .getDataSourceFactory().createRandomDataSource( |
||
845 | recordsetName, DataSourceFactory.AUTOMATIC_OPENING)); |
||
846 | // sds.setSelectionSupport(selectionSupport);
|
||
847 | // ((EditableAdapter)getSource()).setRecordSet(sds);
|
||
848 | 1828 | fernando | } catch (NoSuchTableException e1) {
|
849 | throw new XMLException(e1); |
||
850 | 5152 | fjp | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
|
851 | throw new XMLException(e1); |
||
852 | } catch (DriverLoadException e1) {
|
||
853 | throw new XMLException(e1); |
||
854 | } catch (DriverException e1) {
|
||
855 | throw new XMLException(e1); |
||
856 | 4455 | fjp | } |
857 | 5152 | fjp | // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
|
858 | // el final
|
||
859 | // de la lectura del proyecto
|
||
860 | if (xml.contains("hasJoin")) { |
||
861 | setIsJoined(true);
|
||
862 | PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1); |
||
863 | } else {
|
||
864 | try {
|
||
865 | // legend.setDataSource(getRecordset());
|
||
866 | setLegend(leg); |
||
867 | } catch (FieldNotFoundException e) {
|
||
868 | throw new XMLException(e); |
||
869 | } catch (DriverException e) {
|
||
870 | throw new XMLException(e); |
||
871 | } |
||
872 | } |
||
873 | 3940 | caballero | |
874 | 435 | vcaballero | } |
875 | 562 | fernando | |
876 | /**
|
||
877 | 1034 | vcaballero | * A?ade un LegendListener a la lista de Listeners.
|
878 | 5184 | caballero | *
|
879 | 5152 | fjp | * @param listener
|
880 | * LegendListener.
|
||
881 | 562 | fernando | */
|
882 | public void addLegendListener(LegendListener listener) { |
||
883 | 472 | fernando | layerChangeSupport.addLayerListener(listener); |
884 | } |
||
885 | 562 | fernando | |
886 | /**
|
||
887 | 1034 | vcaballero | * Llamada al m?todo callLegendChanged de los listener.
|
888 | 5184 | caballero | *
|
889 | 5152 | fjp | * @param e
|
890 | * Evento.
|
||
891 | 562 | fernando | */
|
892 | 486 | fjp | private void callLegendChanged(LegendChangedEvent e) { |
893 | 472 | fernando | layerChangeSupport.callLegendChanged(e); |
894 | } |
||
895 | 562 | fernando | |
896 | /**
|
||
897 | 1034 | vcaballero | * Borra un LegendListener de la lista de Listeners
|
898 | 5184 | caballero | *
|
899 | 5152 | fjp | * @param listener
|
900 | * LegendListener.
|
||
901 | 562 | fernando | */
|
902 | public void removeLegendListener(LegendListener listener) { |
||
903 | 472 | fernando | layerChangeSupport.removeLayerListener(listener); |
904 | } |
||
905 | 544 | fernando | |
906 | /**
|
||
907 | 1034 | vcaballero | * Sobreimplementaci?n del m?todo toString para que las bases de datos
|
908 | * identifiquen la capa.
|
||
909 | 5184 | caballero | *
|
910 | 911 | fernando | * @return DOCUMENT ME!
|
911 | */
|
||
912 | public String toString() { |
||
913 | /*
|
||
914 | 5152 | fjp | * Se usa internamente para que la parte de datos identifique de forma
|
915 | * un?voca las tablas
|
||
916 | 911 | fernando | */
|
917 | String ret = super.toString(); |
||
918 | |||
919 | return "layer" + ret.substring(ret.indexOf('@') + 1); |
||
920 | } |
||
921 | 2672 | fjp | |
922 | 5152 | fjp | public boolean isJoined() { |
923 | return bHasJoin;
|
||
924 | } |
||
925 | 5115 | caballero | |
926 | 5152 | fjp | /**
|
927 | 4977 | azabala | * Returns if a layer is spatially indexed
|
928 | 5184 | caballero | *
|
929 | 5152 | fjp | * @return if this layer has the ability to proces spatial queries without
|
930 | * secuential scans.
|
||
931 | 4977 | azabala | */
|
932 | 5152 | fjp | public boolean isSpatiallyIndexed() { |
933 | 4977 | azabala | ReadableVectorial source = getSource(); |
934 | 5152 | fjp | if (source instanceof ISpatialDB) |
935 | 4977 | azabala | return true; |
936 | 5794 | azabala | |
937 | //FIXME azabala
|
||
938 | /*
|
||
939 | * Esto es muy dudoso, y puede cambiar.
|
||
940 | * Estoy diciendo que las que no son fichero o no son
|
||
941 | * BoundedShapes estan indexadas. Esto es mentira, pero
|
||
942 | * as? quien pregunte no querr? generar el indice.
|
||
943 | * Esta por ver si interesa generar el indice para capas
|
||
944 | * HSQLDB, WFS, etc.
|
||
945 | */
|
||
946 | if(!(source instanceof VectorialFileAdapter)){ |
||
947 | return true; |
||
948 | } |
||
949 | if (!(source.getDriver() instanceof BoundedShapes)) { |
||
950 | return true; |
||
951 | } |
||
952 | |||
953 | 5152 | fjp | if (getISpatialIndex() != null) |
954 | 4977 | azabala | return true; |
955 | return false; |
||
956 | } |
||
957 | 2672 | fjp | |
958 | 5152 | fjp | public void setIsJoined(boolean hasJoin) { |
959 | bHasJoin = hasJoin; |
||
960 | } |
||
961 | 2978 | fjp | |
962 | 5152 | fjp | /**
|
963 | * @return Returns the spatialIndex.
|
||
964 | */
|
||
965 | public ISpatialIndex getISpatialIndex() {
|
||
966 | return spatialIndex;
|
||
967 | } |
||
968 | 5679 | azabala | /**
|
969 | * Sets the spatial index. This could be useful if, for some
|
||
970 | * reasons, you want to work with a distinct spatial index
|
||
971 | * (for example, a spatial index which could makes nearest
|
||
972 | * neighbour querys)
|
||
973 | * @param spatialIndex
|
||
974 | */
|
||
975 | public void setISpatialIndex(ISpatialIndex spatialIndex){ |
||
976 | this.spatialIndex = spatialIndex;
|
||
977 | } |
||
978 | |||
979 | 3366 | caballero | |
980 | 5152 | fjp | /*
|
981 | * public SelectableDataSource getRecordset() { try { return
|
||
982 | * getSource().getRecordset(); } catch (DriverLoadException e) { // TODO
|
||
983 | * Auto-generated catch block e.printStackTrace(); } return null; }
|
||
984 | */
|
||
985 | 4977 | azabala | |
986 | 4455 | fjp | /**
|
987 | * @throws DriverException
|
||
988 | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
||
989 | */
|
||
990 | public SelectableDataSource getRecordset() throws DriverException { |
||
991 | 5152 | fjp | if (sds == null) { |
992 | 4455 | fjp | try {
|
993 | SelectableDataSource ds = source.getRecordset(); |
||
994 | |||
995 | if (ds == null) { |
||
996 | return null; |
||
997 | } |
||
998 | |||
999 | sds = ds; |
||
1000 | sds.setSelectionSupport(selectionSupport); |
||
1001 | 4523 | caballero | |
1002 | 4455 | fjp | } catch (DriverLoadException e) {
|
1003 | throw new DriverException(e); |
||
1004 | 5152 | fjp | } |
1005 | 4455 | fjp | } |
1006 | return sds;
|
||
1007 | 4523 | caballero | } |
1008 | |||
1009 | 5152 | fjp | /*
|
1010 | * (non-Javadoc)
|
||
1011 | 5184 | caballero | *
|
1012 | 4147 | fjp | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setEditing(boolean)
|
1013 | */
|
||
1014 | 5152 | fjp | public void setEditing(boolean b) throws EditionException { |
1015 | 4147 | fjp | super.setEditing(b);
|
1016 | 5152 | fjp | try {
|
1017 | if (b) {
|
||
1018 | VectorialEditableAdapter vea = null;
|
||
1019 | // TODO: Qu? pasa si hay m?s tipos de adapters?
|
||
1020 | // FJP: Se podr?a pasar como argumento el
|
||
1021 | // VectorialEditableAdapter
|
||
1022 | // que se quiera usar para evitar meter c?digo aqu? de este
|
||
1023 | // estilo.
|
||
1024 | if (getSource() instanceof VectorialDBAdapter) { |
||
1025 | vea = new VectorialEditableDBAdapter();
|
||
1026 | } else if (this instanceof FLyrAnnotation) { |
||
1027 | 5390 | caballero | vea = new AnnotationEditableAdapter(
|
1028 | (FLyrAnnotation) this);
|
||
1029 | } else {
|
||
1030 | 5152 | fjp | vea = new VectorialEditableAdapter();
|
1031 | 5115 | caballero | } |
1032 | 5152 | fjp | vea.setOriginalVectorialAdapter(getSource()); |
1033 | 5115 | caballero | |
1034 | 5152 | fjp | // /vea.setSpatialIndex(getSpatialIndex());
|
1035 | // /vea.setFullExtent(getFullExtent());
|
||
1036 | 5184 | caballero | vea.startEdition(EditionEvent.GRAPHIC); |
1037 | 5152 | fjp | setSource(vea); |
1038 | getRecordset().setSelectionSupport( |
||
1039 | vea.getOriginalAdapter().getRecordset() |
||
1040 | .getSelectionSupport()); |
||
1041 | |||
1042 | } else {
|
||
1043 | VectorialEditableAdapter vea = (VectorialEditableAdapter) getSource(); |
||
1044 | setSource(vea.getOriginalAdapter()); |
||
1045 | 4159 | fjp | } |
1046 | 5152 | fjp | // Si tenemos una leyenda, hay que pegarle el cambiazo a su
|
1047 | // recordset
|
||
1048 | setRecordset(getSource().getRecordset()); |
||
1049 | if (getLegend() instanceof VectorialLegend) { |
||
1050 | VectorialLegend ley = (VectorialLegend) getLegend(); |
||
1051 | ley.setDataSource(getSource().getRecordset()); |
||
1052 | 5184 | caballero | // Esto lo pongo para evitar que al dibujar sobre un
|
1053 | 5152 | fjp | // dxf, dwg, o dgn no veamos nada. Es debido al checkbox
|
1054 | // de la leyenda de textos "dibujar solo textos".
|
||
1055 | 5390 | caballero | if (!(getSource().getDriver() instanceof IndexedShpDriver)){ |
1056 | 5152 | fjp | ley.setDefaultSymbol(new FSymbol(getShapeType()));
|
1057 | } |
||
1058 | 5390 | caballero | ley.useDefaultSymbol(true);
|
1059 | 4147 | fjp | } |
1060 | 5152 | fjp | } catch (DriverLoadException e) {
|
1061 | e.printStackTrace(); |
||
1062 | throw new EditionException(e); |
||
1063 | } catch (DriverException e) {
|
||
1064 | e.printStackTrace(); |
||
1065 | throw new EditionException(e); |
||
1066 | } catch (FieldNotFoundException e) {
|
||
1067 | e.printStackTrace(); |
||
1068 | throw new EditionException(e); |
||
1069 | 4147 | fjp | } |
1070 | 4223 | caballero | |
1071 | 5576 | fjp | setSpatialCacheEnabled(b); |
1072 | 5152 | fjp | callEditionChanged(LayerEvent |
1073 | .createEditionChangedEvent(this, "edition")); |
||
1074 | |||
1075 | 4147 | fjp | } |
1076 | |||
1077 | 5152 | fjp | /**
|
1078 | * Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
|
||
1079 | * forma, podr?s poner leyendas basadas en el nuevo recordset
|
||
1080 | 5184 | caballero | *
|
1081 | 5152 | fjp | * @param newSds
|
1082 | */
|
||
1083 | public void setRecordset(SelectableDataSource newSds) { |
||
1084 | sds = newSds; |
||
1085 | sds.setSelectionSupport(selectionSupport); |
||
1086 | 3366 | caballero | } |
1087 | 5152 | fjp | /*
|
1088 | * public SelectionSupport getSelectionSupport() { return selectionSupport; }
|
||
1089 | 5184 | caballero | *
|
1090 | 5152 | fjp | * public void setSelectionSupport(SelectionSupport selectionSupport) {
|
1091 | * this.selectionSupport = selectionSupport; }
|
||
1092 | */
|
||
1093 | 3366 | caballero | |
1094 | 5813 | fjp | // public SpatialCache createSpatialCache() {
|
1095 | // spatialCache = new SpatialCache();
|
||
1096 | // return spatialCache;
|
||
1097 | // }
|
||
1098 | public void clearSpatialCache() |
||
1099 | { |
||
1100 | spatialCache.clearAll(); |
||
1101 | 5223 | fjp | } |
1102 | |||
1103 | 5226 | fjp | // public void setSpatialCache(SpatialCache spatialCache) {
|
1104 | // this.spatialCache = spatialCache;
|
||
1105 | // }
|
||
1106 | 5223 | fjp | |
1107 | public boolean isSpatialCacheEnabled() { |
||
1108 | return spatialCacheEnabled;
|
||
1109 | } |
||
1110 | |||
1111 | public void setSpatialCacheEnabled(boolean spatialCacheEnabled) { |
||
1112 | this.spatialCacheEnabled = spatialCacheEnabled;
|
||
1113 | } |
||
1114 | |||
1115 | 5226 | fjp | public SpatialCache getSpatialCache() {
|
1116 | return spatialCache;
|
||
1117 | } |
||
1118 | |||
1119 | 5813 | fjp | /**
|
1120 | * Siempre es un numero mayor de 1000
|
||
1121 | * @param maxFeatures
|
||
1122 | */
|
||
1123 | 5793 | fjp | public void setMaxFeaturesInEditionCache(int maxFeatures) { |
1124 | 5813 | fjp | if (maxFeatures > spatialCache.maxFeatures)
|
1125 | spatialCache.setMaxFeatures(maxFeatures); |
||
1126 | 5793 | fjp | |
1127 | } |
||
1128 | 6197 | jorpiell | |
1129 | /**
|
||
1130 | * This method returns a boolean that is used by the FPopMenu
|
||
1131 | * to make visible the properties menu or not. It is visible by
|
||
1132 | * default, and if a later don't have to show this menu only
|
||
1133 | * has to override this method.
|
||
1134 | * @return
|
||
1135 | * If the properties menu is visible (or not)
|
||
1136 | */
|
||
1137 | public boolean isPropertiesMenuVisible(){ |
||
1138 | return true; |
||
1139 | } |
||
1140 | 5793 | fjp | |
1141 | 214 | fernando | } |