forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggleButton.java
More file actions
executable file
·58 lines (55 loc) · 1.37 KB
/
Copy pathToggleButton.java
File metadata and controls
executable file
·58 lines (55 loc) · 1.37 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
package javaforce.webui;
/** ToggleButton
*
* Toggle button.
*
* @author pquiring
*/
import javaforce.webui.event.*;
public class ToggleButton extends TextComponent {
private boolean state;
private int clrOff, clrOn;
public ToggleButton(String text) {
this.text = text;
this.clrOff = Color.darkGrey;
this.clrOn = Color.grey;
}
public ToggleButton(String text, int clrOff, int clrOn) {
this.text = text;
this.clrOff = clrOff;
this.clrOn = 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() {
return "<button" + getAttrs() + ">" + text + "</button>";
}
public void setText(String text) {
this.text = text;
sendEvent("settext", new String[] {"text=" + text});
}
public void updateText(String text) {
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;
}
}