svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / FMap.java @ 2183
History | View | Annotate | Download (18.7 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; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
44 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
45 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
46 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
47 |
import com.iver.cit.gvsig.fmap.layers.LayerChangeSupport; |
48 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
49 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
50 |
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
51 |
import com.iver.cit.gvsig.fmap.layers.LegendListener; |
52 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
53 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
54 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
55 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
56 |
import com.iver.cit.gvsig.fmap.operations.Cancellable; |
57 |
import com.iver.cit.gvsig.fmap.operations.selection.Record; |
58 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
59 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectByPointVisitor; |
60 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectByRectVisitor; |
61 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedZoomVisitor; |
62 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
63 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
64 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
65 |
|
66 |
import com.iver.utiles.XMLEntity; |
67 |
|
68 |
import org.cresques.cts.ICoordTrans; |
69 |
import org.cresques.cts.IProjection; |
70 |
|
71 |
import org.cresques.geo.Projected; |
72 |
|
73 |
import java.awt.Graphics2D; |
74 |
import java.awt.RenderingHints; |
75 |
import java.awt.Toolkit; |
76 |
import java.awt.geom.Point2D; |
77 |
import java.awt.geom.Rectangle2D; |
78 |
import java.awt.image.BufferedImage; |
79 |
|
80 |
import java.util.ArrayList; |
81 |
import java.util.BitSet; |
82 |
|
83 |
|
84 |
/**
|
85 |
* Modelo del mapa.
|
86 |
*
|
87 |
* @author Fernando Gonz?lez Cort?s
|
88 |
*/
|
89 |
public class FMap implements Projected { |
90 |
public static final double[] CHANGEM = { |
91 |
1000, 1, 0.01, 0.001, 1609.344, 0.9144, 0.3048, 0.0254 |
92 |
}; |
93 |
public static final double[] CHANGE = { |
94 |
100000, 100, 1, 0.1, 160934.4, 91.44, 30.48, 2.54 |
95 |
}; |
96 |
public static final int EQUALS = 0; |
97 |
public static final int DISJOINT = 1; |
98 |
public static final int INTERSECTS = 2; |
99 |
public static final int TOUCHES = 3; |
100 |
public static final int CROSSES = 4; |
101 |
public static final int WITHIN = 5; |
102 |
public static final int CONTAINS = 6; |
103 |
public static final int OVERLAPS = 7; |
104 |
private FLayers layers = new FLayers(this, null); |
105 |
private ViewPort viewPort;
|
106 |
private ArrayList invalidationListeners = new ArrayList(); |
107 |
private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
108 |
private EventBuffer eventBuffer = new EventBuffer(); |
109 |
|
110 |
/**
|
111 |
* Crea un nuevo FMap.
|
112 |
*
|
113 |
* @param vp ViewPort.
|
114 |
*/
|
115 |
public FMap(ViewPort vp) {
|
116 |
this.viewPort = vp;
|
117 |
layers.addLayerCollectionListener(new LayerEventListener());
|
118 |
layers.addLayerCollectionListener(eventBuffer); |
119 |
|
120 |
if (viewPort != null) { |
121 |
viewPort.addViewPortListener(eventBuffer); |
122 |
} |
123 |
} |
124 |
|
125 |
/**
|
126 |
* A?ade un LegendListener.
|
127 |
*
|
128 |
* @param listener LegendListener a a?adir.
|
129 |
*/
|
130 |
public void addLayerListener(LegendListener listener) { |
131 |
layerChangeSupport.addLayerListener(listener); |
132 |
} |
133 |
|
134 |
/**
|
135 |
* M?todo ejecutado cuando hay un cambio de leyenda que se quiera reflejar.
|
136 |
*
|
137 |
* @param e LegendChangedEvent.
|
138 |
*/
|
139 |
public void callLegendChanged(LegendChangedEvent e) { |
140 |
layerChangeSupport.callLegendChanged(e); |
141 |
} |
142 |
|
143 |
/**
|
144 |
* Borra un LegendListener.
|
145 |
*
|
146 |
* @param listener LegendListener a borrar.
|
147 |
*/
|
148 |
public void removeLayerListener(LegendListener listener) { |
149 |
layerChangeSupport.removeLayerListener(listener); |
150 |
} |
151 |
|
152 |
/**
|
153 |
* Devuelve las capas que contiene el mapa.
|
154 |
*
|
155 |
* @return Capas.
|
156 |
*/
|
157 |
public FLayers getLayers() {
|
158 |
return layers;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* Dibuja en la imagen que se pasa como par?metro el contenido de las capas
|
163 |
* visibles del mapa y teniendo en cuenta los datos del ViewPort contenido
|
164 |
* en este FMap
|
165 |
*
|
166 |
* @param b Imagen.
|
167 |
*/
|
168 |
public void drawLabels(BufferedImage b) { |
169 |
} |
170 |
|
171 |
/**
|
172 |
* M?todo de conveniencia que se usa provisionalmente para
|
173 |
* solicitar un refresco de todo lo que dependa del
|
174 |
* FMap (MapContext). Esto provocar? un evento de cambio
|
175 |
* de orden de capas que obligar? a redibujar todo lo que
|
176 |
* depende de FMap (TOC, MapControl, FFrameView, etc).
|
177 |
*/
|
178 |
public void invalidate() |
179 |
{ |
180 |
getLayers().moveTo(0,0); |
181 |
} |
182 |
/**
|
183 |
* Imprime el las capas que contiene el FMap sobre el Graphics2D que se
|
184 |
* pasa como par?metro, normalmente es el Graphics de la impresora.
|
185 |
*
|
186 |
* @param g Graphics2D
|
187 |
*
|
188 |
* @throws DriverException
|
189 |
*/
|
190 |
public void print(Graphics2D g) throws DriverException { |
191 |
RenderingHints renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, |
192 |
RenderingHints.VALUE_ANTIALIAS_ON);
|
193 |
renderHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); |
194 |
g.setRenderingHints(renderHints); |
195 |
layers.print(g, viewPort, |
196 |
new Cancellable() {
|
197 |
/**
|
198 |
* @see com.iver.cit.gvsig.fmap.operations.Cancellable#isCanceled()
|
199 |
*/
|
200 |
public boolean isCanceled() { |
201 |
return false; |
202 |
} |
203 |
}); |
204 |
} |
205 |
|
206 |
/**
|
207 |
* Crea un nuevo FMap con la informaci?n del ViewPort que se pasa como
|
208 |
* par?metro.
|
209 |
*
|
210 |
* @param vp ViewPort.
|
211 |
*
|
212 |
* @return FMap nuevo.
|
213 |
*/
|
214 |
public FMap createNewFMap(ViewPort vp) {
|
215 |
FMap ret = new FMap(vp);
|
216 |
ret.layers = this.layers;
|
217 |
|
218 |
return ret;
|
219 |
} |
220 |
|
221 |
/**
|
222 |
* Crea un nuevo FMap totalmente desligado, se replican las capas y el
|
223 |
* ViewPort
|
224 |
*
|
225 |
* @return FMap clonado.
|
226 |
*
|
227 |
* @throws XMLException
|
228 |
*/
|
229 |
public FMap cloneFMap() throws XMLException { |
230 |
return createFromXML(getXMLEntity());
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* A?ade la capa que se pasa como par?metro al nodo que se pasa como
|
235 |
* parametro y lanza ProjectionMismatchException si no est?n todas las
|
236 |
* capas de este FMap en la misma proyecci?n. Lanza un
|
237 |
* ChildNotAllowedException si la capa no es un FLayers y no permite hijos
|
238 |
*
|
239 |
* @param vectorial DOCUMENT ME!
|
240 |
*/
|
241 |
|
242 |
/* public void addLayer(LayerPath parent, FLayer layer)
|
243 |
throws ProjectionMismatchException, ChildrenNotAllowedException {
|
244 |
layers.addLayer(parent, layer);
|
245 |
}
|
246 |
public void removeLayer(LayerPath parent)throws ChildrenNotAllowedException{
|
247 |
layers.removeLayer(parent);
|
248 |
}
|
249 |
*/
|
250 |
|
251 |
/**
|
252 |
* A?ade una capa al grupo de capas que se sit?a por encima de todas las
|
253 |
* otras capas
|
254 |
*
|
255 |
* @param vectorial FLayer.
|
256 |
*/
|
257 |
public void addToTrackLayer(FLayer vectorial) { |
258 |
} |
259 |
|
260 |
/**
|
261 |
* Devuelve la escala de la vista en pantalla.
|
262 |
*
|
263 |
* @return escala de la vista.
|
264 |
*/
|
265 |
public long getScaleView() { |
266 |
//TODO falta implementar un di?logo para poder especificar el usuario los pixels exactos de su pantalla.
|
267 |
Toolkit kit = Toolkit.getDefaultToolkit(); |
268 |
double dpi = kit.getScreenResolution();
|
269 |
IProjection proj = viewPort.getProjection(); |
270 |
|
271 |
if (viewPort.getImageSize() == null) |
272 |
return -1; |
273 |
|
274 |
double w = ((viewPort.getImageSize().getWidth() / dpi) * 2.54); |
275 |
|
276 |
if (viewPort.getAdjustedExtent() == null) { |
277 |
return 0; |
278 |
} |
279 |
|
280 |
if (proj == null) { |
281 |
return (long) (viewPort.getAdjustedExtent().getWidth() / w * CHANGE[getViewPort() |
282 |
.getMapUnits()]); |
283 |
} |
284 |
|
285 |
return (long) proj.getScale(viewPort.getAdjustedExtent().getMinX(), |
286 |
viewPort.getAdjustedExtent().getMaxX(), |
287 |
viewPort.getImageSize().getWidth(), dpi); |
288 |
} |
289 |
|
290 |
/**
|
291 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#setVectorial(com.iver.cit.gvsig.fmap.VectorialAdapter)
|
292 |
*/
|
293 |
public void setVectorial(VectorialAdapter v) { |
294 |
} |
295 |
|
296 |
/**
|
297 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#process(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor)
|
298 |
*/
|
299 |
public void process(FeatureVisitor visitor) { |
300 |
} |
301 |
|
302 |
/**
|
303 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#processSelected(com.iver.cit.gvsig.fmap.FeatureVisitor)
|
304 |
*/
|
305 |
public void processSelected(FeatureVisitor visitor) { |
306 |
} |
307 |
|
308 |
/**
|
309 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#select(com.iver.cit.gvsig.fmap.FeatureSelectorVisitor,
|
310 |
* VectorialSubSet)
|
311 |
*/
|
312 |
public void select(FeatureVisitor visitor) { |
313 |
} |
314 |
|
315 |
/**
|
316 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectFromSelection()
|
317 |
*/
|
318 |
public void selectFromSelection() { |
319 |
} |
320 |
|
321 |
/**
|
322 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#createIndex()
|
323 |
*/
|
324 |
public void createIndex() { |
325 |
} |
326 |
|
327 |
/**
|
328 |
* @see org.cresques.geo.Projected#getProjection()
|
329 |
*/
|
330 |
public IProjection getProjection() {
|
331 |
return getViewPort().getProjection();
|
332 |
} |
333 |
|
334 |
/**
|
335 |
* Inserta la proyecci?n.
|
336 |
*
|
337 |
* @param proj Proyecci?n.
|
338 |
*/
|
339 |
public void setProjection(IProjection proj) { |
340 |
getViewPort().setProjection(proj); |
341 |
} |
342 |
|
343 |
/**
|
344 |
* @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans)
|
345 |
*/
|
346 |
public void reProject(ICoordTrans arg0) { |
347 |
// TODO implementar reprojecci?n (lo que sea eso)
|
348 |
} |
349 |
|
350 |
/**
|
351 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByPoint(java.awt.geom.Point2D,
|
352 |
* double)
|
353 |
*/
|
354 |
public void selectByPoint(Point2D p, double tolerance) |
355 |
throws DriverException {
|
356 |
Point2D mapPoint = viewPort.toMapPoint((int) p.getX(), (int) p.getY()); |
357 |
SelectByPointVisitor visitor = new SelectByPointVisitor();
|
358 |
visitor.setQueriedPoint(mapPoint); |
359 |
visitor.setTolerance(getViewPort().toMapDistance(3));
|
360 |
|
361 |
try {
|
362 |
layers.process(visitor); |
363 |
} catch (VisitException e) {
|
364 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
365 |
e); |
366 |
} |
367 |
} |
368 |
|
369 |
/**
|
370 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByRect(java.awt.geom.Rectangle2D)
|
371 |
*/
|
372 |
public void selectByRect(Rectangle2D rect) throws DriverException { |
373 |
SelectByRectVisitor visitor = new SelectByRectVisitor();
|
374 |
visitor.setRect(rect); |
375 |
|
376 |
try {
|
377 |
layers.process(visitor); |
378 |
} catch (VisitException e) {
|
379 |
throw new RuntimeException("No se espera que SelectByRectVisitor lance esta excepci?n", |
380 |
e); |
381 |
} |
382 |
} |
383 |
|
384 |
/**
|
385 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#selectByShape(com.iver.cit.gvsig.fmap.fshape.IGeometry,
|
386 |
* int)
|
387 |
*/
|
388 |
public void selectByShape(IGeometry g, int relationship) { |
389 |
} |
390 |
|
391 |
/**
|
392 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(Point2D,
|
393 |
* double)
|
394 |
*/
|
395 |
public Record[] queryByPoint(Point2D p, double tolerance) { |
396 |
return null; |
397 |
} |
398 |
|
399 |
/**
|
400 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByRect(java.awt.geom.Rectangle2D)
|
401 |
*/
|
402 |
public Record[] queryByRect(Rectangle2D rect) { |
403 |
return null; |
404 |
} |
405 |
|
406 |
/**
|
407 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.fshape.IGeometry,
|
408 |
* int)
|
409 |
*/
|
410 |
public Record[] queryByShape(IGeometry g, int relationship) { |
411 |
return null; |
412 |
} |
413 |
|
414 |
/**
|
415 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#getSelectionBounds()
|
416 |
*/
|
417 |
public Rectangle2D getSelectionBounds() { |
418 |
SelectedZoomVisitor visitor = new SelectedZoomVisitor();
|
419 |
|
420 |
|
421 |
try {
|
422 |
layers.process(visitor); |
423 |
} catch (DriverException e1) {
|
424 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
425 |
e1); |
426 |
} catch (VisitException e) {
|
427 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
428 |
e); |
429 |
} |
430 |
|
431 |
return visitor.getSelectBound();
|
432 |
} |
433 |
|
434 |
/**
|
435 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
|
436 |
* java.awt.Graphics2D, FStyle2D)
|
437 |
*/
|
438 |
public void draw(BufferedImage image, Graphics2D g, Cancellable cancel) |
439 |
throws DriverException {
|
440 |
if (viewPort.getExtent() == null) { |
441 |
// System.err.println("viewPort.getExtent() = null");
|
442 |
return;
|
443 |
} |
444 |
|
445 |
// System.out.println("Viewport despues: " + viewPort);
|
446 |
/* if ((viewPort.getImageWidth() <=0) || (viewPort.getImageHeight() <= 0))
|
447 |
{
|
448 |
return;
|
449 |
} */
|
450 |
// M?s c?lidad al texto
|
451 |
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
452 |
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
453 |
|
454 |
layers.draw(image, g, viewPort, cancel); |
455 |
|
456 |
/* g.setColor(Color.BLUE);
|
457 |
GeneralPath shpR = new GeneralPath(viewPort.getExtent());
|
458 |
shpR.transform(viewPort.getAffineTransform());
|
459 |
g.draw(shpR); */
|
460 |
System.gc();
|
461 |
} |
462 |
|
463 |
/**
|
464 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage,
|
465 |
* java.awt.Graphics2D, FStyle2D)
|
466 |
*/
|
467 |
public void draw(BufferedImage image, Graphics2D g) |
468 |
throws DriverException {
|
469 |
draw(image, g, new Cancellable() {
|
470 |
/**
|
471 |
* @see com.iver.cit.gvsig.fmap.operations.Cancellable#isCanceled()
|
472 |
*/
|
473 |
public boolean isCanceled() { |
474 |
return false; |
475 |
} |
476 |
}); |
477 |
} |
478 |
|
479 |
/**
|
480 |
* Devuelve el ViewPort.
|
481 |
*
|
482 |
* @return Returns the viewPort.
|
483 |
*/
|
484 |
public ViewPort getViewPort() {
|
485 |
return viewPort;
|
486 |
} |
487 |
|
488 |
/**
|
489 |
* Inserta un ViewPort.
|
490 |
*
|
491 |
* @param viewPort The viewPort to set.
|
492 |
*/
|
493 |
public void setViewPort(ViewPort viewPort) { |
494 |
if (this.viewPort != null) { |
495 |
this.viewPort.removeViewPortListener(eventBuffer);
|
496 |
} |
497 |
|
498 |
this.viewPort = viewPort;
|
499 |
viewPort.addViewPortListener(eventBuffer); |
500 |
} |
501 |
|
502 |
/**
|
503 |
* M?todo de conveniencia. Recorre las capas y te da el fullExtent
|
504 |
*
|
505 |
* @return fullExtent de todas las capas.
|
506 |
*
|
507 |
* @throws DriverException
|
508 |
*/
|
509 |
public Rectangle2D getFullExtent() throws DriverException { |
510 |
return layers.getFullExtent();
|
511 |
} |
512 |
|
513 |
/**
|
514 |
* Devuelve el XMLEntity.
|
515 |
*
|
516 |
* @return XMLEntity.
|
517 |
* @throws XMLException
|
518 |
*/
|
519 |
public XMLEntity getXMLEntity() throws XMLException { |
520 |
XMLEntity xml = new XMLEntity();
|
521 |
xml.putProperty("className",this.getClass().getName()); |
522 |
xml.addChild(viewPort.getXMLEntity()); |
523 |
xml.addChild(layers.getXMLEntity()); |
524 |
|
525 |
return xml;
|
526 |
} |
527 |
|
528 |
/**
|
529 |
* Crea un nuevo FMAp a partir del XMLEntity.
|
530 |
*
|
531 |
* @param xml XMLEntity
|
532 |
*
|
533 |
* @return Nuevo FMap.
|
534 |
*
|
535 |
* @throws XMLException
|
536 |
*/
|
537 |
public static FMap createFromXML03(XMLEntity xml) throws XMLException { |
538 |
ViewPort vp = ViewPort.createFromXML03(xml.getChild(0));
|
539 |
FMap fmap = new FMap(vp);
|
540 |
fmap.layers.setXMLEntity03(xml.getChild(1));
|
541 |
|
542 |
return fmap;
|
543 |
} |
544 |
|
545 |
/**
|
546 |
* Crea un nuevo FMAp a partir del XMLEntity.
|
547 |
*
|
548 |
* @param xml XMLEntity
|
549 |
*
|
550 |
* @return Nuevo FMap.
|
551 |
*
|
552 |
* @throws XMLException
|
553 |
*/
|
554 |
public static FMap createFromXML(XMLEntity xml) throws XMLException { |
555 |
ViewPort vp = ViewPort.createFromXML(xml.getChild(0));
|
556 |
FMap fmap = new FMap(vp);
|
557 |
fmap.layers.setXMLEntity(xml.getChild(1));
|
558 |
|
559 |
return fmap;
|
560 |
} |
561 |
|
562 |
/**
|
563 |
* A?ade un AtomicEventListener.
|
564 |
*
|
565 |
* @param listener AtomicEventListener.
|
566 |
*
|
567 |
* @return True si se ha a?adido correctamente.
|
568 |
*/
|
569 |
public boolean addAtomicEventListener(AtomicEventListener listener) { |
570 |
return eventBuffer.addAtomicEventListener(listener);
|
571 |
} |
572 |
|
573 |
/**
|
574 |
* Borra un AtomicEventListener de la lista de listeners.
|
575 |
*
|
576 |
* @param listener AtomicEventListener a borrar.
|
577 |
*
|
578 |
* @return True si se ha borrado correctamente.
|
579 |
*/
|
580 |
public boolean removeAtomicEventListener(AtomicEventListener listener) { |
581 |
return eventBuffer.removeAtomicEventListener(listener);
|
582 |
} |
583 |
|
584 |
/**
|
585 |
* Inicializa los AtomicEvent.
|
586 |
*/
|
587 |
public void beginAtomicEvent() { |
588 |
eventBuffer.beginAtomicEvent(); |
589 |
} |
590 |
|
591 |
/**
|
592 |
* Finaliza los AtomicEvent.
|
593 |
*/
|
594 |
public void endAtomicEvent() { |
595 |
eventBuffer.endAtomicEvent(); |
596 |
} |
597 |
|
598 |
/**
|
599 |
* Evento Layer.
|
600 |
*
|
601 |
* @author Fernando Gonz?lez Cort?s
|
602 |
*/
|
603 |
public class LayerEventListener implements LayerCollectionListener { |
604 |
/**
|
605 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
606 |
*/
|
607 |
public void layerAdded(LayerCollectionEvent e) { |
608 |
// Si es la primera capa, fijamos su extent al ViewPort
|
609 |
//if (getLayers().getLayersCount() == 1) {
|
610 |
if (getViewPort().getExtent() == null) { |
611 |
FLayer lyr = e.getAffectedLayer(); |
612 |
|
613 |
try {
|
614 |
getViewPort().setExtent(lyr.getFullExtent()); |
615 |
} catch (DriverException e1) {
|
616 |
} |
617 |
} |
618 |
|
619 |
//Registramos al FMap como listener del legend de las capas
|
620 |
FLayer lyr = e.getAffectedLayer(); |
621 |
|
622 |
lyr.addLayerListener(eventBuffer); |
623 |
|
624 |
if (lyr instanceof Classifiable) { |
625 |
Classifiable c = (Classifiable) lyr; |
626 |
c.addLegendListener(eventBuffer); |
627 |
} |
628 |
|
629 |
if (lyr instanceof Selectable) { |
630 |
Selectable s = (Selectable) lyr; |
631 |
s.addSelectionListener(eventBuffer); |
632 |
} |
633 |
} |
634 |
|
635 |
/**
|
636 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
637 |
*/
|
638 |
public void layerMoved(LayerPositionEvent e) { |
639 |
} |
640 |
|
641 |
/**
|
642 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
643 |
*/
|
644 |
public void layerRemoved(LayerCollectionEvent e) { |
645 |
FLayer lyr = e.getAffectedLayer(); |
646 |
|
647 |
lyr.removeLayerListener(eventBuffer); |
648 |
|
649 |
if (lyr instanceof Classifiable) { |
650 |
Classifiable c = (Classifiable) lyr; |
651 |
c.removeLegendListener(eventBuffer); |
652 |
} |
653 |
|
654 |
if (lyr instanceof Selectable) { |
655 |
Selectable s = (Selectable) lyr; |
656 |
s.addSelectionListener(eventBuffer); |
657 |
} |
658 |
} |
659 |
|
660 |
/**
|
661 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
662 |
*/
|
663 |
public void layerAdding(LayerCollectionEvent e) |
664 |
throws CancelationException {
|
665 |
} |
666 |
|
667 |
/**
|
668 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
669 |
*/
|
670 |
public void layerMoving(LayerPositionEvent e) |
671 |
throws CancelationException {
|
672 |
} |
673 |
|
674 |
/**
|
675 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
676 |
*/
|
677 |
public void layerRemoving(LayerCollectionEvent e) |
678 |
throws CancelationException {
|
679 |
} |
680 |
|
681 |
/**
|
682 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
683 |
*/
|
684 |
public void activationChanged(LayerCollectionEvent e) |
685 |
throws CancelationException {
|
686 |
} |
687 |
|
688 |
/**
|
689 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
690 |
*/
|
691 |
public void visibilityChanged(LayerCollectionEvent e) |
692 |
throws CancelationException {
|
693 |
} |
694 |
} |
695 |
} |