Class Gui
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 Summary
Modifier and TypeMethodDescriptionstatic void
addThemeListener
(ThemeListener listener) Adds aThemeListener
to be notified of theme changes.static Color
Returns a brighter version of the given color or darker if the current theme is dark.static Color
Returns a darker version of the given color or brighter if the current theme is dark.static Color
Returns theColor
registered for the given id.static Font
Returns the currentFont
associated with the given id.static Icon
Returns the Icon registered for the given id.static boolean
Returns true if an color for the given Id has been definedstatic boolean
Returns true if an font for the given Id has been definedstatic boolean
Returns true if an icon for the given Id has been definedstatic boolean
Returns true if the active theme is using dark defaultsstatic boolean
isSystemId
(String id) Returns true if the given id is a system-defined id, such as those starting withlaf.color
orsystem.color
.static void
registerFont
(Component component, String fontId) Binds the component to the font identified by the given font id.static void
removeThemeListener
(ThemeListener listener) Removes the givenThemeListener
from the list of listeners to be notified of theme changes.
-
Method Details
-
getFont
Returns the currentFont
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
Returns theColor
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
Adds aThemeListener
to be notified of theme changes.- Parameters:
listener
- the listener to be notified
-
removeThemeListener
Removes the givenThemeListener
from the list of listeners to be notified of theme changes.- Parameters:
listener
- the listener to be removed
-
getIcon
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
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
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
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
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
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
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.- Parameters:
component
- the component to set/update the fontfontId
- the id of the font to register with the given component
-
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
-
isSystemId
Returns true if the given id is a system-defined id, such as those starting withlaf.color
orsystem.color
.- Parameters:
id
- the id- Returns:
- true if the given id is a system-defined id
-