public class SyntaxScheme extends java.lang.Object implements java.lang.Cloneable, TokenTypes
RSyntaxTextArea
to
color tokens.
You can use this class to programmatically set the fonts and colors used in
an RSyntaxTextArea, but for more powerful, externalized control, consider
using Theme
s instead.
Theme
ANNOTATION, COMMENT_DOCUMENTATION, COMMENT_EOL, COMMENT_KEYWORD, COMMENT_MARKUP, COMMENT_MULTILINE, DATA_TYPE, DEFAULT_NUM_TOKEN_TYPES, 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_CDATA, MARKUP_CDATA_DELIMITER, MARKUP_COMMENT, MARKUP_DTD, MARKUP_ENTITY_REFERENCE, MARKUP_PROCESSING_INSTRUCTION, MARKUP_TAG_ATTRIBUTE, MARKUP_TAG_ATTRIBUTE_VALUE, MARKUP_TAG_DELIMITER, MARKUP_TAG_NAME, NULL, OPERATOR, PREPROCESSOR, REGEX, RESERVED_WORD, RESERVED_WORD_2, SEPARATOR, VARIABLE, WHITESPACE
构造器和说明 |
---|
SyntaxScheme(boolean useDefaults)
Creates a color scheme that either has all color values set to
a default value or set to
null . |
SyntaxScheme(java.awt.Font baseFont)
Creates a default color scheme.
|
SyntaxScheme(java.awt.Font baseFont,
boolean fontStyles)
Creates a default color scheme.
|
限定符和类型 | 方法和说明 |
---|---|
java.lang.Object |
clone()
Returns a deep copy of this color scheme.
|
boolean |
equals(java.lang.Object otherScheme)
Tests whether this color scheme is the same as another color scheme.
|
Style |
getStyle(int index)
Returns the specified style.
|
int |
getStyleCount()
Returns the number of styles.
|
Style[] |
getStyles()
Used by third party implementors e.g.
|
int |
hashCode()
This is implemented to be consistent with
equals(Object) . |
static SyntaxScheme |
load(java.awt.Font baseFont,
java.io.InputStream in)
Loads a syntax scheme from an input stream.
|
static SyntaxScheme |
loadFromString(java.lang.String string)
Loads a syntax highlighting color scheme from a string created from
toCommaSeparatedString . |
static SyntaxScheme |
loadFromString(java.lang.String string,
int tokenTypeCount)
Loads a syntax highlighting color scheme from a string created from
toCommaSeparatedString . |
void |
restoreDefaults(java.awt.Font baseFont)
Restores all colors and fonts to their default values.
|
void |
restoreDefaults(java.awt.Font baseFont,
boolean fontStyles)
Restores all colors and fonts to their default values.
|
void |
setStyle(int type,
Style style)
Sets a style to use when rendering a token type.
|
void |
setStyles(Style[] styles)
Used by third party implementors e.g.
|
java.lang.String |
toCommaSeparatedString()
Returns this syntax highlighting scheme as a comma-separated list of
values as follows:
If a color is non-null, it is added as a 24-bit integer
of the form
((r<<16) | (g<<8) | (b)) ; if it is
null , it is added as "-,". |
public SyntaxScheme(boolean useDefaults)
null
.useDefaults
- If true
, all color values will
be set to default colors; if false
, all colors
will be initially null
.public SyntaxScheme(java.awt.Font baseFont)
baseFont
- The base font to use. Keywords will be a bold version
of this font, and comments will be an italicized version of this
font.public SyntaxScheme(java.awt.Font baseFont, boolean fontStyles)
baseFont
- The base font to use. Keywords will be a bold version
of this font, and comments will be an italicized version of this
font.fontStyles
- Whether bold and italic should be used in the scheme
(vs. all tokens using a plain font).public java.lang.Object clone()
clone
在类中 java.lang.Object
public boolean equals(java.lang.Object otherScheme)
equals
在类中 java.lang.Object
otherScheme
- The color scheme to compare to.true
if this color scheme and
otherScheme
are the same scheme;
false
otherwise.public Style getStyle(int index)
index
- The index of the style.setStyle(int, Style)
,
getStyleCount()
public int getStyleCount()
getStyle(int)
public Style[] getStyles()
Note that the returned array is not a copy of the style data; editing the
array will modify the styles used by any RSyntaxTextArea
using this scheme.
setStyles(Style[])
public int hashCode()
equals(Object)
.
This is a requirement to keep FindBugs happy.hashCode
在类中 java.lang.Object
public static SyntaxScheme load(java.awt.Font baseFont, java.io.InputStream in) throws java.io.IOException
Consider using the Theme
class for saving and loading RSTA
styles rather than using this API.
baseFont
- The font to use as the "base" for the syntax scheme.
If this is null
, a default monospaced font is used.in
- The stream to load from. It is up to the caller to close this
stream when they are done.java.io.IOException
- If an IO error occurs.public static SyntaxScheme loadFromString(java.lang.String string)
toCommaSeparatedString
. This method is useful for saving
and restoring color schemes.
Consider using the Theme
class for saving and loading RSTA
styles rather than using this API.
string
- A string generated from toCommaSeparatedString()
.toCommaSeparatedString()
public static SyntaxScheme loadFromString(java.lang.String string, int tokenTypeCount)
toCommaSeparatedString
. This method is useful for saving
and restoring color schemes.
Consider using the Theme
class for saving and loading RSTA
styles rather than using this API.
string
- A string generated from toCommaSeparatedString()
.tokenTypeCount
- The number of token types saved in this string.
This should be the number of token types saved by your custom
SyntaxScheme subclass,
or TokenTypes.DEFAULT_NUM_TOKEN_TYPES
if you used the
standard implementation (which most people will).loadFromString(String)
,
toCommaSeparatedString()
public void restoreDefaults(java.awt.Font baseFont)
baseFont
- The base font to use when creating this scheme. If
this is null
, then a default monospaced font is
used.public void restoreDefaults(java.awt.Font baseFont, boolean fontStyles)
baseFont
- The base font to use when creating this scheme. If
this is null
, then a default monospaced font is
used.fontStyles
- Whether bold and italic should be used in the scheme
(vs. all tokens using a plain font).public void setStyle(int type, Style style)
type
- The token type.style
- The style for the token type.getStyle(int)
public void setStyles(Style[] styles)
setStyle(int, Style)
.styles
- The new array of styles to use. Note that this should
have length of at least
TokenTypes.DEFAULT_NUM_TOKEN_TYPES
.setStyle(int, Style)
,
getStyles()
public java.lang.String toCommaSeparatedString()
((r<<16) | (g<<8) | (b))
; if it is
null
, it is added as "-,".
i
is the index of the syntax scheme.
-
).
uline
is whether or not the font should be
underlined, and is either t
or f
.
style
is the family,style,size
triplet described above.
loadFromString(String)