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