-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathCheckBox.java
More file actions
executable file
·68 lines (63 loc) · 1.71 KB
/
Copy pathCheckBox.java
File metadata and controls
executable file
·68 lines (63 loc) · 1.71 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
package javaforce.webui;
import javaforce.webui.event.*;
/** CheckBox
*
* @author pquiring
*/
public class CheckBox extends Container {
private HTMLContainer input;
private HTMLContainer label;
private boolean selected;
public CheckBox(String text) {
input = new HTMLContainer("input");
input.setEnclosed(false);
input.addAttr("type", "checkbox");
input.addEvent("onchange", "onCheckBoxChange(event, this);");
input.addChangedListener((c) -> {
selected = !selected;
onChanged(new String[0]);
});
label = new HTMLContainer("label");
label.setText(text);
input.add(label);
add(input);
setClass("noselect");
}
public String html() {
label.addAttr("for", "'" + input.id + "'");
if (selected) {
input.addAttr("checked", null);
}
StringBuilder sb = new StringBuilder();
sb.append("<div" + getAttrs() + ">");
int cnt = count();
for(int a=0;a<cnt;a++) {
sb.append(get(a).html());
}
sb.append("</div>");
return sb.toString();
}
public void setText(String text) {
label.setText(text);
}
public void setSelected(boolean state) {
if (selected == state) return;
selected = state;
input.sendEvent("setchecked", new String[] {"state=" + selected});
}
public boolean isSelected() {
return selected;
}
public void setReadonly(boolean state) {
input.setReadonly(state);
}
public void setDisabled(boolean state) {
input.setDisabled(state);
}
public void addChangedListener(Changed handler) {
input.addChangedListener(handler);
}
public void addClickListener(Click handler) {
input.addClickListener(handler);
}
}