public abstract class LexerBlockRenderer extends java.lang.Object implements BlockRenderer
LexerBlockRenderer
is the abstract starting point for BlockRenderer
implementations based on languages for which there is a Lexer
implementation available. This takes care of implementing common functionality.BlockRenderer
, Lexer
Modifier and Type | Field and Description |
---|---|
protected Lexer |
lexer
The Lexer that is used for tokenizing.
|
protected LexerToken |
lexerToken
The LexerToken structure for interfacing with the Lexer.
|
protected TextBuffer |
textBuffer
The text buffer that we are rendering.
|
Constructor and Description |
---|
LexerBlockRenderer(TextBuffer textBuffer)
Constructs a new block renderer for the specified document.
|
Modifier and Type | Method and Description |
---|---|
protected abstract Lexer |
createLexer()
Creates a Lexer used for breaking apart tokens in the primary language of this
BlockRenderer implementation. |
protected java.lang.String |
getDefaultStyleName()
Fetches the default style to use for rendering text that does not have an associated token.
|
protected Lexer |
getLexer()
Get a cached language-specific Lexer (so that we don't have to constantly recreate it every time.)
|
protected LexerToken |
getLexerToken()
Get a cached lexer-specific LexerToken (that we don't have to recreate every time) from the Lexer.
|
TextBuffer |
getTextBuffer()
Fetches the text buffer that this block renderer is rendering.
|
protected abstract java.lang.String |
mapTokenToStyleName(int token)
Fetches the style to use for the token fetched from the Lexer.
|
void |
renderBlock(StyledFragmentsList fragmentsList, int blockStartOffset, int blockEndOffset, int clipStartOffset, int clipEndOffset)
Renders the region of text bounded by the given offsets.
|
protected void |
renderToken(StyledFragmentsList fragmentsList, int token, int tokenStart, int tokenEnd, int clipStart, int clipEnd)
Renders the token by mapping the given token to a specific style, and adds it to the styled fragments list.
|
protected TextBuffer textBuffer
protected Lexer lexer
protected LexerToken lexerToken
public LexerBlockRenderer(TextBuffer textBuffer)
textBuffer
- the text buffer to renderpublic TextBuffer getTextBuffer()
protected abstract Lexer createLexer()
BlockRenderer
implementation.protected final Lexer getLexer()
protected final LexerToken getLexerToken()
public void renderBlock(StyledFragmentsList fragmentsList, int blockStartOffset, int blockEndOffset, int clipStartOffset, int clipEndOffset)
blockStartOffset
to blockEndOffset
) marks the start and end of the block for the given language. This can be used for example to set the starting position of a language-specific Lexer
.
The second set, clipStartOffset
to clipEndOffset
marks the clip region within which the block should be rendered. Implementations must not add fragments to the fragments list outside the range of these clip offsets, otherwise, an internal exception will occur (this is different from the clip bounds for graphics areas.)
renderBlock
in interface BlockRenderer
fragmentsList
- the fragments list which rendered fragments should be appended toblockStartOffset
- the starting offset of the language blockblockEndOffset
- the ending offset of the language blockclipStartOffset
- the starting offset of the region to renderclipEndOffset
- the ending offset of the region to renderprotected void renderToken(StyledFragmentsList fragmentsList, int token, int tokenStart, int tokenEnd, int clipStart, int clipEnd)
BlockRenderer
implementation. Do not add fragments outside of the clip region, or else an internal exception will occur.fragmentsList
- the styled fragments listtoken
- the token to rendertokenStart
- the starting offset of the token (inclusive)tokenEnd
- the ending offset of the token (exclusive)clipStart
- the start of the clip offsetclipEnd
- the end of the clip offsetprotected abstract java.lang.String mapTokenToStyleName(int token)
token
- the token fetchedprotected java.lang.String getDefaultStyleName()