root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / LayersIterator.java @ 38581
History | View | Annotate | Download (1.88 KB)
1 |
package org.gvsig.fmap.mapcontext.layers; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Iterator; |
5 |
import java.util.NoSuchElementException; |
6 |
|
7 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
8 |
|
9 |
|
10 |
/**
|
11 |
* Interator for iterate in a Layers tree
|
12 |
* <P>
|
13 |
* Extend this class to create an expecific layer iterator
|
14 |
* and override the method <code>evaluate</code> for check
|
15 |
* if a layer will be in the iteration list.
|
16 |
* <P>
|
17 |
* @author jmvivo
|
18 |
*
|
19 |
*/
|
20 |
public class LayersIterator implements Iterator { |
21 |
ArrayList layersList =new ArrayList(); |
22 |
int index = 0; |
23 |
|
24 |
public LayersIterator() {
|
25 |
|
26 |
} |
27 |
|
28 |
public LayersIterator(FLayer layer) {
|
29 |
this.appendLayer(layer);
|
30 |
} |
31 |
|
32 |
protected void appendLayer(FLayer layer) { |
33 |
if (this.evaluate(layer)) { |
34 |
layersList.add(layer); |
35 |
} |
36 |
if (layer instanceof LayerCollection) { |
37 |
appendLayers((LayerCollection)layer); |
38 |
} |
39 |
} |
40 |
|
41 |
private void appendLayers(LayerCollection layers) { |
42 |
int i;
|
43 |
for (i=0;i< layers.getLayersCount();i++) { |
44 |
appendLayer(layers.getLayer(i)); |
45 |
} |
46 |
} |
47 |
|
48 |
public void remove() { |
49 |
throw new UnsupportedOperationException(); |
50 |
} |
51 |
|
52 |
public boolean hasNext() { |
53 |
return index < layersList.size();
|
54 |
} |
55 |
|
56 |
public Object next() { |
57 |
return nextLayer();
|
58 |
} |
59 |
|
60 |
/**
|
61 |
* Returns the next layer in the iteration.
|
62 |
*
|
63 |
* @return the next layer in the iteration.
|
64 |
* @exception NoSuchElementException iteration has no more elements.
|
65 |
*
|
66 |
* @see next()
|
67 |
*/
|
68 |
public FLayer nextLayer() {
|
69 |
if (!this.hasNext()) { |
70 |
throw new NoSuchElementException(); |
71 |
} |
72 |
FLayer aux = (FLayer)layersList.get(index); |
73 |
index++; |
74 |
return aux;
|
75 |
} |
76 |
|
77 |
/**
|
78 |
* Called before add a layer to the iteration
|
79 |
* list.
|
80 |
* @param layer the layer to check
|
81 |
* @return true if the layer will be in the iteration list
|
82 |
*/
|
83 |
public boolean evaluate(FLayer layer) { |
84 |
return true; |
85 |
} |
86 |
|
87 |
} |