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