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