svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 1283
History | View | Annotate | Download (15.8 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 | 408 | fernando | import com.hardcode.driverManager.DriverLoadException; |
44 | 1034 | vcaballero | |
45 | 408 | fernando | import com.hardcode.gdbms.engine.data.DataSource; |
46 | 470 | fjp | import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
47 | 801 | fjp | import com.hardcode.gdbms.engine.values.DoubleValue; |
48 | import com.hardcode.gdbms.engine.values.FloatValue; |
||
49 | 813 | fjp | import com.hardcode.gdbms.engine.values.NullValue; |
50 | 757 | fjp | import com.hardcode.gdbms.engine.values.Value; |
51 | 1034 | vcaballero | |
52 | 652 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
53 | 214 | fernando | import com.iver.cit.gvsig.fmap.ViewPort; |
54 | 757 | fjp | import com.iver.cit.gvsig.fmap.core.IGeometry; |
55 | import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
||
56 | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
||
57 | 214 | fernando | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
58 | 757 | fjp | import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
59 | 562 | fernando | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
60 | import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
||
61 | import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable; |
||
62 | import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData; |
||
63 | import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
||
64 | import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
||
65 | import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
||
66 | 244 | fernando | import com.iver.cit.gvsig.fmap.operations.Cancellable; |
67 | 214 | fernando | import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
68 | 231 | fernando | import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
69 | import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
||
70 | 926 | fernando | import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
71 | 461 | fernando | import com.iver.cit.gvsig.fmap.rendering.Legend; |
72 | import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
||
73 | 214 | fernando | import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
74 | 321 | fernando | import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
75 | 1034 | vcaballero | |
76 | 415 | fernando | import com.iver.utiles.XMLEntity; |
77 | 214 | fernando | |
78 | 1034 | vcaballero | import org.apache.log4j.Logger; |
79 | 562 | fernando | |
80 | 1034 | vcaballero | import org.cresques.cts.ICoordTrans; |
81 | |||
82 | import java.awt.Graphics2D; |
||
83 | import java.awt.geom.Point2D; |
||
84 | import java.awt.geom.Rectangle2D; |
||
85 | import java.awt.image.BufferedImage; |
||
86 | |||
87 | import java.util.ArrayList; |
||
88 | import java.util.BitSet; |
||
89 | |||
90 | |||
91 | 562 | fernando | /**
|
92 | 1034 | vcaballero | * Capa b?sica Vectorial.
|
93 | 562 | fernando | *
|
94 | * @author Fernando Gonz?lez Cort?s
|
||
95 | */
|
||
96 | 885 | fjp | |
97 | 609 | luisw | //TODO Cuando no sea para pruebas debe no ser public
|
98 | public class FLyrVect extends FLyrDefault implements Labelable, Selectable, |
||
99 | 885 | fjp | AlphanumericData, ClassifiableVectorial, SingleLayer, VectorialData, |
100 | RandomVectorialData { |
||
101 | 526 | vcaballero | private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
102 | 562 | fernando | |
103 | 526 | vcaballero | /** Leyenda de la capa vectorial */
|
104 | 562 | fernando | private VectorialLegend legend;
|
105 | private int typeShape = -1; |
||
106 | private SelectionSupport selectionSupport = new SelectionSupport(); |
||
107 | private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
||
108 | private VectorialAdapter source;
|
||
109 | private SelectableDataSource sds;
|
||
110 | 461 | fernando | |
111 | 562 | fernando | /**
|
112 | 1034 | vcaballero | * A?ade un SelectionListener a la lista de listeners.
|
113 | 562 | fernando | *
|
114 | 1034 | vcaballero | * @param listener SelectionListener.
|
115 | 562 | fernando | */
|
116 | public void addSelectionListener(SelectionListener listener) { |
||
117 | selectionSupport.addSelectionListener(listener); |
||
118 | } |
||
119 | 461 | fernando | |
120 | 562 | fernando | /**
|
121 | 1034 | vcaballero | * Borra un selectionListener de la lista de listeners.
|
122 | 562 | fernando | *
|
123 | 1034 | vcaballero | * @param listener SelectionListener
|
124 | 562 | fernando | */
|
125 | public void removeSelectionListener(SelectionListener listener) { |
||
126 | selectionSupport.removeSelectionListener(listener); |
||
127 | } |
||
128 | 214 | fernando | |
129 | 562 | fernando | /**
|
130 | * Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
||
131 | * una gran cantidad de eventos. Con el fin de no propagar todos estos
|
||
132 | * eventos, se realiza la propagaci?n de manera manual al final de la
|
||
133 | * "r?faga" de eventos
|
||
134 | */
|
||
135 | public void fireSelectionEvents() { |
||
136 | selectionSupport.fireSelectionEvents(); |
||
137 | } |
||
138 | 214 | fernando | |
139 | 562 | fernando | /**
|
140 | 1034 | vcaballero | * Devuelve el VectorialAdapater de la capa.
|
141 | 562 | fernando | *
|
142 | 1034 | vcaballero | * @return VectorialAdapter.
|
143 | 562 | fernando | */
|
144 | public VectorialAdapter getSource() {
|
||
145 | return source;
|
||
146 | } |
||
147 | 472 | fernando | |
148 | 562 | fernando | /**
|
149 | 1034 | vcaballero | * Inserta el VectorialAdapter a la capa.
|
150 | 562 | fernando | *
|
151 | 1034 | vcaballero | * @param va VectorialAdapter.
|
152 | 562 | fernando | */
|
153 | public void setSource(VectorialAdapter va) { |
||
154 | source = va; |
||
155 | } |
||
156 | 214 | fernando | |
157 | /**
|
||
158 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
159 | 214 | fernando | */
|
160 | 652 | fernando | public Rectangle2D getFullExtent() throws DriverException { |
161 | 885 | fjp | try {
|
162 | 652 | fernando | Rectangle2D rAux;
|
163 | logger.debug("source.start()");
|
||
164 | source.start(); |
||
165 | rAux = source.getFullExtent(); |
||
166 | logger.debug("source.stop()");
|
||
167 | source.stop(); |
||
168 | 885 | fjp | |
169 | // Si existe reproyecci?n, reproyectar el extent
|
||
170 | ICoordTrans ct = getCoordTrans(); |
||
171 | |||
172 | if (ct != null) { |
||
173 | Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
||
174 | Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
||
175 | pt1 = ct.convert(pt1, null);
|
||
176 | pt2 = ct.convert(pt2, null);
|
||
177 | rAux = new Rectangle2D.Double(); |
||
178 | rAux.setFrameFromDiagonal(pt1, pt2); |
||
179 | } |
||
180 | |||
181 | 652 | fernando | return rAux;
|
182 | 885 | fjp | } catch (DriverIOException e) {
|
183 | 652 | fernando | throw new DriverException(e); |
184 | } |
||
185 | 214 | fernando | } |
186 | |||
187 | /**
|
||
188 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
189 | * java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
||
190 | 214 | fernando | */
|
191 | 562 | fernando | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
192 | 885 | fjp | Cancellable cancel) throws DriverException {
|
193 | 1176 | fjp | |
194 | |||
195 | |||
196 | 230 | fernando | Strategy strategy = StrategyManager.getStrategy(this);
|
197 | |||
198 | 244 | fernando | strategy.draw(image, g, viewPort, cancel); |
199 | 885 | fjp | |
200 | if (getVirtualLayers() != null) { |
||
201 | 745 | fjp | getVirtualLayers().draw(image, g, viewPort, cancel); |
202 | 885 | fjp | } |
203 | |||
204 | if (getLayerText() != null) { |
||
205 | 757 | fjp | getLayerText().draw(image, g, viewPort, cancel); |
206 | 885 | fjp | } |
207 | 214 | fernando | } |
208 | |||
209 | /**
|
||
210 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
211 | * com.iver.cit.gvsig.fmap.ViewPort,
|
||
212 | * com.iver.cit.gvsig.fmap.operations.Cancellable)
|
||
213 | */
|
||
214 | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) |
||
215 | 652 | fernando | throws DriverException {
|
216 | 650 | vcaballero | Strategy strategy = StrategyManager.getStrategy(this);
|
217 | |||
218 | strategy.print(g, viewPort, cancel); |
||
219 | 757 | fjp | |
220 | 885 | fjp | if (getLayerText() != null) { |
221 | 757 | fjp | getLayerText().draw(null, g, viewPort, cancel);
|
222 | 885 | fjp | } |
223 | 562 | fernando | } |
224 | |||
225 | /**
|
||
226 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
|
227 | 214 | fernando | */
|
228 | 562 | fernando | public FLayer createLabelLayer(int fieldId) { |
229 | 757 | fjp | ArrayList labels = new ArrayList(); |
230 | 885 | fjp | |
231 | try {
|
||
232 | 757 | fjp | VectorialAdapter adapter = getSource(); |
233 | DataSource ds = getRecordset();
|
||
234 | logger.debug("adapter.start()");
|
||
235 | adapter.start(); |
||
236 | ds.start(); |
||
237 | |||
238 | VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver(); |
||
239 | int sc;
|
||
240 | |||
241 | sc = adapter.getShapeCount(); |
||
242 | 885 | fjp | |
243 | 801 | fjp | VectorialLegend l = (VectorialLegend) getLegend(); |
244 | int idFieldHeightText = -1; |
||
245 | int idFieldRotationText = -1; |
||
246 | boolean bWithHeightText = false; |
||
247 | 885 | fjp | |
248 | if (l.getLabelHeightField() != null) { |
||
249 | 801 | fjp | bWithHeightText = true;
|
250 | idFieldHeightText = ds.getFieldIndexByName(l.getLabelHeightField()); |
||
251 | } |
||
252 | 885 | fjp | |
253 | 801 | fjp | boolean bWithRotationText = false; |
254 | 885 | fjp | |
255 | if (l.getLabelRotationField() != null) { |
||
256 | 801 | fjp | bWithRotationText = true;
|
257 | idFieldRotationText = ds.getFieldIndexByName(l.getLabelRotationField()); |
||
258 | } |
||
259 | 885 | fjp | |
260 | 757 | fjp | for (int i = 0; i < sc; i++) { |
261 | Value val = ds.getFieldValue(i, fieldId); |
||
262 | 885 | fjp | |
263 | 1126 | fjp | if ((val instanceof NullValue) || (val == null)) { |
264 | 757 | fjp | continue;
|
265 | 885 | fjp | } |
266 | |||
267 | 757 | fjp | IGeometry geom = adapter.getShape(i); |
268 | |||
269 | if (geom == null) { |
||
270 | continue;
|
||
271 | } |
||
272 | |||
273 | 885 | fjp | FSymbol symbol = l.getSymbol(i); |
274 | 757 | fjp | |
275 | // TODO: El m?todo contenedor (createLabelLayer) debe recoger
|
||
276 | // los par?metros de posicionamiento y de allowDuplicates
|
||
277 | 801 | fjp | // if (i >= 328)
|
278 | // System.out.println("i= " + i + " " + val.toString());
|
||
279 | 885 | fjp | FLabel[] lbls = geom.createLabels(0, true); |
280 | |||
281 | for (int j = 0; j < lbls.length; j++) { |
||
282 | if (lbls[j] != null) { |
||
283 | 801 | fjp | lbls[j].setString(val.toString()); |
284 | 885 | fjp | |
285 | if (bWithHeightText) {
|
||
286 | FloatValue height = (FloatValue) ds.getFieldValue(i, |
||
287 | idFieldHeightText); |
||
288 | 801 | fjp | lbls[j].setHeight(height.getValue()); |
289 | 885 | fjp | } else {
|
290 | lbls[j].setHeight(symbol.getFontSize()); |
||
291 | 801 | fjp | } |
292 | 885 | fjp | |
293 | if (bWithRotationText) {
|
||
294 | DoubleValue rotation = (DoubleValue) ds.getFieldValue(i, |
||
295 | idFieldRotationText); |
||
296 | 806 | fjp | lbls[j].setRotation(rotation.getValue()); |
297 | 801 | fjp | } |
298 | 1126 | fjp | labels.add(lbls[j]); |
299 | 801 | fjp | } |
300 | 885 | fjp | |
301 | 1126 | fjp | |
302 | 757 | fjp | } |
303 | } |
||
304 | |||
305 | long t2 = System.currentTimeMillis(); |
||
306 | logger.debug("adapter.stop()");
|
||
307 | ds.stop(); |
||
308 | adapter.stop(); |
||
309 | 885 | fjp | } catch (DriverIOException e) {
|
310 | 757 | fjp | e.printStackTrace(); |
311 | } catch (DriverException e) {
|
||
312 | e.printStackTrace(); |
||
313 | } catch (com.hardcode.gdbms.engine.data.DriverException e) {
|
||
314 | // TODO Auto-generated catch block
|
||
315 | e.printStackTrace(); |
||
316 | 801 | fjp | } catch (FieldNotFoundException e) {
|
317 | // TODO Auto-generated catch block
|
||
318 | e.printStackTrace(); |
||
319 | 757 | fjp | } |
320 | 885 | fjp | |
321 | 757 | fjp | FLyrText layerText = new FLyrText(labels);
|
322 | 885 | fjp | |
323 | 763 | fjp | try {
|
324 | layerText.setLegend((VectorialLegend) getLegend()); |
||
325 | } catch (FieldNotFoundException e1) {
|
||
326 | // TODO Auto-generated catch block
|
||
327 | e1.printStackTrace(); |
||
328 | } catch (DriverException e1) {
|
||
329 | // TODO Auto-generated catch block
|
||
330 | e1.printStackTrace(); |
||
331 | } |
||
332 | 885 | fjp | |
333 | 757 | fjp | setLayerText(layerText); |
334 | 885 | fjp | |
335 | 757 | fjp | return layerText;
|
336 | 214 | fernando | } |
337 | |||
338 | /**
|
||
339 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
|
340 | 214 | fernando | */
|
341 | 228 | fernando | public void removeLabels() { |
342 | 757 | fjp | setLayerText(null);
|
343 | 214 | fernando | } |
344 | |||
345 | /**
|
||
346 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createIndex()
|
347 | 214 | fernando | */
|
348 | 228 | fernando | public void createIndex() { |
349 | 214 | fernando | } |
350 | |||
351 | /**
|
||
352 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
353 | * com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
||
354 | 214 | fernando | */
|
355 | 885 | fjp | public void process(FeatureVisitor visitor, BitSet subset) |
356 | 926 | fernando | throws DriverException, VisitException {
|
357 | 562 | fernando | Strategy s = StrategyManager.getStrategy(this);
|
358 | s.process(visitor, subset); |
||
359 | 228 | fernando | } |
360 | |||
361 | /**
|
||
362 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
363 | */
|
||
364 | 1034 | vcaballero | public void process(FeatureVisitor visitor) |
365 | throws DriverException, VisitException {
|
||
366 | 562 | fernando | Strategy s = StrategyManager.getStrategy(this);
|
367 | s.process(visitor); |
||
368 | } |
||
369 | |||
370 | /**
|
||
371 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
372 | */
|
||
373 | 683 | fernando | public void setSelection(FBitSet selection) { |
374 | 461 | fernando | selectionSupport.setSelection(selection); |
375 | 562 | fernando | fireSelectionEvents(); |
376 | 228 | fernando | } |
377 | |||
378 | /**
|
||
379 | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
|
||
380 | */
|
||
381 | public boolean isSelected(int index) { |
||
382 | 461 | fernando | return selectionSupport.isSelected(index);
|
383 | 228 | fernando | } |
384 | |||
385 | /**
|
||
386 | 456 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
|
387 | */
|
||
388 | 683 | fernando | public FBitSet getSelection() {
|
389 | 461 | fernando | return selectionSupport.getSelection();
|
390 | 456 | fernando | } |
391 | |||
392 | /**
|
||
393 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
|
394 | */
|
||
395 | public void clearSelection() { |
||
396 | 461 | fernando | selectionSupport.clearSelection(); |
397 | 228 | fernando | } |
398 | |||
399 | /**
|
||
400 | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByRect(java.awt.geom.Rectangle2D)
|
||
401 | 214 | fernando | */
|
402 | 652 | fernando | public BitSet queryByRect(Rectangle2D rect) throws DriverException { |
403 | 488 | vcaballero | Strategy s = StrategyManager.getStrategy(this);
|
404 | 562 | fernando | |
405 | 488 | vcaballero | return s.queryByRect(rect);
|
406 | 214 | fernando | } |
407 | |||
408 | /**
|
||
409 | 228 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
410 | */
|
||
411 | 652 | fernando | public SelectableDataSource getRecordset() throws DriverException { |
412 | 562 | fernando | if (sds == null) { |
413 | 884 | fernando | //Nombre en el GDBMS de la tabla
|
414 | String name = this.toString(); |
||
415 | 562 | fernando | |
416 | 911 | fernando | try {
|
417 | 652 | fernando | DataSource ds = source.getRecordset(name);
|
418 | 885 | fjp | |
419 | 652 | fernando | if (ds == null) { |
420 | return null; |
||
421 | } |
||
422 | 885 | fjp | |
423 | 1064 | fernando | sds = new SelectableDataSource(ds);
|
424 | 652 | fernando | sds.setSelectionSupport(selectionSupport); |
425 | 885 | fjp | } catch (DriverLoadException e) {
|
426 | 652 | fernando | throw new DriverException(e); |
427 | 562 | fernando | } |
428 | 544 | fernando | } |
429 | 562 | fernando | |
430 | 461 | fernando | return sds;
|
431 | 217 | fernando | } |
432 | 214 | fernando | |
433 | /**
|
||
434 | 562 | fernando | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
|
435 | * com.iver.cit.gvsig.fmap.rendering.Legend)
|
||
436 | 214 | fernando | */
|
437 | 562 | fernando | public void setLegend(VectorialLegend r) |
438 | 652 | fernando | throws DriverException, FieldNotFoundException {
|
439 | 486 | fjp | VectorialLegend oldLegend = legend; |
440 | 264 | fernando | legend = r; |
441 | 885 | fjp | |
442 | try {
|
||
443 | 652 | fernando | legend.setDataSource(getRecordset()); |
444 | 885 | fjp | |
445 | if (legend.getLabelField() != null) { |
||
446 | 1283 | fjp | sds.start(); |
447 | 757 | fjp | int idLabelField = getRecordset().getFieldIndexByName(legend.getLabelField());
|
448 | createLabelLayer(idLabelField); |
||
449 | 1283 | fjp | sds.stop(); |
450 | 757 | fjp | } |
451 | 1283 | fjp | else
|
452 | removeLabels(); |
||
453 | 885 | fjp | } catch (DriverException e) {
|
454 | 652 | fernando | throw new DriverException(e); |
455 | 757 | fjp | } catch (FieldNotFoundException e) {
|
456 | // TODO Auto-generated catch block
|
||
457 | e.printStackTrace(); |
||
458 | } catch (com.hardcode.gdbms.engine.data.DriverException e) {
|
||
459 | throw new DriverException(e); |
||
460 | 1283 | fjp | } |
461 | 562 | fernando | |
462 | 1082 | fernando | LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(oldLegend, legend); |
463 | 486 | fjp | callLegendChanged(e); |
464 | 214 | fernando | } |
465 | 303 | fernando | |
466 | 321 | fernando | /**
|
467 | 1034 | vcaballero | * Devuelve la Leyenda de la capa.
|
468 | 562 | fernando | *
|
469 | 1034 | vcaballero | * @return Leyenda.
|
470 | 321 | fernando | */
|
471 | 562 | fernando | public Legend getLegend() {
|
472 | return legend;
|
||
473 | 321 | fernando | } |
474 | 373 | fernando | |
475 | /**
|
||
476 | 1034 | vcaballero | * Devuelve el tipo de shape que contiene la capa.
|
477 | 562 | fernando | *
|
478 | 1034 | vcaballero | * @return tipo de shape.
|
479 | 562 | fernando | *
|
480 | 1034 | vcaballero | * @throws DriverException
|
481 | 373 | fernando | */
|
482 | 652 | fernando | public int getShapeType() throws DriverException { |
483 | 562 | fernando | if (typeShape == -1) { |
484 | 885 | fjp | try {
|
485 | 652 | fernando | logger.debug("source.start()");
|
486 | source.start(); |
||
487 | typeShape = source.getShapeType(); |
||
488 | logger.debug("source.stop()");
|
||
489 | source.stop(); |
||
490 | 885 | fjp | } catch (DriverIOException e) {
|
491 | 652 | fernando | throw new DriverException(e); |
492 | } |
||
493 | 526 | vcaballero | } |
494 | 562 | fernando | |
495 | 526 | vcaballero | return typeShape;
|
496 | 373 | fernando | } |
497 | 435 | vcaballero | |
498 | /**
|
||
499 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
||
500 | */
|
||
501 | 652 | fernando | public XMLEntity getXMLEntity() {
|
502 | 562 | fernando | XMLEntity xml = super.getXMLEntity();
|
503 | 435 | vcaballero | xml.addChild(legend.getXMLEntity()); |
504 | 732 | fernando | xml.addChild(selectionSupport.getXMLEntity()); |
505 | 562 | fernando | |
506 | if (source instanceof VectorialFileAdapter) { |
||
507 | xml.putProperty("file", ((VectorialFileAdapter) source).getFile());
|
||
508 | } else if (source instanceof VectorialDBAdapter) { |
||
509 | } else if (source instanceof WFSAdapter) { |
||
510 | 435 | vcaballero | } |
511 | 562 | fernando | |
512 | xml.putProperty("driverName", getSource().getDriver().getName());
|
||
513 | |||
514 | 435 | vcaballero | return xml;
|
515 | } |
||
516 | |||
517 | /**
|
||
518 | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
519 | */
|
||
520 | 885 | fjp | public void setXMLEntity(XMLEntity xml) |
521 | 1056 | vcaballero | throws XMLException {
|
522 | |||
523 | 442 | vcaballero | super.setXMLEntity(xml);
|
524 | 885 | fjp | legend = LegendFactory.createFromXML(xml.getChild(0));
|
525 | |||
526 | try {
|
||
527 | 1283 | fjp | // legend.setDataSource(getRecordset());
|
528 | setLegend(legend); |
||
529 | 558 | vcaballero | } catch (FieldNotFoundException e) {
|
530 | throw new XMLException(e); |
||
531 | } catch (DriverException e) {
|
||
532 | throw new XMLException(e); |
||
533 | 1056 | vcaballero | } |
534 | 885 | fjp | |
535 | 732 | fernando | selectionSupport.setXMLEntity(xml.getChild(1));
|
536 | 435 | vcaballero | } |
537 | 562 | fernando | |
538 | /**
|
||
539 | 1034 | vcaballero | * A?ade un LegendListener a la lista de Listeners.
|
540 | 562 | fernando | *
|
541 | 1034 | vcaballero | * @param listener LegendListener.
|
542 | 562 | fernando | */
|
543 | public void addLegendListener(LegendListener listener) { |
||
544 | 472 | fernando | layerChangeSupport.addLayerListener(listener); |
545 | } |
||
546 | 562 | fernando | |
547 | /**
|
||
548 | 1034 | vcaballero | * Llamada al m?todo callLegendChanged de los listener.
|
549 | 562 | fernando | *
|
550 | 1034 | vcaballero | * @param e Evento.
|
551 | 562 | fernando | */
|
552 | 486 | fjp | private void callLegendChanged(LegendChangedEvent e) { |
553 | 472 | fernando | layerChangeSupport.callLegendChanged(e); |
554 | } |
||
555 | 562 | fernando | |
556 | /**
|
||
557 | 1034 | vcaballero | * Borra un LegendListener de la lista de Listeners
|
558 | 562 | fernando | *
|
559 | 1034 | vcaballero | * @param listener LegendListener.
|
560 | 562 | fernando | */
|
561 | public void removeLegendListener(LegendListener listener) { |
||
562 | 472 | fernando | layerChangeSupport.removeLayerListener(listener); |
563 | } |
||
564 | 544 | fernando | |
565 | /**
|
||
566 | * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#changeRecordsetName()
|
||
567 | */
|
||
568 | 652 | fernando | public void changeRecordsetName(String newName) throws DriverException { |
569 | 544 | fernando | source.changeRecordsetName(newName); |
570 | 526 | vcaballero | } |
571 | 911 | fernando | |
572 | /**
|
||
573 | 1034 | vcaballero | * Sobreimplementaci?n del m?todo toString para que las bases de datos
|
574 | * identifiquen la capa.
|
||
575 | 911 | fernando | *
|
576 | * @return DOCUMENT ME!
|
||
577 | */
|
||
578 | public String toString() { |
||
579 | /*
|
||
580 | * Se usa internamente para que la parte de datos
|
||
581 | * identifique de forma un?voca las tablas
|
||
582 | */
|
||
583 | String ret = super.toString(); |
||
584 | |||
585 | return "layer" + ret.substring(ret.indexOf('@') + 1); |
||
586 | } |
||
587 | 214 | fernando | } |