Class HTMLWriter


class HTMLWriter extends StyledTextWriterBase
The HTMLWriter class is used to write styled content as HTML. The implementation creates a very-very simple HTML, as compatible as possible: simple styles, no JavaScript.

How the concepts are mapped to HTML:

  • Field Details

    • tag

      private String tag
    • multiline

      private boolean multiline
  • Constructor Details

  • Method Details

    • close

      public void close()
      Description copied from class: TextWriter
      Closes the writer. Once closed no more content can be written. NOTE: toString() is not guaranteed to return a valid string unless the writer is closed.
      Overrides:
      close in class TextWriter
    • writeHeader

      void writeHeader()
      Description copied from class: StyledTextWriterBase
      Writes the part that only shows once, at the beginning of the output data.
      Specified by:
      writeHeader in class StyledTextWriterBase
    • writeLineDelimiter

      public void writeLineDelimiter(String lineDelimiter)
      Description copied from class: TextWriter
      Appends the specified line delimiter to the data.
      Overrides:
      writeLineDelimiter in class TextWriter
      Parameters:
      lineDelimiter - line delimiter to write
    • writeLineStart

      String writeLineStart(Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify)
      Description copied from class: StyledTextWriterBase
      Invoked at the beginning of each line in the original widget.

      It should output whatever tags are appropriate to start a new line in the output format.
      It will return the text that has to be output at the end of the line.

      Specified by:
      writeLineStart in class StyledTextWriterBase
      Returns:
      the text to append at the end of the line
    • writeEmptyLine

      void writeEmptyLine()
      Description copied from class: StyledTextWriterBase
      Invoked at the end of each line, writeLineEnd, if there was no text output.

      This is needed for HTML, which does not render empty paragraphs.

      Specified by:
      writeEmptyLine in class StyledTextWriterBase
    • writeSpanStart

      String writeSpanStart(StyleRange style)
      Description copied from class: StyledTextWriterBase
      Invoked at the beginning of each styled span fragment in the original widget.

      It should output whatever tags are appropriate to start a formatted span in the output format.
      It will return the text that has to be output at the end of the span (to close it).

      Specified by:
      writeSpanStart in class StyledTextWriterBase
      Returns:
      the text to append at the end of the styled span
    • escapeText

      String escapeText(String string)
      Description copied from class: StyledTextWriterBase
      Takes plain text and returns the same text escaped using the rules of the output format.
      Specified by:
      escapeText in class StyledTextWriterBase
      Parameters:
      string - the text to escape
      Returns:
      the escaped text
    • colorToHex

      private static String colorToHex(Color color)
    • appendStyle

      private static void appendStyle(StringBuilder buffer, String value)
    • appendStyle

      private static void appendStyle(StringBuilder buffer, String prefix, String value, String postfix)
    • appendStyle

      private static void appendStyle(StringBuilder buffer, String prefix, int value, String postfix)
    • appendStyle

      private static void appendStyle(StringBuilder buffer, String prefix, Color value, String postfix)
    • appendFont

      private static String appendFont(StringBuilder buffer, Font font, int fontStyle)
    • appendAlignAndJustify

      private static void appendAlignAndJustify(StringBuilder buffer, int alignment, boolean justify)