1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.gridsystems.config.app;
25
26 import java.util.ArrayList;
27
28 import javax.swing.Icon;
29
30 import com.gridsystems.config.Configurator;
31 import com.gridsystems.config.SwingConfiguratorView;
32
33
34
35
36
37
38
39
40
41
42 public class ConfigNode implements Comparable {
43
44
45
46 private String label;
47
48
49
50
51 private Configurator cfg;
52
53
54
55
56 private ArrayList<ConfigNode> nodes;
57
58
59
60
61
62
63
64 public ConfigNode(String label, Configurator cfg) {
65 this.label = label;
66 this.cfg = cfg;
67 this.nodes = new ArrayList<ConfigNode>();
68 }
69
70
71
72
73
74
75 public String getLabel() {
76 return this.label;
77 }
78
79
80
81
82
83
84 public Configurator getConfigurator() {
85 return this.cfg;
86 }
87
88
89
90
91 public String toString() {
92 return getLabel();
93 }
94
95
96
97
98
99
100
101 public Icon getIcon() {
102 if (this.cfg != null && Configurator.getViewMode() == Configurator.MODE_SWING) {
103 SwingConfiguratorView view = (SwingConfiguratorView)this.cfg.getView();
104 Icon returnValue = (view == null) ? null : view.getSmallIcon();
105 return returnValue;
106 }
107 return null;
108 }
109
110
111
112
113
114
115 public int getChildCount() {
116 return this.nodes.size();
117 }
118
119
120
121
122
123
124
125 public ConfigNode getChild(int i) {
126 return (ConfigNode)nodes.get(i);
127 }
128
129
130
131
132
133
134
135 public int indexOf(ConfigNode child) {
136 return nodes.indexOf(child);
137 }
138
139
140
141
142
143
144
145
146 public void addNode(String path, Configurator cfg) {
147 int pos = path.indexOf('.');
148 String localLabel = (pos == -1) ? path : path.substring(0, pos);
149
150 for (int i = 0; i < nodes.size(); i++) {
151 ConfigNode n = (ConfigNode)nodes.get(i);
152 if (n.getLabel().equals(localLabel)) {
153 if (pos == -1) {
154
155 if (cfg != null) {
156 n.cfg = cfg;
157 }
158 } else {
159 n.addNode(path.substring(pos + 1), cfg);
160 }
161 return;
162 }
163 }
164
165
166 if (pos == -1) {
167 ConfigNode n = new ConfigNode(localLabel, cfg);
168 nodes.add(n);
169 } else {
170 ConfigNode n = new ConfigNode(localLabel, null);
171 nodes.add(n);
172 n.addNode(path.substring(pos + 1), cfg);
173 }
174 }
175
176
177
178
179
180
181 public void addConfigurator(Configurator cfg) {
182 if (cfg != null && cfg.hasView()) {
183 String path = cfg.getPath();
184 addNode(path, cfg);
185 }
186 }
187
188
189
190
191 public int compareTo(Object o) {
192 String s = o.toString();
193 return this.toString().compareTo(s);
194 }
195 }