Statistics
| Revision:

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

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