Class Theme


  • public class Theme
    extends java.lang.Object
    A theme is a set of fonts and colors to use to style RSyntaxTextArea and RTextScrollPane. Themes are defined in XML files that are validated against org/fife/ui/rsyntaxtextarea/themes/theme.dtd. This provides applications and other consumers with an easy way to style RSyntaxTextArea without having to use the API.

    Sample themes are included in the source tree in the org.fife.ui.rsyntaxtextarea.themes package, and can be loaded via getClass().getResourceAsStream(...).

    All fields are public to facilitate programmatic manipulation, but typically you won't need to reference any fields directly, rather using the load(), save(), and apply() methods for various tasks.

    Note that to save a Theme via save(OutputStream), you must currently create a Theme from a text area wrapped in an RTextScrollPane, so that the color information for the gutter can be retrieved.

    Version:
    1.0
    • Field Detail

      • baseFont

        public java.awt.Font baseFont
      • bgColor

        public java.awt.Color bgColor
      • caretColor

        public java.awt.Color caretColor
      • useSelectionFG

        public boolean useSelectionFG
      • selectionFG

        public java.awt.Color selectionFG
      • selectionBG

        public java.awt.Color selectionBG
      • selectionRoundedEdges

        public boolean selectionRoundedEdges
      • currentLineHighlight

        public java.awt.Color currentLineHighlight
      • fadeCurrentLineHighlight

        public boolean fadeCurrentLineHighlight
      • tabLineColor

        public java.awt.Color tabLineColor
      • marginLineColor

        public java.awt.Color marginLineColor
      • markAllHighlightColor

        public java.awt.Color markAllHighlightColor
      • markOccurrencesColor

        public java.awt.Color markOccurrencesColor
      • markOccurrencesBorder

        public boolean markOccurrencesBorder
      • matchedBracketFG

        public java.awt.Color matchedBracketFG
      • matchedBracketBG

        public java.awt.Color matchedBracketBG
      • matchedBracketHighlightBoth

        public boolean matchedBracketHighlightBoth
      • matchedBracketAnimate

        public boolean matchedBracketAnimate
      • hyperlinkFG

        public java.awt.Color hyperlinkFG
      • secondaryLanguages

        public java.awt.Color[] secondaryLanguages
      • gutterBackgroundColor

        public java.awt.Color gutterBackgroundColor
      • gutterBorderColor

        public java.awt.Color gutterBorderColor
      • activeLineRangeColor

        public java.awt.Color activeLineRangeColor
      • iconRowHeaderInheritsGutterBG

        public boolean iconRowHeaderInheritsGutterBG
      • lineNumberColor

        public java.awt.Color lineNumberColor
      • currentLineNumberColor

        public java.awt.Color currentLineNumberColor
      • lineNumberFont

        public java.lang.String lineNumberFont
      • lineNumberFontSize

        public int lineNumberFontSize
      • foldIndicatorFG

        public java.awt.Color foldIndicatorFG
      • foldIndicatorArmedFG

        public java.awt.Color foldIndicatorArmedFG
      • foldBG

        public java.awt.Color foldBG
      • armedFoldBG

        public java.awt.Color armedFoldBG
    • Constructor Detail

      • Theme

        private Theme​(java.awt.Font baseFont)
        Private constructor, used when loading from a stream.
        Parameters:
        baseFont - The default font to use for any "base font" properties not specified in the theme XML. If this is null, a default monospaced font will be used.
      • Theme

        public Theme​(RSyntaxTextArea textArea)
        Creates a theme from an RSyntaxTextArea. It should be contained in an RTextScrollPane to get all gutter color information.
        Parameters:
        textArea - The text area.
    • Method Detail

      • apply

        public void apply​(RSyntaxTextArea textArea)
        Applies this theme to a text area.
        Parameters:
        textArea - The text area to apply this theme to.
      • colorToString

        private static java.lang.String colorToString​(java.awt.Color c)
      • getDefaultBG

        private static java.awt.Color getDefaultBG()
        Returns the default selection background color to use if "default" is specified in a theme.
        Returns:
        The default selection background to use.
        See Also:
        getDefaultSelectionFG()
      • getDefaultSelectionBG

        private static java.awt.Color getDefaultSelectionBG()
        Returns the default selection background color to use if "default" is specified in a theme.
        Returns:
        The default selection background to use.
        See Also:
        getDefaultSelectionFG()
      • getDefaultSelectionFG

        private static java.awt.Color getDefaultSelectionFG()
        Returns the default "selected text" color to use if "default" is specified in a theme.
        Returns:
        The default selection foreground color to use.
        See Also:
        getDefaultSelectionBG()
      • getFont

        private static java.awt.Font getFont​(java.lang.String family,
                                             int style,
                                             int size)
        Returns the specified font.
        Parameters:
        family - The font family.
        style - The style of font.
        size - The size of the font.
        Returns:
        The font.
      • load

        public static Theme load​(java.io.InputStream in)
                          throws java.io.IOException
        Loads a theme.
        Parameters:
        in - The input stream to read from. This will be closed when this method returns.
        Returns:
        The theme.
        Throws:
        java.io.IOException - If an IO error occurs.
        See Also:
        save(OutputStream)
      • load

        public static Theme load​(java.io.InputStream in,
                                 java.awt.Font baseFont)
                          throws java.io.IOException
        Loads a theme.
        Parameters:
        in - The input stream to read from. This will be closed when this method returns.
        baseFont - The default font to use for any "base font" properties not specified in the theme XML. If this is null, a default monospaced font will be used.
        Returns:
        The theme.
        Throws:
        java.io.IOException - If an IO error occurs.
        See Also:
        save(OutputStream)
      • save

        public void save​(java.io.OutputStream out)
                  throws java.io.IOException
        Saves this theme to an output stream.
        Parameters:
        out - The output stream to write to.
        Throws:
        java.io.IOException - If an IO error occurs.
        See Also:
        load(InputStream)
      • stringToColor

        private static java.awt.Color stringToColor​(java.lang.String s)
        Returns the color represented by a string. The input is expected to be a 6-digit hex string, optionally prefixed by a '$'. For example, either of the following:
         "$00ff00"
         "00ff00"
         
        will return new Color(0, 255, 0).
        Parameters:
        s - The string to evaluate.
        Returns:
        The color.
      • stringToColor

        private static java.awt.Color stringToColor​(java.lang.String s,
                                                    java.awt.Color defaultVal)
        Returns the color represented by a string. The input is expected to be a 6-digit hex string, optionally prefixed by a '$'. For example, either of the following:
         "$00ff00"
         "00ff00"
         
        will return new Color(0, 255, 0).
        Parameters:
        s - The string to evaluate.
        defaultVal - The color to use if s is "default".
        Returns:
        The color.