Package org.fife.ui.rsyntaxtextarea
Class RSyntaxUtilities
- java.lang.Object
-
- org.fife.ui.rsyntaxtextarea.RSyntaxUtilities
-
- All Implemented Interfaces:
javax.swing.SwingConstants
public final class RSyntaxUtilities extends java.lang.Object implements javax.swing.SwingConstants
Utility methods used byRSyntaxTextArea
and its associated classes.- Version:
- 0.2
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BRACKET_MASK
private static java.lang.String
BRACKETS
Used internally.private static javax.swing.text.Segment
charSegment
Used in bracket matching methods.private static int[]
DATA_TABLE
A lookup table used to quickly decide if a 16-bit Java char is a US-ASCII letter (A-Z or a-z), a digit, a whitespace char (either space (0x0020) or tab (0x0009)), etc.private static int
HEX_CHARACTER_MASK
private static int
JAVA_OPERATOR_MASK
private static char[]
JS_AND
private static char[]
JS_KEYWORD_RETURN
Used internally.private static char[]
JS_OR
private static int
LETTER_MASK
private static int
LETTER_OR_DIGIT_MASK
private static java.awt.Color
LIGHT_HYPERLINK_FG
Used for the color of hyperlinks when a LookAndFeel uses light text against a dark background.private static int
OS
static int
OS_LINUX
Integer constant representing Linux.static int
OS_MAC_OSX
Integer constant representing Mac OS X.static int
OS_OTHER
Integer constant representing an "unknown" OS.static int
OS_WINDOWS
Integer constant representing a Windows-variant OS.private static TokenImpl
TEMP_TOKEN
Used in token list manipulation methods.
-
Constructor Summary
Constructors Modifier Constructor Description private
RSyntaxUtilities()
An unused constructor to prevent instantiation, and keep static analysis tools happy.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Map<?,?>
getBestPossibleAntiAliasHints()
Returns the best possible anti-alias hints to use when rendering text.static java.util.Map<?,?>
getDesktopAntiAliasHints()
Returns the rendering hints for text that will most accurately reflect those of the native windowing system.static java.awt.Color
getFoldedLineBottomColor(RSyntaxTextArea textArea)
Returns the color to use for the line underneath a folded region line.static Gutter
getGutter(RTextArea textArea)
Returns the gutter component of the scroll pane containing a text area, if any.static java.awt.Color
getHyperlinkForeground()
Returns the color to use for hyperlink-style components.static java.lang.String
getLeadingWhitespace(java.lang.String text)
Returns the leading whitespace of a string.static java.lang.String
getLeadingWhitespace(java.lang.String text, int upTo)
Returns the leading whitespace of a string.static java.lang.String
getLeadingWhitespace(javax.swing.text.Document doc, int offs)
Returns the leading whitespace of a specific line in a document.private static javax.swing.text.Element
getLineElem(javax.swing.text.Document doc, int offs)
static java.awt.Rectangle
getLineWidthUpTo(RSyntaxTextArea textArea, javax.swing.text.Segment s, int p0, int p1, javax.swing.text.TabExpander e, java.awt.Rectangle rect, int x0)
Returns the bounding box (in the current view) of a specified position in the model.static java.awt.Point
getMatchingBracketPosition(RSyntaxTextArea textArea, java.awt.Point input)
Returns the location of the bracket paired with the one at the current caret position.static Token
getNextImportantToken(Token t, RSyntaxTextArea textArea, int line)
Returns the next non-whitespace, non-comment token in a text area.static int
getNextVisualPositionFrom(int pos, javax.swing.text.Position.Bias b, java.awt.Shape a, int direction, javax.swing.text.Position.Bias[] biasRet, javax.swing.text.View view)
Provides a way to determine the next visually represented model location at which one might place a caret.static int
getOS()
Returns an integer constant representing the OS.private static int
getOSImpl()
Returns an integer constant representing the OS.static int
getPatternFlags(boolean matchCase, int others)
Returns the flags necessary to create aPattern
.static int
getPositionAbove(RSyntaxTextArea c, int offs, float x, javax.swing.text.TabExpander e)
Determines the position in the model that is closest to the given view location in the row above.static int
getPositionBelow(RSyntaxTextArea c, int offs, float x, javax.swing.text.TabExpander e)
Determines the position in the model that is closest to the given view location in the row below.static Token
getPreviousImportantToken(RSyntaxDocument doc, int line)
Returns the last non-whitespace, non-comment token, starting with the specified line.static Token
getPreviousImportantTokenFromOffs(RSyntaxDocument doc, int offs)
Returns the last non-whitespace, non-comment token, before the specified offset.static Token
getTokenAtOffset(RSyntaxDocument doc, int offset)
Returns the token at the specified offset.static Token
getTokenAtOffset(RSyntaxTextArea textArea, int offset)
Returns the token at the specified offset.static Token
getTokenAtOffset(Token tokenList, int offset)
Returns the token at the specified index, ornull
if the given offset isn't in this token list's range.
Note that this method does NOT check to see iftokenList
is null; callers should check for themselves.static Token
getTokenAtOffsetOrLastTokenIfEndOfLine(RSyntaxDocument doc, int offset)
Returns the token at the specified offset.static Token
getTokenAtOffsetOrLastTokenIfEndOfLine(RSyntaxTextArea textArea, int offset)
Returns the token at the specified offset.static Token
getTokenAtOffsetOrLastTokenIfEndOfLine(Token tokenList, int offset)
Returns the token at the specified index, ornull
if the given offset isn't in this token list's range.static float
getTokenListWidth(Token tokenList, RSyntaxTextArea textArea, javax.swing.text.TabExpander e)
Determines the width of the given token list taking tabs into consideration.static float
getTokenListWidth(Token tokenList, RSyntaxTextArea textArea, javax.swing.text.TabExpander e, float x0)
Determines the width of the given token list taking tabs into consideration.static float
getTokenListWidthUpTo(Token tokenList, RSyntaxTextArea textArea, javax.swing.text.TabExpander e, float x0, int upTo)
Determines the width of the given token list taking tabs into consideration and only up to the given index in the document (exclusive).static int
getWordEnd(RSyntaxTextArea textArea, int offs)
Returns the end of the word at the given offset.static int
getWordStart(RSyntaxTextArea textArea, int offs)
Returns the start of the word at the given offset.static boolean
isBracket(char ch)
Returns whether this character is a "bracket" to be matched by such programming languages as C, C++, and Java.static boolean
isDigit(char ch)
Returns whether a character is a digit (0-9).static boolean
isHexCharacter(char ch)
Returns whether this character is a hex character.static boolean
isJavaOperator(char ch)
Returns whether a character is a Java operator.static boolean
isLetter(char ch)
Returns whether a character is a US-ASCII letter (A-Z or a-z).static boolean
isLetterOrDigit(char ch)
Returns whether a character is a US-ASCII letter or a digit.static boolean
isLightForeground(java.awt.Color fg)
Returns whether the specified color is "light" to use as a foreground.static boolean
isNonWordChar(Token t)
Returns whether the specified token is a single non-word char (e.g.static boolean
isOsCaseSensitive()
Returns whether the OS is case-sensitive.static boolean
isWhitespace(char ch)
Returns whether a character is a whitespace character (either a space ' ' or tab '\t').static void
possiblyRepaintGutter(RTextArea textArea)
Repaints the gutter in a text area's scroll pane, if necessary.static boolean
regexCanFollowInJavaScript(Token t)
Returns whether a regular expression token can follow the specified token in JavaScript.static void
selectAndPossiblyCenter(javax.swing.JTextArea textArea, DocumentRange range, boolean select)
Selects a range of text in a text component.static char
toLowerCase(char ch)
If the character is an upper-case US-ASCII letter, it returns the lower-case version of that letter; otherwise, it just returns the character.static java.util.regex.Pattern
wildcardToPattern(java.lang.String wildcard, boolean matchCase, boolean escapeStartChar)
Creates a regular expression pattern that matches a "wildcard" pattern.
-
-
-
Field Detail
-
OS_WINDOWS
public static final int OS_WINDOWS
Integer constant representing a Windows-variant OS.- See Also:
- Constant Field Values
-
OS_MAC_OSX
public static final int OS_MAC_OSX
Integer constant representing Mac OS X.- See Also:
- Constant Field Values
-
OS_LINUX
public static final int OS_LINUX
Integer constant representing Linux.- See Also:
- Constant Field Values
-
OS_OTHER
public static final int OS_OTHER
Integer constant representing an "unknown" OS. 99.99% of the time, this means some UNIX variant (AIX, SunOS, etc.).- See Also:
- Constant Field Values
-
LIGHT_HYPERLINK_FG
private static final java.awt.Color LIGHT_HYPERLINK_FG
Used for the color of hyperlinks when a LookAndFeel uses light text against a dark background.
-
OS
private static final int OS
-
LETTER_MASK
private static final int LETTER_MASK
- See Also:
- Constant Field Values
-
HEX_CHARACTER_MASK
private static final int HEX_CHARACTER_MASK
- See Also:
- Constant Field Values
-
LETTER_OR_DIGIT_MASK
private static final int LETTER_OR_DIGIT_MASK
- See Also:
- Constant Field Values
-
BRACKET_MASK
private static final int BRACKET_MASK
- See Also:
- Constant Field Values
-
JAVA_OPERATOR_MASK
private static final int JAVA_OPERATOR_MASK
- See Also:
- Constant Field Values
-
DATA_TABLE
private static final int[] DATA_TABLE
A lookup table used to quickly decide if a 16-bit Java char is a US-ASCII letter (A-Z or a-z), a digit, a whitespace char (either space (0x0020) or tab (0x0009)), etc. This method should be faster thanCharacter.isLetter
,Character.isDigit
, andCharacter.isWhitespace
because we know we are dealing with ASCII chars and so don't have to worry about code planes, etc.
-
charSegment
private static javax.swing.text.Segment charSegment
Used in bracket matching methods.
-
TEMP_TOKEN
private static final TokenImpl TEMP_TOKEN
Used in token list manipulation methods.
-
JS_KEYWORD_RETURN
private static final char[] JS_KEYWORD_RETURN
Used internally.
-
JS_AND
private static final char[] JS_AND
-
JS_OR
private static final char[] JS_OR
-
BRACKETS
private static final java.lang.String BRACKETS
Used internally.- See Also:
- Constant Field Values
-
-
Method Detail
-
getBestPossibleAntiAliasHints
public static java.util.Map<?,?> getBestPossibleAntiAliasHints()
Returns the best possible anti-alias hints to use when rendering text. IfgetDesktopAntiAliasHints()
returns non-null
, its value is returned. Otherwise, default anti-aliasing values are returned.- Returns:
- The rendering hints. This will never be
null
. - See Also:
getDesktopAntiAliasHints()
-
getDesktopAntiAliasHints
public static java.util.Map<?,?> getDesktopAntiAliasHints()
Returns the rendering hints for text that will most accurately reflect those of the native windowing system.- Returns:
- The rendering hints, or
null
if they cannot be determined. - See Also:
getBestPossibleAntiAliasHints()
-
getFoldedLineBottomColor
public static java.awt.Color getFoldedLineBottomColor(RSyntaxTextArea textArea)
Returns the color to use for the line underneath a folded region line.- Parameters:
textArea
- The text area.- Returns:
- The color to use.
-
getGutter
public static Gutter getGutter(RTextArea textArea)
Returns the gutter component of the scroll pane containing a text area, if any.- Parameters:
textArea
- The text area.- Returns:
- The gutter, or
null
if the text area is not in anRTextScrollPane
. - See Also:
RTextScrollPane.getGutter()
-
getHyperlinkForeground
public static java.awt.Color getHyperlinkForeground()
Returns the color to use for hyperlink-style components. This method will returnColor.blue
unless it appears that the current LookAndFeel uses light text on a dark background, in which case a brighter alternative is returned.- Returns:
- The color to use for hyperlinks.
- See Also:
isLightForeground(Color)
-
getLeadingWhitespace
public static java.lang.String getLeadingWhitespace(java.lang.String text)
Returns the leading whitespace of a string.- Parameters:
text
- The String to check.- Returns:
- The leading whitespace.
- See Also:
getLeadingWhitespace(String, int)
,getLeadingWhitespace(Document, int)
-
getLeadingWhitespace
public static java.lang.String getLeadingWhitespace(java.lang.String text, int upTo)
Returns the leading whitespace of a string.- Parameters:
text
- The String to check.upTo
- Stops checking at the specified offset.- Returns:
- The leading whitespace.
- See Also:
getLeadingWhitespace(String)
-
getLeadingWhitespace
public static java.lang.String getLeadingWhitespace(javax.swing.text.Document doc, int offs) throws javax.swing.text.BadLocationException
Returns the leading whitespace of a specific line in a document.- Parameters:
doc
- The document.offs
- The offset whose line to get the leading whitespace for.- Returns:
- The leading whitespace.
- Throws:
javax.swing.text.BadLocationException
- Ifoffs
is not a valid offset in the document.- See Also:
getLeadingWhitespace(String)
-
getLineElem
private static javax.swing.text.Element getLineElem(javax.swing.text.Document doc, int offs)
-
getLineWidthUpTo
public static java.awt.Rectangle getLineWidthUpTo(RSyntaxTextArea textArea, javax.swing.text.Segment s, int p0, int p1, javax.swing.text.TabExpander e, java.awt.Rectangle rect, int x0) throws javax.swing.text.BadLocationException
Returns the bounding box (in the current view) of a specified position in the model. This method is designed for line-wrapped views to use, as it allows you to specify a "starting position" in the line, from which the x-value is assumed to be zero. The idea is that you specify the first character in a physical line asp0
, as this is the character where the x-pixel value is 0.- Parameters:
textArea
- The text area containing the text.s
- A segment in which to load the line. This is passed in so we don't have to reallocate a newSegment
for each call.p0
- The starting position in the physical line in the document.p1
- The position for which to get the bounding box in the view.e
- How to expand tabs.rect
- The rectangle whose x- and width-values are changed to represent the bounding box ofp1
. This is reused to keep from needlessly reallocating Rectangles.x0
- The x-coordinate (pixel) marking the left-hand border of the text. This is useful if the text area has a border, for example.- Returns:
- The bounding box in the view of the character
p1
. - Throws:
javax.swing.text.BadLocationException
- Ifp0
orp1
is not a valid location in the specified text area's document.java.lang.IllegalArgumentException
- Ifp0
andp1
are not on the same line.
-
getMatchingBracketPosition
public static java.awt.Point getMatchingBracketPosition(RSyntaxTextArea textArea, java.awt.Point input)
Returns the location of the bracket paired with the one at the current caret position.- Parameters:
textArea
- The text area.input
- A point to use as the return value. If this isnull
, a new object is created and returned.- Returns:
- A point representing the matched bracket info. The "x" field
is the offset of the bracket at the caret position (either just
before or just after the caret), and the "y" field is the offset
of the matched bracket. Both "x" and "y" will be
-1
if there isn't a matching bracket (or the caret isn't on a bracket).
-
getNextImportantToken
public static Token getNextImportantToken(Token t, RSyntaxTextArea textArea, int line)
Returns the next non-whitespace, non-comment token in a text area.- Parameters:
t
- The next token in this line's token list.textArea
- The text area.line
- The current line index (the line index oft
).- Returns:
- The next non-whitespace, non-comment token, or
null
if there isn't one. - See Also:
getPreviousImportantToken(RSyntaxDocument, int)
,getPreviousImportantTokenFromOffs(RSyntaxDocument, int)
-
getNextVisualPositionFrom
public static int getNextVisualPositionFrom(int pos, javax.swing.text.Position.Bias b, java.awt.Shape a, int direction, javax.swing.text.Position.Bias[] biasRet, javax.swing.text.View view) throws javax.swing.text.BadLocationException
Provides a way to determine the next visually represented model location at which one might place a caret. Some views may not be visible, they might not be in the same order found in the model, or they just might not allow access to some of the locations in the model.NOTE: You should only call this method if the passed-in
javax.swing.text.View
is an instance ofTokenOrientedView
andjavax.swing.text.TabExpander
; otherwise, aClassCastException
could be thrown.- Parameters:
pos
- the position to convert >= 0b
- The bias of the request.a
- the allocated region in which to renderdirection
- the direction from the current position that can be thought of as the arrow keys typically found on a keyboard. This will be one of the following values:- SwingConstants.WEST
- SwingConstants.EAST
- SwingConstants.NORTH
- SwingConstants.SOUTH
biasRet
- The return bias.view
- The parent view.- Returns:
- The location within the model that best represents the next location visual position.
- Throws:
javax.swing.text.BadLocationException
- ifpos
is invalid.java.lang.IllegalArgumentException
- ifdirection
doesn't have one of the legal values above
-
getOS
public static int getOS()
Returns an integer constant representing the OS. This can be handy for special case situations such as Mac OS-X (special application registration) or Windows (allow mixed case, etc.).- Returns:
- An integer constant representing the OS.
- See Also:
isOsCaseSensitive()
-
getOSImpl
private static int getOSImpl()
Returns an integer constant representing the OS. This can be handy for special case situations such as Mac OS-X (special application registration) or Windows (allow mixed case, etc.).- Returns:
- An integer constant representing the OS.
-
getPatternFlags
public static int getPatternFlags(boolean matchCase, int others)
Returns the flags necessary to create aPattern
.- Parameters:
matchCase
- Whether the pattern should be case-sensitive.others
- Any other flags. This may be0
.- Returns:
- The flags.
-
getPositionAbove
public static int getPositionAbove(RSyntaxTextArea c, int offs, float x, javax.swing.text.TabExpander e) throws javax.swing.text.BadLocationException
Determines the position in the model that is closest to the given view location in the row above. The component given must have a size to compute the result. If the component doesn't have a size a value of -1 will be returned.- Parameters:
c
- the editoroffs
- the offset in the document >= 0x
- the X coordinate >= 0e
- How to expand tabs.- Returns:
- the position >= 0 if the request can be computed, otherwise a value of -1 will be returned.
- Throws:
javax.swing.text.BadLocationException
- if the offset is out of range
-
getPositionBelow
public static int getPositionBelow(RSyntaxTextArea c, int offs, float x, javax.swing.text.TabExpander e) throws javax.swing.text.BadLocationException
Determines the position in the model that is closest to the given view location in the row below. The component given must have a size to compute the result. If the component doesn't have a size a value of -1 will be returned.- Parameters:
c
- the editoroffs
- the offset in the document >= 0x
- the X coordinate >= 0e
- How to expand tabs.- Returns:
- the position >= 0 if the request can be computed, otherwise a value of -1 will be returned.
- Throws:
javax.swing.text.BadLocationException
- if the offset is out of range
-
getPreviousImportantToken
public static Token getPreviousImportantToken(RSyntaxDocument doc, int line)
Returns the last non-whitespace, non-comment token, starting with the specified line.- Parameters:
doc
- The document.line
- The line at which to start looking.- Returns:
- The last non-whitespace, non-comment token, or
null
if there isn't one. - See Also:
getNextImportantToken(Token, RSyntaxTextArea, int)
,getPreviousImportantTokenFromOffs(RSyntaxDocument, int)
-
getPreviousImportantTokenFromOffs
public static Token getPreviousImportantTokenFromOffs(RSyntaxDocument doc, int offs)
Returns the last non-whitespace, non-comment token, before the specified offset.- Parameters:
doc
- The document.offs
- The ending offset for the search.- Returns:
- The last non-whitespace, non-comment token, or
null
if there isn't one. - See Also:
getPreviousImportantToken(RSyntaxDocument, int)
,getNextImportantToken(Token, RSyntaxTextArea, int)
-
getTokenAtOffset
public static Token getTokenAtOffset(RSyntaxTextArea textArea, int offset)
Returns the token at the specified offset.- Parameters:
textArea
- The text area.offset
- The offset of the token.- Returns:
- The token, or
null
if the offset is not valid. - See Also:
getTokenAtOffset(RSyntaxDocument, int)
,getTokenAtOffset(Token, int)
,getTokenAtOffsetOrLastTokenIfEndOfLine(RSyntaxTextArea, int)
-
getTokenAtOffsetOrLastTokenIfEndOfLine
public static Token getTokenAtOffsetOrLastTokenIfEndOfLine(RSyntaxTextArea textArea, int offset)
Returns the token at the specified offset. If the offset is at the very end of a line, the "last" token in that line is returned instead (which may benull
if the line is empty).- Parameters:
textArea
- The text area.offset
- The offset at which to get the token.- Returns:
- The token at
offset
, ornull
if the offset is invalid or there is no token at that offset. - See Also:
getTokenAtOffset(RSyntaxTextArea, int)
,getTokenAtOffset(RSyntaxDocument, int)
,getTokenAtOffset(Token, int)
-
getTokenAtOffset
public static Token getTokenAtOffset(RSyntaxDocument doc, int offset)
Returns the token at the specified offset.- Parameters:
doc
- The document.offset
- The offset of the token.- Returns:
- The token, or
null
if the offset is not valid. - See Also:
getTokenAtOffset(RSyntaxTextArea, int)
,getTokenAtOffset(Token, int)
,getTokenAtOffsetOrLastTokenIfEndOfLine(RSyntaxDocument, int)
-
getTokenAtOffsetOrLastTokenIfEndOfLine
public static Token getTokenAtOffsetOrLastTokenIfEndOfLine(RSyntaxDocument doc, int offset)
Returns the token at the specified offset.- Parameters:
doc
- The document.offset
- The offset of the token.- Returns:
- The token, or
null
if the offset is not valid or there is no token at that offset. - See Also:
getTokenAtOffset(RSyntaxTextArea, int)
,getTokenAtOffset(RSyntaxDocument, int)
,getTokenAtOffset(Token, int)
-
getTokenAtOffset
public static Token getTokenAtOffset(Token tokenList, int offset)
Returns the token at the specified index, ornull
if the given offset isn't in this token list's range.
Note that this method does NOT check to see iftokenList
is null; callers should check for themselves.- Parameters:
tokenList
- The list of tokens in which to search.offset
- The offset at which to get the token.- Returns:
- The token at
offset
, ornull
if none of the tokens are at that offset. - See Also:
getTokenAtOffset(RSyntaxTextArea, int)
,getTokenAtOffset(RSyntaxDocument, int)
,getTokenAtOffsetOrLastTokenIfEndOfLine(Token, int)
-
getTokenAtOffsetOrLastTokenIfEndOfLine
public static Token getTokenAtOffsetOrLastTokenIfEndOfLine(Token tokenList, int offset)
Returns the token at the specified index, ornull
if the given offset isn't in this token list's range. If the offset is at the very end of the token list, the "last" token is returned (which may benull
if the token list is empty).
Note that this method does NOT check to see iftokenList
is null; callers should check for themselves.- Parameters:
tokenList
- The list of tokens in which to search.offset
- The offset at which to get the token.- Returns:
- The token at
offset
, ornull
if none of the tokens are at that offset. - See Also:
getTokenAtOffset(RSyntaxTextArea, int)
,getTokenAtOffset(RSyntaxDocument, int)
,getTokenAtOffset(Token, int)
-
getWordEnd
public static int getWordEnd(RSyntaxTextArea textArea, int offs) throws javax.swing.text.BadLocationException
Returns the end of the word at the given offset.- Parameters:
textArea
- The text area.offs
- The offset into the text area's content.- Returns:
- The end offset of the word.
- Throws:
javax.swing.text.BadLocationException
- Ifoffs
is invalid.- See Also:
getWordStart(RSyntaxTextArea, int)
-
getWordStart
public static int getWordStart(RSyntaxTextArea textArea, int offs) throws javax.swing.text.BadLocationException
Returns the start of the word at the given offset.- Parameters:
textArea
- The text area.offs
- The offset into the text area's content.- Returns:
- The start offset of the word.
- Throws:
javax.swing.text.BadLocationException
- Ifoffs
is invalid.- See Also:
getWordEnd(RSyntaxTextArea, int)
-
getTokenListWidth
public static float getTokenListWidth(Token tokenList, RSyntaxTextArea textArea, javax.swing.text.TabExpander e)
Determines the width of the given token list taking tabs into consideration. This is implemented in a 1.1 style coordinate system where ints are used and 72dpi is assumed.This method also assumes that the passed-in token list begins at x-pixel
0
in the view (for tab purposes).- Parameters:
tokenList
- The tokenList list representing the text.textArea
- The text area in which this token list resides.e
- The tab expander. This value cannot benull
.- Returns:
- The width of the token list, in pixels.
-
getTokenListWidth
public static float getTokenListWidth(Token tokenList, RSyntaxTextArea textArea, javax.swing.text.TabExpander e, float x0)
Determines the width of the given token list taking tabs into consideration. This is implemented in a 1.1 style coordinate system where ints are used and 72dpi is assumed.- Parameters:
tokenList
- The token list representing the text.textArea
- The text area in which this token list resides.e
- The tab expander. This value cannot benull
.x0
- The x-pixel coordinate of the start of the token list.- Returns:
- The width of the token list, in pixels.
- See Also:
getTokenListWidthUpTo(org.fife.ui.rsyntaxtextarea.Token, org.fife.ui.rsyntaxtextarea.RSyntaxTextArea, javax.swing.text.TabExpander, float, int)
-
getTokenListWidthUpTo
public static float getTokenListWidthUpTo(Token tokenList, RSyntaxTextArea textArea, javax.swing.text.TabExpander e, float x0, int upTo)
Determines the width of the given token list taking tabs into consideration and only up to the given index in the document (exclusive).- Parameters:
tokenList
- The token list representing the text.textArea
- The text area in which this token list resides.e
- The tab expander. This value cannot benull
.x0
- The x-pixel coordinate of the start of the token list.upTo
- The document position at which you want to stop, exclusive. If this position is before the starting position of the token list, a width of0
will be returned; similarly, if this position comes after the entire token list, the width of the entire token list is returned.- Returns:
- The width of the token list, in pixels, up to, but not
including, the character at position
upTo
. - See Also:
getTokenListWidth(org.fife.ui.rsyntaxtextarea.Token, org.fife.ui.rsyntaxtextarea.RSyntaxTextArea, javax.swing.text.TabExpander)
-
isBracket
public static boolean isBracket(char ch)
Returns whether this character is a "bracket" to be matched by such programming languages as C, C++, and Java.- Parameters:
ch
- The character to check.- Returns:
- Whether the character is a "bracket" - one of '(', ')', '[', ']', '{', and '}'.
-
isDigit
public static boolean isDigit(char ch)
Returns whether a character is a digit (0-9).- Parameters:
ch
- The character to check.- Returns:
- Whether the character is a digit.
-
isHexCharacter
public static boolean isHexCharacter(char ch)
Returns whether this character is a hex character. This method accepts both upper- and lower-case letters a-f.- Parameters:
ch
- The character to check.- Returns:
- Whether the character is a hex character 0-9, a-f, or A-F.
-
isJavaOperator
public static boolean isJavaOperator(char ch)
Returns whether a character is a Java operator. Note that C and C++ operators are the same as Java operators.- Parameters:
ch
- The character to check.- Returns:
- Whether the character is a Java operator.
-
isLetter
public static boolean isLetter(char ch)
Returns whether a character is a US-ASCII letter (A-Z or a-z).- Parameters:
ch
- The character to check.- Returns:
- Whether the character is a US-ASCII letter.
-
isLetterOrDigit
public static boolean isLetterOrDigit(char ch)
Returns whether a character is a US-ASCII letter or a digit.- Parameters:
ch
- The character to check.- Returns:
- Whether the character is a US-ASCII letter or a digit.
-
isLightForeground
public static boolean isLightForeground(java.awt.Color fg)
Returns whether the specified color is "light" to use as a foreground. Colors that returntrue
indicate that the current Look and Feel probably uses light text colors on a dark background.- Parameters:
fg
- The foreground color.- Returns:
- Whether it is a "light" foreground color.
- See Also:
getHyperlinkForeground()
-
isNonWordChar
public static boolean isNonWordChar(Token t)
Returns whether the specified token is a single non-word char (e.g. not in[A-Za-z]
). This is a HACK to work around the fact that many standard token makers return things like semicolons and periods asTokenTypes.IDENTIFIER
s just to make the syntax highlighting coloring look a little better.- Parameters:
t
- The token to check. This cannot benull
.- Returns:
- Whether the token is a single non-word char.
-
isOsCaseSensitive
public static boolean isOsCaseSensitive()
Returns whether the OS is case-sensitive.- Returns:
- Whether the OS is case-sensitive.
- See Also:
getOS()
-
isWhitespace
public static boolean isWhitespace(char ch)
Returns whether a character is a whitespace character (either a space ' ' or tab '\t'). This checks for the Unicode character values 0x0020 and 0x0009.- Parameters:
ch
- The character to check.- Returns:
- Whether the character is a whitespace character.
-
possiblyRepaintGutter
public static void possiblyRepaintGutter(RTextArea textArea)
Repaints the gutter in a text area's scroll pane, if necessary.- Parameters:
textArea
- The text area.
-
regexCanFollowInJavaScript
public static boolean regexCanFollowInJavaScript(Token t)
Returns whether a regular expression token can follow the specified token in JavaScript.- Parameters:
t
- The token to check, which may benull
.- Returns:
- Whether a regular expression token may follow this one in JavaScript.
-
selectAndPossiblyCenter
public static void selectAndPossiblyCenter(javax.swing.JTextArea textArea, DocumentRange range, boolean select)
Selects a range of text in a text component. If the new selection is outside the previous viewable rectangle, then the view is centered around the new selection.- Parameters:
textArea
- The text component whose selection is to be centered.range
- The range to select.select
- Whether to select (vs. just scroll the text range into view).
-
toLowerCase
public static char toLowerCase(char ch)
If the character is an upper-case US-ASCII letter, it returns the lower-case version of that letter; otherwise, it just returns the character.- Parameters:
ch
- The character to lower-case (if it is a US-ASCII upper-case character).- Returns:
- The lower-case version of the character.
-
wildcardToPattern
public static java.util.regex.Pattern wildcardToPattern(java.lang.String wildcard, boolean matchCase, boolean escapeStartChar)
Creates a regular expression pattern that matches a "wildcard" pattern.- Parameters:
wildcard
- The wildcard pattern.matchCase
- Whether the pattern should be case-sensitive.escapeStartChar
- Whether to escape a starting'^'
character.- Returns:
- The pattern.
-
-