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