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