-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathToggleButton.java
More file actions
executable file
·109 lines (103 loc) · 2.73 KB
/
Copy pathToggleButton.java
File metadata and controls
executable file
·109 lines (103 loc) · 2.73 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package javaforce.webui;
/** ToggleButton
*
* @author pquiring
*/
import javaforce.webui.event.*;
public class ToggleButton extends TextComponent {
private boolean state;
private int clrOff, clrOn;
private Image img;
private Icon icon;
public ToggleButton(String text) {
this.text = text;
setColors(Color.darkGrey, Color.grey);
addEvent("onclick", "onClick(event, this);");
setColor();
setClass("button");
}
public ToggleButton(String text, int clrOff, int clrOn) {
this.text = text;
setColors(clrOff, clrOn);
addEvent("onclick", "onClick(event, this);");
setColor();
setClass("button");
}
public ToggleButton(Resource img, String text) {
this.img = new Image(img);
add(this.img);
this.text = text;
setColors(Color.darkGrey, Color.grey);
addEvent("onclick", "onClick(event, this);");
setColor();
setClass("button");
}
public ToggleButton(Resource img, String text, int clrOff, int clrOn) {
this.img = new Image(img);
add(this.img);
this.text = text;
setColors(clrOff, clrOn);
addEvent("onclick", "onClick(event, this);");
setColor();
setClass("button");
}
public ToggleButton(Icon icon, String text) {
this.icon = icon;
add(this.icon);
this.text = text;
setColors(Color.darkGrey, Color.grey);
addEvent("onclick", "onClick(event, this);");
setColor();
}
public ToggleButton(Icon icon, String text, int clrOff, int clrOn) {
this.icon = icon;
add(this.icon);
this.text = text;
setColors(clrOff, clrOn);
addEvent("onclick", "onClick(event, this);");
setColor();
}
private void setColor() {
setBackColor(state ? clrOn : clrOff);
}
public void onClick(String[] args, MouseEvent me) {
state = !state;
setColor();
onChanged(args);
super.onClick(args, me);
}
public String html() {
StringBuilder html = new StringBuilder();
html.append("<button" + getAttrs() + ">");
if (img != null) {
html.append(img.html());
}
if (icon != null) {
html.append(icon.html());
}
if (text != null) {
html.append(text);
}
html.append("</button>");
return html.toString();
}
public void setText(String text) {
this.text = text;
sendEvent("settext", new String[] {"text=" + text});
}
public void update() {
sendEvent("settext", new String[] {"text=" + text});
}
public void setColors(int clrOff, int clrOn) {
this.clrOff = clrOff;
this.clrOn = clrOn;
setColor();
}
public void setSelected(boolean state) {
this.state = state;
setColor();
}
public boolean isSelected() {
return state;
}
}