1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.universAAL.middleware.ui.rdf;
21
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.List;
25
26
27
28
29
30
31
32
33
34
35
36 public class ChoiceList extends Label {
37 public static final String MY_URI = Form.uAAL_DIALOG_NAMESPACE
38 + "ChoiceList";
39
40
41
42
43
44 public static final String PROP_CHILDREN = Form.uAAL_DIALOG_NAMESPACE
45 + "subchoices";
46
47 private List children;
48
49
50
51
52 public ChoiceList() {
53 super();
54 }
55
56
57
58
59
60
61
62
63
64 public ChoiceList(String labelText, String iconURL) {
65 super(labelText, iconURL);
66 children = new ArrayList();
67 props.put(PROP_CHILDREN, children);
68 }
69
70
71
72
73
74
75
76 public void addChild(ChoiceItem item) {
77 if (item != null)
78 children.add(item);
79 }
80
81
82
83
84
85
86
87 public void addChild(ChoiceList sublist) {
88 if (sublist != null)
89 children.add(sublist);
90 }
91
92
93
94
95
96 public Label[] getChildren() {
97 return (Label[]) children.toArray(new Label[children.size()]);
98 }
99
100 ChoiceItem findItem(String label) {
101 ChoiceItem result = null;
102 if (children != null)
103 for (Iterator i = children.iterator(); result == null
104 && i.hasNext();) {
105 Object child = i.next();
106 if (child instanceof ChoiceList)
107 result = ((ChoiceList) child).findItem(label);
108 else if (child instanceof ChoiceItem
109 && child.toString().equals(label))
110 return (ChoiceItem) child;
111 }
112 return result;
113 }
114
115
116
117
118 int getMaxLength() {
119 int res = -1;
120 for (Iterator i = children.iterator(); i.hasNext();) {
121 Object o = i.next();
122 if (o instanceof Label) {
123 int aux = ((Label) o).getMaxLength();
124 if (aux > res)
125 res = aux;
126 }
127 }
128 return res;
129 }
130
131
132
133
134 public boolean setProperty(String propURI, Object value) {
135 if (PROP_CHILDREN.equals(propURI))
136 if (value instanceof List && children == null) {
137 for (Iterator i = ((List) value).iterator(); i.hasNext();) {
138 Object o = i.next();
139 if (!(o instanceof ChoiceItem)
140 && !(o instanceof ChoiceList))
141 return false;
142 }
143 children = (List) value;
144 props.put(PROP_CHILDREN, children);
145 return true;
146 } else
147 return false;
148 else
149 return super.setProperty(propURI, value);
150 }
151 }