Class EditorDocument

java.lang.Object
com.codename1.ui.editor.EditorDocument

public class EditorDocument extends Object

The plain text backing store shared by the pure Codename One editors. The document keeps the full text in a single buffer addressed by a linear UTF-16 offset space and derives a cached line index (the start offset of every logical line) on demand for rendering and hit testing.

A single buffer keeps offset arithmetic trivial (offsets are direct buffer indices) which is exactly what the caret, selection, undo stack and the platform text input source all operate on. Line oriented feature layers (syntax highlighting, the gutter) sit on top of the line index.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty document.
    Creates a document initialized with the supplied text.
  • Method Summary

    Modifier and Type
    Method
    Description
    char
    charAt(int offset)
    Returns the character at the given offset.
    int
    clamp(int offset)
    Clamps an arbitrary offset into the valid range [0, length()].
    int
    columnOfOffset(int offset)
    Returns the column (offset within its line) for the given absolute offset.
    void
    delete(int start, int end)
    Deletes the range [start, end).
    int
    Returns the number of logical lines (always at least one).
    int
    getLineEnd(int line)
    Returns the end offset (exclusive, not counting the trailing newline) of the given line.
    int
    getLineStart(int line)
    Returns the start offset of the given line.
    getLineText(int line)
    Returns the text of the given line without its trailing newline.
    Returns the full document text.
    void
    insert(int offset, String text)
    Inserts text at the given offset.
    int
    Returns the total number of UTF-16 characters in the document.
    int
    lineOfOffset(int offset)
    Returns the zero based line index containing the given offset.
    static String
    Normalizes platform line endings into the document's canonical LF representation.
    void
    Replaces the entire document content.
    substring(int start, int end)
    Returns the substring in [start, end).

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EditorDocument

      public EditorDocument()
      Creates an empty document.
    • EditorDocument

      public EditorDocument(String text)

      Creates a document initialized with the supplied text.

      Parameters
      • text: the initial text, or null for an empty document
  • Method Details

    • normalizeText

      public static String normalizeText(String text)
      Normalizes platform line endings into the document's canonical LF representation.
    • length

      public int length()
      Returns the total number of UTF-16 characters in the document.
    • getText

      public String getText()
      Returns the full document text.
    • charAt

      public char charAt(int offset)

      Returns the character at the given offset.

      Parameters
      • offset: a valid offset in [0, length())
    • substring

      public String substring(int start, int end)
      Returns the substring in [start, end).
    • setText

      public void setText(String text)

      Replaces the entire document content.

      Parameters
      • text: the new text, or null to clear the document
    • insert

      public void insert(int offset, String text)

      Inserts text at the given offset.

      Parameters
      • offset: the insertion offset in [0, length()]

      • text: the text to insert

    • delete

      public void delete(int start, int end)

      Deletes the range [start, end).

      Parameters
      • start: inclusive start offset

      • end: exclusive end offset

    • clamp

      public int clamp(int offset)
      Clamps an arbitrary offset into the valid range [0, length()].
    • getLineCount

      public int getLineCount()
      Returns the number of logical lines (always at least one).
    • getLineStart

      public int getLineStart(int line)

      Returns the start offset of the given line.

      Parameters
      • line: a zero based line index in [0, getLineCount())
    • getLineEnd

      public int getLineEnd(int line)

      Returns the end offset (exclusive, not counting the trailing newline) of the given line.

      Parameters
      • line: a zero based line index in [0, getLineCount())
    • getLineText

      public String getLineText(int line)

      Returns the text of the given line without its trailing newline.

      Parameters
      • line: a zero based line index in [0, getLineCount())
    • lineOfOffset

      public int lineOfOffset(int offset)

      Returns the zero based line index containing the given offset.

      Parameters
      • offset: an offset in [0, length()]
    • columnOfOffset

      public int columnOfOffset(int offset)

      Returns the column (offset within its line) for the given absolute offset.

      Parameters
      • offset: an offset in [0, length()]