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