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 @ 40559
History | View | Annotate | Download (2.84 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
|
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 |
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 |
*
|
42 |
*/
|
43 |
public class LayersIterator implements Iterator { |
44 |
ArrayList layersList =new ArrayList(); |
45 |
int index = 0; |
46 |
|
47 |
public LayersIterator() {
|
48 |
|
49 |
} |
50 |
|
51 |
public LayersIterator(FLayer layer) {
|
52 |
this.appendLayer(layer);
|
53 |
} |
54 |
|
55 |
protected void appendLayer(FLayer layer) { |
56 |
if (this.evaluate(layer)) { |
57 |
layersList.add(layer); |
58 |
} |
59 |
if (layer instanceof LayerCollection) { |
60 |
appendLayers((LayerCollection)layer); |
61 |
} |
62 |
} |
63 |
|
64 |
private void appendLayers(LayerCollection layers) { |
65 |
int i;
|
66 |
for (i=0;i< layers.getLayersCount();i++) { |
67 |
appendLayer(layers.getLayer(i)); |
68 |
} |
69 |
} |
70 |
|
71 |
public void remove() { |
72 |
throw new UnsupportedOperationException(); |
73 |
} |
74 |
|
75 |
public boolean hasNext() { |
76 |
return index < layersList.size();
|
77 |
} |
78 |
|
79 |
public Object next() { |
80 |
return nextLayer();
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Returns the next layer in the iteration.
|
85 |
*
|
86 |
* @return the next layer in the iteration.
|
87 |
* @exception NoSuchElementException iteration has no more elements.
|
88 |
*
|
89 |
* @see next()
|
90 |
*/
|
91 |
public FLayer nextLayer() {
|
92 |
if (!this.hasNext()) { |
93 |
throw new NoSuchElementException(); |
94 |
} |
95 |
FLayer aux = (FLayer)layersList.get(index); |
96 |
index++; |
97 |
return aux;
|
98 |
} |
99 |
|
100 |
/**
|
101 |
* Called before add a layer to the iteration
|
102 |
* list.
|
103 |
* @param layer the layer to check
|
104 |
* @return true if the layer will be in the iteration list
|
105 |
*/
|
106 |
public boolean evaluate(FLayer layer) { |
107 |
return true; |
108 |
} |
109 |
|
110 |
} |