org.fife.ui.rsyntaxtextarea
Class SyntaxScheme

java.lang.Object
  extended by org.fife.ui.rsyntaxtextarea.SyntaxScheme
All Implemented Interfaces:
Cloneable, TokenTypes

public class SyntaxScheme
extends Object
implements Cloneable, TokenTypes

The set of colors and styles used by an 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 Themes instead.

Version:
1.0
Author:
Robert Futrell
See Also:
Theme

Field Summary
 
Fields inherited from interface org.fife.ui.rsyntaxtextarea.TokenTypes
ANNOTATION, COMMENT_DOCUMENTATION, COMMENT_EOL, COMMENT_KEYWORD, COMMENT_MARKUP, 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_CDATA, MARKUP_PROCESSING_INSTRUCTION, MARKUP_TAG_ATTRIBUTE, MARKUP_TAG_ATTRIBUTE_VALUE, MARKUP_TAG_DELIMITER, MARKUP_TAG_NAME, NULL, NUM_TOKEN_TYPES, OPERATOR, PREPROCESSOR, REGEX, RESERVED_WORD, RESERVED_WORD_2, SEPARATOR, VARIABLE, WHITESPACE
 
Constructor Summary
SyntaxScheme(boolean useDefaults)
          Creates a color scheme that either has all color values set to a default value or set to null.
SyntaxScheme(Font baseFont)
          Creates a default color scheme.
SyntaxScheme(Font baseFont, boolean fontStyles)
          Creates a default color scheme.
 
Method Summary
 Object clone()
          Returns a deep copy of this color scheme.
 boolean equals(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.
 int hashCode()
          This is implemented to be consistent with equals(Object).
static SyntaxScheme load(Font baseFont, InputStream in)
          Loads a syntax scheme from an input stream.
static SyntaxScheme loadFromString(String string)
          Loads a syntax highlighting color scheme from a string created from toCommaSeparatedString.
 void restoreDefaults(Font baseFont)
          Restores all colors and fonts to their default values.
 void restoreDefaults(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.
 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 "-,".
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyntaxScheme

public SyntaxScheme(boolean useDefaults)
Creates a color scheme that either has all color values set to a default value or set to null.

Parameters:
useDefaults - If true, all color values will be set to default colors; if false, all colors will be initially null.

SyntaxScheme

public SyntaxScheme(Font baseFont)
Creates a default color scheme.

Parameters:
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.

SyntaxScheme

public SyntaxScheme(Font baseFont,
                    boolean fontStyles)
Creates a default color scheme.

Parameters:
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).
Method Detail

clone

public Object clone()
Returns a deep copy of this color scheme.

Overrides:
clone in class Object
Returns:
The copy.

equals

public boolean equals(Object otherScheme)
Tests whether this color scheme is the same as another color scheme.

Overrides:
equals in class Object
Parameters:
otherScheme - The color scheme to compare to.
Returns:
true if this color scheme and otherScheme are the same scheme; false otherwise.

getStyle

public Style getStyle(int index)
Returns the specified style.

Parameters:
index - The index of the style.
Returns:
The style.
See Also:
setStyle(int, Style), getStyleCount()

getStyleCount

public int getStyleCount()
Returns the number of styles.

Returns:
The number of styles.
See Also:
getStyle(int)

hashCode

public int hashCode()
This is implemented to be consistent with equals(Object). This is a requirement to keep FindBugs happy.

Overrides:
hashCode in class Object
Returns:
The hash code for this object.

load

public static SyntaxScheme load(Font baseFont,
                                InputStream in)
                         throws IOException
Loads a syntax scheme from an input stream.

Parameters:
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.
Returns:
The syntax scheme.
Throws:
IOException - If an IO error occurs.

loadFromString

public static SyntaxScheme loadFromString(String string)
Loads a syntax highlighting color scheme from a string created from toCommaSeparatedString. This method is useful for saving and restoring color schemes.

Parameters:
string - A string generated from toCommaSeparatedString().
Returns:
A color scheme.

restoreDefaults

public void restoreDefaults(Font baseFont)
Restores all colors and fonts to their default values.

Parameters:
baseFont - The base font to use when creating this scheme. If this is null, then a default monospaced font is used.

restoreDefaults

public void restoreDefaults(Font baseFont,
                            boolean fontStyles)
Restores all colors and fonts to their default values.

Parameters:
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).

setStyle

public void setStyle(int type,
                     Style style)
Sets a style to use when rendering a token type.

Parameters:
type - The token type.
style - The style for the token type.
See Also:
getStyle(int)

toCommaSeparatedString

public String toCommaSeparatedString()
Returns this syntax highlighting scheme as a comma-separated list of values as follows:

Returns:
A string representing the rgb values of the colors.


Copyright © 2003-2012. All Rights Reserved.