Statistics
| Revision:

root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClientOld / descriptor / LayerSet.java @ 3321

History | View | Annotate | Download (2.51 KB)

1
package org.gvsig.remoteClientOld.descriptor;
2

    
3
import java.util.TreeMap;
4

    
5

    
6
/**
7
 * class for storing all the metadata asociated to a map composition (LayerList)
8
 * @author Laura Diaz
9
*/
10
public class LayerSet
11
{
12
  protected int     m_ID; 
13
  private TreeMap layers = new TreeMap();
14

    
15
  /**
16
   * Instance creation. Creates a nameless map composition.
17
   */ 
18
  public LayerSet()
19
  {
20
          layers = new TreeMap();
21
  }
22

    
23
  /**
24
   * returns the unique identifier from this LayerSet
25
   */
26
  public int getID()
27
  {
28
    return m_ID;
29
  }
30

    
31
  /**
32
   * Sets the unique identifier from this LayerSet
33
   */
34
  public void setID(int id)
35
  {
36
    m_ID = id;
37
  }
38

    
39
  /**
40
   * Adds a Layer object to the vector of layers of this LayerSet
41
   */
42
  public void addLayer(Layer layer)
43
  {
44
    String layerName = layer.getName();
45

    
46
    if (layerName == null)
47
    {
48
      throw new RuntimeException("Error: attempt to add a nameless layer");
49
    }
50

    
51
    // We use the lower case version of the name as a key for the hash map.
52
    layerName = layerName.toLowerCase();    
53
    if (layers == null)
54
    {
55
            layers = new TreeMap();
56
    }
57
    layers.put(layerName, layer);
58
  }
59
  
60
  /**
61
   * removes the vector of layers of this LayerSet
62
   */
63
  public void removeAllLayers()
64
  {
65
    layers.clear();    
66
  }
67
  
68
  /**
69
   * checks if there are layers in this LayerSet
70
   * @return true if there are layers in the LayerSet
71
   */
72
  public boolean hasLayers()
73
  {
74
    return ( layers.size() > 0 );
75
  }
76
  
77
  /**
78
   * returns the number of layers the LayerSet
79
   */
80
  public int numberOfLayers()
81
  {
82
    return layers.size();
83
  }
84

    
85
 /**
86
  * returns the layer with this layerName in the LayerSet
87
  * @param String layerName the name of the required layer
88
  * @return Layer. the "first" Layer in this mapComposition with this layerName
89
  */
90
  public Layer getLayer(String layerName)
91
  {
92
          
93
          if (layers.get(layerName) != null)
94
          {
95
      return (Layer)layers.get(layerName);
96
          }
97

    
98
    return null;
99
  }
100

    
101
  public String[] getLayerNames()
102
  {
103
         String[] names;
104
         names = (String[])layers.values().toArray();
105
         
106
         //TODO: Watch out!!!!! this will not work as long as the values
107
         // are the layer objects and not the names.
108
         // Iterate through the Collection and extract the names.?????
109
         return names;
110
  }
111

    
112
  /**
113
   * checks if there is a layer in the mapComposition with this name
114
   * @param layerName, name of the layer to be searched
115
   * @return true if a layer with this name exists in the mapComposition
116
   */
117
  public boolean containsLayer(String layerName)
118
  {
119
    return (getLayer(layerName) != null);
120
  }
121

    
122
}