public class SyntaxTokenizer
extends java.lang.Object
Document doc = ... CodeEditorDefaults defaults = CodeEditorDefaults.getDefaults(); SyntaxTokenizer tokenizer = new SyntaxTokenizer("java", defaults); StyledDocument styleDoc = tokenizer.applySyntax(doc);
StyleDocument
to apply the Syntax. In that case the method will merge the syntax with
the background colors detected in the input StyleDocument
.Constructor and Description |
---|
SyntaxTokenizer(java.lang.String syntax)
Constructor.
|
SyntaxTokenizer(java.lang.String syntax,
CodeEditorDefaults defaults)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
javax.swing.text.StyledDocument |
applySyntax(javax.swing.text.Document doc)
Apply the syntax of the SyntaxTokenizer on a Document and return the associated StyledDocument.
|
java.lang.String |
getSyntax()
Return the SyntaxTokenizer syntax name.
|
public SyntaxTokenizer(java.lang.String syntax)
syntax
- the syntax namepublic SyntaxTokenizer(java.lang.String syntax, CodeEditorDefaults defaults)
syntax
- the syntax namedefaults
- the CodeEditorDefaultspublic java.lang.String getSyntax()
public javax.swing.text.StyledDocument applySyntax(javax.swing.text.Document doc)
StyleDocument
.
For example:
DefaultStyledDocument doc = ... SimpleAttributeSet attrs = new SimpleAttributeSet(); Style style = doc.addStyle("style", null); StyleConstants.setBackground(style, Color.YELLOW); doc.setCharacterAttributes(offset, length, style, false); CodeEditorDefaults defaults = CodeEditorDefaults.getDefaults(); SyntaxTokenizer tokenizer = new SyntaxTokenizer("java", defaults); StyledDocument styleDoc = tokenizer.applySyntax(doc);
doc
- the DocumentCopyright © 2016, 2017, 2018, 2019, 2023 Herve Girod. All Rights Reserved. Documentation and source under the MIT licence