Class JSyntaxDocument

All Implemented Interfaces:
Serializable, Document, StyledDocument

public class JSyntaxDocument extends DefaultStyledDocument
A document that supports being highlighted. The document maintains an internal List of all the Tokens. The Tokens are updated using a Lexer, passed to it during construction.
Author:
Ayman Al-Sairafi
See Also:
  • Constructor Details

    • JSyntaxDocument

      public JSyntaxDocument(JContext jcontext)
  • Method Details

    • getUndoManager

      public UndoManager getUndoManager()
    • fireChangedUpdate

      protected void fireChangedUpdate(DocumentEvent e)
      Overrides:
      fireChangedUpdate in class AbstractDocument
    • fireInsertUpdate

      protected void fireInsertUpdate(DocumentEvent e)
      Overrides:
      fireInsertUpdate in class AbstractDocument
    • fireRemoveUpdate

      protected void fireRemoveUpdate(DocumentEvent e)
      Overrides:
      fireRemoveUpdate in class AbstractDocument
    • fireUndoableEditUpdate

      protected void fireUndoableEditUpdate(UndoableEditEvent e)
      Overrides:
      fireUndoableEditUpdate in class AbstractDocument
    • replaceToken

      public void replaceToken(JToken token, String replacement)
      Replace the token with the replacement string
      Parameters:
      token -
      replacement -
    • getTokens

      public Iterator<JToken> getTokens(int start, int end)
      Return an iterator of tokens between p0 and p1.
      Parameters:
      start - start position for getting tokens
      end - position for last token
      Returns:
      Iterator for tokens that overal with range from start to end
    • getTokenAt

      public JToken getTokenAt(int pos)
      Find the token at a given position. May return null if no token is found (whitespace skipped) or if the position is out of range:
      Parameters:
      pos -
      Returns:
    • getPairFor

      public JToken getPairFor(JToken t)
      This is used to return the other part of a paired token in the document. A paired part has token.pairValue <> 0, and the paired token will have the negative of t.pairValue. This method properly handles nesting of same pairValues, but overlaps are not checked. if The document does not contain a paired
      Parameters:
      t -
      Returns:
      the other pair's token, or null if nothing is found.
    • doUndo

      public void doUndo()
      Perform an undo action, if possible
    • doRedo

      public void doRedo()
      Perform a redo action, if possible.
    • getLineStartOffset

      public int getLineStartOffset(int pos)
      Returns the starting position of the line at pos
      Parameters:
      pos -
      Returns:
      starting position of the line
    • getLineEndOffset

      public int getLineEndOffset(int pos)
      Returns the end position of the line at pos. Does a bounds check to ensure the returned value does not exceed document length
      Parameters:
      pos -
      Returns:
    • getLineCount

      public int getLineCount()
      Return the number of lines in this document
      Returns:
    • getLineNumberAt

      public int getLineNumberAt(int pos)
      Return the line number at given position. The line numbers are zero based
      Parameters:
      pos -
      Returns:
    • clearUndos

      public void clearUndos()
      This will discard all undoable edits
    • toString

      public String toString()
      Overrides:
      toString in class Object