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