Package generic.theme

Class Gui

java.lang.Object
generic.theme.Gui

public class Gui extends Object
Provides a static set of methods for globally managing application themes and their values.

The basic idea is that all the colors, fonts, and icons used in an application should be accessed indirectly via an "id" string. Then the actual color, font, or icon can be changed without changing the source code. The default mapping of the id strings to a value is defined in {name}.theme.properties files which are dynamically discovered by searching the module's data directory. Also, these files can optionally define a dark default value for an id which would replace the standard default value in the event that the current theme specifies that it is a dark theme. Themes are used to specify the application's LookAndFeel, whether or not it is dark, and any customized values for colors, fonts, or icons. There are several "built-in" themes, one for each supported LookAndFeel, but additional themes can be defined and stored in the users application home directory as a {name}.theme file.

  • Method Details

    • getFont

      public static Font getFont(String id)
      Returns the current Font associated with the given id. A default font will be returned if the font can't be resolved and an error message will be printed to the console.
      Parameters:
      id - the id for the desired font
      Returns:
      the current Font associated with the given id.
    • getColor

      public static Color getColor(String id)
      Returns the Color registered for the given id. Will output an error message if the id can't be resolved.
      Parameters:
      id - the id to get the direct color for
      Returns:
      the Color registered for the given id.
    • addThemeListener

      public static void addThemeListener(ThemeListener listener)
      Adds a ThemeListener to be notified of theme changes.
      Parameters:
      listener - the listener to be notified
    • removeThemeListener

      public static void removeThemeListener(ThemeListener listener)
      Removes the given ThemeListener from the list of listeners to be notified of theme changes.
      Parameters:
      listener - the listener to be removed
    • getIcon

      public static Icon getIcon(String id)
      Returns the Icon registered for the given id. If no icon is registered for the id, the default icon will be returned and an error message will be dumped to the console
      Parameters:
      id - the id to get the registered icon for
      Returns:
      the actual icon registered for the given id
    • hasColor

      public static boolean hasColor(String id)
      Returns true if an color for the given Id has been defined
      Parameters:
      id - the id to check for an existing color.
      Returns:
      true if an color for the given Id has been defined
    • hasFont

      public static boolean hasFont(String id)
      Returns true if an font for the given Id has been defined
      Parameters:
      id - the id to check for an existing font.
      Returns:
      true if an font for the given Id has been defined
    • hasIcon

      public static boolean hasIcon(String id)
      Returns true if an icon for the given Id has been defined
      Parameters:
      id - the id to check for an existing icon.
      Returns:
      true if an icon for the given Id has been defined
    • darker

      public static Color darker(Color color)
      Returns a darker version of the given color or brighter if the current theme is dark.
      Parameters:
      color - the color to get a darker version of
      Returns:
      a darker version of the given color or brighter if the current theme is dark
    • brighter

      public static Color brighter(Color color)
      Returns a brighter version of the given color or darker if the current theme is dark.
      Parameters:
      color - the color to get a brighter version of
      Returns:
      a brighter version of the given color or darker if the current theme is dark
    • registerFont

      public static void registerFont(Component component, String fontId)
      Binds the component to the font identified by the given font id. Whenever the font for the font id changes, the component will updated with the new font.

      Calling this method will trigger a call to JComponent.setFont(Font).

      Parameters:
      component - the component to set/update the font
      fontId - the id of the font to register with the given component
    • registerFont

      public static void registerFont(JComponent component, int fontStyle)
      Registers the given component with the given font style. This method allows clients to not define a font id in the theme system, but instead to signal that they want the default font for the given component, modified with the given style. As the underlying font is changed, the client will be updated with that new font with the given style applied.

      Most clients should not be using this method. Instead, use registerFont(JComponent, int).

      The downside of using this method is that the end user cannot modify the style of the font. By using the standard theming mechanism for registering fonts, the end user has full control.

      Parameters:
      component - the component to set/update the font
      fontStyle - the font style, one of Font.BOLD, Font.ITALIC,
    • isDarkTheme

      public static boolean isDarkTheme()
      Returns true if the active theme is using dark defaults
      Returns:
      true if the active theme is using dark defaults
    • isUpdatingTheme

      public static boolean isUpdatingTheme()
      Returns true if the theme system is in the process of updating
      Returns:
      true if the theme system is in the process of updating
    • isSystemId

      public static boolean isSystemId(String id)
      Returns true if the given id is a system-defined id, such as those starting with laf.color or system.color.
      Parameters:
      id - the id
      Returns:
      true if the given id is a system-defined id