Package groovy.console.ui.text
Class SmartDocumentFilter
java.lang.Object
javax.swing.text.DocumentFilter
groovy.console.ui.text.SmartDocumentFilter
The document filter based on Parrot's lexer is for highlighting the content of text editor
- Since:
- 3.0.0
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.text.DocumentFilter
DocumentFilter.FilterBypass -
Field Summary
FieldsModifier and TypeFieldDescriptionToken types rendered with the reserved-word style. -
Constructor Summary
ConstructorsConstructorDescriptionSmartDocumentFilter(DefaultStyledDocument styledDocument) Creates a filter that styles the supplied document. -
Method Summary
Modifier and TypeMethodDescriptionList<org.antlr.v4.runtime.Token>Returns the tokens produced by the most recent successful parse.Returns the character range scheduled for selective re-rendering.voidinsertString(DocumentFilter.FilterBypass fb, int offset, String text, AttributeSet attrs) booleanisLatest()Indicates whether the cached token list reflects the current document text.voidremove(DocumentFilter.FilterBypass fb, int offset, int length) voidForces a full re-parse and re-render of the document with current styles.voidreplace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) voidsetRenderRange(Tuple2<Integer, Integer> renderRange) Limits rendering to the supplied character range for the next parse.static voidUpdates all SmartDocumentFilter styles with current theme colors.
-
Field Details
-
HIGHLIGHTED_TOKEN_TYPE_LIST
Token types rendered with the reserved-word style.
-
-
Constructor Details
-
SmartDocumentFilter
Creates a filter that styles the supplied document.- Parameters:
styledDocument- the document to tokenize and highlight
-
-
Method Details
-
insertString
public void insertString(DocumentFilter.FilterBypass fb, int offset, String text, AttributeSet attrs) throws BadLocationException - Overrides:
insertStringin classDocumentFilter- Throws:
BadLocationException
-
remove
public void remove(DocumentFilter.FilterBypass fb, int offset, int length) throws BadLocationException - Overrides:
removein classDocumentFilter- Throws:
BadLocationException
-
replace
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException - Overrides:
replacein classDocumentFilter- Throws:
BadLocationException
-
reparseDocument
public void reparseDocument()Forces a full re-parse and re-render of the document with current styles. Clears the incremental-render cache first so every token is restyled, not just the ones that differ from the last parse.- Since:
- 6.0.0
-
updateStyles
public static void updateStyles()Updates all SmartDocumentFilter styles with current theme colors. Attribute values are sourced from ThemeManager so custom .theme files feed both this (ANTLR-token-driven) path and the regex-driven GroovyFilter path from one place. Called at init time and on theme switch.- Since:
- 6.0.0
-
isLatest
public boolean isLatest()Indicates whether the cached token list reflects the current document text.- Returns:
trueif the latest parse completed successfully
-
getLatestTokenList
Returns the tokens produced by the most recent successful parse.- Returns:
- the latest token list
-
setRenderRange
Limits rendering to the supplied character range for the next parse.- Parameters:
renderRange- the inclusive start and stop offsets to re-render, ornullfor all text
-
getRenderRange
Returns the character range scheduled for selective re-rendering.- Returns:
- the current render range, or
nullif the whole document will be rendered
-