Package org.fife.ui.rsyntaxtextarea
Class DefaultTokenFactory
- java.lang.Object
-
- org.fife.ui.rsyntaxtextarea.DefaultTokenFactory
-
- All Implemented Interfaces:
TokenFactory
class DefaultTokenFactory extends java.lang.Object implements TokenFactory
This class generates tokens for aTokenMaker. This class is here because it reuses tokens when they aren't needed anymore to prevent This class doesn't actually create new tokens every timecreateTokenis called. Instead, it internally keeps a stack of available already-created tokens. When more tokens are needed to properly display a line, more tokens are added to the available stack. This saves from needless repetitive memory allocation. However, it makes it IMPERATIVE that users callresetTokenListwhen creating a new token list so that the token maker can keep an accurate list of available tokens.NOTE: This class should only be used by
TokenMaker; nobody else needs it!- Version:
- 0.1
-
-
Field Summary
Fields Modifier and Type Field Description private intcurrentFreeTokenprotected static intDEFAULT_INCREMENTprotected static intDEFAULT_START_SIZEprivate intincrementprivate intsizeprivate TokenImpl[]tokenList
-
Constructor Summary
Constructors Constructor Description DefaultTokenFactory()Constructor.DefaultTokenFactory(int size, int increment)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaugmentTokenList()Adds tokens to the internal token list.TokenImplcreateToken()Returns a null token.TokenImplcreateToken(char[] line, int beg, int end, int startOffset, int type)Returns a token.TokenImplcreateToken(javax.swing.text.Segment line, int beg, int end, int startOffset, int type)Returns a token.voidresetAllTokens()Resets the state of this token maker.
-
-
-
Field Detail
-
size
private int size
-
increment
private int increment
-
tokenList
private TokenImpl[] tokenList
-
currentFreeToken
private int currentFreeToken
-
DEFAULT_START_SIZE
protected static final int DEFAULT_START_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_INCREMENT
protected static final int DEFAULT_INCREMENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
augmentTokenList
private void augmentTokenList()
Adds tokens to the internal token list. This is called whenever a request is made and no more tokens are available.
-
createToken
public TokenImpl createToken()
Description copied from interface:TokenFactoryReturns a null token.- Specified by:
createTokenin interfaceTokenFactory- Returns:
- A null token.
-
createToken
public TokenImpl createToken(javax.swing.text.Segment line, int beg, int end, int startOffset, int type)
Description copied from interface:TokenFactoryReturns a token.- Specified by:
createTokenin interfaceTokenFactory- Parameters:
line- The segment from which to get the token's text.beg- The starting offset of the token's text in the segment.end- The ending offset of the token's text in the segment.startOffset- The offset in the document of the token.type- The type of token.- Returns:
- The token.
-
createToken
public TokenImpl createToken(char[] line, int beg, int end, int startOffset, int type)
Description copied from interface:TokenFactoryReturns a token.- Specified by:
createTokenin interfaceTokenFactory- Parameters:
line- The char array from which to get the token's text.beg- The starting offset of the token's text in the char array.end- The ending offset of the token's text in the char array.startOffset- The offset in the document of the token.type- The type of token.- Returns:
- The token.
-
resetAllTokens
public void resetAllTokens()
Resets the state of this token maker. This method should be called by theTokenMakerevery time a token list is generated for a new line so the tokens can be reused.- Specified by:
resetAllTokensin interfaceTokenFactory
-
-