Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wmts / struct / WMTSTheme.java @ 38531

History | View | Annotate | Download (3.46 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.remoteclient.wmts.struct;
23

    
24
import java.util.ArrayList;
25

    
26
/**
27
 * Layer hierarchy
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public abstract class WMTSTheme extends WMTSBaseStruct {
31
        //WMTSTheme
32
        private ArrayList        theme      = null;
33
        //String
34
        private ArrayList        layerRef   = null;
35
        private WMTSLayer        layer      = null; 
36
        
37
        public void setLayer(WMTSLayer layer) {
38
                this.layer = layer;
39
        }
40
        
41
        public WMTSLayer getLayer() {
42
                return layer;
43
        }
44
        
45
        public ArrayList getThemeList() {
46
                if(theme == null)
47
                        theme = new ArrayList();
48
                return theme;
49
        }
50
        
51
        public ArrayList getLayerRef() {
52
                if(layerRef == null)
53
                        layerRef = new ArrayList();
54
                return layerRef;
55
        }
56
        
57
        /**
58
         * Assign the layer associated
59
         * @param layers
60
         */
61
        public void calculateLayers(ArrayList layers) {
62
                if(theme != null && theme.size() > 0) {
63
                        for (int i = 0; i < theme.size(); i++) {
64
                                ((WMTSTheme)theme.get(i)).calculateLayers(layers);
65
                        }
66
                }
67
                        
68
                if(layerRef != null && layerRef.size() > 0) {
69
                        for (int i = 0; i < layers.size(); i++) {
70
                                WMTSLayer tmpLayer = (WMTSLayer)layers.get(i);
71
                                for (int j = 0; j < layerRef.size(); j++) {
72
                                        String layerRef_I = (String)layerRef.get(j);
73
                                        if(tmpLayer.getTitle().compareTo(layerRef_I) == 0) {
74
                                                layer = tmpLayer;
75
                                        }
76
                                }
77
                        }
78
                }
79
        }
80
        
81
        /**
82
         * Gets a node by its name
83
         * @param name
84
         * @return
85
         */
86
        public WMTSTheme getNodeByName(String name) {
87
                WMTSTheme result = null;
88
                if(theme == null)
89
                        return null;
90
                
91
                for (int i = 0; i < theme.size(); i++) {
92
                        WMTSTheme t = ((WMTSTheme)(theme.get(i)));
93
                        String title = t.getTitle();
94
                        
95
                        if(title.compareTo(name) == 0)
96
                                result = t;
97
                        else 
98
                                result = t.getNodeByName(name);
99
                        
100
                        if(result != null)
101
                                return result;
102
                }
103
                
104
                return null;
105
        }
106
        
107
        /**
108
         * Gets the number of nodes
109
         * @param parent
110
         * @return
111
         */
112
        public int getChildCount() {
113
                if(theme == null || theme.size() == 0)
114
                        return 0;
115
                else {
116
                        int acum = 0;
117
                        for (int i = 0; i < theme.size(); i++) {
118
                                acum += 1 + ((WMTSTheme)theme.get(i)).getChildCount();
119
                        }
120
                        return acum;
121
                }
122
        }
123
        
124
        /**
125
         * Gets the children of the index position
126
         * @param index
127
         * @return
128
         */
129
        public WMTSTheme getChildren(int index) {
130
                if(theme != null)
131
                        return (WMTSTheme)theme.get(index);        
132
                return null;
133
        }
134
        
135
        /**
136
         * Gets the index of a children
137
         * @param parent
138
         * @param child
139
         * @return
140
         */
141
        public int getIndexOfChild(WMTSTheme child) {
142
                if(theme != null) {
143
                        for (int i = 0; i < theme.size(); i++)
144
                                if (child == getChildren(i)) 
145
                                        return i;
146
                }
147
                return -1;
148
        }
149
        
150
        public String toString() {
151
                return this.getTitle();
152
        }
153
}