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