-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathComboBox.java
More file actions
executable file
·81 lines (67 loc) · 1.89 KB
/
Copy pathComboBox.java
File metadata and controls
executable file
·81 lines (67 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package javaforce.webui;
import java.util.*;
/** ComboBox
*
* @author pquiring
*/
public class ComboBox extends Component {
public ComboBox() {
addEvent("onchange", "onComboBoxChange(event, this);");
}
private ArrayList<String> values = new ArrayList<String>();
private ArrayList<String> texts = new ArrayList<String>();
private int index = -1;
public String html() {
StringBuilder sb = new StringBuilder();
sb.append("<select" + getAttrs() + ">");
int cnt = values.size();
for(int a=0;a<cnt;a++) {
sb.append("<option value='" + values.get(a) + "'" + (a == index ? " selected" : "") + ">");
sb.append(texts.get(a));
sb.append("</option>");
}
sb.append("</select>");
return sb.toString();
}
public void add(String value, String text) {
if (index == -1) index = 0;
values.add(value);
texts.add(text);
if (client != null) {
sendEvent("addoption", new String[] {"value=" + value, "text=" + text});
}
}
public void clear() {
for(int a=0;a<values.size();a++) {
sendEvent("removeoption", new String[] {"idx=0"});
}
index = -1;
values.clear();
texts.clear();
}
public int getCount() {
return values.size();
}
public int getSelectedIndex() {
return index;
}
public String getSelectedValue() {
int idx = getSelectedIndex();
if (idx == -1) return null;
return values.get(idx);
}
public String getSelectedText() {
int idx = getSelectedIndex();
if (idx == -1) return null;
return texts.get(idx);
}
public void setSelectedIndex(int idx) {
index = idx;
sendEvent("setidx", new String[] {"idx=" + idx});
}
public void onChanged(String[] args) {
int idx = args[0].indexOf("=");
index = Integer.valueOf(args[0].substring(idx+1));
super.onChanged(args);
}
}