Extension SDK 10.1.2

oracle.javatools.editor.language
Class LexerBlockRenderer

java.lang.Object
  extended byoracle.javatools.editor.language.LexerBlockRenderer
All Implemented Interfaces:
BlockRenderer

public abstract class LexerBlockRenderer
extends java.lang.Object
implements BlockRenderer

The 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.

See Also:
BlockRenderer, Lexer

Field Summary
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 Summary
LexerBlockRenderer(TextBuffer textBuffer)
          Constructs a new block renderer for the specified document.
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

textBuffer

protected TextBuffer textBuffer
The text buffer that we are rendering.


lexer

protected Lexer lexer
The Lexer that is used for tokenizing.


lexerToken

protected LexerToken lexerToken
The LexerToken structure for interfacing with the Lexer.

Constructor Detail

LexerBlockRenderer

public LexerBlockRenderer(TextBuffer textBuffer)
Constructs a new block renderer for the specified document.

Parameters:
textBuffer - the text buffer to render
Method Detail

getTextBuffer

public TextBuffer getTextBuffer()
Fetches the text buffer that this block renderer is rendering.


createLexer

protected abstract Lexer createLexer()
Creates a Lexer used for breaking apart tokens in the primary language of this BlockRenderer implementation.

Returns:
the language-specific lexer

getLexer

protected final Lexer getLexer()
Get a cached language-specific Lexer (so that we don't have to constantly recreate it every time.)

Returns:
the language-specific lexer

getLexerToken

protected final LexerToken getLexerToken()
Get a cached lexer-specific LexerToken (that we don't have to recreate every time) from the Lexer.

Returns:
a Lexer-specific LexerToken

renderBlock

public void renderBlock(StyledFragmentsList fragmentsList,
                        int blockStartOffset,
                        int blockEndOffset,
                        int clipStartOffset,
                        int clipEndOffset)
Renders the region of text bounded by the given offsets. The styles generated should be added (appended) to the provided fragments list. There are two sets of offsets provided. The first set, 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.)

Specified by:
renderBlock in interface BlockRenderer
Parameters:
fragmentsList - the fragments list which rendered fragments should be appended to
blockStartOffset - the starting offset of the language block
blockEndOffset - the ending offset of the language block
clipStartOffset - the starting offset of the region to render
clipEndOffset - the ending offset of the region to render

renderToken

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. This may be overrided by implementations where a given token needs to be sub-rendered by a different BlockRenderer implementation. Do not add fragments outside of the clip region, or else an internal exception will occur.

Parameters:
fragmentsList - the styled fragments list
token - the token to render
tokenStart - the starting offset of the token (inclusive)
tokenEnd - the ending offset of the token (exclusive)
clipStart - the start of the clip offset
clipEnd - the end of the clip offset

mapTokenToStyleName

protected abstract java.lang.String mapTokenToStyleName(int token)
Fetches the style to use for the token fetched from the Lexer.

Parameters:
token - the token fetched
Returns:
the name of the style to map the current token to

getDefaultStyleName

protected java.lang.String getDefaultStyleName()
Fetches the default style to use for rendering text that does not have an associated token.

Returns:
the name of the default style name to use (i.e., plain text style)

Extension SDK

 

Copyright © 1997, 2004, Oracle. All rights reserved.