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