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