root / branches / pilotoDWG / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 1532
History | View | Annotate | Download (19.9 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.layers; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.geom.Point2D; |
46 |
import java.awt.geom.Rectangle2D; |
47 |
import java.awt.image.BufferedImage; |
48 |
import java.io.IOException; |
49 |
import java.util.ArrayList; |
50 |
import java.util.BitSet; |
51 |
import java.util.Iterator; |
52 |
|
53 |
import org.apache.log4j.Logger; |
54 |
import org.cresques.cts.ICoordTrans; |
55 |
|
56 |
import com.hardcode.driverManager.DriverLoadException; |
57 |
import com.hardcode.gdbms.engine.data.DataSource; |
58 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
59 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
60 |
import com.hardcode.gdbms.engine.values.FloatValue; |
61 |
import com.hardcode.gdbms.engine.values.NullValue; |
62 |
import com.hardcode.gdbms.engine.values.Value; |
63 |
import com.iver.cit.gvsig.fmap.DriverException; |
64 |
import com.iver.cit.gvsig.fmap.ViewPort; |
65 |
import com.iver.cit.gvsig.fmap.core.FGeometry; |
66 |
import com.iver.cit.gvsig.fmap.core.Handler; |
67 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
68 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
69 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
70 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
71 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
72 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
73 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
74 |
import com.iver.cit.gvsig.fmap.edition.DefaultEditableFeatureSource; |
75 |
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource; |
76 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
77 |
import com.iver.cit.gvsig.fmap.edition.FileEditableFeatureSource; |
78 |
import com.iver.cit.gvsig.fmap.edition.MemoryExpansionFile; |
79 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
80 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
81 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.EditableVectorialLayer; |
82 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.EditionListener; |
83 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable; |
84 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData; |
85 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
86 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
87 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
88 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
89 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
90 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
91 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
92 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
93 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
94 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
95 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
96 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
97 |
import com.iver.utiles.XMLEntity; |
98 |
import com.vividsolutions.jts.geom.Envelope; |
99 |
|
100 |
|
101 |
/**
|
102 |
* Capa b?sica Vectorial.
|
103 |
*
|
104 |
* @author Fernando Gonz?lez Cort?s
|
105 |
*/
|
106 |
|
107 |
//TODO Cuando no sea para pruebas debe no ser public
|
108 |
public class FLyrVect extends FLyrDefault implements EditableVectorialLayer, Labelable, Selectable, |
109 |
AlphanumericData, SingleLayer, VectorialData, ClassifiableVectorial, |
110 |
RandomVectorialData { |
111 |
private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
112 |
|
113 |
/** Leyenda de la capa vectorial */
|
114 |
private VectorialLegend legend;
|
115 |
private int typeShape = -1; |
116 |
private SelectionSupport selectionSupport = new SelectionSupport(); |
117 |
private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
118 |
private VectorialAdapter source;
|
119 |
private SelectableDataSource sds;
|
120 |
private EditableFeatureSource efs;
|
121 |
|
122 |
private ArrayList editionListeners = new ArrayList(); |
123 |
|
124 |
/**
|
125 |
* @throws EditionException
|
126 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.EditableVectorialLayer#stopEdition()
|
127 |
*/
|
128 |
public void stopEdition() throws EditionException { |
129 |
efs.stopEdition(); |
130 |
efs = null;
|
131 |
|
132 |
for (Iterator iter = editionListeners.iterator(); iter.hasNext();) { |
133 |
EditionListener element = (EditionListener) iter.next(); |
134 |
element.stopEdition(EditionEvent.createEditionEvent(this, efs));
|
135 |
} |
136 |
} |
137 |
|
138 |
public boolean isEditing(){ |
139 |
return efs != null; |
140 |
} |
141 |
|
142 |
public void addEditionListener(EditionListener listener){ |
143 |
editionListeners.add(listener); |
144 |
} |
145 |
|
146 |
public void removeEditionListener(EditionListener listener){ |
147 |
editionListeners.remove(listener); |
148 |
} |
149 |
|
150 |
/**
|
151 |
* @throws EditionException
|
152 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.EditableVectorialLayer#startEdition()
|
153 |
*/
|
154 |
public EditableFeatureSource startEdition() throws EditionException { |
155 |
FileEditableFeatureSource fefs = new FileEditableFeatureSource((VectorialFileAdapter) source);
|
156 |
MemoryExpansionFile mef = new MemoryExpansionFile();
|
157 |
efs = new DefaultEditableFeatureSource(mef,
|
158 |
fefs); |
159 |
|
160 |
efs.startEdition(); |
161 |
|
162 |
for (Iterator iter = editionListeners.iterator(); iter.hasNext();) { |
163 |
EditionListener element = (EditionListener) iter.next(); |
164 |
element.startEdition(EditionEvent.createEditionEvent(this, efs));
|
165 |
} |
166 |
|
167 |
return efs;
|
168 |
} |
169 |
|
170 |
/**
|
171 |
* A?ade un SelectionListener a la lista de listeners.
|
172 |
*
|
173 |
* @param listener SelectionListener.
|
174 |
*/
|
175 |
public void addSelectionListener(SelectionListener listener) { |
176 |
selectionSupport.addSelectionListener(listener); |
177 |
} |
178 |
|
179 |
/**
|
180 |
* Borra un selectionListener de la lista de listeners.
|
181 |
*
|
182 |
* @param listener SelectionListener
|
183 |
*/
|
184 |
public void removeSelectionListener(SelectionListener listener) { |
185 |
selectionSupport.removeSelectionListener(listener); |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
190 |
* una gran cantidad de eventos. Con el fin de no propagar todos estos
|
191 |
* eventos, se realiza la propagaci?n de manera manual al final de la
|
192 |
* "r?faga" de eventos
|
193 |
*/
|
194 |
public void fireSelectionEvents() { |
195 |
selectionSupport.fireSelectionEvents(); |
196 |
} |
197 |
|
198 |
/**
|
199 |
* Devuelve el VectorialAdapater de la capa.
|
200 |
*
|
201 |
* @return VectorialAdapter.
|
202 |
*/
|
203 |
public VectorialAdapter getSource() {
|
204 |
return source;
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* Inserta el VectorialAdapter a la capa.
|
209 |
*
|
210 |
* @param va VectorialAdapter.
|
211 |
*/
|
212 |
public void setSource(VectorialAdapter va) { |
213 |
source = va; |
214 |
} |
215 |
|
216 |
/**
|
217 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
218 |
*/
|
219 |
public Rectangle2D getFullExtent() throws DriverException { |
220 |
try {
|
221 |
Rectangle2D rAux;
|
222 |
logger.debug("source.start()");
|
223 |
source.start(); |
224 |
rAux = source.getFullExtent(); |
225 |
logger.debug("source.stop()");
|
226 |
source.stop(); |
227 |
|
228 |
// Si existe reproyecci?n, reproyectar el extent
|
229 |
ICoordTrans ct = getCoordTrans(); |
230 |
|
231 |
if (ct != null) { |
232 |
Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
233 |
Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
234 |
pt1 = ct.convert(pt1, null);
|
235 |
pt2 = ct.convert(pt2, null);
|
236 |
rAux = new Rectangle2D.Double(); |
237 |
rAux.setFrameFromDiagonal(pt1, pt2); |
238 |
} |
239 |
|
240 |
return rAux;
|
241 |
} catch (DriverIOException e) {
|
242 |
throw new DriverException(e); |
243 |
} |
244 |
} |
245 |
|
246 |
/**
|
247 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
248 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
249 |
*/
|
250 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
251 |
Cancellable cancel) throws DriverException {
|
252 |
|
253 |
FSymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.BLACK); |
254 |
if (efs == null){ |
255 |
Strategy strategy = StrategyManager.getStrategy(this);
|
256 |
|
257 |
strategy.draw(image, g, viewPort, cancel); |
258 |
|
259 |
if (getVirtualLayers() != null) { |
260 |
getVirtualLayers().draw(image, g, viewPort, cancel); |
261 |
} |
262 |
|
263 |
if (getLayerText() != null) { |
264 |
getLayerText().draw(image, g, viewPort, cancel); |
265 |
} |
266 |
}else{
|
267 |
try {
|
268 |
BufferedImage selectionImage = new BufferedImage(viewPort.getImageWidth(), viewPort.getImageHeight(), BufferedImage.TYPE_INT_ARGB); |
269 |
Graphics2D gs = selectionImage.createGraphics();
|
270 |
|
271 |
long t1 = System.currentTimeMillis(); |
272 |
|
273 |
FSymbol selectionSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.RED); |
274 |
|
275 |
Rectangle2D r = viewPort.getAdjustedExtent();
|
276 |
int[] indexes = efs.getGeometriesIndexes(r); |
277 |
for (int i = 0; i < indexes.length; i++){ |
278 |
IGeometry ig = efs.getGeometry(indexes[i]); |
279 |
if (selectionSupport.isSelected(indexes[i])){
|
280 |
Handler[] handlers=ig.getHandlers(FGeometry.SELECTHANDLER); |
281 |
ig.cloneGeometry().draw((Graphics2D) g, viewPort, selectionSymbol);
|
282 |
FGraphicUtilities.DrawHandlers((Graphics2D)g,viewPort.getAffineTransform(),handlers);
|
283 |
ig.draw(gs, viewPort, selectionSymbol); |
284 |
FGraphicUtilities.DrawHandlers(gs,viewPort.getAffineTransform(),handlers); |
285 |
}else{
|
286 |
ig.draw(g, viewPort, symbol); |
287 |
} |
288 |
} |
289 |
|
290 |
System.err.println("tiempo indice:" +(System.currentTimeMillis() - t1)); |
291 |
/*
|
292 |
t1 = System.currentTimeMillis();
|
293 |
|
294 |
for (int i = 0; i < efs.getGeometryCount(); i++){
|
295 |
IGeometry ig = efs.getGeometry(i);
|
296 |
if (selectionSupport.isSelected(i)){
|
297 |
Handler[] handlers=ig.getHandlers(FGeometry.SELECTHANDLER);
|
298 |
ig.cloneGeometry().draw((Graphics2D) g, viewPort, selectionSymbol);
|
299 |
ig.draw(gs, viewPort, selectionSymbol);
|
300 |
FGraphicUtilities.DrawHandlers((Graphics2D)g,viewPort.getAffineTransform(),handlers);
|
301 |
|
302 |
}else{
|
303 |
ig.draw(g, viewPort, symbol);
|
304 |
}
|
305 |
}
|
306 |
|
307 |
System.err.println("tiempo sin indice:" +(System.currentTimeMillis() - t1));
|
308 |
*/
|
309 |
efs.setImage(selectionImage); |
310 |
} catch (DriverIOException e) {
|
311 |
e.printStackTrace(); |
312 |
} catch (IOException e) { |
313 |
e.printStackTrace(); |
314 |
} |
315 |
} |
316 |
} |
317 |
|
318 |
/**
|
319 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
320 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
321 |
* com.iver.cit.gvsig.fmap.operations.Cancellable)
|
322 |
*/
|
323 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) |
324 |
throws DriverException {
|
325 |
Strategy strategy = StrategyManager.getStrategy(this);
|
326 |
|
327 |
strategy.print(g, viewPort, cancel); |
328 |
|
329 |
if (getLayerText() != null) { |
330 |
getLayerText().draw(null, g, viewPort, cancel);
|
331 |
} |
332 |
} |
333 |
|
334 |
/**
|
335 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
|
336 |
*/
|
337 |
public FLayer createLabelLayer(int fieldId) { |
338 |
ArrayList labels = new ArrayList(); |
339 |
|
340 |
try {
|
341 |
VectorialAdapter adapter = getSource(); |
342 |
DataSource ds = getRecordset();
|
343 |
logger.debug("adapter.start()");
|
344 |
adapter.start(); |
345 |
ds.start(); |
346 |
|
347 |
VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver(); |
348 |
int sc;
|
349 |
|
350 |
sc = adapter.getShapeCount(); |
351 |
|
352 |
VectorialLegend l = (VectorialLegend) getLegend(); |
353 |
int idFieldHeightText = -1; |
354 |
int idFieldRotationText = -1; |
355 |
boolean bWithHeightText = false; |
356 |
|
357 |
if (l.getLabelHeightField() != null) { |
358 |
bWithHeightText = true;
|
359 |
idFieldHeightText = ds.getFieldIndexByName(l.getLabelHeightField()); |
360 |
} |
361 |
|
362 |
boolean bWithRotationText = false; |
363 |
|
364 |
if (l.getLabelRotationField() != null) { |
365 |
bWithRotationText = true;
|
366 |
idFieldRotationText = ds.getFieldIndexByName(l.getLabelRotationField()); |
367 |
} |
368 |
|
369 |
for (int i = 0; i < sc; i++) { |
370 |
Value val = ds.getFieldValue(i, fieldId); |
371 |
|
372 |
if ((val instanceof NullValue) || (val == null)) { |
373 |
continue;
|
374 |
} |
375 |
|
376 |
IGeometry geom = adapter.getShape(i); |
377 |
|
378 |
if (geom == null) { |
379 |
continue;
|
380 |
} |
381 |
|
382 |
FSymbol symbol = l.getSymbol(i); |
383 |
|
384 |
// TODO: El m?todo contenedor (createLabelLayer) debe recoger
|
385 |
// los par?metros de posicionamiento y de allowDuplicates
|
386 |
// if (i >= 328)
|
387 |
// System.out.println("i= " + i + " " + val.toString());
|
388 |
FLabel[] lbls = geom.createLabels(0, true); |
389 |
|
390 |
for (int j = 0; j < lbls.length; j++) { |
391 |
if (lbls[j] != null) { |
392 |
lbls[j].setString(val.toString()); |
393 |
|
394 |
if (bWithHeightText) {
|
395 |
FloatValue height = (FloatValue) ds.getFieldValue(i, |
396 |
idFieldHeightText); |
397 |
lbls[j].setHeight(height.getValue()); |
398 |
} else {
|
399 |
lbls[j].setHeight(symbol.getFontSize()); |
400 |
} |
401 |
|
402 |
if (bWithRotationText) {
|
403 |
DoubleValue rotation = (DoubleValue) ds.getFieldValue(i, |
404 |
idFieldRotationText); |
405 |
lbls[j].setRotation(rotation.getValue()); |
406 |
} |
407 |
labels.add(lbls[j]); |
408 |
} |
409 |
|
410 |
|
411 |
} |
412 |
} |
413 |
|
414 |
long t2 = System.currentTimeMillis(); |
415 |
logger.debug("adapter.stop()");
|
416 |
ds.stop(); |
417 |
adapter.stop(); |
418 |
} catch (DriverIOException e) {
|
419 |
e.printStackTrace(); |
420 |
} catch (DriverException e) {
|
421 |
e.printStackTrace(); |
422 |
} catch (com.hardcode.gdbms.engine.data.DriverException e) {
|
423 |
// TODO Auto-generated catch block
|
424 |
e.printStackTrace(); |
425 |
} catch (FieldNotFoundException e) {
|
426 |
// TODO Auto-generated catch block
|
427 |
e.printStackTrace(); |
428 |
} |
429 |
|
430 |
FLyrText layerText = new FLyrText(labels);
|
431 |
|
432 |
try {
|
433 |
layerText.setLegend((VectorialLegend) getLegend()); |
434 |
} catch (FieldNotFoundException e1) {
|
435 |
// TODO Auto-generated catch block
|
436 |
e1.printStackTrace(); |
437 |
} catch (DriverException e1) {
|
438 |
// TODO Auto-generated catch block
|
439 |
e1.printStackTrace(); |
440 |
} |
441 |
|
442 |
setLayerText(layerText); |
443 |
|
444 |
return layerText;
|
445 |
} |
446 |
|
447 |
/**
|
448 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
|
449 |
*/
|
450 |
public void removeLabels() { |
451 |
setLayerText(null);
|
452 |
} |
453 |
|
454 |
/**
|
455 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createIndex()
|
456 |
*/
|
457 |
public void createIndex() { |
458 |
} |
459 |
|
460 |
/**
|
461 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
462 |
* com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
463 |
*/
|
464 |
public void process(FeatureVisitor visitor, BitSet subset) |
465 |
throws DriverException, VisitException {
|
466 |
Strategy s = StrategyManager.getStrategy(this);
|
467 |
s.process(visitor, subset); |
468 |
} |
469 |
|
470 |
/**
|
471 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
472 |
*/
|
473 |
public void process(FeatureVisitor visitor) |
474 |
throws DriverException, VisitException {
|
475 |
Strategy s = StrategyManager.getStrategy(this);
|
476 |
s.process(visitor); |
477 |
} |
478 |
|
479 |
/**
|
480 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
481 |
*/
|
482 |
public void setSelection(FBitSet selection) { |
483 |
selectionSupport.setSelection(selection); |
484 |
fireSelectionEvents(); |
485 |
} |
486 |
|
487 |
/**
|
488 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
|
489 |
*/
|
490 |
public boolean isSelected(int index) { |
491 |
return selectionSupport.isSelected(index);
|
492 |
} |
493 |
|
494 |
/**
|
495 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
|
496 |
*/
|
497 |
public FBitSet getSelection() {
|
498 |
return selectionSupport.getSelection();
|
499 |
} |
500 |
|
501 |
/**
|
502 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
|
503 |
*/
|
504 |
public void clearSelection() { |
505 |
selectionSupport.clearSelection(); |
506 |
} |
507 |
|
508 |
/**
|
509 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByRect(java.awt.geom.Rectangle2D)
|
510 |
*/
|
511 |
public BitSet queryByRect(Rectangle2D rect) throws DriverException { |
512 |
Strategy s = StrategyManager.getStrategy(this);
|
513 |
|
514 |
return s.queryByRect(rect);
|
515 |
} |
516 |
|
517 |
/**
|
518 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
519 |
*/
|
520 |
public SelectableDataSource getRecordset() throws DriverException { |
521 |
if (sds == null) { |
522 |
//Nombre en el GDBMS de la tabla
|
523 |
String name = this.toString(); |
524 |
|
525 |
try {
|
526 |
DataSource ds = source.getRecordset(name);
|
527 |
|
528 |
if (ds == null) { |
529 |
return null; |
530 |
} |
531 |
|
532 |
sds = new SelectableDataSource(ds);
|
533 |
sds.setSelectionSupport(selectionSupport); |
534 |
} catch (DriverLoadException e) {
|
535 |
throw new DriverException(e); |
536 |
} |
537 |
} |
538 |
|
539 |
return sds;
|
540 |
} |
541 |
|
542 |
/**
|
543 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
|
544 |
* com.iver.cit.gvsig.fmap.rendering.Legend)
|
545 |
*/
|
546 |
public void setLegend(VectorialLegend r) |
547 |
throws DriverException, FieldNotFoundException {
|
548 |
VectorialLegend oldLegend = legend; |
549 |
legend = r; |
550 |
|
551 |
try {
|
552 |
legend.setDataSource(getRecordset()); |
553 |
|
554 |
if (legend.getLabelField() != null) { |
555 |
sds.start(); |
556 |
int idLabelField = getRecordset().getFieldIndexByName(legend.getLabelField());
|
557 |
createLabelLayer(idLabelField); |
558 |
sds.stop(); |
559 |
} |
560 |
else
|
561 |
removeLabels(); |
562 |
} catch (DriverException e) {
|
563 |
throw new DriverException(e); |
564 |
} catch (FieldNotFoundException e) {
|
565 |
// TODO Auto-generated catch block
|
566 |
e.printStackTrace(); |
567 |
} catch (com.hardcode.gdbms.engine.data.DriverException e) {
|
568 |
throw new DriverException(e); |
569 |
} |
570 |
|
571 |
LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(oldLegend, legend); |
572 |
callLegendChanged(e); |
573 |
} |
574 |
|
575 |
/**
|
576 |
* Devuelve la Leyenda de la capa.
|
577 |
*
|
578 |
* @return Leyenda.
|
579 |
*/
|
580 |
public Legend getLegend() {
|
581 |
return legend;
|
582 |
} |
583 |
|
584 |
/**
|
585 |
* Devuelve el tipo de shape que contiene la capa.
|
586 |
*
|
587 |
* @return tipo de shape.
|
588 |
*
|
589 |
* @throws DriverException
|
590 |
*/
|
591 |
public int getShapeType() throws DriverException { |
592 |
if (typeShape == -1) { |
593 |
try {
|
594 |
logger.debug("source.start()");
|
595 |
source.start(); |
596 |
typeShape = source.getShapeType(); |
597 |
logger.debug("source.stop()");
|
598 |
source.stop(); |
599 |
} catch (DriverIOException e) {
|
600 |
throw new DriverException(e); |
601 |
} |
602 |
} |
603 |
|
604 |
return typeShape;
|
605 |
} |
606 |
|
607 |
/**
|
608 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
609 |
*/
|
610 |
public XMLEntity getXMLEntity() {
|
611 |
XMLEntity xml = super.getXMLEntity();
|
612 |
xml.addChild(legend.getXMLEntity()); |
613 |
xml.addChild(selectionSupport.getXMLEntity()); |
614 |
|
615 |
if (source instanceof VectorialFileAdapter) { |
616 |
xml.putProperty("file", ((VectorialFileAdapter) source).getFile());
|
617 |
} else if (source instanceof VectorialDBAdapter) { |
618 |
} else if (source instanceof WFSAdapter) { |
619 |
} |
620 |
|
621 |
xml.putProperty("driverName", getSource().getDriver().getName());
|
622 |
|
623 |
return xml;
|
624 |
} |
625 |
|
626 |
/**
|
627 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
628 |
*/
|
629 |
public void setXMLEntity(XMLEntity xml) |
630 |
throws XMLException {
|
631 |
|
632 |
super.setXMLEntity(xml);
|
633 |
legend = LegendFactory.createFromXML(xml.getChild(0));
|
634 |
|
635 |
try {
|
636 |
// legend.setDataSource(getRecordset());
|
637 |
setLegend(legend); |
638 |
} catch (FieldNotFoundException e) {
|
639 |
throw new XMLException(e); |
640 |
} catch (DriverException e) {
|
641 |
throw new XMLException(e); |
642 |
} |
643 |
|
644 |
selectionSupport.setXMLEntity(xml.getChild(1));
|
645 |
} |
646 |
|
647 |
/**
|
648 |
* A?ade un LegendListener a la lista de Listeners.
|
649 |
*
|
650 |
* @param listener LegendListener.
|
651 |
*/
|
652 |
public void addLegendListener(LegendListener listener) { |
653 |
layerChangeSupport.addLayerListener(listener); |
654 |
} |
655 |
|
656 |
/**
|
657 |
* Llamada al m?todo callLegendChanged de los listener.
|
658 |
*
|
659 |
* @param e Evento.
|
660 |
*/
|
661 |
private void callLegendChanged(LegendChangedEvent e) { |
662 |
layerChangeSupport.callLegendChanged(e); |
663 |
} |
664 |
|
665 |
/**
|
666 |
* Borra un LegendListener de la lista de Listeners
|
667 |
*
|
668 |
* @param listener LegendListener.
|
669 |
*/
|
670 |
public void removeLegendListener(LegendListener listener) { |
671 |
layerChangeSupport.removeLayerListener(listener); |
672 |
} |
673 |
|
674 |
/**
|
675 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#changeRecordsetName()
|
676 |
*/
|
677 |
public void changeRecordsetName(String newName) throws DriverException { |
678 |
source.changeRecordsetName(newName); |
679 |
} |
680 |
|
681 |
/**
|
682 |
* Sobreimplementaci?n del m?todo toString para que las bases de datos
|
683 |
* identifiquen la capa.
|
684 |
*
|
685 |
* @return DOCUMENT ME!
|
686 |
*/
|
687 |
public String toString() { |
688 |
/*
|
689 |
* Se usa internamente para que la parte de datos
|
690 |
* identifique de forma un?voca las tablas
|
691 |
*/
|
692 |
String ret = super.toString(); |
693 |
|
694 |
return "layer" + ret.substring(ret.indexOf('@') + 1); |
695 |
} |
696 |
} |