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