Class JSyntaxDocument
java.lang.Object
javax.swing.text.AbstractDocument
javax.swing.text.DefaultStyledDocument
net.thevpc.jeep.editor.JSyntaxDocument
- All Implemented Interfaces:
Serializable, Document, StyledDocument
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class DefaultStyledDocument
DefaultStyledDocument.AttributeUndoableEdit, DefaultStyledDocument.ElementBuffer, DefaultStyledDocument.ElementSpec, DefaultStyledDocument.SectionElementNested classes/interfaces inherited from class AbstractDocument
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement -
Field Summary
Fields inherited from class DefaultStyledDocument
buffer, BUFFER_SIZE_DEFAULTFields inherited from class AbstractDocument
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementNameFields inherited from interface Document
StreamDescriptionProperty, TitleProperty -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis will discard all undoable editsvoiddoRedo()Perform a redo action, if possible.voiddoUndo()Perform an undo action, if possibleprotected voidprotected voidprotected voidprotected voidintReturn the number of lines in this documentintgetLineEndOffset(int pos) Returns the end position of the line at pos.intgetLineNumberAt(int pos) Return the line number at given position.intgetLineStartOffset(int pos) Returns the starting position of the line at posgetPairFor(JToken t) This is used to return the other part of a paired token in the document.getTokenAt(int pos) Find the token at a given position.getTokens(int start, int end) Return an iterator of tokens between p0 and p1.voidreplaceToken(JToken token, String replacement) Replace the token with the replacement stringtoString()Methods inherited from class DefaultStyledDocument
addDocumentListener, addStyle, create, createDefaultRoot, getBackground, getCharacterElement, getDefaultRootElement, getFont, getForeground, getLogicalStyle, getParagraphElement, getStyle, getStyleNames, insert, insertUpdate, removeDocumentListener, removeElement, removeStyle, removeUpdate, setCharacterAttributes, setLogicalStyle, setParagraphAttributes, styleChangedMethods inherited from class AbstractDocument
addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, insertString, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlockMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Document
addUndoableEditListener, createPosition, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, insertString, putProperty, remove, removeUndoableEditListener, render
-
Constructor Details
-
JSyntaxDocument
-
-
Method Details
-
getUndoManager
-
fireChangedUpdate
- Overrides:
fireChangedUpdatein classAbstractDocument
-
fireInsertUpdate
- Overrides:
fireInsertUpdatein classAbstractDocument
-
fireRemoveUpdate
- Overrides:
fireRemoveUpdatein classAbstractDocument
-
fireUndoableEditUpdate
- Overrides:
fireUndoableEditUpdatein classAbstractDocument
-
replaceToken
-
getTokens
-
getTokenAt
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
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
-