Class Theme

java.lang.Object
org.fife.ui.rsyntaxtextarea.Theme

public class Theme extends 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 Details

    • baseFont

      public Font baseFont
    • bgColor

      public Color bgColor
    • caretColor

      public Color caretColor
    • useSelectionFG

      public boolean useSelectionFG
    • selectionFG

      public Color selectionFG
    • selectionBG

      public Color selectionBG
    • selectionRoundedEdges

      public boolean selectionRoundedEdges
    • currentLineHighlight

      public Color currentLineHighlight
    • fadeCurrentLineHighlight

      public boolean fadeCurrentLineHighlight
    • tabLineColor

      public Color tabLineColor
    • marginLineColor

      public Color marginLineColor
    • markAllHighlightColor

      public Color markAllHighlightColor
    • markOccurrencesColor

      public Color markOccurrencesColor
    • markOccurrencesBorder

      public boolean markOccurrencesBorder
    • matchedBracketFG

      public Color matchedBracketFG
    • matchedBracketBG

      public Color matchedBracketBG
    • matchedBracketHighlightBoth

      public boolean matchedBracketHighlightBoth
    • matchedBracketAnimate

      public boolean matchedBracketAnimate
    • hyperlinkFG

      public Color hyperlinkFG
    • secondaryLanguages

      public Color[] secondaryLanguages
    • scheme

      public SyntaxScheme scheme
    • gutterBackgroundColor

      public Color gutterBackgroundColor
    • gutterBorderColor

      public Color gutterBorderColor
    • activeLineRangeColor

      public Color activeLineRangeColor
    • iconRowHeaderInheritsGutterBG

      public boolean iconRowHeaderInheritsGutterBG
    • lineNumberColor

      public Color lineNumberColor
    • currentLineNumberColor

      public Color currentLineNumberColor
    • lineNumberFont

      public String lineNumberFont
    • lineNumberFontSize

      public int lineNumberFontSize
    • foldIndicatorFG

      public Color foldIndicatorFG
    • foldIndicatorArmedFG

      public Color foldIndicatorArmedFG
    • foldBG

      public Color foldBG
    • armedFoldBG

      public Color armedFoldBG
  • Constructor Details

    • Theme

      private Theme(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 Details

    • 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 String colorToString(Color c)
    • getDefaultBG

      private static 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:
    • getDefaultSelectionBG

      private static 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

      private static 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:
    • getFont

      private static Font getFont(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(InputStream in) throws IOException
      Loads a theme.
      Parameters:
      in - The input stream to read from. This will be closed when this method returns.
      Returns:
      The theme.
      Throws:
      IOException - If an IO error occurs.
      See Also:
    • load

      public static Theme load(InputStream in, Font baseFont) throws 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:
      IOException - If an IO error occurs.
      See Also:
    • save

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

      private static Color stringToColor(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 Color stringToColor(String s, 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.