@Test public void testFromHTML() { String s = "<HTML><b>Bold</b>, <i>italics</i>, <font size='3'>sized font!</font>"; String text = HTMLUtilities.fromHTML(s); assertEquals("Bold, italics, sized font!", text); }
public static String fromHTML(String text) { if (text == null) { return null; } if (!BasicHTML.isHTMLString(text)) { return text; } JLabel label = new JLabel(text) { @Override public void paint(Graphics g) { super.paintComponent(g); } }; View v = (View) label.getClientProperty(BasicHTML.propertyKey); if (v == null) { return text; } Dimension size = label.getPreferredSize(); label.setBounds(new Rectangle(0, 0, size.width, size.height)); Rectangle bounds = new Rectangle(-size.width, -size.height, size.width * 2, size.height * 10); TextLayoutGraphics g = new TextLayoutGraphics(); g.setClip(bounds); label.paint(g); g.flush(); String raw = g.getBuffer(); raw = raw.trim(); String updated = replaceKnownSpecialCharacters(raw); String condensed = condense(updated); return condensed; }
HTMLUtilities { public static String fromHTML(String text) { if (text == null) { return null; } if (!BasicHTML.isHTMLString(text)) { return text; } JLabel label = new JLabel(text) { @Override public void paint(Graphics g) { super.paintComponent(g); } }; View v = (View) label.getClientProperty(BasicHTML.propertyKey); if (v == null) { return text; } Dimension size = label.getPreferredSize(); label.setBounds(new Rectangle(0, 0, size.width, size.height)); Rectangle bounds = new Rectangle(-size.width, -size.height, size.width * 2, size.height * 10); TextLayoutGraphics g = new TextLayoutGraphics(); g.setClip(bounds); label.paint(g); g.flush(); String raw = g.getBuffer(); raw = raw.trim(); String updated = replaceKnownSpecialCharacters(raw); String condensed = condense(updated); return condensed; } }
HTMLUtilities { public static String fromHTML(String text) { if (text == null) { return null; } if (!BasicHTML.isHTMLString(text)) { return text; } JLabel label = new JLabel(text) { @Override public void paint(Graphics g) { super.paintComponent(g); } }; View v = (View) label.getClientProperty(BasicHTML.propertyKey); if (v == null) { return text; } Dimension size = label.getPreferredSize(); label.setBounds(new Rectangle(0, 0, size.width, size.height)); Rectangle bounds = new Rectangle(-size.width, -size.height, size.width * 2, size.height * 10); TextLayoutGraphics g = new TextLayoutGraphics(); g.setClip(bounds); label.paint(g); g.flush(); String raw = g.getBuffer(); raw = raw.trim(); String updated = replaceKnownSpecialCharacters(raw); String condensed = condense(updated); return condensed; }  }
HTMLUtilities { public static String fromHTML(String text) { if (text == null) { return null; } if (!BasicHTML.isHTMLString(text)) { return text; } JLabel label = new JLabel(text) { @Override public void paint(Graphics g) { super.paintComponent(g); } }; View v = (View) label.getClientProperty(BasicHTML.propertyKey); if (v == null) { return text; } Dimension size = label.getPreferredSize(); label.setBounds(new Rectangle(0, 0, size.width, size.height)); Rectangle bounds = new Rectangle(-size.width, -size.height, size.width * 2, size.height * 10); TextLayoutGraphics g = new TextLayoutGraphics(); g.setClip(bounds); label.paint(g); g.flush(); String raw = g.getBuffer(); raw = raw.trim(); String updated = replaceKnownSpecialCharacters(raw); String condensed = condense(updated); return condensed; }  static String wrapAsHTML(String text); static String colorString(Color color, String text); static String colorString(String rgbColor, String text); static String colorString(String rgbColor, int value); static String spaces(int num); static String bold(String text); static String underline(String text); static String italic(String text); static boolean isHTML(String text); static String setFontSize(String text, int ptSize); static String setFont(String text, Color color, int ptSize); static String wrapWithLinkPlaceholder(String htmlText, String content); static String convertLinkPlaceholdersToHyperlinks(String text); static String toHTML(String text); static String toWrappedHTML(String text); static String toWrappedHTML(String text, int maxLineLength); static String toLiteralHTMLForTooltip(String text); static String friendlyEncodeHTML(String text); static String escapeHTML(String text); static String toLiteralHTML(String text, int maxLineLength); static String lineWrapWithHTMLLineBreaks(String text); static String lineWrapWithHTMLLineBreaks(String text, int maxLineLength); static String fromHTML(String text); static String toRGBString(Color color); static String toHexString(Color color); }
HTMLUtilities { public static String fromHTML(String text) { if (text == null) { return null; } if (!BasicHTML.isHTMLString(text)) { return text; } JLabel label = new JLabel(text) { @Override public void paint(Graphics g) { super.paintComponent(g); } }; View v = (View) label.getClientProperty(BasicHTML.propertyKey); if (v == null) { return text; } Dimension size = label.getPreferredSize(); label.setBounds(new Rectangle(0, 0, size.width, size.height)); Rectangle bounds = new Rectangle(-size.width, -size.height, size.width * 2, size.height * 10); TextLayoutGraphics g = new TextLayoutGraphics(); g.setClip(bounds); label.paint(g); g.flush(); String raw = g.getBuffer(); raw = raw.trim(); String updated = replaceKnownSpecialCharacters(raw); String condensed = condense(updated); return condensed; }  static String wrapAsHTML(String text); static String colorString(Color color, String text); static String colorString(String rgbColor, String text); static String colorString(String rgbColor, int value); static String spaces(int num); static String bold(String text); static String underline(String text); static String italic(String text); static boolean isHTML(String text); static String setFontSize(String text, int ptSize); static String setFont(String text, Color color, int ptSize); static String wrapWithLinkPlaceholder(String htmlText, String content); static String convertLinkPlaceholdersToHyperlinks(String text); static String toHTML(String text); static String toWrappedHTML(String text); static String toWrappedHTML(String text, int maxLineLength); static String toLiteralHTMLForTooltip(String text); static String friendlyEncodeHTML(String text); static String escapeHTML(String text); static String toLiteralHTML(String text, int maxLineLength); static String lineWrapWithHTMLLineBreaks(String text); static String lineWrapWithHTMLLineBreaks(String text, int maxLineLength); static String fromHTML(String text); static String toRGBString(Color color); static String toHexString(Color color); static final String HTML; static final String HTML_CLOSE; static final String BR; static final String PRE; static final String PRE_CLOSE; static final String LINK_PLACEHOLDER_OPEN; static final String LINK_PLACEHOLDER_CLOSE; static String HTML_SPACE; static String HTML_NEW_LINE; static final String MAROON; static final String GREEN; static final String BLUE; static final String PURPLE; static final String DARK_CYAN; static final String OLIVE; static final String ORANGE; static final String PINK; static final String YELLOW; static final String GRAY; }