forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.java
More file actions
executable file
·42 lines (40 loc) · 1015 Bytes
/
Copy pathButton.java
File metadata and controls
executable file
·42 lines (40 loc) · 1015 Bytes
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
package javaforce.webui;
/** Button
*
* Generic button.
*
* @author pquiring
*/
public class Button extends TextComponent {
private String url;
private Resource img;
public Button(String text) {
this.text = text;
setClass("button");
}
public Button(Resource res) {
img = res;
setClass("button");
}
public String html() {
if (img != null) {
return "<img" + getAttrs() + " src='/static/" + img.id + "'>";
}
StringBuilder sb = new StringBuilder();
sb.append("<button" + getAttrs() + ">");
sb.append(text);
sb.append("</button>");
return sb.toString();
}
public void updateText(String text) {
sendEvent("settext", new String[] {"text=" + text});
}
public void setURL(String url) {
addEvent("onclick", "window.open(\"" + url + "\");");
this.url = url;
}
public void setImage(Resource img) {
this.img = img;
sendEvent("setsrc", new String[] {"src=/static/" + img.id});
}
}