gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.app / org.gvsig.raster.wmts.app.wmtsclient / src / main / java / org / gvsig / raster / wmts / app / wmtsclient / gui / wizard / LayerTreeModel.java @ 393
History | View | Annotate | Download (3.42 KB)
1 | 393 | nbrodin | /* 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.wmts.app.wmtsclient.gui.wizard; |
||
24 | |||
25 | import java.util.ArrayList; |
||
26 | |||
27 | import javax.swing.event.TreeModelListener; |
||
28 | import javax.swing.tree.TreeModel; |
||
29 | import javax.swing.tree.TreePath; |
||
30 | |||
31 | import org.gvsig.remoteclient.wmts.struct.WMTSTheme; |
||
32 | import org.gvsig.remoteclient.wmts.struct.WMTSThemes; |
||
33 | |||
34 | /**
|
||
35 | * Model for the layer three
|
||
36 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
37 | */
|
||
38 | @SuppressWarnings("unchecked") |
||
39 | public class LayerTreeModel implements TreeModel { |
||
40 | |||
41 | private WMTSThemes root = null; |
||
42 | |||
43 | public LayerTreeModel(WMTSThemes root){
|
||
44 | this.root = root;
|
||
45 | } |
||
46 | |||
47 | public Object getRoot() { |
||
48 | return root;
|
||
49 | } |
||
50 | |||
51 | public int getChildCount(Object parent) { |
||
52 | if(parent instanceof WMTSTheme) |
||
53 | return ((WMTSTheme)parent).getChildCount();
|
||
54 | if(parent instanceof WMTSThemes) |
||
55 | return ((WMTSThemes)parent).getChildCount();
|
||
56 | return 0; |
||
57 | } |
||
58 | |||
59 | public boolean isLeaf(Object node) { |
||
60 | return (getChildCount(node) <= 0); |
||
61 | } |
||
62 | |||
63 | public void addTreeModelListener(TreeModelListener l) { |
||
64 | } |
||
65 | |||
66 | public void removeTreeModelListener(TreeModelListener l) { |
||
67 | } |
||
68 | |||
69 | public Object getChild(Object parent, int index) { |
||
70 | if(parent instanceof WMTSTheme) |
||
71 | return ((WMTSTheme)parent).getChildren(index);
|
||
72 | if(parent instanceof WMTSThemes) |
||
73 | return ((WMTSThemes)parent).getChildren(index);
|
||
74 | return null; |
||
75 | } |
||
76 | |||
77 | public int getIndexOfChild(Object parent, Object child) { |
||
78 | if(parent instanceof WMTSTheme) |
||
79 | return ((WMTSTheme)parent).getIndexOfChild((WMTSTheme)parent);
|
||
80 | if(parent instanceof WMTSThemes) |
||
81 | return ((WMTSThemes)parent).getIndexOfChild((WMTSTheme)parent);
|
||
82 | return -1; |
||
83 | } |
||
84 | |||
85 | public void valueForPathChanged(TreePath path, Object newValue) { |
||
86 | } |
||
87 | |||
88 | /**
|
||
89 | * @param node, the tree's desired node.
|
||
90 | * @return Returns the name of the node.
|
||
91 | */
|
||
92 | public String getName(Object node) { |
||
93 | return ((WMTSTheme) node).getLayer().getTitle();
|
||
94 | } |
||
95 | |||
96 | /**
|
||
97 | * @param node, the tree's desired node.
|
||
98 | * @return Returns the namedStyles.
|
||
99 | */
|
||
100 | public ArrayList getStyles(Object node) { |
||
101 | return ((WMTSTheme) node).getLayer().getStyle();
|
||
102 | } |
||
103 | |||
104 | /**
|
||
105 | * @param node, the tree's desired node.
|
||
106 | * @return Returns the title.
|
||
107 | */
|
||
108 | public String getTitle(Object node) { |
||
109 | return ((WMTSTheme) node).getTitle();
|
||
110 | } |
||
111 | |||
112 | public String toString(){ |
||
113 | return getTitle(this); |
||
114 | } |
||
115 | |||
116 | /**
|
||
117 | * Searches in the tree for the first (and must be the unique) RemoteLayerNode with
|
||
118 | * the name specified by name.
|
||
119 | * @param name
|
||
120 | * @return
|
||
121 | */
|
||
122 | public Object getNodeByName(String name) { |
||
123 | return root.getNodeByName(name);
|
||
124 | } |
||
125 | |||
126 | } |