forked from processing/processing4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPdeLabel.java
More file actions
76 lines (60 loc) · 1.51 KB
/
PdeLabel.java
File metadata and controls
76 lines (60 loc) · 1.51 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
package processing.app.laf;
import javax.swing.JTextPane;
import javax.swing.text.html.HTMLDocument;
// not in use; this all works with JLabel, but it's confusing as heck
public class PdeLabel extends JTextPane {
String message;
String css;
public PdeLabel() {
setEditable(false);
setOpaque(false);
setContentType("text/html");
/*
pane.addHyperlinkListener(e -> {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (e.getURL() != null) {
Platform.openURL(e.getURL().toString());
}
}
});
*/
}
@Override
public void setText(String message) {
this.message = message;
rebuild();
}
public void setText(String message, String css) {
this.message = message;
this.css = css;
rebuild();
}
private void rebuild() {
StringBuffer buffer = new StringBuffer("<html><head>");
// if (css != null) {
// buffer.append("<style type='text/css'>").append(css).append("</style>");
// }
buffer.append("</head><body>");
buffer.append(message);
// System.out.println(buffer);
super.setText(buffer.toString());
if (css != null) {
((HTMLDocument) getDocument()).getStyleSheet().addRule(css);
}
/*
if (css != null) { // reapply the styles
setStyle(css);
}
*/
}
public void setStyle(String css) {
//((HTMLDocument) getDocument()).getStyleSheet().addRule(css);
this.css = css;
rebuild();
}
/*
public void setURL(String url) {
this.url = url;
}
*/
}