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 / LayersIterator.java @ 43610
History | View | Annotate | Download (2.88 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
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
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | package org.gvsig.fmap.mapcontext.layers; |
25 | |||
26 | import java.util.ArrayList; |
||
27 | import java.util.Iterator; |
||
28 | import java.util.NoSuchElementException; |
||
29 | |||
30 | import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
||
31 | |||
32 | |||
33 | /**
|
||
34 | * Interator for iterate in a Layers tree
|
||
35 | * <P>
|
||
36 | * Extend this class to create an expecific layer iterator
|
||
37 | * and override the method <code>evaluate</code> for check
|
||
38 | * if a layer will be in the iteration list.
|
||
39 | * <P>
|
||
40 | * @author jmvivo
|
||
41 | 43610 | jjdelcerro | * @deprecated use layers.deepiterator
|
42 | 40435 | jjdelcerro | *
|
43 | */
|
||
44 | public class LayersIterator implements Iterator { |
||
45 | ArrayList layersList =new ArrayList(); |
||
46 | int index = 0; |
||
47 | |||
48 | public LayersIterator() {
|
||
49 | |||
50 | } |
||
51 | |||
52 | public LayersIterator(FLayer layer) {
|
||
53 | this.appendLayer(layer);
|
||
54 | } |
||
55 | |||
56 | protected void appendLayer(FLayer layer) { |
||
57 | if (this.evaluate(layer)) { |
||
58 | layersList.add(layer); |
||
59 | } |
||
60 | if (layer instanceof LayerCollection) { |
||
61 | appendLayers((LayerCollection)layer); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | private void appendLayers(LayerCollection layers) { |
||
66 | int i;
|
||
67 | for (i=0;i< layers.getLayersCount();i++) { |
||
68 | appendLayer(layers.getLayer(i)); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | public void remove() { |
||
73 | throw new UnsupportedOperationException(); |
||
74 | } |
||
75 | |||
76 | public boolean hasNext() { |
||
77 | return index < layersList.size();
|
||
78 | } |
||
79 | |||
80 | public Object next() { |
||
81 | return nextLayer();
|
||
82 | } |
||
83 | |||
84 | /**
|
||
85 | * Returns the next layer in the iteration.
|
||
86 | *
|
||
87 | * @return the next layer in the iteration.
|
||
88 | * @exception NoSuchElementException iteration has no more elements.
|
||
89 | *
|
||
90 | * @see next()
|
||
91 | */
|
||
92 | public FLayer nextLayer() {
|
||
93 | if (!this.hasNext()) { |
||
94 | throw new NoSuchElementException(); |
||
95 | } |
||
96 | FLayer aux = (FLayer)layersList.get(index); |
||
97 | index++; |
||
98 | return aux;
|
||
99 | } |
||
100 | |||
101 | /**
|
||
102 | * Called before add a layer to the iteration
|
||
103 | * list.
|
||
104 | * @param layer the layer to check
|
||
105 | * @return true if the layer will be in the iteration list
|
||
106 | */
|
||
107 | public boolean evaluate(FLayer layer) { |
||
108 | return true; |
||
109 | } |
||
110 | |||
111 | } |