root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / descriptor / MapComposition.java @ 2992
History | View | Annotate | Download (2.47 KB)
1 |
package org.gvsig.remoteClient.descriptor; |
---|---|
2 |
|
3 |
import java.util.TreeMap; |
4 |
|
5 |
/**
|
6 |
* class for storing all the metadata asociated to a map composition (LayerList)
|
7 |
* @author Laura Diaz
|
8 |
*/
|
9 |
public class MapComposition |
10 |
{ |
11 |
protected int m_ID; |
12 |
private TreeMap layers = new TreeMap(); |
13 |
|
14 |
/**
|
15 |
* Instance creation. Creates a nameless map composition.
|
16 |
*/
|
17 |
public MapComposition()
|
18 |
{ |
19 |
} |
20 |
|
21 |
/**
|
22 |
* returns the unique identifier from this mapComposition
|
23 |
*/
|
24 |
public int getID() |
25 |
{ |
26 |
return m_ID;
|
27 |
} |
28 |
|
29 |
/**
|
30 |
* Sets the unique identifier from this mapComposition
|
31 |
*/
|
32 |
public void setID(int id) |
33 |
{ |
34 |
m_ID = id; |
35 |
} |
36 |
|
37 |
/**
|
38 |
* Adds a Layer object to the vector of layers of this mapComposition
|
39 |
*/
|
40 |
public void addLayer(Layer layer) |
41 |
{ |
42 |
String layerName = layer.getName();
|
43 |
|
44 |
if (layerName == null) |
45 |
{ |
46 |
throw new RuntimeException("Error: attempt to add a nameless layer"); |
47 |
} |
48 |
|
49 |
// We use the lower case version of the name as a key for the hash map.
|
50 |
layerName = layerName.toLowerCase(); |
51 |
layers.put(layerName, layer); |
52 |
} |
53 |
|
54 |
/**
|
55 |
* removes the vector of layers of this mapComposition
|
56 |
*/
|
57 |
public void removeAllLayers() |
58 |
{ |
59 |
layers.clear(); |
60 |
} |
61 |
|
62 |
/**
|
63 |
* checks if there are layers in this mapComposition
|
64 |
* @return true if there are layers in the mapComposition
|
65 |
*/
|
66 |
public boolean hasLayers() |
67 |
{ |
68 |
return ( layers.size() > 0 ); |
69 |
} |
70 |
|
71 |
/**
|
72 |
* returns the number of layers the mapComposition
|
73 |
*/
|
74 |
public int numberOfLayers() |
75 |
{ |
76 |
return layers.size();
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* returns the layer with this layerName in the mapComposition
|
81 |
* @param String layerName the name of the required layer
|
82 |
* @return Layer. the "first" Layer in this mapComposition with this layerName
|
83 |
*/
|
84 |
public Layer getLayer(String layerName) |
85 |
{ |
86 |
Layer layer; |
87 |
|
88 |
if (layers.get(layerName) != null) |
89 |
{ |
90 |
layers.get(layerName); |
91 |
} |
92 |
|
93 |
return null; |
94 |
} |
95 |
|
96 |
public String[] getLayerNames() |
97 |
{ |
98 |
String[] names; |
99 |
names = (String[])layers.values().toArray(); |
100 |
|
101 |
//TODO: Watch out!!!!! this will not work as long as the values
|
102 |
// are the layer objects and not the names.
|
103 |
// Iterate through the Collection and extract the names.?????
|
104 |
return names;
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* checks if there is a layer in the mapComposition with this name
|
109 |
* @param layerName, name of the layer to be searched
|
110 |
* @return true if a layer with this name exists in the mapComposition
|
111 |
*/
|
112 |
public boolean containsLayer(String layerName) |
113 |
{ |
114 |
return (getLayer(layerName) != null); |
115 |
} |
116 |
|
117 |
} |