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