Class DefaultDocumentModel

java.lang.Object
com.simsilica.lemur.text.DefaultDocumentModel
All Implemented Interfaces:
VersionedObject<DocumentModel>, DocumentModel, Cloneable

public class DefaultDocumentModel extends Object implements DocumentModel, Cloneable
A default implementation of the DocumentModel interface.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deletes the character immediately before the current carat position.
    Deep clones this document model.
    Returns a VersionedReference that can be watched for changes to the carat position.
    protected void
     
    Creates a new VersionedReference that can be used to monitor when this object changes.
    void
    Deletes the character immediately after the current carat position.
    void
    deleteCharAt(int pos)
    Deletes the character at the specified position.
    int
    Moves the carat position to the next line if there is one.
    int
    end(boolean currentLine)
    Moves the carat to the document's end position or the current line's end position depending on the specified 'currentLine' value.
    protected void
    findPosition(int pos, int[] location)
    Find the line and column of the specified text position.
    int
    During text selection, this is one end of the selection where the other end is the carat position.
    int
    Returns the column number of the current anchor position in the line returned by getAnchorLine().
    int
    Returns the line number containing the current anchor position.
    int
    Returns the current 'carat' position.
    int
    Returns the column number of the current carat position in the line returned by getCaratLine().
    int
    Returns the line number containing the current carat position.
    getLine(int line)
    Returns the string representing just the specified line of text.
    int
    Returns the current number of lines in this document.
    Returns the object that is being versioned.
    Returns the current text value contained in this DocumentModel.
    long
    Returns the current version of the versioned object.
    int
    home(boolean currentLine)
    Moves the carat to the document's home position or the current line's home position depending on the specified 'currentLine' value.
    void
    insert(char c)
    Inserts a character at the current carat position.
    void
    insert(String text)
    Bulk inserts a string of text.
    void
    Inserts a new line at the current carat position.
    int
    Moves the carat one position to the left, potentially moving it to the previous line depending on the actual DocumentModel implementation.
    protected void
     
    int
    Moves the carat one position to the right, potentially moving it to the next line depending on the actual DocumentModel implementation.
    void
    Replaces the text contained in this DocumentModel.
     
    int
    up()
    Moves the carat position to the previous line if there is one.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • DefaultDocumentModel

      public DefaultDocumentModel()
    • DefaultDocumentModel

      public DefaultDocumentModel(String text)
  • Method Details

    • clone

      public DefaultDocumentModel clone()
      Description copied from interface: DocumentModel
      Deep clones this document model.
      Specified by:
      clone in interface DocumentModel
      Overrides:
      clone in class Object
    • setText

      public void setText(String text)
      Description copied from interface: DocumentModel
      Replaces the text contained in this DocumentModel.
      Specified by:
      setText in interface DocumentModel
    • getText

      public String getText()
      Description copied from interface: DocumentModel
      Returns the current text value contained in this DocumentModel.
      Specified by:
      getText in interface DocumentModel
    • getLine

      public String getLine(int line)
      Description copied from interface: DocumentModel
      Returns the string representing just the specified line of text.
      Specified by:
      getLine in interface DocumentModel
    • getLineCount

      public int getLineCount()
      Description copied from interface: DocumentModel
      Returns the current number of lines in this document.
      Specified by:
      getLineCount in interface DocumentModel
    • getCarat

      public int getCarat()
      Description copied from interface: DocumentModel
      Returns the current 'carat' position. The 'carat' is where new text characters will be inserted. It's the current edit position.
      Specified by:
      getCarat in interface DocumentModel
    • getCaratLine

      public int getCaratLine()
      Description copied from interface: DocumentModel
      Returns the line number containing the current carat position.
      Specified by:
      getCaratLine in interface DocumentModel
    • getCaratColumn

      public int getCaratColumn()
      Description copied from interface: DocumentModel
      Returns the column number of the current carat position in the line returned by getCaratLine().
      Specified by:
      getCaratColumn in interface DocumentModel
    • getAnchorLine

      public int getAnchorLine()
      Description copied from interface: DocumentModel
      Returns the line number containing the current anchor position.
      Specified by:
      getAnchorLine in interface DocumentModel
    • getAnchorColumn

      public int getAnchorColumn()
      Description copied from interface: DocumentModel
      Returns the column number of the current anchor position in the line returned by getAnchorLine().
      Specified by:
      getAnchorColumn in interface DocumentModel
    • getAnchor

      public int getAnchor()
      Description copied from interface: DocumentModel
      During text selection, this is one end of the selection where the other end is the carat position.
      Specified by:
      getAnchor in interface DocumentModel
    • home

      public int home(boolean currentLine)
      Description copied from interface: DocumentModel
      Moves the carat to the document's home position or the current line's home position depending on the specified 'currentLine' value. If currentLine is true then the home position is just before the first character in the current line. If the currentLine parameter is false then the home position is just before the first character in the whole document.
      Specified by:
      home in interface DocumentModel
    • end

      public int end(boolean currentLine)
      Description copied from interface: DocumentModel
      Moves the carat to the document's end position or the current line's end position depending on the specified 'currentLine' value. If currentLine is true then the end position is just after the last character in the current line. If the currentLine parameter is false then the end position is just after the last character in the whole document.
      Specified by:
      end in interface DocumentModel
    • up

      public int up()
      Description copied from interface: DocumentModel
      Moves the carat position to the previous line if there is one. After this call, the new column position is implementation dependent.
      Specified by:
      up in interface DocumentModel
    • down

      public int down()
      Description copied from interface: DocumentModel
      Moves the carat position to the next line if there is one. After this call, the new column position is implementation dependent.
      Specified by:
      down in interface DocumentModel
    • left

      public int left()
      Description copied from interface: DocumentModel
      Moves the carat one position to the left, potentially moving it to the previous line depending on the actual DocumentModel implementation.
      Specified by:
      left in interface DocumentModel
    • right

      public int right()
      Description copied from interface: DocumentModel
      Moves the carat one position to the right, potentially moving it to the next line depending on the actual DocumentModel implementation.
      Specified by:
      right in interface DocumentModel
    • insertNewLine

      public void insertNewLine()
      Description copied from interface: DocumentModel
      Inserts a new line at the current carat position.
      Specified by:
      insertNewLine in interface DocumentModel
    • deleteCharAt

      public void deleteCharAt(int pos)
      Description copied from interface: DocumentModel
      Deletes the character at the specified position.
      Specified by:
      deleteCharAt in interface DocumentModel
    • backspace

      public void backspace()
      Description copied from interface: DocumentModel
      Deletes the character immediately before the current carat position. This may move the carat to the previous line if the carat was previously at the beginning of a line.
      Specified by:
      backspace in interface DocumentModel
    • delete

      public void delete()
      Description copied from interface: DocumentModel
      Deletes the character immediately after the current carat position.
      Specified by:
      delete in interface DocumentModel
    • findPosition

      protected void findPosition(int pos, int[] location)
      Find the line and column of the specified text position.
    • insert

      public void insert(char c)
      Description copied from interface: DocumentModel
      Inserts a character at the current carat position.
      Specified by:
      insert in interface DocumentModel
    • insert

      public void insert(String text)
      Description copied from interface: DocumentModel
      Bulk inserts a string of text.
      Specified by:
      insert in interface DocumentModel
    • getVersion

      public long getVersion()
      Description copied from interface: VersionedObject
      Returns the current version of the versioned object.
      Specified by:
      getVersion in interface VersionedObject<DocumentModel>
    • getObject

      public DocumentModel getObject()
      Description copied from interface: VersionedObject
      Returns the object that is being versioned.
      Specified by:
      getObject in interface VersionedObject<DocumentModel>
    • createReference

      public VersionedReference<DocumentModel> createReference()
      Description copied from interface: VersionedObject
      Creates a new VersionedReference that can be used to monitor when this object changes.
      Specified by:
      createReference in interface VersionedObject<DocumentModel>
    • createCaratReference

      public VersionedReference<Integer> createCaratReference()
      Description copied from interface: DocumentModel
      Returns a VersionedReference that can be watched for changes to the carat position.
      Specified by:
      createCaratReference in interface DocumentModel
    • parseText

      protected void parseText(String text)
    • createComposite

      protected void createComposite()
    • toString

      public String toString()
      Overrides:
      toString in class Object