Class TextWriter

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

class TextWriter extends Object
The TextWriter class is used to write widget content to a string. Whole and partial lines and line breaks can be written. To write partial lines, specify the start and length of the desired segment during object creation.

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

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    private int
     
    private boolean
     
    private int
     
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    void
    Closes the writer.
    int
    Returns the number of characters to write.
    int
    Returns the offset where writing starts.
    boolean
    Returns whether the writer is closed.
    Returns the string.
    (package private) void
    write(char i)
    Appends the given character to the data.
    (package private) void
    write(int i)
    Appends the given int to the data.
    (package private) void
    write(String string)
    Appends the given string to the data.
    (package private) void
    write(String string, int offset)
    Inserts the given string to the data at the specified offset.
    void
    writeLine(String line, int lineOffset)
    Appends the specified line text to the data.
    void
    writeLineDelimiter(String lineDelimiter)
    Appends the specified line delimiter to the data.

    Methods inherited from class Object

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

    • buffer

      private StringBuilder buffer
    • startOffset

      private int startOffset
    • endOffset

      private int endOffset
    • isClosed

      private boolean isClosed
  • Constructor Details

    • TextWriter

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

    • close

      public void close()
      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.
    • getCharCount

      public int getCharCount()
      Returns the number of characters to write.
      Returns:
      the integer number of characters to write
    • getStart

      public int getStart()
      Returns the offset where writing starts. 0 based from the start of the widget text. Used to write partial lines.
      Returns:
      the integer offset where writing starts
    • isClosed

      public boolean isClosed()
      Returns whether the writer is closed.
      Returns:
      a boolean specifying whether or not the writer is closed
    • toString

      public String toString()
      Returns the string. close() must be called before toString() is guaranteed to return a valid string.
      Overrides:
      toString in class Object
      Returns:
      the string
    • write

      void write(String string)
      Appends the given string to the data.
    • write

      void write(String string, int offset)
      Inserts the given string to the data at the specified offset.

      Do nothing if "offset" is < 0 or > getCharCount()

      Parameters:
      string - text to insert
      offset - offset in the existing data to insert "string" at.
    • write

      void write(int i)
      Appends the given int to the data.
    • write

      void write(char i)
      Appends the given character to the data.
    • writeLine

      public void writeLine(String line, int lineOffset)
      Appends the specified line text to the data.
      Parameters:
      line - line text to write. 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.
      Throws:
      SWTException -
      • ERROR_IO when the writer is closed.
    • writeLineDelimiter

      public void writeLineDelimiter(String lineDelimiter)
      Appends the specified line delimiter to the data.
      Parameters:
      lineDelimiter - line delimiter to write
      Throws:
      SWTException -
      • ERROR_IO when the writer is closed.