Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wms / branches / org.gvsig.raster.wms_dataaccess_refactoring / org.gvsig.raster.wms.app.wmsclient / src / main / java / org / gvsig / raster / wms / app / wmsclient / gui / wizard / LayerTreeModel.java @ 2378

History | View | Annotate | Download (3.87 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
 
23
package org.gvsig.raster.wms.app.wmsclient.gui.wizard;
24

    
25
import java.util.List;
26

    
27
import javax.swing.event.TreeModelListener;
28
import javax.swing.tree.TreeModel;
29
import javax.swing.tree.TreePath;
30

    
31
import org.gvsig.raster.wms.io.WMSLayerNode;
32

    
33

    
34

    
35

    
36
public class LayerTreeModel implements TreeModel {
37

    
38
        WMSLayerNode root;
39

    
40
        public LayerTreeModel(WMSLayerNode root){
41
                this.root = root;
42
        }
43

    
44
        public Object getRoot() {
45
                return root;
46
        }
47

    
48
        public int getChildCount(Object parent) {
49
                return ((WMSLayerNode)parent).getChildren().size();
50
        }
51

    
52
    public boolean isLeaf(Object node) {
53
                return ((WMSLayerNode)node).getChildren().size() == 0;
54
        }
55

    
56
        public void addTreeModelListener(TreeModelListener l) {
57
        }
58

    
59
        public void removeTreeModelListener(TreeModelListener l) {
60
        }
61

    
62
        public Object getChild(Object parent, int index) {
63
                return (WMSLayerNode)((WMSLayerNode)parent).getChildren().get(index);
64
        }
65

    
66
        public int getIndexOfChild(Object parent, Object child) {
67
        WMSLayerNode pare = (WMSLayerNode) parent;
68
                for (int i = 0; i < pare.getChildren().size(); i++)
69
                        if (child == pare.getChildren().get(i)) return i;
70
                return -1;
71
        }
72

    
73
        public void valueForPathChanged(TreePath path, Object newValue) {
74
        }
75

    
76
    /**
77
     * @param node, the tree's desired node.
78
     * @return Returns the name of the node.
79
     */
80
    public String getName(Object node) {
81
        return ((WMSLayerNode) node).getName();
82
    }
83
    
84
    /**
85
     * @param node, the tree's desired node.
86
     * @return Returns the queryable.
87
     */
88
    public boolean isQueryable(Object node) {
89
        return ((WMSLayerNode) node).isQueryable();
90
    }
91
    
92
    /**
93
     * @param node, the tree's desired node.
94
     * @return Returns the srs.
95
     */
96
    public List<String> getSrs(Object node) {
97
        return ((WMSLayerNode) node).getAllSrs();
98
    }
99
    /**
100
     * @param node, the tree's desired node.
101
     * @return Returns the title.
102
     */
103
    public String getTitle(Object node) {
104
        return ((WMSLayerNode) node).getTitle();
105
    }
106
    /**
107
     * @param node, the tree's desired node.
108
     * @return Returns the transparency.
109
     */
110
    public boolean hasTransparency(Object node) {
111
        return ((WMSLayerNode) node).isTransparent();
112
    }
113
    
114
    public String toString(){
115
        return getTitle(this);
116
    }
117
    
118
    /**
119
     * Searches in the tree for the first (and must be the unique) RemoteLayerNode with
120
     * the name specified by name.
121
     * @param name
122
     * @return
123
     */
124
    public Object getNodeByName(String name) {
125
            return getNodeByName(root, name);
126
    }
127
    
128
    /**
129
     * Service method.
130
     * @param node
131
     * @param name
132
     * @return
133
     */
134
    private Object getNodeByName(WMSLayerNode node, String name) {
135
            WMSLayerNode n = node;
136
            if (n.getName()!= null && n.getName().equals(name)) {
137
                    return n;
138
            } else {
139
                    for (int i = 0; i < getChildCount(n); i++) {
140
                            WMSLayerNode n1 = (WMSLayerNode) n.getChildren().get(i);
141
                            Object obj = getNodeByName(n1, name);
142
                            if (obj!= null)
143
                                    return obj;
144
                        }
145
            }
146
            return null;
147
    }
148
}