19 package org.sleuthkit.autopsy.corecomponents;
21 import java.text.MessageFormat;
22 import javax.swing.JTextPane;
23 import javax.swing.SizeRequirements;
24 import javax.swing.text.Element;
25 import javax.swing.text.View;
26 import static javax.swing.text.View.GoodBreakWeight;
27 import javax.swing.text.ViewFactory;
28 import javax.swing.text.html.HTMLEditorKit;
29 import javax.swing.text.html.InlineView;
30 import javax.swing.text.html.ParagraphView;
31 import javax.swing.text.html.StyleSheet;
45 HTMLEditorKit editorKit =
new HTMLEditorKit() {
46 private static final long serialVersionUID = 1L;
49 public ViewFactory getViewFactory() {
51 return new HTMLEditorKit.HTMLFactory() {
53 public View create(Element e) {
54 View v = super.create(e);
55 if (v instanceof InlineView) {
56 return new InlineView(e) {
58 public int getBreakWeight(
int axis,
float pos,
float len) {
59 return GoodBreakWeight;
63 public View breakView(
int axis,
int p0,
float pos,
float len) {
64 if (axis == View.X_AXIS) {
66 int p1 = getGlyphPainter().getBoundedPosition(
this, p0, pos, len);
67 if (p0 == getStartOffset() && p1 == getEndOffset()) {
70 return createFragment(p0, p1);
75 }
else if (v instanceof ParagraphView) {
76 return new ParagraphView(e) {
78 protected SizeRequirements calculateMinorAxisRequirements(
int axis, SizeRequirements r) {
79 SizeRequirements requirements = r;
80 if (requirements == null) {
81 requirements =
new SizeRequirements();
83 float pref = layoutPool.getPreferredSpan(axis);
84 float min = layoutPool.getMinimumSpan(axis);
86 requirements.minimum = (int) min;
87 requirements.preferred = Math.max(requirements.minimum, (
int) pref);
88 requirements.maximum = Integer.MAX_VALUE;
89 requirements.alignment = 0.5f;
100 this.setEditorKit(editorKit);
108 String style = String.format(
"font-family: %s; font-size: %dpt; margin: 0px; padding: 0px 0px %dpx 0px;",
111 super.setText(MessageFormat.format(
"<pre style=\"{0}\">{1}</pre>", style,
EscapeUtil.
escapeHtml(text)));
static String escapeHtml(String toEscape)
static Integer getLineSpacing()
void setText(String text)