-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathButton.java
More file actions
executable file
·88 lines (84 loc) · 1.92 KB
/
Copy pathButton.java
File metadata and controls
executable file
·88 lines (84 loc) · 1.92 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
package javaforce.webui;
/** Button
*
* @author pquiring
*/
public class Button extends TextComponent {
protected String url;
protected Image img;
protected Icon icon;
public Button(String text) {
this.text = text;
setClass("button");
}
public Button(Resource img) {
this.img = new Image(img);
add(this.img);
setClass("button");
}
public Button(Image img) {
this.img = img;
add(this.img);
setClass("button");
}
public Button(Icon icon) {
this.icon = icon;
add(this.icon);
setClass("button");
}
public Button(Resource img, String text) {
this.img = new Image(img);
add(this.img);
this.text = text;
setClass("button");
}
public Button(Image img, String text) {
this.img = img;
add(this.img);
this.text = text;
setClass("button");
}
public Button(Icon icon, String text) {
this.icon = icon;
add(this.icon);
this.text = text;
setClass("button");
}
public String html() {
StringBuilder html = new StringBuilder();
html.append("<button" + getAttrs() + ">");
html.append(innerHTML());
html.append("</button>");
return html.toString();
}
public String innerHTML() {
StringBuilder html = new StringBuilder();
if (img != null) {
html.append(img.html());
}
if (icon != null) {
html.append(icon.html());
}
if (text != null) {
html.append(text);
}
return html.toString();
}
public void update() {
sendEvent("sethtml", new String[] {"html=" + innerHTML()});
}
public void setURL(String url) {
addEvent("onclick", "window.open(\"" + url + "\");");
this.url = url;
}
public String getURL() {
return url;
}
public void setImage(Resource img) {
this.img.setImage(img);
}
public void setIcon(Icon icon) {
this.icon = icon;
update();
}
}