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 @ 43271
History | View | Annotate | Download (44.4 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 |
layers.add(item); |
780 |
} |
781 |
} |
782 |
|
783 |
/*
|
784 |
* (non-Javadoc)
|
785 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMapContext()
|
786 |
*/
|
787 |
@Override
|
788 |
public MapContext getMapContext() {
|
789 |
return fmap;
|
790 |
} |
791 |
|
792 |
/*
|
793 |
* (non-Javadoc)
|
794 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#setAllActives(boolean)
|
795 |
*/
|
796 |
@Override
|
797 |
public void setAllActives(boolean active) { |
798 |
FLayer lyr; |
799 |
|
800 |
for (int i = 0; i < layers.size(); i++) { |
801 |
lyr = ((FLayer) layers.get(i)); |
802 |
lyr.setActive(active); |
803 |
|
804 |
if (lyr instanceof LayerCollection) { |
805 |
((LayerCollection) lyr).setAllActives(active); |
806 |
} |
807 |
} |
808 |
} |
809 |
|
810 |
/*
|
811 |
* (non-Javadoc)
|
812 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection#getActives()
|
813 |
*/
|
814 |
@Override
|
815 |
public FLayer[] getActives() { |
816 |
List ret = new ArrayList(); |
817 |
LayersIterator it = new LayersIterator(this) { |
818 |
|
819 |
@Override
|
820 |
public boolean evaluate(FLayer layer) { |
821 |
return layer.isActive();
|
822 |
} |
823 |
|
824 |
}; |
825 |
|
826 |
while (it.hasNext()) {
|
827 |
ret.add(it.next()); |
828 |
} |
829 |
return (FLayer[]) ret.toArray(new FLayer[0]); |
830 |
} |
831 |
|
832 |
/*
|
833 |
* (non-Javadoc)
|
834 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMinScale()
|
835 |
*/
|
836 |
@Override
|
837 |
public double getMinScale() { |
838 |
return -1; // La visibilidad o no la controla cada capa |
839 |
// dentro de una colecci?n
|
840 |
} |
841 |
/*
|
842 |
* (non-Javadoc)
|
843 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getMaxScale()
|
844 |
*/
|
845 |
|
846 |
@Override
|
847 |
public double getMaxScale() { |
848 |
return -1; |
849 |
} |
850 |
/*
|
851 |
* (non-Javadoc)
|
852 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setMinScale(double)
|
853 |
*/
|
854 |
|
855 |
@Override
|
856 |
public void setMinScale(double minScale) { |
857 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
858 |
FLayer lyr = (FLayer) iter.next(); |
859 |
lyr.setMinScale(minScale); |
860 |
} |
861 |
} |
862 |
/*
|
863 |
* (non-Javadoc)
|
864 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setMaxScale(double)
|
865 |
*/
|
866 |
|
867 |
@Override
|
868 |
public void setMaxScale(double maxScale) { |
869 |
for (Iterator iter = layers.iterator(); iter.hasNext();) { |
870 |
FLayer lyr = (FLayer) iter.next(); |
871 |
lyr.setMinScale(maxScale); |
872 |
} |
873 |
} |
874 |
/*
|
875 |
* (non-Javadoc)
|
876 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setActive(boolean)
|
877 |
*/
|
878 |
|
879 |
@Override
|
880 |
public void setActive(boolean b) { |
881 |
super.setActive(b);
|
882 |
for (int i = 0; i < layers.size(); i++) { |
883 |
((FLayer) layers.get(i)).setActive(b); |
884 |
} |
885 |
} |
886 |
/* (non-Javadoc)
|
887 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#addLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
|
888 |
*/
|
889 |
|
890 |
@Override
|
891 |
public boolean addLayerListener(LayerListener o) { |
892 |
for (int i = 0; i < layers.size(); i++) { |
893 |
((FLayer) layers.get(i)).addLayerListener(o); |
894 |
} |
895 |
return true; |
896 |
} |
897 |
|
898 |
@Override
|
899 |
public DynObjectSet getInfo(Point p, double tolerance, |
900 |
Cancellable cancel) throws LoadLayerException, DataException {
|
901 |
return getInfo(this.getMapContext().getViewPort().convertToMapPoint(p), tolerance); |
902 |
} |
903 |
|
904 |
@Override
|
905 |
public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel, |
906 |
boolean fast) throws LoadLayerException, DataException { |
907 |
return getInfo(this.getMapContext().getViewPort().convertToMapPoint(p), tolerance); |
908 |
} |
909 |
|
910 |
@Override
|
911 |
public DynObjectSet getInfo(org.gvsig.fmap.geom.primitive.Point p,
|
912 |
double tolerance) throws LoadLayerException, DataException { |
913 |
int i;
|
914 |
FLayer layer; |
915 |
List res = new ArrayList(); |
916 |
for (i = 0; i < this.layers.size(); i++) { |
917 |
layer = (FLayer) layers.get(i); |
918 |
if (layer instanceof InfoByPoint) { |
919 |
InfoByPoint queryable_layer = (InfoByPoint) layer; |
920 |
res.add(queryable_layer.getInfo(p, tolerance)); |
921 |
} |
922 |
} |
923 |
DynObjectSet[] innerSets
|
924 |
= (DynObjectSet[]) res.toArray(new DynObjectSet[res.size()]); |
925 |
return new MultiDynObjectSet(innerSets); |
926 |
} |
927 |
|
928 |
/*
|
929 |
* (non-Javadoc)
|
930 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getTocImageIcon()
|
931 |
*/
|
932 |
@Override
|
933 |
public String getTocImageIcon() { |
934 |
return "layer-icon-group"; |
935 |
} |
936 |
|
937 |
/**
|
938 |
* <p>
|
939 |
* Sets the <code>MapContext</code> that contains this layer node.</p>
|
940 |
*
|
941 |
* @param mapContext the <code>MapContext</code> that contains this layer
|
942 |
* node
|
943 |
*/
|
944 |
public void setMapContext(MapContext mapContext) { |
945 |
this.fmap = mapContext;
|
946 |
} |
947 |
|
948 |
@Override
|
949 |
public void accept(Visitor visitor) throws BaseException { |
950 |
for (int i = 0; i < this.getLayersCount(); i++) { |
951 |
FLayer layer = this.getLayer(i);
|
952 |
try {
|
953 |
if (layer instanceof LayersVisitable) { |
954 |
((LayersVisitable) layer).accept(visitor); |
955 |
} else {
|
956 |
visitor.visit(layer); |
957 |
} |
958 |
} catch (VisitCanceledException ex) {
|
959 |
break;
|
960 |
} |
961 |
} |
962 |
} |
963 |
|
964 |
@Override
|
965 |
public void accept(LayersVisitor visitor) throws BaseException { |
966 |
for (int i = 0; i < this.getLayersCount(); i++) { |
967 |
FLayer layer = this.getLayer(i);
|
968 |
if (layer instanceof LayersVisitable) { |
969 |
((LayersVisitable) layer).accept(visitor); |
970 |
} else {
|
971 |
visitor.visit(layer); |
972 |
} |
973 |
} |
974 |
} |
975 |
|
976 |
/*
|
977 |
* (non-Javadoc)
|
978 |
*
|
979 |
* @see org.gvsig.metadata.Metadata#getMetadataID()
|
980 |
*/
|
981 |
@Override
|
982 |
public Object getMetadataID() throws MetadataException { |
983 |
StringBuilder strb = new StringBuilder(); |
984 |
strb.append("Layers(");
|
985 |
strb.append(this.getName());
|
986 |
strb.append("):{");
|
987 |
Iterator iter = this.layers.iterator(); |
988 |
while (iter.hasNext()) {
|
989 |
strb.append(((FLayer) iter.next()).getMetadataID()); |
990 |
strb.append(",");
|
991 |
} |
992 |
strb.append("}");
|
993 |
return strb.toString();
|
994 |
|
995 |
} |
996 |
|
997 |
/*
|
998 |
* (non-Javadoc)
|
999 |
*
|
1000 |
* @see org.gvsig.metadata.Metadata#getMetadataChildren()
|
1001 |
*/
|
1002 |
@Override
|
1003 |
public Set getMetadataChildren() { |
1004 |
Set ret = new TreeSet(); |
1005 |
Iterator iter = this.layers.iterator(); |
1006 |
while (iter.hasNext()) {
|
1007 |
ret.add(iter.next()); |
1008 |
} |
1009 |
return ret;
|
1010 |
} |
1011 |
|
1012 |
/*
|
1013 |
* (non-Javadoc)
|
1014 |
*
|
1015 |
* @see org.gvsig.metadata.Metadata#getMetadataName()
|
1016 |
*/
|
1017 |
@Override
|
1018 |
public String getMetadataName() throws MetadataException { |
1019 |
StringBuilder strb = new StringBuilder(); |
1020 |
strb.append("Layer Group '");
|
1021 |
strb.append(this.getName());
|
1022 |
strb.append("': {");
|
1023 |
Iterator iter = this.layers.iterator(); |
1024 |
while (iter.hasNext()) {
|
1025 |
strb.append(((FLayer) iter.next()).getMetadataName()); |
1026 |
strb.append(",");
|
1027 |
} |
1028 |
strb.append("}");
|
1029 |
return strb.toString();
|
1030 |
} |
1031 |
|
1032 |
@Override
|
1033 |
public void beginDraw(Graphics2D g, ViewPort viewPort) { |
1034 |
if( fmap == null ) { |
1035 |
return;
|
1036 |
} |
1037 |
LayerDrawEvent beforeEvent = new LayerDrawEvent(this, g, viewPort, LayerDrawEvent.LAYER_BEFORE_DRAW); |
1038 |
fmap.fireLayerDrawingEvent(beforeEvent); |
1039 |
} |
1040 |
|
1041 |
@Override
|
1042 |
public void endDraw(Graphics2D g, ViewPort viewPort) { |
1043 |
if( fmap == null ) { |
1044 |
return;
|
1045 |
} |
1046 |
LayerDrawEvent afterEvent = new LayerDrawEvent(this, g, viewPort, LayerDrawEvent.LAYER_AFTER_DRAW); |
1047 |
fmap.fireLayerDrawingEvent(afterEvent); |
1048 |
} |
1049 |
|
1050 |
public static class RegisterPersistence implements Callable { |
1051 |
|
1052 |
@Override
|
1053 |
public Object call() { |
1054 |
|
1055 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
1056 |
DynStruct definition = manager.addDefinition( |
1057 |
FLayers.class, |
1058 |
"FLayers",
|
1059 |
"FLayers Persistence definition",
|
1060 |
null,
|
1061 |
null
|
1062 |
); |
1063 |
definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, "FLyrDefault");
|
1064 |
|
1065 |
definition.addDynFieldObject("mapContext").setClassOfValue(MapContext.class).setMandatory(true); |
1066 |
definition.addDynFieldList("layers").setClassOfItems(FLayer.class).setMandatory(true); |
1067 |
|
1068 |
return Boolean.TRUE; |
1069 |
} |
1070 |
} |
1071 |
|
1072 |
@Override
|
1073 |
protected void doDispose() throws BaseException { |
1074 |
if (layers != null) { |
1075 |
for (int i = 0; i < layers.size(); i++) { |
1076 |
dispose((Disposable) layers.get(i)); |
1077 |
} |
1078 |
} |
1079 |
} |
1080 |
|
1081 |
@Override
|
1082 |
public void move(FLayer layer, LayerCollection group, int where, FLayer adjoiningLayer) throws LayerNotFoundInCollectionException { |
1083 |
|
1084 |
callLayerRemoving(LayerCollectionEvent.createLayerRemovingEvent(layer)); |
1085 |
group.addLayer(layer, where, adjoiningLayer); |
1086 |
removeLayer(layer); |
1087 |
this.updateDrawVersion();
|
1088 |
callLayerRemoved(LayerCollectionEvent.createLayerRemovedEvent(layer)); |
1089 |
|
1090 |
} |
1091 |
|
1092 |
public void join(FLayer layer, LayerCollection group) { |
1093 |
try {
|
1094 |
layers.remove(layer); |
1095 |
group.addLayer(layer, END, null);
|
1096 |
this.updateDrawVersion();
|
1097 |
} catch (LayerNotFoundInCollectionException e) {
|
1098 |
throw new MapContextRuntimeException(e); |
1099 |
} |
1100 |
} |
1101 |
|
1102 |
@Override
|
1103 |
public void move(FLayer layer, LayerCollection group) { |
1104 |
try {
|
1105 |
move(layer, group, END, null);
|
1106 |
} catch (LayerNotFoundInCollectionException e) {
|
1107 |
throw new MapContextRuntimeException(e); |
1108 |
} |
1109 |
} |
1110 |
|
1111 |
@Override
|
1112 |
public void addLayer(FLayer layer, int where, FLayer adjoiningLayer) |
1113 |
throws LayerNotFoundInCollectionException {
|
1114 |
|
1115 |
switch (where) {
|
1116 |
case BEGIN:
|
1117 |
addLayer(0, layer);
|
1118 |
break;
|
1119 |
case BEFORE:
|
1120 |
if (adjoiningLayer != null) { |
1121 |
if (this.layers.contains(adjoiningLayer)) { |
1122 |
for (int i = 0; i < this.getLayersCount(); i++) { |
1123 |
if (adjoiningLayer == this.getLayer(i)) { |
1124 |
addLayer(i, layer); |
1125 |
break;
|
1126 |
} |
1127 |
} |
1128 |
} else {
|
1129 |
throw new LayerNotFoundInCollectionException(adjoiningLayer, this); |
1130 |
} |
1131 |
} else {
|
1132 |
addLayer(0, layer);
|
1133 |
} |
1134 |
break;
|
1135 |
case AFTER:
|
1136 |
if (adjoiningLayer != null) { |
1137 |
if (this.layers.contains(adjoiningLayer)) { |
1138 |
for (int i = 0; i < this.getLayersCount(); i++) { |
1139 |
if (adjoiningLayer == this.getLayer(i)) { |
1140 |
addLayer(i + 1, layer);
|
1141 |
break;
|
1142 |
} |
1143 |
} |
1144 |
} else {
|
1145 |
throw new LayerNotFoundInCollectionException(adjoiningLayer, this); |
1146 |
} |
1147 |
} else {
|
1148 |
this.addLayer(layer);
|
1149 |
} |
1150 |
break;
|
1151 |
default: // By default add layer an the end of the collection |
1152 |
this.addLayer(layer);
|
1153 |
break;
|
1154 |
} |
1155 |
|
1156 |
} |
1157 |
|
1158 |
public FLayer getFirstActiveLayer() {
|
1159 |
LayersIterator it = new LayersIterator(this) { |
1160 |
@Override
|
1161 |
public boolean evaluate(FLayer layer) { |
1162 |
return layer.isActive();
|
1163 |
} |
1164 |
}; |
1165 |
if( it.hasNext() ) {
|
1166 |
return (FLayer) it.next();
|
1167 |
} |
1168 |
return null; |
1169 |
} |
1170 |
|
1171 |
public FLyrVect getFirstActiveVectorLayer() {
|
1172 |
LayersIterator it = new LayersIterator(this) { |
1173 |
@Override
|
1174 |
public boolean evaluate(FLayer layer) { |
1175 |
return layer.isActive() && layer instanceof FLyrVect; |
1176 |
} |
1177 |
}; |
1178 |
if( it.hasNext() ) {
|
1179 |
return (FLyrVect) it.next();
|
1180 |
} |
1181 |
return null; |
1182 |
} |
1183 |
|
1184 |
@Override
|
1185 |
public Iterator iterator() { |
1186 |
return this.layers.iterator(); |
1187 |
} |
1188 |
|
1189 |
public Iterator deepiterator() { |
1190 |
List layers = toPlainList(this); |
1191 |
return layers.iterator();
|
1192 |
} |
1193 |
|
1194 |
@Override
|
1195 |
public int size() { |
1196 |
return this.layers.size(); |
1197 |
} |
1198 |
|
1199 |
@Override
|
1200 |
public FLayer get(int index) { |
1201 |
return this.layers.get(index); |
1202 |
} |
1203 |
|
1204 |
@Override
|
1205 |
public boolean isEmpty() { |
1206 |
return this.layers.isEmpty(); |
1207 |
} |
1208 |
|
1209 |
@Override
|
1210 |
public boolean contains(Object o) { |
1211 |
return this.layers.contains(o); |
1212 |
} |
1213 |
|
1214 |
@Override
|
1215 |
public Object[] toArray() { |
1216 |
return this.layers.toArray(); |
1217 |
} |
1218 |
|
1219 |
@Override
|
1220 |
public Object[] toArray(Object[] ts) { |
1221 |
return this.layers.toArray(ts); |
1222 |
} |
1223 |
|
1224 |
@Override
|
1225 |
public boolean add(FLayer e) { |
1226 |
this.addLayer(e);
|
1227 |
return true; |
1228 |
} |
1229 |
|
1230 |
@Override
|
1231 |
public boolean remove(Object o) { |
1232 |
this.removeLayer((FLayer) o);
|
1233 |
return true; |
1234 |
} |
1235 |
|
1236 |
@Override
|
1237 |
public boolean containsAll(Collection clctn) { |
1238 |
return this.layers.containsAll(clctn); |
1239 |
} |
1240 |
|
1241 |
@Override
|
1242 |
public void add(int i, FLayer e) { |
1243 |
this.addLayer(i, (FLayer) e);
|
1244 |
} |
1245 |
|
1246 |
@Override
|
1247 |
public FLayer remove(int i) { |
1248 |
FLayer o = this.getLayer(i);
|
1249 |
this.removeLayer(i);
|
1250 |
return o;
|
1251 |
} |
1252 |
|
1253 |
@Override
|
1254 |
public int indexOf(Object o) { |
1255 |
return this.layers.indexOf(o); |
1256 |
} |
1257 |
|
1258 |
@Override
|
1259 |
public int lastIndexOf(Object o) { |
1260 |
return this.layers.lastIndexOf(o); |
1261 |
} |
1262 |
|
1263 |
@Override
|
1264 |
public ListIterator listIterator() { |
1265 |
return this.layers.listIterator(); |
1266 |
} |
1267 |
|
1268 |
@Override
|
1269 |
public ListIterator listIterator(int i) { |
1270 |
return this.layers.listIterator(i); |
1271 |
} |
1272 |
|
1273 |
@Override
|
1274 |
public List subList(int i, int i1) { |
1275 |
return this.layers.subList(i, i1); |
1276 |
} |
1277 |
|
1278 |
@Override
|
1279 |
public boolean addAll(Collection clctn) { |
1280 |
Iterator it = clctn.iterator();
|
1281 |
while( it.hasNext() ) {
|
1282 |
this.add((FLayer) it.next());
|
1283 |
} |
1284 |
return true; |
1285 |
} |
1286 |
|
1287 |
@Override
|
1288 |
public boolean addAll(int i, Collection clctn) { |
1289 |
Iterator it = clctn.iterator();
|
1290 |
while( it.hasNext() ) {
|
1291 |
this.add(i, (FLayer) it.next());
|
1292 |
} |
1293 |
return true; |
1294 |
} |
1295 |
|
1296 |
@Override
|
1297 |
public boolean removeAll(Collection clctn) { |
1298 |
Iterator it = clctn.iterator();
|
1299 |
while( it.hasNext() ) {
|
1300 |
this.remove((FLayer) it.next());
|
1301 |
} |
1302 |
return true; |
1303 |
} |
1304 |
|
1305 |
@Override
|
1306 |
public boolean retainAll(Collection clctn) { |
1307 |
Iterator it = this.layers.iterator(); |
1308 |
while( it.hasNext() ) {
|
1309 |
Object o = it.next();
|
1310 |
if( !clctn.contains(o) ) {
|
1311 |
this.remove((FLayer) o);
|
1312 |
} |
1313 |
} |
1314 |
return true; |
1315 |
} |
1316 |
|
1317 |
@Override
|
1318 |
public FLayer set(int i, FLayer e) { |
1319 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
1320 |
} |
1321 |
|
1322 |
} |