Package jsyntaxpane
Class SyntaxDocument
java.lang.Object
javax.swing.text.AbstractDocument
javax.swing.text.PlainDocument
jsyntaxpane.SyntaxDocument
- All Implemented Interfaces:
Serializable
,Document
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.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
-
Field Summary
Fields inherited from class javax.swing.text.PlainDocument
lineLimitAttribute, tabSizeAttribute
Fields inherited from class javax.swing.text.AbstractDocument
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
Fields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppend the given string to the text of this document.void
This will discard all undoable editsvoid
doRedo()
Perform a redo action, if possible.void
doUndo()
Perform an undo action, if possibleprotected void
protected void
protected void
getLineAt
(int pos) Gets the line at given position.int
Return the number of lines in this documentint
getLineEndOffset
(int pos) Returns the end position of the line at pos.int
getLineNumberAt
(int pos) Return the line number at given position.int
getLineStartOffset
(int pos) Returns the starting position of the line at posgetMatcher
(Pattern pattern) Return a matcher that matches the given pattern on the entire documentgetMatcher
(Pattern pattern, int start) Return a matcher that matches the given pattern in the part of the document starting at offset start.getMatcher
(Pattern pattern, int start, int length) Return a matcher that matches the given pattern in the part of the document starting at offset start and ending at start + length.getNextToken
(Token tok) Return the token following the current token, or null This is an expensive operation, so do not use it to update the guigetPairFor
(Token t) This is used to return the other part of a paired token in the document.getPrevToken
(Token tok) Return the token prior to the given token, or null This is an expensive operation, so do not use it to update the guigetTokenAt
(int pos) Find the token at a given position.getTokens
(int start, int end) Return an iterator of tokens between p0 and p1.getUncommentedText
(int aStart, int anEnd) Gets the text without the comments.void
removeLineAt
(int pos) Deletes the line at given positionvoid
replace
(int offset, int length, String text, AttributeSet attrs) We override this here so that the replace is treated as one operation by the undomanagervoid
replaceLineAt
(int pos, String newLines) Replace the line at given position with the given string, which can span multiple linesvoid
replaceToken
(Token token, String replacement) Replace the token with the replacement stringtoString()
Methods inherited from class javax.swing.text.PlainDocument
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertString, insertUpdate, removeUpdate
Methods inherited from class javax.swing.text.AbstractDocument
addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock
-
Constructor Details
-
SyntaxDocument
-
-
Method Details
-
fireChangedUpdate
- Overrides:
fireChangedUpdate
in classAbstractDocument
-
fireInsertUpdate
- Overrides:
fireInsertUpdate
in classAbstractDocument
-
fireRemoveUpdate
- Overrides:
fireRemoveUpdate
in classAbstractDocument
-
replaceToken
Replace the token with the replacement string- Parameters:
token
-replacement
-
-
getTokens
Return an iterator of tokens between p0 and p1.- Parameters:
start
- start position for getting tokensend
- position for last token- Returns:
- Iterator for tokens that overal with range from start to end
-
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:
-
getWordAt
-
getNextToken
Return the token following the current token, or null This is an expensive operation, so do not use it to update the gui- Parameters:
tok
-- Returns:
-
getPrevToken
Return the token prior to the given token, or null This is an expensive operation, so do not use it to update the gui- Parameters:
tok
-- Returns:
-
getPairFor
This is used to return the other part of a paired token in the document. A paired part has token.pairValue invalid input: '<'> 0, and the paired token will have the negative of t.pairValue. This method properly handles nestings of same pairValues, but overlaps are not checked. if The document does not contain a paired token, then null is returned.- 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. -
getMatcher
Return a matcher that matches the given pattern on the entire document- Parameters:
pattern
-- Returns:
- matcher object
-
getMatcher
Return a matcher that matches the given pattern in the part of the document starting at offset start. Note that the matcher will have offset starting fromstart
- Parameters:
pattern
-start
-- Returns:
- matcher that MUST be offset by start to get the proper location within the document
-
getMatcher
Return a matcher that matches the given pattern in the part of the document starting at offset start and ending at start + length. Note that the matcher will have offset starting fromstart
- Parameters:
pattern
-start
-length
-- Returns:
- matcher that MUST be offset by start to get the proper location within the document
-
clearUndos
public void clearUndos()This will discard all undoable edits -
getLineAt
Gets the line at given position. The line returned will NOT include the line terminator '\n'- Parameters:
pos
- Position (usually from text.getCaretPosition()- Returns:
- the STring of text at given position
- Throws:
BadLocationException
-
removeLineAt
Deletes the line at given position- Parameters:
pos
-- Throws:
BadLocationException
-
replaceLineAt
Replace the line at given position with the given string, which can span multiple lines- Parameters:
pos
-newLines
-- Throws:
BadLocationException
-
getUncommentedText
Gets the text without the comments. For example for the string{ // it's a comment
this method will return "{ ".- Parameters:
aStart
- start of the text.anEnd
- end of the text.- Returns:
- String for the line without comments (if exists).
-
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:
-
toString
-
replace
public void replace(int offset, int length, String text, AttributeSet attrs) throws BadLocationException We override this here so that the replace is treated as one operation by the undomanager- Overrides:
replace
in classAbstractDocument
- Parameters:
offset
-length
-text
-attrs
-- Throws:
BadLocationException
-
append
Append the given string to the text of this document.- Parameters:
str
-- Returns:
- this document
-