svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 787
History | View | Annotate | Download (12.9 KB)
1 |
/* Generated by Together */
|
---|---|
2 |
package com.iver.cit.gvsig.fmap.layers; |
3 |
|
4 |
import java.awt.Graphics2D; |
5 |
import java.awt.geom.AffineTransform; |
6 |
import java.awt.geom.Rectangle2D; |
7 |
import java.awt.image.BufferedImage; |
8 |
import java.util.ArrayList; |
9 |
import java.util.BitSet; |
10 |
|
11 |
import org.apache.log4j.Logger; |
12 |
|
13 |
import com.hardcode.driverManager.DriverLoadException; |
14 |
import com.hardcode.gdbms.engine.data.DataSource; |
15 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
16 |
import com.hardcode.gdbms.engine.values.Value; |
17 |
import com.iver.cit.gvsig.fmap.DriverException; |
18 |
import com.iver.cit.gvsig.fmap.ViewPort; |
19 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
20 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
21 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
22 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
23 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
24 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
25 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
26 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable; |
27 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData; |
28 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
29 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
30 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
31 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
32 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
33 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
34 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
35 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
36 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
37 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
38 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
39 |
import com.iver.utiles.XMLEntity; |
40 |
|
41 |
|
42 |
/**
|
43 |
* DOCUMENT ME!
|
44 |
*
|
45 |
* @author Fernando Gonz?lez Cort?s
|
46 |
*/
|
47 |
//TODO Cuando no sea para pruebas debe no ser public
|
48 |
public class FLyrVect extends FLyrDefault implements Labelable, Selectable, |
49 |
AlphanumericData, ClassifiableVectorial, SingleLayer, VectorialData, RandomVectorialData { |
50 |
private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
51 |
|
52 |
/** Leyenda de la capa vectorial */
|
53 |
private VectorialLegend legend;
|
54 |
private int typeShape = -1; |
55 |
private SelectionSupport selectionSupport = new SelectionSupport(); |
56 |
private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
57 |
private VectorialAdapter source;
|
58 |
private SelectableDataSource sds;
|
59 |
|
60 |
/**
|
61 |
* DOCUMENT ME!
|
62 |
*
|
63 |
* @param listener DOCUMENT ME!
|
64 |
*/
|
65 |
public void addSelectionListener(SelectionListener listener) { |
66 |
selectionSupport.addSelectionListener(listener); |
67 |
} |
68 |
|
69 |
/**
|
70 |
* DOCUMENT ME!
|
71 |
*
|
72 |
* @param listener DOCUMENT ME!
|
73 |
*/
|
74 |
public void removeSelectionListener(SelectionListener listener) { |
75 |
selectionSupport.removeSelectionListener(listener); |
76 |
} |
77 |
|
78 |
/**
|
79 |
* Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
80 |
* una gran cantidad de eventos. Con el fin de no propagar todos estos
|
81 |
* eventos, se realiza la propagaci?n de manera manual al final de la
|
82 |
* "r?faga" de eventos
|
83 |
*/
|
84 |
public void fireSelectionEvents() { |
85 |
selectionSupport.fireSelectionEvents(); |
86 |
} |
87 |
|
88 |
/**
|
89 |
* DOCUMENT ME!
|
90 |
*
|
91 |
* @return DOCUMENT ME!
|
92 |
*/
|
93 |
public VectorialAdapter getSource() {
|
94 |
return source;
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* DOCUMENT ME!
|
99 |
*
|
100 |
* @param va DOCUMENT ME!
|
101 |
*/
|
102 |
public void setSource(VectorialAdapter va) { |
103 |
source = va; |
104 |
} |
105 |
|
106 |
/**
|
107 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
108 |
*/
|
109 |
public Rectangle2D getFullExtent() throws DriverException { |
110 |
try{
|
111 |
Rectangle2D rAux;
|
112 |
logger.debug("source.start()");
|
113 |
source.start(); |
114 |
rAux = source.getFullExtent(); |
115 |
logger.debug("source.stop()");
|
116 |
source.stop(); |
117 |
return rAux;
|
118 |
}catch(DriverIOException e){
|
119 |
throw new DriverException(e); |
120 |
} |
121 |
} |
122 |
|
123 |
/**
|
124 |
* DOCUMENT ME!
|
125 |
*
|
126 |
* @param image DOCUMENT ME!
|
127 |
* @param g DOCUMENT ME!
|
128 |
* @param viewPort DOCUMENT ME!
|
129 |
* @param cancel DOCUMENT ME!
|
130 |
*
|
131 |
* @throws DriverIOException
|
132 |
* @throws DriverLoadException
|
133 |
* @throws DriverException
|
134 |
*
|
135 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
136 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
137 |
*/
|
138 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
139 |
Cancellable cancel) |
140 |
throws DriverException {
|
141 |
Strategy strategy = StrategyManager.getStrategy(this);
|
142 |
|
143 |
strategy.draw(image, g, viewPort, cancel); |
144 |
if (getVirtualLayers() != null) |
145 |
getVirtualLayers().draw(image, g, viewPort, cancel); |
146 |
if (getLayerText() != null) |
147 |
getLayerText().draw(image, g, viewPort, cancel); |
148 |
} |
149 |
|
150 |
/**
|
151 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
152 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
153 |
* com.iver.cit.gvsig.fmap.operations.Cancellable)
|
154 |
*/
|
155 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel) |
156 |
throws DriverException {
|
157 |
Strategy strategy = StrategyManager.getStrategy(this);
|
158 |
|
159 |
strategy.print(g, viewPort, cancel); |
160 |
|
161 |
if (getLayerText() != null) |
162 |
getLayerText().draw(null, g, viewPort, cancel);
|
163 |
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
|
168 |
*/
|
169 |
public FLayer createLabelLayer(int fieldId) { |
170 |
ArrayList labels = new ArrayList(); |
171 |
try{
|
172 |
VectorialAdapter adapter = getSource(); |
173 |
DataSource ds = getRecordset();
|
174 |
logger.debug("adapter.start()");
|
175 |
adapter.start(); |
176 |
ds.start(); |
177 |
|
178 |
VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver(); |
179 |
int sc;
|
180 |
|
181 |
sc = adapter.getShapeCount(); |
182 |
|
183 |
for (int i = 0; i < sc; i++) { |
184 |
Value val = ds.getFieldValue(i, fieldId); |
185 |
if (val == null) |
186 |
continue;
|
187 |
IGeometry geom = adapter.getShape(i); |
188 |
|
189 |
if (geom == null) { |
190 |
continue;
|
191 |
} |
192 |
|
193 |
VectorialLegend l = (VectorialLegend) getLegend(); |
194 |
|
195 |
FSymbol symbol = l.getSymbol(i); |
196 |
|
197 |
// TODO: El m?todo contenedor (createLabelLayer) debe recoger
|
198 |
// los par?metros de posicionamiento y de allowDuplicates
|
199 |
FLabel[] lbls = geom.createLabels(0,true); |
200 |
for (int j=0; j < lbls.length; j++) |
201 |
{ |
202 |
lbls[j].setString(val.toString()); |
203 |
lbls[j].setHeight(symbol.getFontSize()); |
204 |
|
205 |
labels.add(lbls[j]); |
206 |
} |
207 |
} |
208 |
|
209 |
long t2 = System.currentTimeMillis(); |
210 |
logger.debug("adapter.stop()");
|
211 |
ds.stop(); |
212 |
adapter.stop(); |
213 |
}catch(DriverIOException e){
|
214 |
e.printStackTrace(); |
215 |
} catch (DriverException e) {
|
216 |
e.printStackTrace(); |
217 |
} catch (com.hardcode.gdbms.engine.data.DriverException e) {
|
218 |
// TODO Auto-generated catch block
|
219 |
e.printStackTrace(); |
220 |
} |
221 |
|
222 |
FLyrText layerText = new FLyrText(labels);
|
223 |
try {
|
224 |
layerText.setLegend((VectorialLegend) getLegend()); |
225 |
} catch (FieldNotFoundException e1) {
|
226 |
// TODO Auto-generated catch block
|
227 |
e1.printStackTrace(); |
228 |
} catch (DriverException e1) {
|
229 |
// TODO Auto-generated catch block
|
230 |
e1.printStackTrace(); |
231 |
} |
232 |
setLayerText(layerText); |
233 |
return layerText;
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
|
238 |
*/
|
239 |
public void removeLabels() { |
240 |
setLayerText(null);
|
241 |
} |
242 |
|
243 |
/**
|
244 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createIndex()
|
245 |
*/
|
246 |
public void createIndex() { |
247 |
} |
248 |
|
249 |
/**
|
250 |
* @throws DriverIOException
|
251 |
* @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
252 |
* com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
253 |
*/
|
254 |
public void process(FeatureVisitor visitor, BitSet subset) throws DriverException { |
255 |
Strategy s = StrategyManager.getStrategy(this);
|
256 |
s.process(visitor, subset); |
257 |
} |
258 |
|
259 |
/**
|
260 |
* @throws DriverIOException
|
261 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
262 |
*/
|
263 |
public void process(FeatureVisitor visitor) throws DriverException { |
264 |
Strategy s = StrategyManager.getStrategy(this);
|
265 |
s.process(visitor); |
266 |
} |
267 |
|
268 |
/**
|
269 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
|
270 |
*/
|
271 |
public void setSelection(FBitSet selection) { |
272 |
selectionSupport.setSelection(selection); |
273 |
fireSelectionEvents(); |
274 |
} |
275 |
|
276 |
/**
|
277 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
|
278 |
*/
|
279 |
public boolean isSelected(int index) { |
280 |
return selectionSupport.isSelected(index);
|
281 |
} |
282 |
|
283 |
/**
|
284 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
|
285 |
*/
|
286 |
public FBitSet getSelection() {
|
287 |
return selectionSupport.getSelection();
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
|
292 |
*/
|
293 |
public void clearSelection() { |
294 |
selectionSupport.clearSelection(); |
295 |
} |
296 |
|
297 |
/**
|
298 |
* DOCUMENT ME!
|
299 |
*
|
300 |
* @param rect DOCUMENT ME!
|
301 |
*
|
302 |
* @return DOCUMENT ME!
|
303 |
*
|
304 |
* @throws DriverIOException
|
305 |
*
|
306 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByRect(java.awt.geom.Rectangle2D)
|
307 |
*/
|
308 |
public BitSet queryByRect(Rectangle2D rect) throws DriverException { |
309 |
Strategy s = StrategyManager.getStrategy(this);
|
310 |
|
311 |
return s.queryByRect(rect);
|
312 |
} |
313 |
|
314 |
/**
|
315 |
* DOCUMENT ME!
|
316 |
*
|
317 |
* @return DOCUMENT ME!
|
318 |
*
|
319 |
* @throws DriverLoadException
|
320 |
*
|
321 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
|
322 |
*/
|
323 |
public SelectableDataSource getRecordset() throws DriverException { |
324 |
if (sds == null) { |
325 |
String name = getName();
|
326 |
|
327 |
if (name == null) { |
328 |
return null; |
329 |
} |
330 |
|
331 |
try{
|
332 |
DataSource ds = source.getRecordset(name);
|
333 |
|
334 |
if (ds == null) { |
335 |
return null; |
336 |
} |
337 |
|
338 |
sds = new SelectableDataSource(getName(), ds);
|
339 |
sds.setSelectionSupport(selectionSupport); |
340 |
}catch (DriverLoadException e){
|
341 |
throw new DriverException(e); |
342 |
} |
343 |
} |
344 |
|
345 |
return sds;
|
346 |
} |
347 |
|
348 |
/**
|
349 |
* DOCUMENT ME!
|
350 |
*
|
351 |
* @param r DOCUMENT ME!
|
352 |
*
|
353 |
* @throws FieldNotFoundException
|
354 |
* @throws DriverException
|
355 |
* @throws DriverLoadException
|
356 |
*
|
357 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
|
358 |
* com.iver.cit.gvsig.fmap.rendering.Legend)
|
359 |
*/
|
360 |
public void setLegend(VectorialLegend r) |
361 |
throws DriverException, FieldNotFoundException {
|
362 |
VectorialLegend oldLegend = legend; |
363 |
legend = r; |
364 |
try{
|
365 |
legend.setDataSource(getRecordset()); |
366 |
if (legend.getLabelField() != null) |
367 |
{ |
368 |
int idLabelField = getRecordset().getFieldIndexByName(legend.getLabelField());
|
369 |
createLabelLayer(idLabelField); |
370 |
} |
371 |
} catch(DriverException e){
|
372 |
throw new DriverException(e); |
373 |
} catch (FieldNotFoundException e) {
|
374 |
// TODO Auto-generated catch block
|
375 |
e.printStackTrace(); |
376 |
} catch (com.hardcode.gdbms.engine.data.DriverException e) {
|
377 |
throw new DriverException(e); |
378 |
} |
379 |
|
380 |
LegendChangedEvent e = new LegendChangedEvent(oldLegend, legend);
|
381 |
callLegendChanged(e); |
382 |
} |
383 |
|
384 |
/**
|
385 |
* DOCUMENT ME!
|
386 |
*
|
387 |
* @return DOCUMENT ME!
|
388 |
*/
|
389 |
public Legend getLegend() {
|
390 |
return legend;
|
391 |
} |
392 |
|
393 |
/**
|
394 |
* DOCUMENT ME!
|
395 |
*
|
396 |
* @return DOCUMENT ME!
|
397 |
*
|
398 |
* @throws DriverIOException DOCUMENT ME!
|
399 |
*/
|
400 |
public int getShapeType() throws DriverException { |
401 |
if (typeShape == -1) { |
402 |
try{
|
403 |
logger.debug("source.start()");
|
404 |
source.start(); |
405 |
typeShape = source.getShapeType(); |
406 |
logger.debug("source.stop()");
|
407 |
source.stop(); |
408 |
}catch(DriverIOException e){
|
409 |
throw new DriverException(e); |
410 |
} |
411 |
} |
412 |
|
413 |
return typeShape;
|
414 |
} |
415 |
|
416 |
/**
|
417 |
* DOCUMENT ME!
|
418 |
*
|
419 |
* @return DOCUMENT ME!
|
420 |
*
|
421 |
* @throws DriverException
|
422 |
*
|
423 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
424 |
*/
|
425 |
public XMLEntity getXMLEntity() {
|
426 |
XMLEntity xml = super.getXMLEntity();
|
427 |
xml.addChild(legend.getXMLEntity()); |
428 |
xml.addChild(selectionSupport.getXMLEntity()); |
429 |
|
430 |
if (source instanceof VectorialFileAdapter) { |
431 |
xml.putProperty("file", ((VectorialFileAdapter) source).getFile());
|
432 |
} else if (source instanceof VectorialDBAdapter) { |
433 |
} else if (source instanceof WFSAdapter) { |
434 |
} |
435 |
|
436 |
xml.putProperty("driverName", getSource().getDriver().getName());
|
437 |
|
438 |
return xml;
|
439 |
} |
440 |
|
441 |
/**
|
442 |
* DOCUMENT ME!
|
443 |
*
|
444 |
* @param xml DOCUMENT ME!
|
445 |
* @throws XMLException
|
446 |
* @throws DriverException
|
447 |
*
|
448 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
449 |
*/
|
450 |
public void setXMLEntity(XMLEntity xml) throws XMLException, DriverException{ |
451 |
super.setXMLEntity(xml);
|
452 |
legend=LegendFactory.createFromXML(xml.getChild(0));
|
453 |
try{
|
454 |
legend.setDataSource(getRecordset()); |
455 |
} catch (FieldNotFoundException e) {
|
456 |
throw new XMLException(e); |
457 |
} catch (DriverException e) {
|
458 |
throw new XMLException(e); |
459 |
} |
460 |
selectionSupport.setXMLEntity(xml.getChild(1));
|
461 |
|
462 |
} |
463 |
|
464 |
/**
|
465 |
* DOCUMENT ME!
|
466 |
*
|
467 |
* @param listener DOCUMENT ME!
|
468 |
*/
|
469 |
public void addLegendListener(LegendListener listener) { |
470 |
layerChangeSupport.addLayerListener(listener); |
471 |
} |
472 |
|
473 |
/**
|
474 |
* DOCUMENT ME!
|
475 |
*
|
476 |
* @param e DOCUMENT ME!
|
477 |
*/
|
478 |
private void callLegendChanged(LegendChangedEvent e) { |
479 |
layerChangeSupport.callLegendChanged(e); |
480 |
} |
481 |
|
482 |
/**
|
483 |
* DOCUMENT ME!
|
484 |
*
|
485 |
* @param listener DOCUMENT ME!
|
486 |
*/
|
487 |
public void removeLegendListener(LegendListener listener) { |
488 |
layerChangeSupport.removeLayerListener(listener); |
489 |
} |
490 |
|
491 |
/**
|
492 |
* @see com.iver.cit.gvsig.fmap.layers.CommonOperations#changeRecordsetName()
|
493 |
*/
|
494 |
public void changeRecordsetName(String newName) throws DriverException { |
495 |
source.changeRecordsetName(newName); |
496 |
} |
497 |
} |