org.fife.ui.rsyntaxtextarea
Class VisibleWhitespaceToken

java.lang.Object
  extended by org.fife.ui.rsyntaxtextarea.Token
      extended by org.fife.ui.rsyntaxtextarea.DefaultToken
          extended by org.fife.ui.rsyntaxtextarea.VisibleWhitespaceToken

public class VisibleWhitespaceToken
extends DefaultToken

This token class paints spaces and tabs with special symbols so the user can see the whitespace in his document. Rendering hints are honored.

The current implementation paints as follows:

This means that rendering hints are applied to all groups of characters within a token, excluding whitespace and tabs.

A problem with this implementation is that FontMetrics.charsWidth() is still used to calculate the width of a group of chars painted. Thus, the group of characters will be painted with the rendering hints specified, but the following tab (or group of characters if the current group was the end of a token) will not necessarily be painted at the proper x-coordinate (as FontMetrics.charsWidth() returns an int and not a float). The way around this would be to calculate the token's width in such a way that a float is returned (Font.getStringBounds()?).

Version:
0.5
Author:
Robert Futrell
See Also:
Token, DefaultToken

Field Summary
 
Fields inherited from class org.fife.ui.rsyntaxtextarea.Token
COMMENT_DOCUMENTATION, COMMENT_EOL, COMMENT_MULTILINE, DATA_TYPE, ERROR_CHAR, ERROR_IDENTIFIER, ERROR_NUMBER_FORMAT, ERROR_STRING_DOUBLE, FUNCTION, IDENTIFIER, LITERAL_BACKQUOTE, LITERAL_BOOLEAN, LITERAL_CHAR, LITERAL_NUMBER_DECIMAL_INT, LITERAL_NUMBER_FLOAT, LITERAL_NUMBER_HEXADECIMAL, LITERAL_STRING_DOUBLE_QUOTE, MARKUP_TAG_ATTRIBUTE, MARKUP_TAG_DELIMITER, MARKUP_TAG_NAME, NULL, NUM_TOKEN_TYPES, offset, OPERATOR, PREPROCESSOR, RESERVED_WORD, SEPARATOR, text, textCount, textOffset, type, VARIABLE, WHITESPACE
 
Constructor Summary
VisibleWhitespaceToken()
          Creates a "null token."
VisibleWhitespaceToken(char[] line, int beg, int end, int startOffset, int type)
          Constructor.
VisibleWhitespaceToken(Segment line, int beg, int end, int startOffset, int type)
          Constructor.
 
Method Summary
 float paint(Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart)
          Paints this token, using special symbols for whitespace characters.
 
Methods inherited from class org.fife.ui.rsyntaxtextarea.DefaultToken
getListOffset, getWidthUpTo, listOffsetToView
 
Methods inherited from class org.fife.ui.rsyntaxtextarea.Token
appendHTMLRepresentation, containsPosition, copyFrom, documentToToken, getHTMLRepresentation, getLastNonCommentNonWhitespaceToken, getLastPaintableToken, getLexeme, getNextToken, getOffsetBeforeX, getWidth, is, isComment, isHyperlink, isLeftCurly, isPaintable, isRightCurly, isSingleChar, isWhitespace, makeStartAt, moveOffset, paint, paintBackground, set, setHyperlink, setNextToken, tokenToDocument, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VisibleWhitespaceToken

public VisibleWhitespaceToken()
Creates a "null token." The token itself is not null; rather, it signifies that it is the last token in a linked list of tokens and that it is not part of a "multi-line token."


VisibleWhitespaceToken

public VisibleWhitespaceToken(Segment line,
                              int beg,
                              int end,
                              int startOffset,
                              int type)
Constructor.

Parameters:
line - The segment from which to get the token.
beg - The first character's position in line.
end - The last character's position in line.
startOffset - The offset into the document at which this token begins.
type - A token type listed as "generic" above.

VisibleWhitespaceToken

public VisibleWhitespaceToken(char[] line,
                              int beg,
                              int end,
                              int startOffset,
                              int type)
Constructor.

Parameters:
line - The segment from which to get the token.
beg - The first character's position in line.
end - The last character's position in line.
startOffset - The offset into the document at which this token begins.
type - A token type listed as "generic" above.
Method Detail

paint

public final float paint(Graphics2D g,
                         float x,
                         float y,
                         RSyntaxTextArea host,
                         TabExpander e,
                         float clipStart)
Paints this token, using special symbols for whitespace characters.

Overrides:
paint in class DefaultToken
Parameters:
g - The graphics context in which to paint.
x - The x-coordinate at which to paint.
y - The y-coordinate at which to paint.
host - The text area this token is in.
e - How to expand tabs.
clipStart - The left boundary of the clip rectangle in which we're painting. This optimizes painting by allowing us to not paint not paint when this token is "to the left" of the clip rectangle.
Returns:
The x-coordinate representing the end of the painted text.