Class 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.

    See Also:
    Theme
    • 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.
      • getStyleCount

        public int getStyleCount()
        Returns the number of styles.
        Returns:
        The number of styles.
        See Also:
        getStyle(int)
      • getStyles

        public Style[] getStyles()
        Used by third party implementors e.g. SquirreL SQL. Most applications do not need to call this method.

        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.

        Returns:
        The style array.
        See Also:
        setStyles(Style[])
      • 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.

        Consider using the Theme class for saving and loading RSTA styles rather than using this API.

        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.

        Consider using the Theme class for saving and loading RSTA styles rather than using this API.

        Parameters:
        string - A string generated from toCommaSeparatedString().
        Returns:
        A color scheme.
        See Also:
        toCommaSeparatedString()
      • loadFromString

        public static SyntaxScheme loadFromString​(String string,
                                                  int tokenTypeCount)
        Loads a syntax highlighting color scheme from a string created from 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.

        Parameters:
        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).
        Returns:
        A color scheme.
        See Also:
        loadFromString(String), toCommaSeparatedString()
      • 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:
        • If a color is non-null, it is added as a 24-bit integer of the form ((r<*lt;16) | (g<*lt;8) | (b)); if it is null, it is added as "-,".
        • The font and style (bold/italic) is added as an integer like so: "family, style, size".
        • The entire syntax highlighting scheme is thus one long string of color schemes of the format "i,[fg],[bg],uline,[style], where:
          • i is the index of the syntax scheme.
          • fg and bg are the foreground and background colors for the scheme, and may be null (represented by -).
          • 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.
        Returns:
        A string representing the rgb values of the colors.
        See Also:
        loadFromString(String)