Class StyledTextWriterBase

java.lang.Object
org.eclipse.swt.custom.TextWriter
org.eclipse.swt.custom.StyledTextWriterBase
Direct Known Subclasses:
HTMLWriter, RTFWriter

abstract class StyledTextWriterBase extends TextWriter
The base class encapsulating the logic used to write styled content as a rich format (HTML, RTF, maybe more). It contains the common parts: iterates on lines, then on each line iterates on plain text and StyleRange(s).

toString() is guaranteed to return a valid formatted string only after close() has been called.

Whole and partial lines and line breaks can be written. Lines will be formatted using the styles queried from the LineStyleListener, if set, or those set directly in the widget. All styles are applied to the stream like they are rendered by the widget. In addition, the widget font name and size is used for the whole text.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) final StyledText
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    StyledTextWriterBase(StyledText styledText, int start, int length)
    Creates a writer that processed content starting at offset "start" in the document.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) abstract String
    Takes plain text and returns the same text escaped using the rules of the output format.
    (package private) abstract void
    Invoked at the end of each line, writeLineEnd, if there was no text output.
    (package private) void
    writeEscaped(String string, int start, int end)
    Appends the specified segment of "string" to the output data.
    (package private) abstract void
    Writes the part that only shows once, at the beginning of the output data.
    void
    writeLine(String line, int lineOffset)
    Appends the specified line text to the output data.
    (package private) void
    writeLineEnd(String prepared)
    Invoked at the end of of each line in the original widget.
    (package private) abstract String
    writeLineStart(Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify)
    Invoked at the beginning of each line in the original widget.
    (package private) void
    writeSpanEnd(String prepared)
    Invoked at the end of of each styled span fragment in the original widget.
    (package private) abstract String
    Invoked at the beginning of each styled span fragment in the original widget.
    (package private) void
    writeStyledLine(String line, int lineOffset, int[] ranges, StyleRange[] styles, Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify)
    Appends the specified line text to the output data.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • StyledTextWriterBase

      public StyledTextWriterBase(StyledText styledText, int start, int length)
      Creates a writer that processed content starting at offset "start" in the document. start and length can be set to specify partial lines.
      Parameters:
      styledText - the widget to produce the RTF from
      start - start offset of content to write, 0 based from beginning of document
      length - length of content to write
  • Method Details

    • writeEscaped

      void writeEscaped(String string, int start, int end)
      Appends the specified segment of "string" to the output data. Copy from start up to, but excluding, end.
      Parameters:
      string - string to copy a segment from. Must not contain line breaks. Line breaks should be written using
      invalid reference
      #writeLineDelimiter()
      start - start offset of segment. 0 based.
      end - end offset of segment
    • writeLine

      public void writeLine(String line, int lineOffset)
      Appends the specified line text to the output data. Lines will be formatted using the styles queried from the LineStyleListener, if set, or those set directly in the widget.
      Overrides:
      writeLine in class TextWriter
      Parameters:
      line - line text to write. Must not contain line breaks Line breaks should be written using TextWriter.writeLineDelimiter(String)
      lineOffset - offset of the line. 0 based from the start of the widget document. Any text occurring before the start offset or after the end offset specified during object creation is ignored.
      Throws:
      SWTException - ERROR_IO when the writer is closed.
    • writeStyledLine

      void writeStyledLine(String line, int lineOffset, int[] ranges, StyleRange[] styles, Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify)
      Appends the specified line text to the output data.

      Use the colors and font styles specified in styles and lineBackground. Formatting is written to reflect the text rendering by the text widget. Style background colors take precedence over the line background color.

      Parameters:
      line - line text to write as RTF. Must not contain line breaks Line breaks should be written using writeLineDelimiter()
      lineOffset - offset of the line. 0 based from the start of the widget document. Any text occurring before the start offset or after the end offset specified during object creation is ignored.
      styles - styles to use for formatting. Must not be null.
      lineBackground - line background color to use for formatting. May be null.
    • writeHeader

      abstract void writeHeader()
      Writes the part that only shows once, at the beginning of the output data.
    • escapeText

      abstract String escapeText(String text)
      Takes plain text and returns the same text escaped using the rules of the output format.
      Parameters:
      text - the text to escape
      Returns:
      the escaped text
    • writeLineStart

      abstract String writeLineStart(Color lineBackground, int indent, int verticalIndent, int alignment, boolean justify)
      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.

      Returns:
      the text to append at the end of the line
    • writeLineEnd

      void writeLineEnd(String prepared)
      Invoked at the end of of each line in the original widget.

      It receives whatever text writeLineStart(Color,int,int,int,boolean) returned and it will output it. A class might override it to do more.

      Parameters:
      prepared - the leftover text prepared by writeLineStart
    • writeEmptyLine

      abstract void writeEmptyLine()
      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.

    • writeSpanStart

      abstract String writeSpanStart(StyleRange style)
      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).

      Returns:
      the text to append at the end of the styled span
    • writeSpanEnd

      void writeSpanEnd(String prepared)
      Invoked at the end of of each styled span fragment in the original widget.

      It receives whatever text writeSpanStart(StyleRange) returned and it will output it. A class might override it to do more.

      Parameters:
      prepared - the leftover text prepared by writeSpanStart