| 14 |
|
import javax.swing.event.HyperlinkEvent; |
| 15 |
|
import javax.swing.event.HyperlinkListener; |
| 16 |
|
import javax.swing.text.DefaultCaret; |
| 17 |
+ |
import javax.swing.text.html.CSS; |
| 18 |
|
import javax.swing.text.html.HTMLEditorKit; |
| 19 |
|
import javax.swing.text.html.StyleSheet; |
| 20 |
|
|
| 39 |
|
.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); |
| 40 |
|
|
| 41 |
|
setContentType("text/html"); |
| 42 |
< |
|
| 42 |
< |
HTMLEditorKit hek = (HTMLEditorKit) getEditorKit(); |
| 43 |
< |
StyleSheet css = hek.getStyleSheet(); |
| 44 |
< |
css.removeStyle("p"); |
| 45 |
< |
|
| 42 |
> |
|
| 43 |
|
Font font = new JLabel().getFont(); |
| 44 |
|
|
| 45 |
|
StringBuffer style = new StringBuffer("font-family:" + font.getFamily() |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
/** |
| 79 |
+ |
* Add or reset a CSS attribute for styling the text |
| 80 |
+ |
* |
| 81 |
+ |
* @param selector |
| 82 |
+ |
* CSS selector |
| 83 |
+ |
* @param attribute |
| 84 |
+ |
* CSS attribute |
| 85 |
+ |
* @param value |
| 86 |
+ |
* Value |
| 87 |
+ |
*/ |
| 88 |
+ |
public void setCssAttribute(String selector, CSS.Attribute attribute, |
| 89 |
+ |
String value) { |
| 90 |
+ |
HTMLEditorKit hek = (HTMLEditorKit) getEditorKit(); |
| 91 |
+ |
StyleSheet css = hek.getStyleSheet(); |
| 92 |
+ |
css.addRule(String.format("%s {%s: %s}", selector, attribute.toString(), value)); |
| 93 |
+ |
} |
| 94 |
+ |
|
| 95 |
+ |
/** |
| 96 |
|
* Allow or forbid to set a non-null border |
| 97 |
|
* |
| 98 |
|
* @param enable |
| 112 |
|
|
| 113 |
|
@Override |
| 114 |
|
public void setText(String t) { |
| 115 |
+ |
if (t.startsWith("<p>")) |
| 116 |
+ |
t = t.replaceFirst("<p>", "<p style=\"margin-top: 0\">"); |
| 117 |
|
super.setText(prefix + t + suffix); |
| 118 |
|
} |
| 119 |
|
|