public class RSyntaxUtilities
extends java.lang.Object
implements javax.swing.SwingConstants
RSyntaxTextArea
and its associated
classes.限定符和类型 | 字段和说明 |
---|---|
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. 99.99% of the
time, this means some UNIX variant (AIX, SunOS, etc.).
|
static int |
OS_WINDOWS
Integer constant representing a Windows-variant OS.
|
构造器和说明 |
---|
RSyntaxUtilities() |
限定符和类型 | 方法和说明 |
---|---|
static java.lang.String |
escapeForHtml(java.lang.String s,
java.lang.String newlineReplacement,
boolean inPreBlock)
Returns a string with characters that are special to HTML (such as
< , > and & ) replaced
by their HTML escape sequences. |
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(javax.swing.text.Document doc,
int offs)
Returns the leading whitespace of a specific line in a document.
|
static java.lang.String |
getLeadingWhitespace(java.lang.String text)
Returns the leading whitespace of a string.
|
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.
|
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(RSyntaxTextArea textArea,
int line)
Returns the last non-whitespace, non-comment token, starting with the
specified line.
|
static Token |
getTokenAtOffset(Token tokenList,
int offset)
Returns the token at the specified index, or
null 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 or not this character is a "bracket" to be matched by
such programming languages as C, C++, and Java.
|
static boolean |
isDigit(char ch)
Returns whether or not a character is a digit (0-9).
|
static boolean |
isHexCharacter(char ch)
Returns whether or not 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 or not 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 |
isWhitespace(char ch)
Returns whether or not a character is a whitespace character (either
a space ' ' or tab '\t').
|
static boolean |
regexCanFollowInJavaScript(Token t)
Returns whether a regular expression token can follow the specified
token in JavaScript.
|
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.
|
public static final int OS_WINDOWS
public static final int OS_MAC_OSX
public static final int OS_LINUX
public static final int OS_OTHER
public static final java.lang.String escapeForHtml(java.lang.String s, java.lang.String newlineReplacement, boolean inPreBlock)
<
, >
and &
) replaced
by their HTML escape sequences.s
- The input string.newlineReplacement
- What to replace newline characters with.
If this is null
, they are simply removed.inPreBlock
- Whether this HTML will be in within pre
tags. If this is true
, spaces will be kept as-is;
otherwise, they will be converted to "
".s
.public static java.util.Map<?,?> getDesktopAntiAliasHints()
null
if they cannot be
determined.public static java.awt.Color getFoldedLineBottomColor(RSyntaxTextArea textArea)
textArea
- The text area.public static Gutter getGutter(RTextArea textArea)
textArea
- The text area.null
if the text area is not in
an RTextScrollPane
.RTextScrollPane.getGutter()
public static final java.awt.Color getHyperlinkForeground()
Color.blue
unless it appears that the current
LookAndFeel uses light text on a dark background, in which case a
brighter alternative is returned.isLightForeground(Color)
public static java.lang.String getLeadingWhitespace(java.lang.String text)
text
- The String to check.getLeadingWhitespace(Document, int)
public static java.lang.String getLeadingWhitespace(javax.swing.text.Document doc, int offs) throws javax.swing.text.BadLocationException
doc
- The document.offs
- The offset whose line to get the leading whitespace for.javax.swing.text.BadLocationException
- If offs
is not a valid offset
in the document.getLeadingWhitespace(String)
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
p0
, as this is
the character where the x-pixel value is 0.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 new Segment
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 of p1
. 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.p1
.javax.swing.text.BadLocationException
- If p0
or p1
is
not a valid location in the specified text area's document.java.lang.IllegalArgumentException
- If p0
and p1
are not on the same line.public static java.awt.Point getMatchingBracketPosition(RSyntaxTextArea textArea, java.awt.Point input)
textArea
- The text area.input
- A point to use as the return value. If this is
null
, a new object is created and returned.-1
if there isn't a matching bracket (or the caret
isn't on a bracket).public static final Token getNextImportantToken(Token t, RSyntaxTextArea textArea, int line)
t
- The next token in this line's token list.textArea
- The text area.line
- The current line index (the line index of t
).null
if there isn't one.getPreviousImportantToken(RSyntaxTextArea, int)
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
NOTE: You should only call this method if the passed-in
javax.swing.text.View
is an instance of
TokenOrientedView
and javax.swing.text.TabExpander
;
otherwise, a ClassCastException
could be thrown.
pos
- the position to convert >= 0a
- 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:
javax.swing.text.BadLocationException
java.lang.IllegalArgumentException
- if direction
doesn't have one of the legal values abovepublic static final int getPositionAbove(RSyntaxTextArea c, int offs, float x, javax.swing.text.TabExpander e) throws javax.swing.text.BadLocationException
c
- the editoroffs
- the offset in the document >= 0x
- the X coordinate >= 0javax.swing.text.BadLocationException
- if the offset is out of rangepublic static final int getPositionBelow(RSyntaxTextArea c, int offs, float x, javax.swing.text.TabExpander e) throws javax.swing.text.BadLocationException
c
- the editoroffs
- the offset in the document >= 0x
- the X coordinate >= 0javax.swing.text.BadLocationException
- if the offset is out of rangepublic static final Token getPreviousImportantToken(RSyntaxTextArea textArea, int line)
textArea
- The text area.line
- The line at which to start looking.null
if there isn't one.getNextImportantToken(Token, RSyntaxTextArea, int)
public static final Token getTokenAtOffset(Token tokenList, int offset)
null
if
the given offset isn't in this token list's range.tokenList
is null; callers should check for themselves.tokenList
- The list of tokens in which to search.offset
- The offset at which to get the token.offset
, or null
if
none of the tokens are at that offset.public static int getWordEnd(RSyntaxTextArea textArea, int offs) throws javax.swing.text.BadLocationException
textArea
- The text area.offs
- The offset into the text area's content.javax.swing.text.BadLocationException
- If offs
is invalid.getWordStart(RSyntaxTextArea, int)
public static int getWordStart(RSyntaxTextArea textArea, int offs) throws javax.swing.text.BadLocationException
textArea
- The text area.offs
- The offset into the text area's content.javax.swing.text.BadLocationException
- If offs
is invalid.getWordEnd(RSyntaxTextArea, int)
public static final float getTokenListWidth(Token tokenList, RSyntaxTextArea textArea, javax.swing.text.TabExpander e)
This method also assumes that the passed-in token list begins at
x-pixel 0
in the view (for tab purposes).
tokenList
- The tokenList list representing the text.textArea
- The text area in which this token list resides.e
- The tab expander. This value cannot be null
.public static final float getTokenListWidth(Token tokenList, RSyntaxTextArea textArea, javax.swing.text.TabExpander e, float x0)
tokenList
- The token list list representing the text.textArea
- The text area in which this token list resides.e
- The tab expander. This value cannot be null
.x0
- The x-pixel coordinate of the start of the token list.getTokenListWidthUpTo(com.fr.design.gui.syntax.ui.rsyntaxtextarea.Token, com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea, javax.swing.text.TabExpander, float, int)
public static final float getTokenListWidthUpTo(Token tokenList, RSyntaxTextArea textArea, javax.swing.text.TabExpander e, float x0, int upTo)
tokenList
- The token list representing the text.textArea
- The text area in which this token list resides.e
- The tab expander. This value cannot be null
.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 of 0
will be
returned; similarly, if this position comes after the entire
token list, the width of the entire token list is returned.upTo
.getTokenListWidth(com.fr.design.gui.syntax.ui.rsyntaxtextarea.Token, com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea, javax.swing.text.TabExpander)
public static final boolean isBracket(char ch)
ch
- The character to check.public static final boolean isDigit(char ch)
ch
- The character to check.public static final boolean isHexCharacter(char ch)
ch
- The character to check.public static final boolean isJavaOperator(char ch)
ch
- The character to check.public static final boolean isLetter(char ch)
ch
- The character to check.public static final boolean isLetterOrDigit(char ch)
ch
- The character to check.public static final boolean isLightForeground(java.awt.Color fg)
true
indicate that the current Look and
Feel probably uses light text colors on a dark background.fg
- The foreground color.getHyperlinkForeground()
public static final boolean isWhitespace(char ch)
ch
- The character to check.public static boolean regexCanFollowInJavaScript(Token t)
t
- The token to check, which may be null
.public static final char toLowerCase(char ch)
ch
- The character to lower-case (if it is a US-ASCII upper-case
character).public static final int getOS()
public static java.util.regex.Pattern wildcardToPattern(java.lang.String wildcard, boolean matchCase, boolean escapeStartChar)
wildcard
- The wildcard pattern.matchCase
- Whether the pattern should be case sensitive.escapeStartChar
- Whether to escape a starting '^'
character.