svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / fmap / mapcontext / layers / FLayers.java @ 43608
History | View | Annotate | Download (44.7 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.mapcontext.layers; |
24 |
|
25 |
import java.awt.Graphics2D; |
26 |
import java.awt.Point; |
27 |
import java.awt.image.BufferedImage; |
28 |
import java.util.ArrayList; |
29 |
import java.util.Collection; |
30 |
import java.util.Collections; |
31 |
import java.util.Iterator; |
32 |
import java.util.List; |
33 |
import java.util.ListIterator; |
34 |
import java.util.Set; |
35 |
import java.util.TreeSet; |
36 |
|
37 |
import org.cresques.cts.ICoordTrans; |
38 |
import org.cresques.cts.IProjection; |
39 |
import org.slf4j.Logger; |
40 |
import org.slf4j.LoggerFactory; |
41 |
|
42 |
import org.gvsig.compat.print.PrintAttributes; |
43 |
import org.gvsig.fmap.dal.DataStore; |
44 |
import org.gvsig.fmap.dal.exception.DataException; |
45 |
import org.gvsig.fmap.dal.exception.ReadException; |
46 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
47 |
import org.gvsig.fmap.geom.primitive.Envelope; |
48 |
import org.gvsig.fmap.mapcontext.MapContext; |
49 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
50 |
import org.gvsig.fmap.mapcontext.MapContextRuntimeException; |
51 |
import org.gvsig.fmap.mapcontext.Messages; |
52 |
import org.gvsig.fmap.mapcontext.ViewPort; |
53 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
54 |
import org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer; |
55 |
import org.gvsig.fmap.mapcontext.layers.operations.InfoByPoint; |
56 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
57 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerNotFoundInCollectionException; |
58 |
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitable; |
59 |
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitor; |
60 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
61 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelable; |
62 |
import org.gvsig.metadata.exceptions.MetadataException; |
63 |
import org.gvsig.tools.ToolsLocator; |
64 |
import org.gvsig.tools.dispose.Disposable; |
65 |
import org.gvsig.tools.dynobject.DynObjectSet; |
66 |
import org.gvsig.tools.dynobject.DynStruct; |
67 |
import org.gvsig.tools.dynobject.impl.MultiDynObjectSet; |
68 |
import org.gvsig.tools.exception.BaseException; |
69 |
import org.gvsig.tools.persistence.PersistenceManager; |
70 |
import org.gvsig.tools.persistence.PersistentState; |
71 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
72 |
import org.gvsig.tools.task.Cancellable; |
73 |
import org.gvsig.tools.util.Callable; |
74 |
import org.gvsig.tools.visitor.VisitCanceledException; |
75 |
import org.gvsig.tools.visitor.Visitor; |
76 |
|
77 |
/**
|
78 |
* <p>
|
79 |
* Represents a generic collection of layers, that can be represented as a node
|
80 |
* in a tree of nodes of layers.</p>
|
81 |
*
|
82 |
* <p>
|
83 |
* Adapts the basic functionality implemented for a layer in the abstract class
|
84 |
* <code>FLyrDefault</code>, to a collection of layers, implementing, as well,
|
85 |
* specific methods for this kind of object, defined in the interfaces
|
86 |
* <code>VectorialData</code>, <code>LayerCollection</code>, and
|
87 |
* <code>InfoByPoint</code>.</p>
|
88 |
*
|
89 |
* @see FLyrDefault
|
90 |
*/
|
91 |
public class FLayers extends FLyrDefault implements LayerCollection, |
92 |
InfoByPoint, List<FLayer> {
|
93 |
|
94 |
/**
|
95 |
* List with all listeners registered for this kind of node.
|
96 |
*/
|
97 |
protected ArrayList layerCollectionListeners = null; |
98 |
|
99 |
/**
|
100 |
* A synchronized list with the layers.
|
101 |
*/
|
102 |
protected List<FLayer> layers = null; |
103 |
|
104 |
protected MapContext fmap;
|
105 |
|
106 |
/**
|
107 |
* Useful for debug the problems during the implementation.
|
108 |
*/
|
109 |
private static final Logger logger = LoggerFactory.getLogger(FLayers.class); |
110 |
|
111 |
public FLayers() {
|
112 |
super();
|
113 |
layerCollectionListeners = new ArrayList(); |
114 |
layers = Collections.synchronizedList(new ArrayList()); |
115 |
} |
116 |
/*
|
117 |
* (non-Javadoc)
|
118 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#addLayerCollectionListener(com.iver.cit.gvsig.fmap.layers.LayerCollectionListener)
|
119 |
*/
|
120 |
|
121 |
@Override
|
122 |
public void addLayerCollectionListener(LayerCollectionListener listener) { |
123 |
if (!layerCollectionListeners.contains(listener)) {
|
124 |
layerCollectionListeners.add(listener); |
125 |
} |
126 |
} |
127 |
|
128 |
/*
|
129 |
* (non-Javadoc)
|
130 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#setAllVisibles(boolean)
|
131 |
*/
|
132 |
@Override
|
133 |
public void setAllVisibles(boolean visible) { |
134 |
FLayer lyr; |
135 |
|
136 |
for (int i = 0; i < layers.size(); i++) { |
137 |
lyr = ((FLayer) layers.get(i)); |
138 |
lyr.setVisible(visible); |
139 |
|
140 |
if (lyr instanceof LayerCollection) { |
141 |
((LayerCollection) lyr).setAllVisibles(visible); |
142 |
} |
143 |
} |
144 |
} |
145 |
|
146 |
/*
|
147 |
* (non-Javadoc)
|
148 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayerCollectionListener(com.iver.cit.gvsig.fmap.layers.LayerCollectionListener)
|
149 |
*/
|
150 |
@Override
|
151 |
public void removeLayerCollectionListener(LayerCollectionListener listener) { |
152 |
layerCollectionListeners.remove(listener); |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Adds a layer on an specified position in this node.
|
157 |
*
|
158 |
* @param pos position in the inner list where the layer will be added
|
159 |
* @param layer a layer
|
160 |
*/
|
161 |
private void doAddLayer(int pos, FLayer layer) { |
162 |
layers.add(pos, layer); |
163 |
ToolsLocator.getDisposableManager().bind(layer); |
164 |
layer.setParentLayer(this);
|
165 |
IProjection layerProj = layer.getProjection(); |
166 |
if (layerProj != null && fmap != null) { |
167 |
IProjection mapContextProj = fmap.getProjection(); |
168 |
// TODO REVISAR ESTO !!!!
|
169 |
// Esta condici?n puede que no fuese exacta para todos los casos
|
170 |
if (!layerProj.getAbrev().equals(mapContextProj.getAbrev())) {
|
171 |
ICoordTrans ct = layerProj.getCT(mapContextProj); |
172 |
layer.setCoordTrans(ct); |
173 |
} else {
|
174 |
layer.setCoordTrans(null);
|
175 |
} |
176 |
} |
177 |
this.updateDrawVersion();
|
178 |
} |
179 |
|
180 |
/*
|
181 |
* (non-Javadoc)
|
182 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#addLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
|
183 |
*/
|
184 |
@Override
|
185 |
public void addLayer(FLayer layer) { |
186 |
|
187 |
MapContext mco = this.getMapContext();
|
188 |
|
189 |
if (mco != null) { |
190 |
/*
|
191 |
* Get order manager from map context
|
192 |
*/
|
193 |
int position = mco.getOrderManager().getPosition(this, layer); |
194 |
addLayer(position, layer); |
195 |
} else {
|
196 |
/*
|
197 |
* This happens when FLayers object is not in a
|
198 |
* map context, so no order manager is available.
|
199 |
*/
|
200 |
addLayer(layers.size(), layer); |
201 |
} |
202 |
} |
203 |
|
204 |
public void addLayer(DataStore store) { |
205 |
FLayer layer; |
206 |
try {
|
207 |
layer = MapContextLocator.getMapContextManager().createLayer( |
208 |
store.getName(), |
209 |
store |
210 |
); |
211 |
|
212 |
} catch (LoadLayerException ex) {
|
213 |
throw new RuntimeException("Can't create layer from store.", ex); |
214 |
} |
215 |
this.addLayer(layer);
|
216 |
} |
217 |
|
218 |
/**
|
219 |
* Adds a layer in an specified position in this node.
|
220 |
*
|
221 |
* @param pos
|
222 |
* @param layer a layer
|
223 |
*/
|
224 |
public void addLayer(int pos, FLayer layer) { |
225 |
try {
|
226 |
if (layer instanceof FLayers) { |
227 |
FLayers layers = (FLayers) layer; |
228 |
if( fmap != null ) { |
229 |
fmap.addAsCollectionListener(layers); |
230 |
} |
231 |
} |
232 |
callLayerAdding(LayerCollectionEvent.createLayerAddingEvent(layer)); |
233 |
|
234 |
doAddLayer(pos, layer); |
235 |
|
236 |
callLayerAdded(LayerCollectionEvent.createLayerAddedEvent(layer)); |
237 |
} catch (CancelationException e) {
|
238 |
logger.warn(e.getMessage()); |
239 |
} |
240 |
} |
241 |
|
242 |
/*
|
243 |
* (non-Javadoc)
|
244 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#moveTo(int, int)
|
245 |
*/
|
246 |
@Override
|
247 |
public void moveTo(int from, int to) throws CancelationException { |
248 |
int newfrom = layers.size() - from - 1; |
249 |
int newto = layers.size() - to - 1; |
250 |
if (newfrom < 0 || newfrom >= layers.size() || newto < 0 || newto >= layers.size()) { |
251 |
return;
|
252 |
} |
253 |
FLayer aux = (FLayer) layers.get(newfrom); |
254 |
callLayerMoving(LayerPositionEvent.createLayerMovingEvent(aux, newfrom, newto)); |
255 |
layers.remove(newfrom); |
256 |
layers.add(newto, aux); |
257 |
this.updateDrawVersion();
|
258 |
callLayerMoved(LayerPositionEvent.createLayerMovedEvent(aux, newfrom, newto)); |
259 |
} |
260 |
|
261 |
/**
|
262 |
* Removes an inner layer.
|
263 |
*
|
264 |
* @param lyr a layer
|
265 |
*/
|
266 |
private void doRemoveLayer(FLayer lyr) { |
267 |
layers.remove(lyr); |
268 |
lyr.dispose(); |
269 |
this.updateDrawVersion();
|
270 |
} |
271 |
|
272 |
/*
|
273 |
* (non-Javadoc)
|
274 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
|
275 |
*/
|
276 |
@Override
|
277 |
public void removeLayer(FLayer lyr) throws CancelationException { |
278 |
callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr)); |
279 |
doRemoveLayer(lyr); |
280 |
callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(lyr)); |
281 |
} |
282 |
|
283 |
/*
|
284 |
* (non-Javadoc)
|
285 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayer(int)
|
286 |
*/
|
287 |
@Override
|
288 |
public void removeLayer(int idLayer) { |
289 |
FLayer lyr = (FLayer) layers.get(idLayer); |
290 |
callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(lyr)); |
291 |
this.doRemoveLayer(lyr);
|
292 |
// layers.remove(idLayer);
|
293 |
// this.updateDrawVersion();
|
294 |
callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(lyr)); |
295 |
} |
296 |
|
297 |
/*
|
298 |
* (non-Javadoc)
|
299 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#removeLayer(java.lang.String)
|
300 |
*/
|
301 |
@Override
|
302 |
public void removeLayer(String layerName) { |
303 |
FLayer lyr; |
304 |
|
305 |
for (int i = 0; i < layers.size(); i++) { |
306 |
lyr = ((FLayer) layers.get(i)); |
307 |
|
308 |
if (lyr.getName().compareToIgnoreCase(layerName) == 0) { |
309 |
removeLayer(i); |
310 |
|
311 |
break;
|
312 |
} |
313 |
} |
314 |
} |
315 |
|
316 |
/**
|
317 |
* Replace a layer identified by its name, by another.
|
318 |
*
|
319 |
* @param layerName the name of the layer to be replaced
|
320 |
* @param layer the new layer
|
321 |
* @throws org.gvsig.fmap.mapcontext.exceptions.LoadLayerException
|
322 |
* @deprecated use {@link FLayers#replaceLayer(FLayer, FLayer)}
|
323 |
*/
|
324 |
public void replaceLayer(String layerName, FLayer layer) throws LoadLayerException { |
325 |
replaceLayer(getLayer(layerName), layer); |
326 |
} |
327 |
|
328 |
/**
|
329 |
* Replace a layer by another layer. It search recursively by all the
|
330 |
* ILayerCollection nodes
|
331 |
*
|
332 |
* @param layer the layer to be replaced
|
333 |
* @param newLayer the new layer
|
334 |
* @throws org.gvsig.fmap.mapcontext.exceptions.LoadLayerException
|
335 |
*/
|
336 |
public void replaceLayer(FLayer layer, FLayer newLayer) throws LoadLayerException { |
337 |
replaceLayer(this, layer, newLayer);
|
338 |
} |
339 |
|
340 |
/**
|
341 |
* Replace a layer by other layer. It search recursively by all the
|
342 |
* ILayerCollection nodes
|
343 |
*
|
344 |
* @param parentLayer the parent layer
|
345 |
* @param layer the layer to be replaced
|
346 |
* @param newLayer the new layer
|
347 |
* @throws LoadLayerException
|
348 |
*/
|
349 |
private void replaceLayer(FLayers parentLayer, FLayer layer, FLayer newLayer) throws LoadLayerException { |
350 |
FLayer lyr; |
351 |
for (int i = 0; i < parentLayer.getLayersCount(); i++) { |
352 |
lyr = ((FLayer) parentLayer.getLayer(i)); |
353 |
if (lyr.equals(layer)) {
|
354 |
parentLayer.removeLayer(i); |
355 |
parentLayer.addLayer(i, newLayer); |
356 |
break;
|
357 |
} |
358 |
if (lyr instanceof LayerCollection) { |
359 |
replaceLayer((FLayers) lyr, layer, newLayer); |
360 |
} |
361 |
} |
362 |
} |
363 |
|
364 |
/*
|
365 |
* (non-Javadoc)
|
366 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getVisibles()
|
367 |
*/
|
368 |
@Override
|
369 |
public FLayer[] getVisibles() { |
370 |
ArrayList array = new ArrayList(); |
371 |
LayersIterator iter = new LayersIterator(this) { |
372 |
@Override
|
373 |
public boolean evaluate(FLayer layer) { |
374 |
return layer.isVisible();
|
375 |
} |
376 |
|
377 |
}; |
378 |
|
379 |
while (iter.hasNext()) {
|
380 |
array.add(iter.nextLayer()); |
381 |
} |
382 |
|
383 |
return (FLayer[]) array.toArray(new FLayer[0]); |
384 |
} |
385 |
|
386 |
/*
|
387 |
* (non-Javadoc)
|
388 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getLayer(int)
|
389 |
*/
|
390 |
@Override
|
391 |
public FLayer getLayer(int index) { |
392 |
return (FLayer) layers.get(index);
|
393 |
} |
394 |
|
395 |
/*
|
396 |
* (non-Javadoc)
|
397 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getLayer(java.lang.String)
|
398 |
*/
|
399 |
@Override
|
400 |
public FLayer getLayer(String layerName) { |
401 |
for (int i = 0; i < layers.size(); i++) { |
402 |
FLayer lyr = ((FLayer) layers.get(i)); |
403 |
if (lyr.getName().compareToIgnoreCase(layerName) == 0) { |
404 |
return lyr;
|
405 |
} |
406 |
if (lyr instanceof FLayers) { |
407 |
List layerList = toPlainList(lyr);
|
408 |
for (int j = 0; j < layerList.size(); j++) { |
409 |
FLayer lyr2 = ((FLayer) layerList.get(j)); |
410 |
if (lyr2.getName().compareToIgnoreCase(layerName) == 0) { |
411 |
return lyr2;
|
412 |
} |
413 |
} |
414 |
} |
415 |
} |
416 |
return null; |
417 |
} |
418 |
|
419 |
private List toPlainList(FLayer layer) { |
420 |
return toPlainList(layer, new ArrayList()); |
421 |
} |
422 |
|
423 |
private List toPlainList(FLayer layer, List result) { |
424 |
if (layer instanceof FLayers) { |
425 |
FLayers layerGroup = (FLayers) layer; |
426 |
for (int i = 0; i < layerGroup.getLayersCount(); i++) { |
427 |
toPlainList(layerGroup.getLayer(i), result); |
428 |
} |
429 |
} else {
|
430 |
result.add(layer); |
431 |
} |
432 |
return result;
|
433 |
} |
434 |
|
435 |
/*
|
436 |
* (non-Javadoc)
|
437 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getLayersCount()
|
438 |
*/
|
439 |
@Override
|
440 |
public int getLayersCount() { |
441 |
return layers.size();
|
442 |
} |
443 |
|
444 |
/*
|
445 |
* (non-Javadoc)
|
446 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.utiles.swing.threads.Cancellable, double)
|
447 |
*/
|
448 |
@Override
|
449 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
450 |
Cancellable cancel, double scale) throws ReadException { |
451 |
// FIXME Arreglar este error
|
452 |
throw new RuntimeException("Esto no deberia de llamarse"); |
453 |
} |
454 |
|
455 |
/*
|
456 |
* (non-Javadoc)
|
457 |
*
|
458 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
459 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
460 |
* com.iver.utiles.swing.threads.Cancellable, double,
|
461 |
* javax.print.attribute.PrintAttributes)
|
462 |
*/
|
463 |
@Override
|
464 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
465 |
double scale, PrintAttributes properties)
|
466 |
throws ReadException {
|
467 |
throw new RuntimeException("No deberia pasar por aqui"); |
468 |
} |
469 |
|
470 |
public void print_old(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
471 |
double scale, PrintAttributes properties)
|
472 |
throws ReadException {
|
473 |
this.print_old(g, viewPort, cancel, scale, properties, null); |
474 |
} |
475 |
|
476 |
/**
|
477 |
* <p>
|
478 |
* Checks all layers (each one as a sub-node of this node <i>collection of
|
479 |
* layers</i>) of this collection and draws their requested properties. If a
|
480 |
* node is a group of layers (<code>ComposedLayer</code>), executes it's
|
481 |
* drawn.</p>
|
482 |
*
|
483 |
* <p>
|
484 |
* All nodes which could group with the composed layer <code>group</code>,
|
485 |
* will be drawn together. And once the <code>
|
486 |
* group</code> is drawn, will be set to <code>null</code> if hasn't a
|
487 |
* parent layer.</p>
|
488 |
*
|
489 |
* <p>
|
490 |
* The particular implementation depends on the kind of each layer and
|
491 |
* composed layer. And this process can be cancelled at any time by the
|
492 |
* shared object <code>cancel</code>.</p>
|
493 |
*
|
494 |
* <p>
|
495 |
* According the print quality, labels will be printed in different
|
496 |
* resolution:
|
497 |
* <ul>
|
498 |
* <li><b>PrintQuality.DRAFT</b>: 72 dpi (dots per inch).</li>
|
499 |
* <li><b>PrintQuality.NORMAL</b>: 300 dpi (dots per inch).</li>
|
500 |
* <li><b>PrintQuality.HIGH</b>: 600 dpi (dots per inch).</li>
|
501 |
* </ul>
|
502 |
* </p>
|
503 |
*
|
504 |
* @param g for rendering 2-dimensional shapes, text and images on the
|
505 |
* Java(tm) platform
|
506 |
* @param viewPort the information for drawing the layers
|
507 |
* @param cancel shared object that determines if this layer can continue
|
508 |
* being drawn
|
509 |
* @param scale the scale of the view. Must be between
|
510 |
* {@linkplain FLayer#getMinScale()} and {@linkplain FLayer#getMaxScale()}.
|
511 |
* @param properties properties that will be print
|
512 |
* @param group a composed layer pending to paint; if this parameter is
|
513 |
* <code>null</code>, the composed layer
|
514 |
*
|
515 |
* @return <code>null</code> if the layers in <code>group</code> had been
|
516 |
* drawn or were <code>null</code>; otherwise, the <code>group</code>
|
517 |
* @throws org.gvsig.fmap.dal.exception.ReadException
|
518 |
*
|
519 |
* @see FLayer#print(Graphics2D, ViewPort, Cancellable, double,
|
520 |
* PrintAttributes)
|
521 |
*/
|
522 |
public ComposedLayer print_old(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintAttributes properties, ComposedLayer group) |
523 |
throws ReadException {
|
524 |
double dpi = 72; |
525 |
|
526 |
int resolution = properties.getPrintQuality();
|
527 |
if (resolution == PrintAttributes.PRINT_QUALITY_NORMAL) {
|
528 |
dpi = 300;
|
529 |
} else if (resolution == PrintAttributes.PRINT_QUALITY_HIGH) { |
530 |
dpi = 600;
|
531 |
} else if (resolution == PrintAttributes.PRINT_QUALITY_DRAFT) { |
532 |
dpi = 72;
|
533 |
} |
534 |
|
535 |
// TODO: A la hora de imprimir, isWithinScale falla, porque est?
|
536 |
// calculando la escala en pantalla, no para el layout.
|
537 |
// Revisar esto.
|
538 |
// TODO: We have to check when we have to call the drawLabels method when exists a ComposedLayer group.
|
539 |
for (int i = 0; i < layers.size(); i++) { |
540 |
FLayer lyr = (FLayer) layers.get(i); |
541 |
if (!lyr.isVisible() || !lyr.isWithinScale(scale)) {
|
542 |
continue;
|
543 |
} |
544 |
|
545 |
try {
|
546 |
|
547 |
// Checks for draw group (ComposedLayer)
|
548 |
if (group != null) { |
549 |
if (lyr instanceof FLayers) { |
550 |
group = ((FLayers) lyr).print_old(g, viewPort, cancel, scale, properties, group); |
551 |
} else {
|
552 |
// If layer can be added to the group, does it
|
553 |
if (lyr instanceof ILabelable |
554 |
&& ((ILabelable) lyr).isLabeled() |
555 |
&& ((ILabelable) lyr).getLabelingStrategy() != null
|
556 |
&& ((ILabelable) lyr).getLabelingStrategy().shouldDrawLabels(scale)) { |
557 |
group.add(lyr); |
558 |
} else {
|
559 |
// draw the 'pending to draw' layer group
|
560 |
group.print(g, viewPort, cancel, scale, properties); |
561 |
|
562 |
// gets a new group instance
|
563 |
if (lyr instanceof ILabelable |
564 |
&& ((ILabelable) lyr).isLabeled() |
565 |
&& ((ILabelable) lyr).getLabelingStrategy() != null
|
566 |
&& ((ILabelable) lyr).getLabelingStrategy().shouldDrawLabels(scale)) { |
567 |
group = lyr.newComposedLayer(); |
568 |
} else {
|
569 |
group = null;
|
570 |
} |
571 |
// if layer hasn't group, draws it inmediately
|
572 |
if (group == null) { |
573 |
if (lyr instanceof FLayers) { |
574 |
group = ((FLayers) lyr).print_old(g, viewPort, cancel, scale, properties, group); |
575 |
} else {
|
576 |
lyr.print(g, viewPort, cancel, scale, properties); |
577 |
if (lyr instanceof ILabelable |
578 |
&& ((ILabelable) lyr).isLabeled() |
579 |
&& ((ILabelable) lyr).getLabelingStrategy() != null
|
580 |
&& ((ILabelable) lyr).getLabelingStrategy().shouldDrawLabels(scale)) { |
581 |
ILabelable lLayer = (ILabelable) lyr; |
582 |
lLayer.drawLabels(null, g, viewPort, cancel, scale, dpi);
|
583 |
} |
584 |
} |
585 |
} else {
|
586 |
// add the layer to the group
|
587 |
group.setMapContext(fmap); |
588 |
group.add(lyr); |
589 |
|
590 |
} |
591 |
|
592 |
} |
593 |
} |
594 |
} else {
|
595 |
// gets a new group instance
|
596 |
group = lyr.newComposedLayer(); |
597 |
// if layer hasn't group, draws it inmediately
|
598 |
if (group == null) { |
599 |
if (lyr instanceof FLayers) { |
600 |
group = ((FLayers) lyr).print_old(g, viewPort, cancel, scale, properties, group); |
601 |
} else {
|
602 |
lyr.print(g, viewPort, cancel, scale, properties); |
603 |
if (lyr instanceof ILabelable && ((ILabelable) lyr).isLabeled()) { |
604 |
ILabelable lLayer = (ILabelable) lyr; |
605 |
|
606 |
lLayer.drawLabels(null, g, viewPort, cancel, scale, dpi);
|
607 |
} |
608 |
} |
609 |
} else {
|
610 |
// add the layer to the group
|
611 |
group.setMapContext(fmap); |
612 |
group.add(lyr); |
613 |
|
614 |
} |
615 |
} |
616 |
|
617 |
} catch (Exception e) { |
618 |
String mesg = Messages.getString("error_printing_layer") + " " + lyr.getName() + ": " + e.getMessage(); |
619 |
if( fmap!=null ) { |
620 |
fmap.addLayerError(mesg); |
621 |
} |
622 |
logger.error(mesg, e); |
623 |
} |
624 |
|
625 |
} |
626 |
|
627 |
if (group != null && this.getParentLayer() == null) { |
628 |
//si tenemos un grupo pendiente de pintar, pintamos
|
629 |
group.print(g, viewPort, cancel, scale, properties); |
630 |
group = null;
|
631 |
|
632 |
} |
633 |
return group;
|
634 |
} |
635 |
|
636 |
/*
|
637 |
* (non-Javadoc)
|
638 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
639 |
*/
|
640 |
@Override
|
641 |
public Envelope getFullEnvelope() {
|
642 |
Envelope rAux = null;
|
643 |
boolean first = true; |
644 |
|
645 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
646 |
FLayer capa = (FLayer) iter.next(); |
647 |
try {
|
648 |
if (first) {
|
649 |
rAux = (Envelope) capa.getFullEnvelope().clone(); |
650 |
first = false;
|
651 |
} else {
|
652 |
rAux.add(capa.getFullEnvelope()); |
653 |
} |
654 |
} catch (Exception e) { |
655 |
logger.warn("Can't calculate the envelope of the layer group '"+this.getName()+"'.",e); |
656 |
} |
657 |
} |
658 |
|
659 |
return rAux;
|
660 |
} |
661 |
|
662 |
/**
|
663 |
* Notifies all listeners associated to this collection of layers, that
|
664 |
* another layer is going to be added or replaced in the internal list of
|
665 |
* layers.
|
666 |
*
|
667 |
* @param event a layer collection event with the new layer
|
668 |
*/
|
669 |
protected void callLayerAdding(LayerCollectionEvent event) |
670 |
throws CancelationException {
|
671 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
672 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
673 |
((LayerCollectionListener) iter.next()).layerAdding(event); |
674 |
} |
675 |
} |
676 |
|
677 |
/**
|
678 |
* Notifies all listeners associated to this collection of layers, that a
|
679 |
* layer is going to be removed from the internal list of layers.
|
680 |
*
|
681 |
* @param event a layer collection event with the layer being removed
|
682 |
*
|
683 |
* @throws CancelationException any exception produced during the
|
684 |
* cancellation of the driver.
|
685 |
*/
|
686 |
protected void callLayerRemoving(LayerCollectionEvent event) |
687 |
throws CancelationException {
|
688 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
689 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
690 |
((LayerCollectionListener) iter.next()).layerRemoving(event); |
691 |
} |
692 |
} |
693 |
|
694 |
/**
|
695 |
* Notifies all listeners associated to this collection of layers, that a
|
696 |
* layer is going to be moved in the internal list of layers.
|
697 |
*
|
698 |
* @param event a layer collection event with the layer being moved, and the
|
699 |
* initial and final positions
|
700 |
*
|
701 |
* @throws CancelationException any exception produced during the
|
702 |
* cancellation of the driver.
|
703 |
*/
|
704 |
protected void callLayerMoving(LayerPositionEvent event) |
705 |
throws CancelationException {
|
706 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
707 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
708 |
((LayerCollectionListener) iter.next()).layerMoving(event); |
709 |
} |
710 |
} |
711 |
|
712 |
/**
|
713 |
* Notifies all listeners associated to this collection of layers, that
|
714 |
* another layer has been added or replaced in the internal list of layers.
|
715 |
*
|
716 |
* @param event a layer collection event with the new layer
|
717 |
*/
|
718 |
protected void callLayerAdded(LayerCollectionEvent event) { |
719 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
720 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
721 |
((LayerCollectionListener) iter.next()).layerAdded(event); |
722 |
} |
723 |
} |
724 |
|
725 |
/**
|
726 |
* Notifies all listeners associated to this collection of layers, that
|
727 |
* another layer has been removed from the internal list of layers.
|
728 |
*
|
729 |
* @param event a layer collection event with the layer removed
|
730 |
*/
|
731 |
protected void callLayerRemoved(LayerCollectionEvent event) { |
732 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
733 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
734 |
((LayerCollectionListener) iter.next()).layerRemoved(event); |
735 |
} |
736 |
} |
737 |
|
738 |
/**
|
739 |
* Notifies all listeners associated to this collection of layers, that
|
740 |
* another layer has been moved in the internal list of layers.
|
741 |
*
|
742 |
* @param event a layer collection event with the layer moved, and the initial
|
743 |
* and final positions
|
744 |
*/
|
745 |
protected void callLayerMoved(LayerPositionEvent event) { |
746 |
ArrayList aux = (ArrayList) layerCollectionListeners.clone(); |
747 |
for (Iterator iter = aux.iterator(); iter.hasNext();) { |
748 |
((LayerCollectionListener) iter.next()).layerMoved(event); |
749 |
} |
750 |
} |
751 |
|
752 |
@Override
|
753 |
public void saveToState(PersistentState state) throws PersistenceException { |
754 |
|
755 |
super.saveToState(state);
|
756 |
|
757 |
state.set("mapContext", fmap);
|
758 |
|
759 |
List layersToSave = new ArrayList(); |
760 |
Iterator iter = this.layers.iterator(); |
761 |
while (iter.hasNext()) {
|
762 |
FLayer layer = (FLayer) iter.next(); |
763 |
if (!layer.isTemporary()) {
|
764 |
layersToSave.add(layer); |
765 |
} |
766 |
} |
767 |
state.set("layers", layersToSave);
|
768 |
} |
769 |
|
770 |
@Override
|
771 |
public void loadFromState(PersistentState state) throws PersistenceException { |
772 |
|
773 |
super.loadFromState(state);
|
774 |
|
775 |
setMapContext((MapContext) state.get("mapContext"));
|
776 |
Iterator iter = state.getIterator("layers"); |
777 |
while (iter.hasNext()) {
|
778 |
FLayer item = (FLayer) iter.next(); |
779 |
// Cuando falla la carga de la capa desde la persistencia, puede
|
780 |
// haberse perdido quien es el parent. Asi que lo asignamos aqui
|
781 |
// por si acaso.
|
782 |
item.setParentLayer(this);
|
783 |
layers.add(item); |
784 |
} |
785 |
} |
786 |
|
787 |
/*
|
788 |
* (non-Javadoc)
|
789 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMapContext()
|
790 |
*/
|
791 |
@Override
|
792 |
public MapContext getMapContext() {
|
793 |
return fmap;
|
794 |
} |
795 |
|
796 |
/*
|
797 |
* (non-Javadoc)
|
798 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#setAllActives(boolean)
|
799 |
*/
|
800 |
@Override
|
801 |
public void setAllActives(boolean active) { |
802 |
FLayer lyr; |
803 |
|
804 |
for (int i = 0; i < layers.size(); i++) { |
805 |
lyr = ((FLayer) layers.get(i)); |
806 |
lyr.setActive(active); |
807 |
|
808 |
if (lyr instanceof LayerCollection) { |
809 |
((LayerCollection) lyr).setAllActives(active); |
810 |
} |
811 |
} |
812 |
} |
813 |
|
814 |
/*
|
815 |
* (non-Javadoc)
|
816 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getActives()
|
817 |
*/
|
818 |
@Override
|
819 |
public FLayer[] getActives() { |
820 |
List ret = new ArrayList(); |
821 |
LayersIterator it = new LayersIterator(this) { |
822 |
|
823 |
@Override
|
824 |
public boolean evaluate(FLayer layer) { |
825 |
return layer.isActive();
|
826 |
} |
827 |
|
828 |
}; |
829 |
|
830 |
while (it.hasNext()) {
|
831 |
ret.add(it.next()); |
832 |
} |
833 |
return (FLayer[]) ret.toArray(new FLayer[0]); |
834 |
} |
835 |
|
836 |
/*
|
837 |
* (non-Javadoc)
|
838 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMinScale()
|
839 |
*/
|
840 |
@Override
|
841 |
public double getMinScale() { |
842 |
return -1; // La visibilidad o no la controla cada capa |
843 |
// dentro de una colecci?n
|
844 |
} |
845 |
/*
|
846 |
* (non-Javadoc)
|
847 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMaxScale()
|
848 |
*/
|
849 |
|
850 |
@Override
|
851 |
public double getMaxScale() { |
852 |
return -1; |
853 |
} |
854 |
/*
|
855 |
* (non-Javadoc)
|
856 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setMinScale(double)
|
857 |
*/
|
858 |
|
859 |
@Override
|
860 |
public void setMinScale(double minScale) { |
861 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
862 |
FLayer lyr = (FLayer) iter.next(); |
863 |
lyr.setMinScale(minScale); |
864 |
} |
865 |
} |
866 |
/*
|
867 |
* (non-Javadoc)
|
868 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setMaxScale(double)
|
869 |
*/
|
870 |
|
871 |
@Override
|
872 |
public void setMaxScale(double maxScale) { |
873 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
874 |
FLayer lyr = (FLayer) iter.next(); |
875 |
lyr.setMinScale(maxScale); |
876 |
} |
877 |
} |
878 |
/*
|
879 |
* (non-Javadoc)
|
880 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setActive(boolean)
|
881 |
*/
|
882 |
|
883 |
@Override
|
884 |
public void setActive(boolean b) { |
885 |
super.setActive(b);
|
886 |
for (int i = 0; i < layers.size(); i++) { |
887 |
((FLayer) layers.get(i)).setActive(b); |
888 |
} |
889 |
} |
890 |
/* (non-Javadoc)
|
891 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#addLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
|
892 |
*/
|
893 |
|
894 |
@Override
|
895 |
public boolean addLayerListener(LayerListener o) { |
896 |
for (int i = 0; i < layers.size(); i++) { |
897 |
((FLayer) layers.get(i)).addLayerListener(o); |
898 |
} |
899 |
return true; |
900 |
} |
901 |
|
902 |
@Override
|
903 |
public DynObjectSet getInfo(Point p, double tolerance, |
904 |
Cancellable cancel) throws LoadLayerException, DataException {
|
905 |
return getInfo(this.getMapContext().getViewPort().convertToMapPoint(p), tolerance); |
906 |
} |
907 |
|
908 |
@Override
|
909 |
public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel, |
910 |
boolean fast) throws LoadLayerException, DataException { |
911 |
return getInfo(this.getMapContext().getViewPort().convertToMapPoint(p), tolerance); |
912 |
} |
913 |
|
914 |
@Override
|
915 |
public DynObjectSet getInfo(org.gvsig.fmap.geom.primitive.Point p,
|
916 |
double tolerance) throws LoadLayerException, DataException { |
917 |
int i;
|
918 |
FLayer layer; |
919 |
List res = new ArrayList(); |
920 |
for (i = 0; i < this.layers.size(); i++) { |
921 |
layer = (FLayer) layers.get(i); |
922 |
if (layer instanceof InfoByPoint) { |
923 |
InfoByPoint queryable_layer = (InfoByPoint) layer; |
924 |
res.add(queryable_layer.getInfo(p, tolerance)); |
925 |
} |
926 |
} |
927 |
DynObjectSet[] innerSets
|
928 |
= (DynObjectSet[]) res.toArray(new DynObjectSet[res.size()]); |
929 |
return new MultiDynObjectSet(innerSets); |
930 |
} |
931 |
|
932 |
/*
|
933 |
* (non-Javadoc)
|
934 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getTocImageIcon()
|
935 |
*/
|
936 |
@Override
|
937 |
public String getTocImageIcon() { |
938 |
return "layer-icon-group"; |
939 |
} |
940 |
|
941 |
/**
|
942 |
* <p>
|
943 |
* Sets the <code>MapContext</code> that contains this layer node.</p>
|
944 |
*
|
945 |
* @param mapContext the <code>MapContext</code> that contains this layer
|
946 |
* node
|
947 |
*/
|
948 |
public void setMapContext(MapContext mapContext) { |
949 |
this.fmap = mapContext;
|
950 |
} |
951 |
|
952 |
@Override
|
953 |
public void accept(Visitor visitor) throws BaseException { |
954 |
for (int i = 0; i < this.getLayersCount(); i++) { |
955 |
FLayer layer = this.getLayer(i);
|
956 |
try {
|
957 |
if (layer instanceof LayersVisitable) { |
958 |
((LayersVisitable) layer).accept(visitor); |
959 |
} else {
|
960 |
visitor.visit(layer); |
961 |
} |
962 |
} catch (VisitCanceledException ex) {
|
963 |
break;
|
964 |
} |
965 |
} |
966 |
} |
967 |
|
968 |
@Override
|
969 |
public void accept(LayersVisitor visitor) throws BaseException { |
970 |
for (int i = 0; i < this.getLayersCount(); i++) { |
971 |
FLayer layer = this.getLayer(i);
|
972 |
if (layer instanceof LayersVisitable) { |
973 |
((LayersVisitable) layer).accept(visitor); |
974 |
} else {
|
975 |
visitor.visit(layer); |
976 |
} |
977 |
} |
978 |
} |
979 |
|
980 |
/*
|
981 |
* (non-Javadoc)
|
982 |
*
|
983 |
* @see org.gvsig.metadata.Metadata#getMetadataID()
|
984 |
*/
|
985 |
@Override
|
986 |
public Object getMetadataID() throws MetadataException { |
987 |
StringBuilder strb = new StringBuilder(); |
988 |
strb.append("Layers(");
|
989 |
strb.append(this.getName());
|
990 |
strb.append("):{");
|
991 |
Iterator iter = this.layers.iterator(); |
992 |
while (iter.hasNext()) {
|
993 |
strb.append(((FLayer) iter.next()).getMetadataID()); |
994 |
strb.append(",");
|
995 |
} |
996 |
strb.append("}");
|
997 |
return strb.toString();
|
998 |
|
999 |
} |
1000 |
|
1001 |
/*
|
1002 |
* (non-Javadoc)
|
1003 |
*
|
1004 |
* @see org.gvsig.metadata.Metadata#getMetadataChildren()
|
1005 |
*/
|
1006 |
@Override
|
1007 |
public Set getMetadataChildren() { |
1008 |
Set ret = new TreeSet(); |
1009 |
Iterator iter = this.layers.iterator(); |
1010 |
while (iter.hasNext()) {
|
1011 |
ret.add(iter.next()); |
1012 |
} |
1013 |
return ret;
|
1014 |
} |
1015 |
|
1016 |
/*
|
1017 |
* (non-Javadoc)
|
1018 |
*
|
1019 |
* @see org.gvsig.metadata.Metadata#getMetadataName()
|
1020 |
*/
|
1021 |
@Override
|
1022 |
public String getMetadataName() throws MetadataException { |
1023 |
StringBuilder strb = new StringBuilder(); |
1024 |
strb.append("Layer Group '");
|
1025 |
strb.append(this.getName());
|
1026 |
strb.append("': {");
|
1027 |
Iterator iter = this.layers.iterator(); |
1028 |
while (iter.hasNext()) {
|
1029 |
strb.append(((FLayer) iter.next()).getMetadataName()); |
1030 |
strb.append(",");
|
1031 |
} |
1032 |
strb.append("}");
|
1033 |
return strb.toString();
|
1034 |
} |
1035 |
|
1036 |
@Override
|
1037 |
public void beginDraw(Graphics2D g, ViewPort viewPort) { |
1038 |
if( fmap == null ) { |
1039 |
return;
|
1040 |
} |
1041 |
LayerDrawEvent beforeEvent = new LayerDrawEvent(this, g, viewPort, LayerDrawEvent.LAYER_BEFORE_DRAW); |
1042 |
fmap.fireLayerDrawingEvent(beforeEvent); |
1043 |
} |
1044 |
|
1045 |
@Override
|
1046 |
public void endDraw(Graphics2D g, ViewPort viewPort) { |
1047 |
if( fmap == null ) { |
1048 |
return;
|
1049 |
} |
1050 |
LayerDrawEvent afterEvent = new LayerDrawEvent(this, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW); |
1051 |
fmap.fireLayerDrawingEvent(afterEvent); |
1052 |
} |
1053 |
|
1054 |
public static class RegisterPersistence implements Callable { |
1055 |
|
1056 |
@Override
|
1057 |
public Object call() { |
1058 |
|
1059 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
1060 |
DynStruct definition = manager.addDefinition( |
1061 |
FLayers.class, |
1062 |
"FLayers",
|
1063 |
"FLayers Persistence definition",
|
1064 |
null,
|
1065 |
null
|
1066 |
); |
1067 |
definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, "FLyrDefault");
|
1068 |
|
1069 |
definition.addDynFieldObject("mapContext").setClassOfValue(MapContext.class).setMandatory(true); |
1070 |
definition.addDynFieldList("layers").setClassOfItems(FLayer.class).setMandatory(true); |
1071 |
|
1072 |
return Boolean.TRUE; |
1073 |
} |
1074 |
} |
1075 |
|
1076 |
@Override
|
1077 |
protected void doDispose() throws BaseException { |
1078 |
if (layers != null) { |
1079 |
for (int i = 0; i < layers.size(); i++) { |
1080 |
dispose((Disposable) layers.get(i)); |
1081 |
} |
1082 |
} |
1083 |
} |
1084 |
|
1085 |
@Override
|
1086 |
public void move(FLayer layer, LayerCollection group, int where, FLayer adjoiningLayer) throws LayerNotFoundInCollectionException { |
1087 |
|
1088 |
callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(layer)); |
1089 |
group.addLayer(layer, where, adjoiningLayer); |
1090 |
removeLayer(layer); |
1091 |
this.updateDrawVersion();
|
1092 |
callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(layer)); |
1093 |
|
1094 |
} |
1095 |
|
1096 |
public void join(FLayer layer, LayerCollection group) { |
1097 |
try {
|
1098 |
layers.remove(layer); |
1099 |
group.addLayer(layer, END, null);
|
1100 |
this.updateDrawVersion();
|
1101 |
} catch (LayerNotFoundInCollectionException e) {
|
1102 |
throw new MapContextRuntimeException(e); |
1103 |
} |
1104 |
} |
1105 |
|
1106 |
@Override
|
1107 |
public void move(FLayer layer, LayerCollection group) { |
1108 |
try {
|
1109 |
move(layer, group, END, null);
|
1110 |
} catch (LayerNotFoundInCollectionException e) {
|
1111 |
throw new MapContextRuntimeException(e); |
1112 |
} |
1113 |
} |
1114 |
|
1115 |
@Override
|
1116 |
public void addLayer(FLayer layer, int where, FLayer adjoiningLayer) |
1117 |
throws LayerNotFoundInCollectionException {
|
1118 |
|
1119 |
switch (where) {
|
1120 |
case BEGIN:
|
1121 |
addLayer(0, layer);
|
1122 |
break;
|
1123 |
case BEFORE:
|
1124 |
if (adjoiningLayer != null) { |
1125 |
if (this.layers.contains(adjoiningLayer)) { |
1126 |
for (int i = 0; i < this.getLayersCount(); i++) { |
1127 |
if (adjoiningLayer == this.getLayer(i)) { |
1128 |
addLayer(i, layer); |
1129 |
break;
|
1130 |
} |
1131 |
} |
1132 |
} else {
|
1133 |
throw new LayerNotFoundInCollectionException(adjoiningLayer, this); |
1134 |
} |
1135 |
} else {
|
1136 |
addLayer(0, layer);
|
1137 |
} |
1138 |
break;
|
1139 |
case AFTER:
|
1140 |
if (adjoiningLayer != null) { |
1141 |
if (this.layers.contains(adjoiningLayer)) { |
1142 |
for (int i = 0; i < this.getLayersCount(); i++) { |
1143 |
if (adjoiningLayer == this.getLayer(i)) { |
1144 |
addLayer(i + 1, layer);
|
1145 |
break;
|
1146 |
} |
1147 |
} |
1148 |
} else {
|
1149 |
throw new LayerNotFoundInCollectionException(adjoiningLayer, this); |
1150 |
} |
1151 |
} else {
|
1152 |
this.addLayer(layer);
|
1153 |
} |
1154 |
break;
|
1155 |
default: // By default add layer an the end of the collection |
1156 |
this.addLayer(layer);
|
1157 |
break;
|
1158 |
} |
1159 |
|
1160 |
} |
1161 |
|
1162 |
public FLayer getFirstActiveLayer() {
|
1163 |
LayersIterator it = new LayersIterator(this) { |
1164 |
@Override
|
1165 |
public boolean evaluate(FLayer layer) { |
1166 |
return layer.isActive();
|
1167 |
} |
1168 |
}; |
1169 |
if( it.hasNext() ) {
|
1170 |
return (FLayer) it.next();
|
1171 |
} |
1172 |
return null; |
1173 |
} |
1174 |
|
1175 |
public FLyrVect getFirstActiveVectorLayer() {
|
1176 |
LayersIterator it = new LayersIterator(this) { |
1177 |
@Override
|
1178 |
public boolean evaluate(FLayer layer) { |
1179 |
return layer.isActive() && layer instanceof FLyrVect; |
1180 |
} |
1181 |
}; |
1182 |
if( it.hasNext() ) {
|
1183 |
return (FLyrVect) it.next();
|
1184 |
} |
1185 |
return null; |
1186 |
} |
1187 |
|
1188 |
@Override
|
1189 |
public Iterator<FLayer> iterator() { |
1190 |
return this.layers.iterator(); |
1191 |
} |
1192 |
|
1193 |
public Iterator<FLayer> deepiterator() { |
1194 |
List layers = toPlainList(this); |
1195 |
return layers.iterator();
|
1196 |
} |
1197 |
|
1198 |
@Override
|
1199 |
public int size() { |
1200 |
return this.layers.size(); |
1201 |
} |
1202 |
|
1203 |
@Override
|
1204 |
public FLayer get(int index) { |
1205 |
return this.layers.get(index); |
1206 |
} |
1207 |
|
1208 |
@Override
|
1209 |
public boolean isEmpty() { |
1210 |
return this.layers.isEmpty(); |
1211 |
} |
1212 |
|
1213 |
@Override
|
1214 |
public boolean contains(Object o) { |
1215 |
return this.layers.contains(o); |
1216 |
} |
1217 |
|
1218 |
@Override
|
1219 |
public Object[] toArray() { |
1220 |
return this.layers.toArray(); |
1221 |
} |
1222 |
|
1223 |
@Override
|
1224 |
public Object[] toArray(Object[] ts) { |
1225 |
return this.layers.toArray(ts); |
1226 |
} |
1227 |
|
1228 |
@Override
|
1229 |
public boolean add(FLayer e) { |
1230 |
this.addLayer(e);
|
1231 |
return true; |
1232 |
} |
1233 |
|
1234 |
@Override
|
1235 |
public boolean remove(Object o) { |
1236 |
this.removeLayer((FLayer) o);
|
1237 |
return true; |
1238 |
} |
1239 |
|
1240 |
@Override
|
1241 |
public boolean containsAll(Collection clctn) { |
1242 |
return this.layers.containsAll(clctn); |
1243 |
} |
1244 |
|
1245 |
@Override
|
1246 |
public void add(int i, FLayer e) { |
1247 |
this.addLayer(i, (FLayer) e);
|
1248 |
} |
1249 |
|
1250 |
@Override
|
1251 |
public FLayer remove(int i) { |
1252 |
FLayer o = this.getLayer(i);
|
1253 |
this.removeLayer(i);
|
1254 |
return o;
|
1255 |
} |
1256 |
|
1257 |
@Override
|
1258 |
public int indexOf(Object o) { |
1259 |
return this.layers.indexOf(o); |
1260 |
} |
1261 |
|
1262 |
@Override
|
1263 |
public int lastIndexOf(Object o) { |
1264 |
return this.layers.lastIndexOf(o); |
1265 |
} |
1266 |
|
1267 |
@Override
|
1268 |
public ListIterator listIterator() { |
1269 |
return this.layers.listIterator(); |
1270 |
} |
1271 |
|
1272 |
@Override
|
1273 |
public ListIterator listIterator(int i) { |
1274 |
return this.layers.listIterator(i); |
1275 |
} |
1276 |
|
1277 |
@Override
|
1278 |
public List subList(int i, int i1) { |
1279 |
return this.layers.subList(i, i1); |
1280 |
} |
1281 |
|
1282 |
@Override
|
1283 |
public boolean addAll(Collection clctn) { |
1284 |
Iterator it = clctn.iterator();
|
1285 |
while( it.hasNext() ) {
|
1286 |
this.add((FLayer) it.next());
|
1287 |
} |
1288 |
return true; |
1289 |
} |
1290 |
|
1291 |
@Override
|
1292 |
public boolean addAll(int i, Collection clctn) { |
1293 |
Iterator it = clctn.iterator();
|
1294 |
while( it.hasNext() ) {
|
1295 |
this.add(i, (FLayer) it.next());
|
1296 |
} |
1297 |
return true; |
1298 |
} |
1299 |
|
1300 |
@Override
|
1301 |
public boolean removeAll(Collection clctn) { |
1302 |
Iterator it = clctn.iterator();
|
1303 |
while( it.hasNext() ) {
|
1304 |
this.remove((FLayer) it.next());
|
1305 |
} |
1306 |
return true; |
1307 |
} |
1308 |
|
1309 |
@Override
|
1310 |
public boolean retainAll(Collection clctn) { |
1311 |
Iterator it = this.layers.iterator(); |
1312 |
while( it.hasNext() ) {
|
1313 |
Object o = it.next();
|
1314 |
if( !clctn.contains(o) ) {
|
1315 |
this.remove((FLayer) o);
|
1316 |
} |
1317 |
} |
1318 |
return true; |
1319 |
} |
1320 |
|
1321 |
@Override
|
1322 |
public FLayer set(int i, FLayer e) { |
1323 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
1324 |
} |
1325 |
|
1326 |
} |