public class DefaultToken extends Token
org.fife.ui.rsyntaxtextarea
syntax
package. This token type paints itself as you would expect, and properly
accounts for rendering hints (anti-aliasing and fractional font metrics).The current implementation paints as follows:
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()?).
Token
,
VisibleWhitespaceToken
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 and Description |
---|
DefaultToken()
Creates a "null token."
|
DefaultToken(char[] line,
int beg,
int end,
int startOffset,
int type)
Constructor.
|
DefaultToken(Segment line,
int beg,
int end,
int startOffset,
int type)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
getListOffset(RSyntaxTextArea textArea,
TabExpander e,
float x0,
float x)
Determines the offset into this token list (i.e., into the
document) that covers pixel location
x if the token list
starts at pixel location x0 . |
float |
getWidthUpTo(int numChars,
RSyntaxTextArea textArea,
TabExpander e,
float x0)
Returns the width of a specified number of characters in this token.
|
Rectangle |
listOffsetToView(RSyntaxTextArea textArea,
TabExpander e,
int pos,
int x0,
Rectangle rect)
Returns the bounding box for the specified document location.
|
float |
paint(Graphics2D g,
float x,
float y,
RSyntaxTextArea host,
TabExpander e,
float clipStart)
Paints this 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
public DefaultToken()
public DefaultToken(Segment line, int beg, int end, int startOffset, int type)
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.public DefaultToken(char[] line, int beg, int end, int startOffset, int type)
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.public int getListOffset(RSyntaxTextArea textArea, TabExpander e, float x0, float x)
x
if the token list
starts at pixel location x0
.
This method will return the document position "closest" to the
x-coordinate (i.e., if they click on the "right-half" of the
w
in awe
, the caret will be placed in
between the w
and e
; similarly, clicking on
the left-half places the caret between the a
and
w
). This makes it useful for methods such as
viewToModel
found in javax.swing.text.View
subclasses.
getListOffset
in class Token
textArea
- The text area from which the token list was derived.e
- How to expand tabs.x0
- The pixel x-location that is the beginning of
tokenList
.x
- The pixel-position for which you want to get the corresponding
offset.tokenList
is
null
or has type Token.NULL
, then
-1
public float getWidthUpTo(int numChars, RSyntaxTextArea textArea, TabExpander e, float x0)
3
here returns the width of the "whi" portion of the token.getWidthUpTo
in class Token
numChars
- The number of characters for which to get the width.textArea
- The text area in which this token is being painted.e
- How to expand tabs. This value cannot be null
.x0
- The pixel-location at which this token begins. This is needed
because of tabs.Token.getWidth(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea, javax.swing.text.TabExpander, float)
public Rectangle listOffsetToView(RSyntaxTextArea textArea, TabExpander e, int pos, int x0, Rectangle rect)
listOffsetToView
in class Token
textArea
- The text area from which the token list was derived.e
- How to expand tabs.pos
- The position in the document for which to get the bounding
box in the view.x0
- The pixel x-location that is the beginning of
tokenList
.rect
- The rectangle in which we'll be returning the results. This
object is reused to keep from frequent memory allocations.public float paint(Graphics2D g, float x, float y, RSyntaxTextArea host, TabExpander e, float clipStart)
paint
in class Token
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
when this token is "to the left" of the clip rectangle.