svn-gvsig-desktop / tags / v1_1_Build_1007 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLayers.java @ 12478
History | View | Annotate | Download (49.5 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.layers; |
42 |
|
43 |
import java.awt.Graphics2D; |
44 |
import java.awt.Point; |
45 |
import java.awt.geom.Rectangle2D; |
46 |
import java.awt.image.BufferedImage; |
47 |
import java.awt.image.WritableRaster; |
48 |
import java.io.File; |
49 |
import java.util.ArrayList; |
50 |
import java.util.Collections; |
51 |
import java.util.Iterator; |
52 |
import java.util.List; |
53 |
import java.util.Vector; |
54 |
|
55 |
import javax.print.attribute.PrintRequestAttributeSet; |
56 |
import javax.swing.ImageIcon; |
57 |
|
58 |
import org.apache.log4j.Logger; |
59 |
import org.cresques.cts.ICoordTrans; |
60 |
import org.cresques.cts.IProjection; |
61 |
|
62 |
import com.hardcode.driverManager.Driver; |
63 |
import com.hardcode.driverManager.DriverLoadException; |
64 |
import com.iver.cit.gvsig.fmap.DriverException; |
65 |
import com.iver.cit.gvsig.fmap.MapContext; |
66 |
import com.iver.cit.gvsig.fmap.MapControl; |
67 |
import com.iver.cit.gvsig.fmap.ViewPort; |
68 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
69 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
70 |
import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver; |
71 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
72 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
73 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer; |
74 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint; |
75 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection; |
76 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
77 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem; |
78 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
79 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
80 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
81 |
import com.iver.utiles.IPersistance; |
82 |
import com.iver.utiles.XMLEntity; |
83 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
84 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
85 |
import com.iver.utiles.swing.threads.Cancellable; |
86 |
|
87 |
/**
|
88 |
* Representa un nodo interno en el ?rbol de capas
|
89 |
*/
|
90 |
public class FLayers extends FLyrDefault implements VectorialData, LayerCollection, InfoByPoint |
91 |
{ |
92 |
//ArrayList de Listener registrados.
|
93 |
protected ArrayList layerCollectionListeners = new ArrayList(); |
94 |
|
95 |
|
96 |
protected List layers = Collections.synchronizedList(new ArrayList()); |
97 |
protected MapContext fmap;
|
98 |
protected static Logger logger = Logger.getLogger(FLayers.class.getName()); |
99 |
/**
|
100 |
* Crea un nuevo FLayers.
|
101 |
*
|
102 |
* @param fmap
|
103 |
* @param parent
|
104 |
*/
|
105 |
public FLayers(MapContext fmap, FLayers parent) {
|
106 |
setParentLayer(parent); |
107 |
this.fmap = fmap;
|
108 |
} |
109 |
|
110 |
/**
|
111 |
* A?ade un listener de los eventos de la colecci?n de capas
|
112 |
*
|
113 |
* @param listener
|
114 |
*/
|
115 |
public void addLayerCollectionListener(LayerCollectionListener listener) { |
116 |
if (!layerCollectionListeners.contains(listener))
|
117 |
layerCollectionListeners.add(listener); |
118 |
} |
119 |
|
120 |
|
121 |
/**
|
122 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#setAllVisibles(boolean)
|
123 |
*/
|
124 |
public void setAllVisibles(boolean visible) { |
125 |
FLayer lyr; |
126 |
|
127 |
for (int i = 0; i < layers.size(); i++) { |
128 |
lyr = ((FLayer) layers.get(i)); |
129 |
lyr.setVisible(visible); |
130 |
|
131 |
if (lyr instanceof LayerCollection) { |
132 |
((LayerCollection) lyr).setAllVisibles(visible); |
133 |
} |
134 |
} |
135 |
} |
136 |
|
137 |
/**
|
138 |
* Elimina un listener de los eventos de la colecci?n de capas
|
139 |
*
|
140 |
* @param listener
|
141 |
*/
|
142 |
public void removeLayerCollectionListener(LayerCollectionListener listener) { |
143 |
layerCollectionListeners.remove(listener); |
144 |
} |
145 |
|
146 |
/**
|
147 |
* A?ade una capa.
|
148 |
*
|
149 |
* @param layer
|
150 |
*/
|
151 |
// private void doAddLayer(FLayer layer) {
|
152 |
// layers.add(layer);
|
153 |
// layer.setParentLayer(this);
|
154 |
// }
|
155 |
private void doAddLayer(int pos,FLayer layer) { |
156 |
layers.add(pos,layer); |
157 |
layer.setParentLayer(this);
|
158 |
} |
159 |
public void addLayer(FLayer layer) { |
160 |
addLayer(layers.size(),layer); |
161 |
} |
162 |
/**
|
163 |
* A?ade una capa en la posici?n pos de la lista de subcapas
|
164 |
*
|
165 |
* @param layer
|
166 |
*
|
167 |
* @throws CancelationException
|
168 |
*/
|
169 |
public void addLayer(int pos,FLayer layer) throws CancelationException { |
170 |
//Notificamos a la capa que va a ser a?adida
|
171 |
//FLyrDefault layerDef = (FLyrDefault)layer;
|
172 |
//if (!layerDef.isUnavailable()) {
|
173 |
if (layer instanceof FLyrDefault) |
174 |
((FLyrDefault)layer).wakeUp(); |
175 |
|
176 |
if (layer instanceof FLayers){ |
177 |
FLayers layers=(FLayers)layer; |
178 |
fmap.addAsCollectionListener(layers); |
179 |
} |
180 |
callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer)); |
181 |
//}
|
182 |
|
183 |
doAddLayer(pos,layer); |
184 |
|
185 |
//if (!layerDef.isUnavailable()) {
|
186 |
callLayerAdded(LayerCollectionEvent.createLayerAddedEvent(layer)); |
187 |
//}
|
188 |
} |
189 |
|
190 |
/**
|
191 |
* Mueve una capa de la posici?n from a la posici?n to. (Se supone que
|
192 |
* est?n dentro del mismo nivel). Para mover entre niveles, usar otro
|
193 |
* m?todo (por hacer)
|
194 |
*
|
195 |
* @param from origen.
|
196 |
* @param to destino.
|
197 |
*
|
198 |
* @throws CancelationException
|
199 |
*/
|
200 |
public void moveTo(int from, int to) throws CancelationException { |
201 |
int newfrom=layers.size()-from-1; |
202 |
int newto=layers.size()-to-1; |
203 |
if ( newfrom < 0 || newfrom >=layers.size() || newto < 0 || newto >= layers.size()) return; |
204 |
FLayer aux = (FLayer) layers.get(newfrom); |
205 |
callLayerMoving(LayerPositionEvent.createLayerMovingEvent(aux, newfrom, newto)); |
206 |
layers.remove(newfrom); |
207 |
layers.add(newto, aux); |
208 |
callLayerMoved(LayerPositionEvent.createLayerMovedEvent(aux, newfrom, newto)); |
209 |
} |
210 |
|
211 |
/**
|
212 |
* Borra una capa del ArrayList que contiene a las capas.
|
213 |
*
|
214 |
* @param lyr FLayer.
|
215 |
*/
|
216 |
private void doRemoveLayer(FLayer lyr) { |
217 |
layers.remove(lyr); |
218 |
} |
219 |
|
220 |
/**
|
221 |
* Borra una capa de la colecci?n de capas.
|
222 |
*
|
223 |
* @param lyr FLayer
|
224 |
*
|
225 |
* @throws CancelationException
|
226 |
*/
|
227 |
public void removeLayer(FLayer lyr) throws CancelationException { |
228 |
callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr)); |
229 |
doRemoveLayer(lyr); |
230 |
callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(lyr)); |
231 |
} |
232 |
|
233 |
/**
|
234 |
* Borra una FLayer del vector a partir del identificador.
|
235 |
*
|
236 |
* @param idLayer
|
237 |
*/
|
238 |
public void removeLayer(int idLayer) { |
239 |
FLayer lyr = (FLayer) layers.get(idLayer); |
240 |
callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr)); |
241 |
layers.remove(idLayer); |
242 |
callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(lyr)); |
243 |
} |
244 |
|
245 |
/**
|
246 |
* M?todo de conveniencia para borrar una capa con ese nombre
|
247 |
*
|
248 |
* @param layerName
|
249 |
*/
|
250 |
public void removeLayer(String layerName) { |
251 |
FLayer lyr; |
252 |
|
253 |
for (int i = 0; i < layers.size(); i++) { |
254 |
lyr = ((FLayer) layers.get(i)); |
255 |
|
256 |
if (lyr.getName().compareToIgnoreCase(layerName) == 0) { |
257 |
removeLayer(i); |
258 |
|
259 |
break;
|
260 |
} |
261 |
} |
262 |
} |
263 |
/**
|
264 |
* M?todo de conveniencia para reemplazar una capa con ese nombre
|
265 |
*
|
266 |
* @param layerName
|
267 |
*/
|
268 |
public void replaceLayer(String layerName, FLayer layer) |
269 |
{ |
270 |
FLayer lyr; |
271 |
FLayer parent; |
272 |
for (int i = 0; i < layers.size(); i++) { |
273 |
lyr = ((FLayer) layers.get(i)); |
274 |
|
275 |
if (lyr.getName().compareToIgnoreCase(layerName) == 0) { |
276 |
parent = lyr.getParentLayer(); |
277 |
removeLayer(i); |
278 |
if (parent != null) |
279 |
//Notificamos a la capa que va a ser a?adida
|
280 |
if (layer instanceof FLyrDefault) |
281 |
((FLyrDefault)layer).wakeUp(); |
282 |
|
283 |
if (layer instanceof FLayers){ |
284 |
FLayers layers=(FLayers)layer; |
285 |
fmap.addAsCollectionListener(layers); |
286 |
} |
287 |
callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer)); |
288 |
|
289 |
layers.add(i,layer); |
290 |
layer.setParentLayer(this);
|
291 |
|
292 |
callLayerAdded(LayerCollectionEvent.createLayerAddedEvent(layer)); |
293 |
break;
|
294 |
} |
295 |
} |
296 |
} |
297 |
|
298 |
|
299 |
/**
|
300 |
* Obtiene el array de capas visibles que penden del arbol cuya ra?z es
|
301 |
* este nodo
|
302 |
*
|
303 |
* @return Vector de FLayer.
|
304 |
*/
|
305 |
public FLayer[] getVisibles() { |
306 |
ArrayList array = new ArrayList(); |
307 |
LayersIterator iter = new LayersIterator(this) { |
308 |
public boolean evaluate(FLayer layer) { |
309 |
return layer.isVisible();
|
310 |
} |
311 |
|
312 |
}; |
313 |
|
314 |
while (iter.hasNext()) {
|
315 |
array.add(iter.nextLayer()); |
316 |
} |
317 |
|
318 |
return (FLayer[]) array.toArray(new FLayer[0]); |
319 |
} |
320 |
|
321 |
/**
|
322 |
* Obtiene el hijo i-?simo (de abajo a arriba) directo de esta colecci?n.
|
323 |
*
|
324 |
* @param index ?ndice.
|
325 |
*
|
326 |
* @return capa seleccionada.
|
327 |
*/
|
328 |
public FLayer getLayer(int index) { |
329 |
return (FLayer) layers.get(index);
|
330 |
} |
331 |
|
332 |
/**
|
333 |
* M?todo de conveniencia para buscar una capa por su nombre Es conveniente
|
334 |
* usar getLayer(int) siempre que se pueda, es m?s directo.
|
335 |
*
|
336 |
* @param layerName nombre.
|
337 |
*
|
338 |
* @return capa seleccionada.
|
339 |
*/
|
340 |
public FLayer getLayer(String layerName) { |
341 |
FLayer lyr; |
342 |
FLayer lyr2; |
343 |
ArrayList layerList;
|
344 |
|
345 |
for (int i = 0; i < layers.size(); i++) { |
346 |
lyr = ((FLayer) layers.get(i)); |
347 |
|
348 |
if (lyr.getName().compareToIgnoreCase(layerName) == 0) { |
349 |
return lyr;
|
350 |
} |
351 |
|
352 |
layerList = new ArrayList(); |
353 |
getLayerFromGroup(lyr,layerList); |
354 |
|
355 |
for(int j = 0; j<layerList.size(); j++ ) |
356 |
{ |
357 |
lyr2 = ((FLayer)layerList.get(j)); |
358 |
if (lyr2.getName().compareToIgnoreCase(layerName) == 0) { |
359 |
return lyr2;
|
360 |
} |
361 |
} |
362 |
|
363 |
} |
364 |
|
365 |
return null; |
366 |
} |
367 |
// looks in the layertree including FLayers
|
368 |
private void getLayerFromGroup(FLayer layer, ArrayList result){ |
369 |
int i;
|
370 |
FLayers layerGroup; |
371 |
if (layer instanceof FLayers) |
372 |
{ |
373 |
result.add(layer); |
374 |
layerGroup = (FLayers)layer; |
375 |
for (i=0; i < layerGroup.getLayersCount(); i++ ) |
376 |
{ |
377 |
getLayerFromGroup(layerGroup.getLayer(i),result); |
378 |
} |
379 |
} |
380 |
else
|
381 |
{ |
382 |
result.add(layer); |
383 |
} |
384 |
} |
385 |
|
386 |
|
387 |
// this is to to split up a layer group in order to get a layer by name
|
388 |
// when there are layergroups.
|
389 |
private void splitLayerGroup(FLayer layer, ArrayList result) |
390 |
{ |
391 |
int i;
|
392 |
FLayers layerGroup; |
393 |
if (layer instanceof FLayers) |
394 |
{ |
395 |
layerGroup = (FLayers)layer; |
396 |
for (i=0; i < layerGroup.getLayersCount(); i++ ) |
397 |
{ |
398 |
splitLayerGroup(layerGroup.getLayer(i),result); |
399 |
} |
400 |
} |
401 |
else
|
402 |
{ |
403 |
result.add(layer); |
404 |
} |
405 |
} |
406 |
|
407 |
/**
|
408 |
* Obtiene el n?mero de capas que hay en su mismo nivel Es decir, no cuenta
|
409 |
* las subcapas de un FLayers
|
410 |
*
|
411 |
* @return n?mero de capas.
|
412 |
*/
|
413 |
public int getLayersCount() { |
414 |
return layers.size();
|
415 |
} |
416 |
|
417 |
/**
|
418 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
|
419 |
* java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
420 |
*/
|
421 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
422 |
Cancellable cancel,double scale) throws DriverException { |
423 |
draw(image,g,viewPort,cancel, scale, null);
|
424 |
} |
425 |
|
426 |
|
427 |
public ComposedLayer draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
428 |
Cancellable cancel,double scale, ComposedLayer group) throws DriverException { |
429 |
//double scale = getFMap().getScaleView();
|
430 |
// Iterator iter = layers.iterator();
|
431 |
// try
|
432 |
// {
|
433 |
boolean bNeedRecalculateCache = false; |
434 |
|
435 |
///// CHEMA ComposedLayer
|
436 |
long tg1 = System.currentTimeMillis(); |
437 |
///// CHEMA ComposedLayer
|
438 |
|
439 |
|
440 |
|
441 |
// while (iter.hasNext())
|
442 |
// {
|
443 |
for (int i=0; i < layers.size(); i++) { |
444 |
if (cancel.isCanceled())
|
445 |
break; // M?s que nada porque las capas raster no son interrumpibles por ahora. |
446 |
// FLayer lyr = (FLayer) iter.next();
|
447 |
FLayer lyr = (FLayer) layers.get(i); |
448 |
|
449 |
|
450 |
|
451 |
/* if (lyr instanceof FLyrVect && ((FLyrVect)lyr).isBroken()){
|
452 |
continue;
|
453 |
}
|
454 |
*/
|
455 |
LayerDrawEvent beforeEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_BEFORE_DRAW);
|
456 |
fmap.fireLayerDrawingEvent(beforeEvent); |
457 |
if ((lyr.isDirty()) && (lyr.isCachingDrawnLayers() == false)) |
458 |
bNeedRecalculateCache = true;
|
459 |
|
460 |
if (lyr.isVisible()) {
|
461 |
|
462 |
long t1 = System.currentTimeMillis(); |
463 |
System.err.println("Layer " + lyr.getName() + " dirty=" + lyr.isDirty()+ " isCachingDrawnLayers= "+lyr.isCachingDrawnLayers()); |
464 |
// synchronized (this) {
|
465 |
//Sincronizaci?n del m?todo dibujar de cada Layer, esto es posible hacerlo de otra forma,
|
466 |
//pero de momento se queda as?, para solucionar el refresco de una misma vista que est? a?adida en el Layout.
|
467 |
try{
|
468 |
/* if (lyr instanceof IComposedDrawing)
|
469 |
{
|
470 |
// Acumulamos las peticiones hasta que sea
|
471 |
// otro servidor o otro tipo de capa o la ?ltima
|
472 |
// Si hay que dibujar:
|
473 |
lyr.draw(image, g, viewPort, cancel,scale);
|
474 |
// Si hay que acumlar:
|
475 |
lyr.acumulateDrawing(antLayer);
|
476 |
|
477 |
}
|
478 |
else */
|
479 |
|
480 |
if (lyr.isCachingDrawnLayers())
|
481 |
{ |
482 |
if ((bNeedRecalculateCache) || (lyr.getCacheImageDrawnLayers()==null)) |
483 |
{ |
484 |
//if (bNeedRecalculateCache)
|
485 |
// {
|
486 |
|
487 |
///// CHEMA ComposedLayer
|
488 |
if (group != null) { |
489 |
//si tenemos un grupo pendiente de pintar, pintamos
|
490 |
// para que la cache sea fiable
|
491 |
group.draw(image, g, viewPort, cancel,scale); |
492 |
group = null;
|
493 |
} |
494 |
///// CHEMA ComposedLayer
|
495 |
|
496 |
|
497 |
// Copiamos la imagen actual
|
498 |
BufferedImage buff = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); |
499 |
WritableRaster w = buff.getRaster();
|
500 |
image.copyData(w); |
501 |
lyr.setCacheImageDrawnLayers(buff); |
502 |
System.err.println("RECALCULO LA CACHE CON LO QUE HABIA ANTES DE " + lyr.getName()); |
503 |
} |
504 |
// }
|
505 |
// else
|
506 |
// {
|
507 |
if (lyr.getCacheImageDrawnLayers() != null) |
508 |
{ |
509 |
// Previo a esto hemos tenido que fijar
|
510 |
// la imagen que queremos usar, en el
|
511 |
// prepareDrawing de FMap.
|
512 |
if (lyr.isDirty())
|
513 |
{ |
514 |
|
515 |
|
516 |
///// CHEMA ComposedLayer
|
517 |
// Checks for draw group (ComposedLayer)
|
518 |
if (group != null) { |
519 |
// it's going to load a cache image,
|
520 |
// the current draw isn't needed
|
521 |
group = null;
|
522 |
} |
523 |
///// CHEMA ComposedLayer
|
524 |
|
525 |
|
526 |
g.drawImage(lyr.getCacheImageDrawnLayers(), 0, 0, null); |
527 |
System.err.println("Pinto con acelerado lo que hab?a antes de " + lyr.getName()); |
528 |
} |
529 |
} |
530 |
// }
|
531 |
} |
532 |
// Si la capa est? "sucia" o alguna de las de abajo est? sucia
|
533 |
// hay que volver a dibujar.
|
534 |
if (lyr.isDirty() || bNeedRecalculateCache)
|
535 |
{ |
536 |
if (!lyr.getFLayerStatus().isDriverLoaded())
|
537 |
{ |
538 |
continue;
|
539 |
} |
540 |
|
541 |
///// CHEMA ComposedLayer
|
542 |
//lyr.draw(image, g, viewPort, cancel,scale);
|
543 |
//bNeedRecalculateCache = true;
|
544 |
//System.err.println("Pinto sin acelerado " + lyr.getName());
|
545 |
///// CHEMA ComposedLayer
|
546 |
|
547 |
///// CHEMA ComposedLayer
|
548 |
// Checks for draw group (ComposedLayer)
|
549 |
if (group != null) { |
550 |
if (lyr instanceof FLayers){ |
551 |
group = ((FLayers)lyr).draw(image, g, viewPort, cancel,scale,group); |
552 |
LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
|
553 |
fmap.fireLayerDrawingEvent(afterEvent); |
554 |
} else {
|
555 |
// If layer can be added to the group, does it
|
556 |
if (group.canAdd(lyr)) {
|
557 |
group.add(lyr); |
558 |
} else {
|
559 |
// draw the 'pending to draw' layer group
|
560 |
group.draw(image, g, viewPort, cancel,scale); |
561 |
|
562 |
// gets a new group instance
|
563 |
group = lyr.newComposedLayer(); |
564 |
// if layer hasn't group, draws it inmediately
|
565 |
if (group == null) { |
566 |
if (lyr instanceof FLayers){ |
567 |
group = ((FLayers)lyr).draw(image, g, viewPort, cancel,scale,group); |
568 |
} else {
|
569 |
lyr.draw(image, g, viewPort, cancel,scale); |
570 |
} |
571 |
LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
|
572 |
fmap.fireLayerDrawingEvent(afterEvent); |
573 |
} else {
|
574 |
// add the layer to the group
|
575 |
group.setMapContext(fmap); |
576 |
group.add(lyr); |
577 |
|
578 |
} |
579 |
} |
580 |
} |
581 |
} else {
|
582 |
// gets a new group instance
|
583 |
group = lyr.newComposedLayer(); |
584 |
// if layer hasn't group, draws it inmediately
|
585 |
if (group == null) { |
586 |
if (lyr instanceof FLayers){ |
587 |
group = ((FLayers)lyr).draw(image, g, viewPort, cancel,scale,group); |
588 |
} else {
|
589 |
lyr.draw(image, g, viewPort, cancel,scale); |
590 |
} |
591 |
LayerDrawEvent afterEvent = new LayerDrawEvent(lyr, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW);
|
592 |
fmap.fireLayerDrawingEvent(afterEvent); |
593 |
} else {
|
594 |
// adds the layer to the group
|
595 |
group.setMapContext(fmap); |
596 |
group.add(lyr); |
597 |
} |
598 |
} |
599 |
///// CHEMA ComposedLayer
|
600 |
bNeedRecalculateCache = true;
|
601 |
} |
602 |
} catch (DriverException e){
|
603 |
// fmap.callNewErrorEvent(new ErrorEvent(lyr.getName(), e));
|
604 |
fmap.addLayerError("La capa " + lyr.getName() + " es err?nea."); |
605 |
e.printStackTrace(); |
606 |
lyr.setAvailable(false);
|
607 |
// this.removeLayer(lyr);
|
608 |
} catch (Exception e) { |
609 |
fmap.addLayerError("La capa " + lyr.getName() + " es err?nea."); |
610 |
e.printStackTrace(); |
611 |
lyr.setAvailable(false);
|
612 |
} |
613 |
// }
|
614 |
long t2 = System.currentTimeMillis(); |
615 |
System.out.println("Layer " + lyr.getName() + " " |
616 |
+ (t2-t1) + " milisecs.");
|
617 |
if (!cancel.isCanceled())
|
618 |
lyr.setDirty(false);
|
619 |
} |
620 |
|
621 |
} |
622 |
///// CHEMA ComposedLayer
|
623 |
if (group != null && this.getParentLayer() == null) { |
624 |
//si tenemos un grupo pendiente de pintar, pintamos
|
625 |
group.draw(image, g, viewPort, cancel,scale); |
626 |
group = null;
|
627 |
|
628 |
} |
629 |
///// CHEMA ComposedLayer
|
630 |
if (getVirtualLayers() != null) { |
631 |
getVirtualLayers().draw(image, g, viewPort, cancel,scale); |
632 |
} |
633 |
|
634 |
///// CHEMA ComposedLayer
|
635 |
return group;
|
636 |
///// CHEMA ComposedLayer
|
637 |
|
638 |
// }
|
639 |
// catch (ConcurrentModificationException e)
|
640 |
// {
|
641 |
// System.err.println(e.getMessage());
|
642 |
// }
|
643 |
} |
644 |
|
645 |
/**
|
646 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
647 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
648 |
* com.iver.utiles.swing.threads.Cancellable)
|
649 |
*/
|
650 |
public ComposedLayer print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties, ComposedLayer group) |
651 |
throws DriverException {
|
652 |
|
653 |
// TODO: A la hora de imprimir, isWithinScale falla, porque est?
|
654 |
// calculando la escala en pantalla, no para el layout.
|
655 |
// Revisar esto.
|
656 |
for (int i=0; i < layers.size(); i++) { |
657 |
FLayer lyr = (FLayer) layers.get(i); |
658 |
|
659 |
try{
|
660 |
|
661 |
///// CHEMA ComposedLayer
|
662 |
// Checks for draw group (ComposedLayer)
|
663 |
if (group != null) { |
664 |
if (lyr instanceof FLayers){ |
665 |
group = ((FLayers)lyr).print(g, viewPort, cancel,scale,properties,group); |
666 |
} else {
|
667 |
// If layer can be added to the group, does it
|
668 |
if (group.canAdd(lyr)){
|
669 |
group.add(lyr); |
670 |
} else {
|
671 |
// draw the 'pending to draw' layer group
|
672 |
group.print(g,viewPort,cancel,scale,properties); |
673 |
|
674 |
// gets a new group instance
|
675 |
group = lyr.newComposedLayer(); |
676 |
// if layer hasn't group, draws it inmediately
|
677 |
if (group == null) { |
678 |
if (lyr instanceof FLayers){ |
679 |
group = ((FLayers)lyr).print(g, viewPort, cancel,scale,properties,group); |
680 |
} else {
|
681 |
lyr.print(g, viewPort, cancel,scale,properties); |
682 |
} |
683 |
} else {
|
684 |
// add the layer to the group
|
685 |
group.setMapContext(fmap); |
686 |
group.add(lyr); |
687 |
|
688 |
} |
689 |
|
690 |
} |
691 |
} |
692 |
} else {
|
693 |
// gets a new group instance
|
694 |
group = lyr.newComposedLayer(); |
695 |
// if layer hasn't group, draws it inmediately
|
696 |
if (group == null) { |
697 |
if (lyr instanceof FLayers){ |
698 |
group = ((FLayers)lyr).print(g, viewPort, cancel,scale,properties,group); |
699 |
} else {
|
700 |
lyr.print(g, viewPort, cancel,scale,properties); |
701 |
} |
702 |
} else {
|
703 |
// add the layer to the group
|
704 |
group.setMapContext(fmap); |
705 |
group.add(lyr); |
706 |
|
707 |
} |
708 |
} |
709 |
///// CHEMA ComposedLayer
|
710 |
|
711 |
} catch (Exception e){ |
712 |
fmap.addLayerError("Error en la impresion de la capa " + lyr.getName() + ": " + e.getMessage()); |
713 |
e.printStackTrace(); |
714 |
} |
715 |
|
716 |
} |
717 |
|
718 |
///// CHEMA ComposedLayer
|
719 |
if (group != null && this.getParentLayer() == null) { |
720 |
//si tenemos un grupo pendiente de pintar, pintamos
|
721 |
group.print(g, viewPort, cancel,scale,properties); |
722 |
group = null;
|
723 |
|
724 |
} |
725 |
///// CHEMA ComposedLayer
|
726 |
|
727 |
if (getVirtualLayers() != null) { |
728 |
getVirtualLayers().print( g, viewPort, cancel, scale, properties); |
729 |
} |
730 |
|
731 |
///// CHEMA ComposedLayer
|
732 |
return group;
|
733 |
///// CHEMA ComposedLayer
|
734 |
|
735 |
} |
736 |
|
737 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties) |
738 |
throws DriverException {
|
739 |
this.print(g, viewPort, cancel, scale, properties, null); |
740 |
} |
741 |
/**
|
742 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
743 |
*/
|
744 |
public Rectangle2D getFullExtent() throws DriverException { |
745 |
Rectangle2D rAux = null; |
746 |
boolean first = true; |
747 |
|
748 |
|
749 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
750 |
FLayer capa = (FLayer) iter.next(); |
751 |
try{
|
752 |
if (first) {
|
753 |
rAux = capa.getFullExtent(); |
754 |
first=false;
|
755 |
} else {
|
756 |
rAux.add(capa.getFullExtent()); |
757 |
} |
758 |
}catch (Exception e) { |
759 |
e.printStackTrace();//TODO hay que revisar para determinar el comportamiento que espera el usuario.
|
760 |
} |
761 |
} |
762 |
|
763 |
return rAux;
|
764 |
} |
765 |
|
766 |
/**
|
767 |
* Llama al m?todo layerAdding de los listeners dados de alta.
|
768 |
*
|
769 |
* @param event
|
770 |
*
|
771 |
* @throws CancelationException
|
772 |
*/
|
773 |
protected void callLayerAdding(LayerCollectionEvent event) |
774 |
throws CancelationException {
|
775 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
776 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
777 |
((LayerCollectionListener) iter.next()).layerAdding(event); |
778 |
} |
779 |
} |
780 |
|
781 |
/**
|
782 |
* Llama al m?todo layerRemoving de los listeners dados de alta.
|
783 |
*
|
784 |
* @param event
|
785 |
*
|
786 |
* @throws CancelationException
|
787 |
*/
|
788 |
protected void callLayerRemoving(LayerCollectionEvent event) |
789 |
throws CancelationException {
|
790 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
791 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
792 |
((LayerCollectionListener) iter.next()).layerRemoving(event); |
793 |
} |
794 |
} |
795 |
|
796 |
|
797 |
/**
|
798 |
* Llama al m?todo layerMoving de los listeners dados de alta.
|
799 |
*
|
800 |
* @param event
|
801 |
*
|
802 |
* @throws CancelationException
|
803 |
*/
|
804 |
protected void callLayerMoving(LayerPositionEvent event) |
805 |
throws CancelationException {
|
806 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
807 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
808 |
((LayerCollectionListener) iter.next()).layerMoving(event); |
809 |
} |
810 |
} |
811 |
|
812 |
/**
|
813 |
* Llama al m?todo layerAdded de los listeners dados de alta.
|
814 |
*
|
815 |
* @param event
|
816 |
*/
|
817 |
protected void callLayerAdded(LayerCollectionEvent event) { |
818 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
819 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
820 |
((LayerCollectionListener) iter.next()).layerAdded(event); |
821 |
} |
822 |
} |
823 |
|
824 |
/**
|
825 |
* Llama al m?todo layerRemoved de los listeners dados de alta.
|
826 |
*
|
827 |
* @param event
|
828 |
*/
|
829 |
protected void callLayerRemoved(LayerCollectionEvent event) { |
830 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
831 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
832 |
((LayerCollectionListener) iter.next()).layerRemoved(event); |
833 |
} |
834 |
} |
835 |
|
836 |
/**
|
837 |
* Llama al m?todo layerMoved de los listeners dados de alta.
|
838 |
*
|
839 |
* @param event
|
840 |
*/
|
841 |
protected void callLayerMoved(LayerPositionEvent event) { |
842 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
843 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
844 |
((LayerCollectionListener) iter.next()).layerMoved(event); |
845 |
} |
846 |
} |
847 |
|
848 |
/**
|
849 |
* @throws XMLException
|
850 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
851 |
*/
|
852 |
public XMLEntity getXMLEntity() throws XMLException { |
853 |
XMLEntity xml = super.getXMLEntity();
|
854 |
|
855 |
ArrayList names = new ArrayList(); |
856 |
|
857 |
|
858 |
FLayer layer; |
859 |
for (int i = 0; i < layers.size(); i++) { |
860 |
layer = (FLayer)layers.get(i); |
861 |
// XXX: Parche para no guardar capas raster de memoria en el proyecto
|
862 |
if (layer instanceof FLyrRaster){ |
863 |
if (((FLyrRaster)layer).getSource() instanceof RasterFileAdapter){ |
864 |
if (((RasterFileAdapter)((FLyrRaster)layer).getSource()).getFile() == null){ |
865 |
continue;
|
866 |
} |
867 |
} |
868 |
} |
869 |
// XXX: Parche para no guardar capas raster de memoria en el proyecto
|
870 |
try{
|
871 |
names.add(layer.getName()); |
872 |
xml.addChild(layer.getXMLEntity()); |
873 |
}catch (XMLException e) {
|
874 |
e.printStackTrace(); |
875 |
} |
876 |
} |
877 |
|
878 |
String[] s = new String[names.size()]; |
879 |
System.arraycopy(names.toArray(),0,s,0,names.size()); |
880 |
xml.putProperty("numLayers", names.size());
|
881 |
xml.putProperty("LayerNames", s);
|
882 |
|
883 |
return xml;
|
884 |
} |
885 |
|
886 |
/**
|
887 |
* DOCUMENT ME!
|
888 |
*
|
889 |
* @param xml DOCUMENT ME!
|
890 |
*
|
891 |
* @throws XMLException
|
892 |
*
|
893 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
894 |
*/
|
895 |
public void setXMLEntity03(XMLEntity xml) throws XMLException{ |
896 |
super.setXMLEntity03(xml);
|
897 |
int numLayers = xml.getIntProperty("numLayers"); |
898 |
|
899 |
String[] s = xml.getStringArrayProperty("LayerNames"); |
900 |
try {
|
901 |
for (int i = 0; i < numLayers; i++) { |
902 |
FLayer layer = null;
|
903 |
|
904 |
String className = xml.getChild(i).getStringProperty("className"); |
905 |
|
906 |
if (className.equals(FLyrVect.class.getName())) {
|
907 |
if (xml.getChild(i).contains("file")) { |
908 |
|
909 |
layer = LayerFactory.createLayer(s[i], |
910 |
(VectorialFileDriver)LayerFactory.getDM().getDriver(xml.getChild(i).getStringProperty("driverName")),
|
911 |
new File(xml.getChild(i).getStringProperty("file")), |
912 |
this.getMapContext().getViewPort().getProjection());
|
913 |
|
914 |
} else if (true) { |
915 |
//TODO falta por implementar
|
916 |
} else if (true) { |
917 |
//TODO falta por implementar
|
918 |
} |
919 |
|
920 |
layer.setXMLEntity03(xml.getChild(i)); |
921 |
// Comprobar que la proyecci?n es la misma que la de FMap
|
922 |
// Si no lo es, es una capa que est? reproyectada al vuelo
|
923 |
IProjection proj = layer.getProjection(); |
924 |
if (proj != null) |
925 |
if (proj != fmap.getProjection())
|
926 |
{ |
927 |
ICoordTrans ct = proj.getCT(fmap.getProjection()); |
928 |
layer.setCoordTrans(ct); |
929 |
System.err.println("coordTrans = " + |
930 |
proj.getAbrev() + " " +
|
931 |
fmap.getProjection().getAbrev()); |
932 |
} |
933 |
|
934 |
// } else if (className.equals(FLyrWMS.class.getName())) {
|
935 |
// try {
|
936 |
// layer = LayerFactory.createLayer(s[i],
|
937 |
// StringUtilities.string2Rect(
|
938 |
// xml.getChild(i).getStringProperty("fullExtent")),
|
939 |
// new URL(xml.getChild(i).getStringProperty("host")),
|
940 |
// xml.getChild(i).getStringProperty("format"),
|
941 |
// xml.getChild(i).getStringProperty("layerQuery"),
|
942 |
// xml.getChild(i).getStringProperty("infoLayerQuery"),
|
943 |
// xml.getChild(i).getStringProperty("srs"));
|
944 |
// } catch (MalformedURLException e) {
|
945 |
// throw new XMLException(e);
|
946 |
// }
|
947 |
} else if (className.equals((FLyrRaster.class.getName()))) { |
948 |
//if (xml.getChild(i).contains("file")) {
|
949 |
/*layer = LayerFactory.createLayer(s[i],
|
950 |
xml.getChild(i).getStringProperty("driverName"),
|
951 |
new File(xml.getChild(i).getStringProperty("file")),
|
952 |
this.getFMap().getViewPort().getProjection());*/
|
953 |
layer = new FLyrRaster();
|
954 |
layer.setName(s[i]); |
955 |
if (!xml.getChild(i).contains("proj")) |
956 |
((FLyrRaster)layer).setProjection(this.getMapContext().getViewPort().getProjection());
|
957 |
layer.setXMLEntity03(xml.getChild(i)); |
958 |
try {
|
959 |
layer.load(); |
960 |
|
961 |
} catch (DriverIOException e) {
|
962 |
throw new XMLException(e); |
963 |
} |
964 |
|
965 |
}else if (className.equals((FLayers.class.getName()))) { |
966 |
layer = new FLayers(getMapContext(),this); |
967 |
layer.setXMLEntity(xml.getChild(i)); |
968 |
} else {
|
969 |
// Capas Nuevas (externas)
|
970 |
try {
|
971 |
Class clase = Class.forName(className); |
972 |
layer = (FLayer) clase.newInstance(); |
973 |
layer.setName(s[i]); |
974 |
layer.setXMLEntity03(xml.getChild(i)); |
975 |
try {
|
976 |
layer.load(); |
977 |
} catch (DriverIOException e) {
|
978 |
throw new XMLException(e); |
979 |
} |
980 |
} catch (Exception e) { |
981 |
//e.printStackTrace();
|
982 |
throw new XMLException(e); |
983 |
} |
984 |
} |
985 |
|
986 |
this.addLayer(layer);
|
987 |
} |
988 |
} /*azabala-modificaciones en layerfactory-
|
989 |
catch (DriverException e) {
|
990 |
throw new XMLException(e);
|
991 |
}*/
|
992 |
catch (DriverLoadException e) {
|
993 |
throw new XMLException(e); |
994 |
} |
995 |
|
996 |
} |
997 |
|
998 |
/**
|
999 |
* DOCUMENT ME!
|
1000 |
*
|
1001 |
* @param xml DOCUMENT ME!
|
1002 |
*
|
1003 |
* @throws XMLException
|
1004 |
*
|
1005 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
1006 |
*/
|
1007 |
public void setXMLEntity(XMLEntity xml) throws XMLException{ |
1008 |
super.setXMLEntity(xml);
|
1009 |
//LoadLayerException loadLayerException=new LoadLayerException();
|
1010 |
int numLayers = xml.getIntProperty("numLayers"); |
1011 |
|
1012 |
String[] s = xml.getStringArrayProperty("LayerNames"); |
1013 |
// try {
|
1014 |
fmap.clearErrors(); |
1015 |
for (int i = 0; i < numLayers; i++) { |
1016 |
this.addLayerFromXML(xml.getChild(i),s[i]);
|
1017 |
|
1018 |
|
1019 |
} |
1020 |
/* } catch (DriverException e) {
|
1021 |
throw new XMLException(e);
|
1022 |
} */
|
1023 |
/*if (loadLayerException.getExceptions().size()>0){
|
1024 |
throw loadLayerException;
|
1025 |
}*/
|
1026 |
} |
1027 |
|
1028 |
/**
|
1029 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
|
1030 |
* FBitSet)
|
1031 |
*/
|
1032 |
public void process(FeatureVisitor visitor, FBitSet subset) |
1033 |
throws DriverException, VisitException {
|
1034 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
1035 |
FLayer layer = (FLayer) iter.next(); |
1036 |
|
1037 |
if (layer instanceof VectorialData) { |
1038 |
((VectorialData) layer).process(visitor, subset); |
1039 |
} |
1040 |
} |
1041 |
} |
1042 |
|
1043 |
/**
|
1044 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
|
1045 |
*/
|
1046 |
public void process(FeatureVisitor visitor) |
1047 |
throws DriverException, VisitException {
|
1048 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
1049 |
FLayer layer = (FLayer) iter.next(); |
1050 |
|
1051 |
if (layer instanceof FLayers){ |
1052 |
FLayers lyrs=(FLayers)layer; |
1053 |
for (int i=0;i<lyrs.getLayersCount();i++){ |
1054 |
FLayer lyr=lyrs.getLayer(i); |
1055 |
if (lyr.isActive()) {
|
1056 |
if (lyr instanceof VectorialData) { |
1057 |
((VectorialData) lyr).process(visitor); |
1058 |
} |
1059 |
} |
1060 |
} |
1061 |
} |
1062 |
if (layer.isActive()) {
|
1063 |
if (layer instanceof VectorialData) { |
1064 |
((VectorialData) layer).process(visitor); |
1065 |
} |
1066 |
} |
1067 |
} |
1068 |
} |
1069 |
/**
|
1070 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor, Rectangle2D)
|
1071 |
*/
|
1072 |
public void process(FeatureVisitor visitor, Rectangle2D rect) throws DriverException, VisitException { |
1073 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
1074 |
FLayer layer = (FLayer) iter.next(); |
1075 |
|
1076 |
if (layer.isActive()) {
|
1077 |
if (layer instanceof VectorialData) { |
1078 |
((VectorialData) layer).process(visitor, rect); |
1079 |
} |
1080 |
} |
1081 |
} |
1082 |
|
1083 |
} |
1084 |
|
1085 |
/**
|
1086 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getMapContext()
|
1087 |
*/
|
1088 |
public MapContext getMapContext() {
|
1089 |
return fmap;
|
1090 |
} |
1091 |
|
1092 |
/* (non-Javadoc)
|
1093 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setCoordTrans(org.cresques.cts.ICoordTrans)
|
1094 |
*/
|
1095 |
public void setCoordTrans(ICoordTrans ct) { |
1096 |
super.setCoordTrans(ct);
|
1097 |
|
1098 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
1099 |
FLayer layer = (FLayer) iter.next(); |
1100 |
layer.setCoordTrans(ct); |
1101 |
} |
1102 |
} |
1103 |
|
1104 |
/**
|
1105 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#setAllActives(boolean)
|
1106 |
*/
|
1107 |
public void setAllActives(boolean active) { |
1108 |
FLayer lyr; |
1109 |
|
1110 |
for (int i = 0; i < layers.size(); i++) { |
1111 |
lyr = ((FLayer) layers.get(i)); |
1112 |
lyr.setActive(active); |
1113 |
|
1114 |
if (lyr instanceof LayerCollection) { |
1115 |
((LayerCollection) lyr).setAllActives(active); |
1116 |
} |
1117 |
} |
1118 |
} |
1119 |
|
1120 |
/**
|
1121 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getActives()
|
1122 |
*/
|
1123 |
public FLayer[] getActives() { |
1124 |
ArrayList ret = new ArrayList(); |
1125 |
LayersIterator it = new LayersIterator(this) { |
1126 |
|
1127 |
public boolean evaluate(FLayer layer) { |
1128 |
return layer.isActive();
|
1129 |
} |
1130 |
|
1131 |
}; |
1132 |
|
1133 |
while (it.hasNext())
|
1134 |
{ |
1135 |
ret.add(it.next()); |
1136 |
} |
1137 |
return (FLayer[]) ret.toArray(new FLayer[0]); |
1138 |
} |
1139 |
|
1140 |
/* (non-Javadoc)
|
1141 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getMinScale()
|
1142 |
*/
|
1143 |
public double getMinScale() { |
1144 |
return -1; // La visibilidad o no la controla cada capa |
1145 |
// dentro de una colecci?n
|
1146 |
} |
1147 |
|
1148 |
/* (non-Javadoc)
|
1149 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
|
1150 |
*/
|
1151 |
public double getMaxScale() { |
1152 |
return -1; |
1153 |
} |
1154 |
public void setMinScale(double minScale) |
1155 |
{ |
1156 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
1157 |
FLayer lyr = (FLayer) iter.next(); |
1158 |
lyr.setMinScale(minScale); |
1159 |
} |
1160 |
} |
1161 |
public void setMaxScale(double maxScale) |
1162 |
{ |
1163 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
1164 |
FLayer lyr = (FLayer) iter.next(); |
1165 |
lyr.setMinScale(maxScale); |
1166 |
} |
1167 |
} |
1168 |
public void setActive(boolean b){ |
1169 |
super.setActive(b);
|
1170 |
for (int i=0;i<layers.size();i++){ |
1171 |
((FLayer)layers.get(i)).setActive(b); |
1172 |
} |
1173 |
} |
1174 |
|
1175 |
/* (non-Javadoc)
|
1176 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#addLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
|
1177 |
*/
|
1178 |
public boolean addLayerListener(LayerListener o) { |
1179 |
for (int i = 0; i < layers.size(); i++) |
1180 |
((FLayer) layers.get(i)).addLayerListener(o); |
1181 |
return true; |
1182 |
} |
1183 |
|
1184 |
public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws DriverException { |
1185 |
int i;
|
1186 |
Vector items = new Vector(); |
1187 |
FLayer layer; |
1188 |
XMLItem[] aux;
|
1189 |
for (i = 0; i < this.layers.size(); i++){ |
1190 |
layer = (FLayer)layers.get(i); |
1191 |
if (layer instanceof InfoByPoint){ |
1192 |
InfoByPoint queryable_layer = (InfoByPoint) layer; |
1193 |
aux = queryable_layer.getInfo(p, tolerance, null);
|
1194 |
if (!(queryable_layer instanceof FLayers)){ |
1195 |
for(int j = 0; j < aux.length; j++){ |
1196 |
items.add(aux[j]); |
1197 |
} |
1198 |
} |
1199 |
} |
1200 |
} |
1201 |
return (XMLItem[])items.toArray(new XMLItem[0]); |
1202 |
|
1203 |
// for (i = 0; i < this.layers.size(); i++){
|
1204 |
// FLayer laCapa = (FLayer) layers.get(i);
|
1205 |
// if (laCapa instanceof FLyrVect){
|
1206 |
// }
|
1207 |
// else if (laCapa instanceof RasterOperations) {
|
1208 |
// try {
|
1209 |
// RasterOperations layer = (RasterOperations) laCapa;
|
1210 |
// sb.append(layer.getInfo(p, tolerance));
|
1211 |
// } catch (DriverException e) {
|
1212 |
// e.printStackTrace();
|
1213 |
// }
|
1214 |
// }
|
1215 |
// else if (laCapa instanceof InfoByPoint) {
|
1216 |
// try {
|
1217 |
// InfoByPoint layer = (InfoByPoint) laCapa;
|
1218 |
// sb.append(layer.getInfo(p, tolerance));
|
1219 |
// } catch (DriverException e) {
|
1220 |
// e.printStackTrace();
|
1221 |
// }
|
1222 |
// }
|
1223 |
// }
|
1224 |
|
1225 |
} |
1226 |
|
1227 |
public ImageIcon getTocImageIcon() { |
1228 |
return new ImageIcon(MapControl.class.getResource("images/layerGroup.png")); |
1229 |
} |
1230 |
|
1231 |
public boolean isDirty() { |
1232 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
1233 |
FLayer lyr = (FLayer) iter.next(); |
1234 |
if (lyr.isDirty())
|
1235 |
return true; |
1236 |
} |
1237 |
return false; |
1238 |
} |
1239 |
|
1240 |
public void setDirty(boolean dirty) { |
1241 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
1242 |
FLayer lyr = (FLayer) iter.next(); |
1243 |
lyr.setDirty(dirty); |
1244 |
} |
1245 |
|
1246 |
} |
1247 |
|
1248 |
public boolean addLayerFromXMLEntity(XMLEntity xml, String name) { |
1249 |
fmap.clearErrors(); |
1250 |
this.addLayerFromXML(xml,name);
|
1251 |
|
1252 |
return (fmap.getLayersError().size() == 0); |
1253 |
|
1254 |
} |
1255 |
|
1256 |
private void addLayerFromXML(XMLEntity xml, String name) { |
1257 |
FLayer layer = null;
|
1258 |
long t1 = System.currentTimeMillis(); |
1259 |
try {
|
1260 |
if (name == null) name = xml.getName(); |
1261 |
|
1262 |
|
1263 |
String className = xml.getStringProperty("className"); |
1264 |
//TODO VCN FLyrAnnotation es un parche para no tener que duplicar todo el c?digo de aq? y de los diferentes m?todos de LayerFactory,
|
1265 |
//ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver Vectorial.
|
1266 |
if (className.equals(FLyrVect.class.getName()) || className.equals(FLyrAnnotation.class.getName())) {
|
1267 |
String type = xml.getStringProperty("type"); |
1268 |
if ("vectorial".equals(type)){ |
1269 |
//String recordsetName = xml.getChild(i).getStringProperty("recordset-name");
|
1270 |
IProjection proj = null;
|
1271 |
if (xml.contains("proj")) { |
1272 |
proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
1273 |
} |
1274 |
else
|
1275 |
{ |
1276 |
proj = this.getMapContext().getViewPort().getProjection();
|
1277 |
} |
1278 |
if (xml.contains("file")) { |
1279 |
Driver d;
|
1280 |
try {
|
1281 |
d = LayerFactory.getDM().getDriver(xml.getStringProperty("driverName"));
|
1282 |
} catch (DriverLoadException e1) {
|
1283 |
throw new XMLException(e1); |
1284 |
} |
1285 |
layer = LayerFactory.createLayer(name, (VectorialFileDriver) d, |
1286 |
new File(xml.getStringProperty("file")), |
1287 |
proj); |
1288 |
|
1289 |
|
1290 |
} |
1291 |
if (xml.contains("db")) { |
1292 |
|
1293 |
String driverName = xml.getStringProperty("db"); |
1294 |
IVectorialDatabaseDriver driver; |
1295 |
try {
|
1296 |
driver = (IVectorialDatabaseDriver) LayerFactory.getDM().getDriver(driverName); |
1297 |
//Hay que separar la carga de los datos del XMLEntity del load.
|
1298 |
driver.setXMLEntity(xml.getChild(2));
|
1299 |
|
1300 |
boolean loadOk = false; |
1301 |
// if (driver instanceof DefaultJDBCDriver) {
|
1302 |
try {
|
1303 |
((IVectorialDatabaseDriver) driver).load(); |
1304 |
if (((IVectorialDatabaseDriver) driver)
|
1305 |
.getConnection() != null) {
|
1306 |
loadOk = true;
|
1307 |
} |
1308 |
} catch (DriverException e) {
|
1309 |
e.printStackTrace(); |
1310 |
loadOk = false;
|
1311 |
} |
1312 |
// } else {
|
1313 |
// try{
|
1314 |
// ((IVectorialDatabaseDriver)driver).load();
|
1315 |
// loadOk=true;
|
1316 |
// }catch (Exception e) {
|
1317 |
// loadOk=false;
|
1318 |
// }
|
1319 |
// }
|
1320 |
|
1321 |
layer = LayerFactory.createDBLayer(driver, name, proj); |
1322 |
if (!loadOk) {
|
1323 |
layer.setAvailable(false);
|
1324 |
} |
1325 |
|
1326 |
} catch (DriverLoadException e) {
|
1327 |
e.printStackTrace(); |
1328 |
throw new XMLException(e); |
1329 |
} |
1330 |
|
1331 |
} |
1332 |
// Clases con algun driver gen?rico creado por otro
|
1333 |
// programador
|
1334 |
if (xml.contains("other")) { |
1335 |
|
1336 |
String driverName = xml.getStringProperty("other"); |
1337 |
VectorialDriver driver = null;
|
1338 |
try {
|
1339 |
driver = (VectorialDriver) LayerFactory.getDM().getDriver(driverName); |
1340 |
} catch (DriverLoadException e) {
|
1341 |
// Si no existe ese driver, no pasa nada.
|
1342 |
// Puede que el desarrollador no quiera que
|
1343 |
// aparezca en el cuadro de di?logo y ha metido
|
1344 |
// el jar con sus clases en nuestro directorio lib.
|
1345 |
// Intentamos cargar esa clase "a pelo".
|
1346 |
if (xml.getChild(2).contains("className")) |
1347 |
{ |
1348 |
String className2 = xml.getChild(2).getStringProperty("className"); |
1349 |
try {
|
1350 |
driver = (VectorialDriver) Class.forName(className2).newInstance();
|
1351 |
} catch (Exception e1) { |
1352 |
throw new XMLException(e1); |
1353 |
} |
1354 |
} |
1355 |
} catch (NullPointerException npe) { |
1356 |
// Si no existe ese driver, no pasa nada.
|
1357 |
// Puede que el desarrollador no quiera que
|
1358 |
// aparezca en el cuadro de di?logo y ha metido
|
1359 |
// el jar con sus clases en nuestro directorio lib.
|
1360 |
// Intentamos cargar esa clase "a pelo".
|
1361 |
if (xml.getChild(2).contains("className")) |
1362 |
{ |
1363 |
String className2 = xml.getChild(2).getStringProperty("className"); |
1364 |
try {
|
1365 |
driver = (VectorialDriver) Class.forName(className2).newInstance();
|
1366 |
} catch (Exception e1) { |
1367 |
throw new XMLException(e1); |
1368 |
} |
1369 |
} |
1370 |
} |
1371 |
if (driver instanceof IPersistance) |
1372 |
{ |
1373 |
IPersistance persist = (IPersistance) driver; |
1374 |
persist.setXMLEntity(xml.getChild(2));
|
1375 |
} |
1376 |
layer = LayerFactory.createLayer(name, driver, proj); |
1377 |
} |
1378 |
|
1379 |
} |
1380 |
|
1381 |
//TODO VCN FLyrAnnotation es un parche para no tener que duplicar todo el c?digo de aq? y de los diferentes m?todos de LayerFactory,
|
1382 |
//ya que los drivers de una FLyrAnnotation no sabemos cual es puede ser cualquier Driver Vectorial.
|
1383 |
if (className.equals(FLyrAnnotation.class.getName())){
|
1384 |
layer=FLyrAnnotation.createLayerFromVect((FLyrVect)layer); |
1385 |
} |
1386 |
|
1387 |
|
1388 |
layer.setXMLEntity(xml); |
1389 |
|
1390 |
// } else if (className.equals(FLyrWMS.class.getName())) {
|
1391 |
// try {
|
1392 |
// layer = LayerFactory.createLayer(s[i],
|
1393 |
// StringUtilities.string2Rect(
|
1394 |
// xml.getChild(i).getStringProperty("fullExtent")),
|
1395 |
// new URL(xml.getChild(i).getStringProperty("host")),
|
1396 |
// xml.getChild(i).getStringProperty("format"),
|
1397 |
// xml.getChild(i).getStringProperty("layerQuery"),
|
1398 |
// xml.getChild(i).getStringProperty("infoLayerQuery"),
|
1399 |
// xml.getChild(i).getStringProperty("srs"));
|
1400 |
// layer.setXMLEntity(xml.getChild(i));
|
1401 |
// } catch (MalformedURLException e) {
|
1402 |
// throw new XMLException(e);
|
1403 |
// }
|
1404 |
} else if (className.equals((FLyrRaster.class.getName()))) { |
1405 |
//if (xml.getChild(i).contains("file")) {
|
1406 |
/*layer = LayerFactory.createLayer(s[i],
|
1407 |
xml.getChild(i).getStringProperty("driverName"),
|
1408 |
new File(xml.getChild(i).getStringProperty("file")),
|
1409 |
this.getFMap().getViewPort().getProjection());*/
|
1410 |
Class clase = LayerFactory.getLayerClassForLayerClassName(className);
|
1411 |
layer = (FLayer) clase.newInstance(); |
1412 |
layer.setName(name); |
1413 |
if (!xml.contains("proj")) |
1414 |
((FLyrRaster)layer).setProjection(this.getMapContext().getViewPort().getProjection());
|
1415 |
layer.setXMLEntity(xml); |
1416 |
try {
|
1417 |
layer.load(); |
1418 |
} catch (DriverIOException e) {
|
1419 |
throw new XMLException(e); |
1420 |
} |
1421 |
|
1422 |
}else if (className.equals((FLayers.class.getName()))) { |
1423 |
layer = new FLayers(getMapContext(),this); |
1424 |
layer.setXMLEntity(xml); |
1425 |
} else {
|
1426 |
// Capas Nuevas (externas)
|
1427 |
Class clase = LayerFactory.getLayerClassForLayerClassName(className);
|
1428 |
layer = (FLayer) clase.newInstance(); |
1429 |
layer.setName(name); |
1430 |
layer.setXMLEntity(xml); |
1431 |
try {
|
1432 |
layer.load(); |
1433 |
}catch (DriverIOException e) {
|
1434 |
throw new XMLException(e); |
1435 |
} |
1436 |
|
1437 |
} |
1438 |
|
1439 |
this.addLayer(layer);
|
1440 |
long t2 = System.currentTimeMillis(); |
1441 |
logger.debug("layer: "+ layer.getName() +" loaded. " + (t2-t1) + " msecs."); |
1442 |
// Comprobar que la proyecci?n es la misma que la de FMap
|
1443 |
// Si no lo es, es una capa que est? reproyectada al vuelo
|
1444 |
IProjection proj = layer.getProjection(); |
1445 |
if ((proj != null)) |
1446 |
if (proj != getMapContext().getProjection())
|
1447 |
{ |
1448 |
ICoordTrans ct = proj.getCT(getMapContext().getProjection()); |
1449 |
// TODO: REVISAR CON LUIS
|
1450 |
// Se lo fijamos a todas, luego cada una que se reproyecte
|
1451 |
// si puede, o que no haga nada
|
1452 |
layer.setCoordTrans(ct); |
1453 |
// NOTA: DESPU?S DE ESTO DEBER?AMOS CREAR LAS ETIQUETAS
|
1454 |
// SI ES NECESARIO.
|
1455 |
// TODO: REVISAR A FONDO ESTO, PORQUE LAS ETIQUETAS SE CREAN
|
1456 |
// 2 VECES SI HAY REPROYECC?N
|
1457 |
if (layer instanceof FLyrVect) |
1458 |
{ |
1459 |
FLyrVect lyrVect = (FLyrVect)layer; |
1460 |
VectorialLegend legend = (VectorialLegend) lyrVect.getLegend(); |
1461 |
if (legend.getLabelField() != null) { |
1462 |
lyrVect.createLabelLayer(lyrVect.getRecordset()); |
1463 |
} |
1464 |
|
1465 |
} |
1466 |
} |
1467 |
}catch (Exception e) { |
1468 |
fmap.addLayerError(xml.getStringProperty("name"));
|
1469 |
//loadLayerException.addException(e);
|
1470 |
/*if (layer!=null){
|
1471 |
layer.setActive(false);
|
1472 |
layer.setVisible(false);
|
1473 |
this.addLayer(layer);
|
1474 |
}*/
|
1475 |
//throw new XMLException(e);
|
1476 |
System.err.println("No se ha podido cargar la capa : "+xml.getStringProperty("name")); |
1477 |
logger.debug("No se ha podido cargar la capa : "+xml.getStringProperty("name") + ". Raz?n:"); |
1478 |
// logger.debug(e.fillInStackTrace());
|
1479 |
e.printStackTrace(); |
1480 |
} |
1481 |
} |
1482 |
|
1483 |
private void addLayerFromXMLNew(XMLEntity xml, String name) { |
1484 |
FLayer layer = null;
|
1485 |
|
1486 |
|
1487 |
try {
|
1488 |
String className = xml.getStringProperty("className"); |
1489 |
|
1490 |
if (className.equals((FLayers.class.getName()))){
|
1491 |
layer = new FLayers(getMapContext(),this); |
1492 |
} else {
|
1493 |
// Por compatibilidad
|
1494 |
if (className.equals(FLyrVect.class.getName())) {
|
1495 |
if (xml.contains("file")) { |
1496 |
layer = new FLayerFileVectorial();
|
1497 |
} else if (xml.contains("db")) { |
1498 |
try {
|
1499 |
layer = (FLayer)((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create("com.iver.cit.gvsig.fmap.layers.FLayerJDBCVectorial"); |
1500 |
} catch (Exception e) { |
1501 |
throw new XMLException(new Exception("No se tiene registrada la capa de tipo JDBC")); |
1502 |
} |
1503 |
//className = FLayerJDBCVectorial.class.getName();
|
1504 |
} else if (xml.contains("other")){ |
1505 |
layer = new FLayerGenericVectorial();
|
1506 |
} else {
|
1507 |
throw new XMLException(new Exception("Capa vectorial de tipo no reconocido")); |
1508 |
} |
1509 |
// Fin por compatibilidad
|
1510 |
} else {
|
1511 |
try {
|
1512 |
layer = (FLayer)(((ExtensionPoint)ExtensionPointsSingleton.getInstance().get("Layers")).create(className));
|
1513 |
} catch (Exception e) { |
1514 |
//puende que no este registrada como punto de extension
|
1515 |
Class clase = Class.forName(className); |
1516 |
layer = (FLayer) clase.newInstance(); |
1517 |
// FIXME: Hacemos algo aqui o dejamos que suba el error?
|
1518 |
} |
1519 |
} |
1520 |
|
1521 |
} |
1522 |
layer.setXMLEntity(xml); |
1523 |
if (name != null) layer.setName(name); |
1524 |
try {
|
1525 |
layer.load(); |
1526 |
}catch (DriverIOException e) {
|
1527 |
throw new XMLException(e); |
1528 |
} |
1529 |
|
1530 |
this.addLayer(layer);
|
1531 |
logger.debug("layer: "+ layer.getName() +" loaded"); |
1532 |
// Comprobar que la proyecci?n es la misma que la de FMap
|
1533 |
// Si no lo es, es una capa que est? reproyectada al vuelo
|
1534 |
IProjection proj = layer.getProjection(); |
1535 |
if ((proj != null)) |
1536 |
if (proj != getMapContext().getProjection())
|
1537 |
{ |
1538 |
ICoordTrans ct = proj.getCT(getMapContext().getProjection()); |
1539 |
// TODO: REVISAR CON LUIS
|
1540 |
// Se lo fijamos a todas, luego cada una que se reproyecte
|
1541 |
// si puede, o que no haga nada
|
1542 |
layer.setCoordTrans(ct); |
1543 |
// NOTA: DESPU?S DE ESTO DEBER?AMOS CREAR LAS ETIQUETAS
|
1544 |
// SI ES NECESARIO.
|
1545 |
// TODO: REVISAR A FONDO ESTO, PORQUE LAS ETIQUETAS SE CREAN
|
1546 |
// 2 VECES SI HAY REPROYECC?N
|
1547 |
if (layer instanceof FLyrVect) |
1548 |
{ |
1549 |
FLyrVect lyrVect = (FLyrVect)layer; |
1550 |
VectorialLegend legend = (VectorialLegend) lyrVect.getLegend(); |
1551 |
if (legend.getLabelField() != null) { |
1552 |
lyrVect.createLabelLayer(lyrVect.getRecordset()); |
1553 |
} |
1554 |
|
1555 |
} |
1556 |
} |
1557 |
}catch (Exception e) { |
1558 |
fmap.addLayerError(xml.getStringProperty("name"));
|
1559 |
//loadLayerException.addException(e);
|
1560 |
/*if (layer!=null){
|
1561 |
layer.setActive(false);
|
1562 |
layer.setVisible(false);
|
1563 |
this.addLayer(layer);
|
1564 |
}*/
|
1565 |
//throw new XMLException(e);
|
1566 |
System.err.println("No se ha podido cargar la capa : "+xml.getStringProperty("name")); |
1567 |
logger.debug("No se ha podido cargar la capa : "+xml.getStringProperty("name") + ". Raz?n:"); |
1568 |
// logger.debug(e.fillInStackTrace());
|
1569 |
e.printStackTrace(); |
1570 |
} |
1571 |
} |
1572 |
|
1573 |
/**
|
1574 |
* This method calls recursively to its layer children to tell that the layer is going
|
1575 |
* to be removed from the view. This overwrites FLyrDefault.removingThisLayer().
|
1576 |
*/
|
1577 |
public void removingThisLayer() { |
1578 |
|
1579 |
for (int i=0; i < layers.size(); i++) { |
1580 |
FLayer lyr = (FLayer) layers.get(i); |
1581 |
if (lyr instanceof FLyrDefault) { |
1582 |
((FLyrDefault) lyr).removingThisLayer(); |
1583 |
} |
1584 |
} |
1585 |
} |
1586 |
|
1587 |
} |