svn-gvsig-desktop / tags / v1_0_RELEASE / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / LayersIterator.java @ 9167
History | View | Annotate | Download (1.76 KB)
1 |
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 |
public LayersIterator(FLayer layer) {
|
24 |
this.appendLayer(layer);
|
25 |
} |
26 |
|
27 |
private void appendLayer(FLayer layer) { |
28 |
if (this.evaluate(layer)) { |
29 |
layersList.add(layer); |
30 |
} |
31 |
if (layer instanceof LayerCollection) { |
32 |
appendLayers((LayerCollection)layer); |
33 |
} |
34 |
} |
35 |
|
36 |
private void appendLayers(LayerCollection layers) { |
37 |
int i;
|
38 |
for (i=0;i< layers.getLayersCount();i++) { |
39 |
appendLayer(layers.getLayer(i)); |
40 |
} |
41 |
} |
42 |
|
43 |
public void remove() { |
44 |
throw new UnsupportedOperationException(); |
45 |
} |
46 |
|
47 |
public boolean hasNext() { |
48 |
return index < layersList.size();
|
49 |
} |
50 |
|
51 |
public Object next() { |
52 |
return nextLayer();
|
53 |
} |
54 |
|
55 |
/**
|
56 |
* Returns the next layer in the iteration.
|
57 |
*
|
58 |
* @return the next layer in the iteration.
|
59 |
* @exception NoSuchElementException iteration has no more elements.
|
60 |
*
|
61 |
* @see next()
|
62 |
*/
|
63 |
public FLayer nextLayer() {
|
64 |
if (!this.hasNext()) { |
65 |
throw new NoSuchElementException(); |
66 |
} |
67 |
FLayer aux = (FLayer)layersList.get(index); |
68 |
index++; |
69 |
return aux;
|
70 |
} |
71 |
|
72 |
/**
|
73 |
* Called before add a layer to the iteration
|
74 |
* list.
|
75 |
* @param layer the layer to check
|
76 |
* @return true if the layer will be in the iteration list
|
77 |
*/
|
78 |
public boolean evaluate(FLayer layer) { |
79 |
return true; |
80 |
} |
81 |
|
82 |
} |