Package generic.theme
Class ApplicationThemeManager
java.lang.Object
generic.theme.ThemeManager
generic.theme.ApplicationThemeManager
This is the fully functional
ThemeManager
that manages themes in a application. To
activate the theme functionality, Applications (or tests) must call
initialize()
-
Field Summary
Fields inherited from class generic.theme.ThemeManager
activeLafType, activeTheme, applicationDefaults, currentValues, INSTANCE, javaDefaults, THEME_DIR, useDarkDefaults
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the given theme to set of all themes.protected void
This method is called to create the internal set of theme value used by the application.void
deleteTheme
(GTheme theme) Removes the theme from the set of all themes.protected void
Returns a set of all known themes.Gets a UIResource version of the GColor for the given id.Returns a set of all known themes that are supported on the current platform.Returns the known theme that has the given name.boolean
Returns true if there are any unsaved changes to the current theme.boolean
Returns true if any theme values have changed.static void
Initialized the Theme and its values for the application.boolean
Returns true if the application should allow blinking cursors, false otherwise.boolean
isChangedColor
(String id) Returns true if the color associated with the given id has been changed from the current theme value for that id.boolean
isChangedFont
(String id) Returns true if the font associated with the given id has been changed from the current theme value for that id.boolean
isChangedIcon
(String id) Returns true if the Icon associated with the given id has been changed from the current theme value for that id.protected Collection
<GTheme> void
void
registerFont
(Component component, String fontId) Binds the component to the font identified by the given font id.void
registerFont
(Component component, String fontId, int fontStyle) Binds the component to the font identified by the given font id.void
restoreColor
(String id) Restores the current color value for the given color id to the value established by the current theme.void
restoreFont
(String id) Restores the current font value for the given font id to the value established by the current theme.void
restoreIcon
(String id) Restores the current icon value for the given icon id to the value established by the current theme.void
Restores all the current application back to the values as specified by the active theme.void
setBlinkingCursors
(boolean b) Sets application's blinking cursor state.void
setColor
(ColorValue newValue) Updates the current value for the color id in the newValuevoid
Updates the current value for the font id in the newValuevoid
Updates the current value for theIcon
id in the newValuevoid
Sets the map of Java default UI values.void
setLookAndFeel
(LafType lafType, boolean useDarkDefaults) Sets the currentLookAndFeel
.void
Sets the application's active theme to the given theme.void
unRegisterFont
(JComponent component, String fontId) Removes the component and font id binding made in a previous call toThemeManager.registerFont(Component, String)
.Methods inherited from class generic.theme.ThemeManager
addThemeListener, adjustFonts, error, getActiveTheme, getApplicationDarkDefaults, getApplicationLightDefaults, getColor, getCurrentValues, getDefaults, getDefaultTheme, getFont, getIcon, getInstance, getJavaDefaults, getLookAndFeelType, getNonDefaultValues, getThemeValues, hasColor, hasFont, hasIcon, installInGui, isDarkTheme, isUpdatingTheme, isUsingAquaUI, isUsingNimbusUI, loadApplicationDefaults, notifyThemeChanged, removeThemeListener, setColor, setFont, setIcon, update
-
Field Details
-
themePreferences
-
lookAndFeelManager
-
-
Constructor Details
-
ApplicationThemeManager
protected ApplicationThemeManager()
-
-
Method Details
-
initialize
public static void initialize()Initialized the Theme and its values for the application. -
doInitialize
protected void doInitialize() -
restoreThemeValues
public void restoreThemeValues()Description copied from class:ThemeManager
Restores all the current application back to the values as specified by the active theme. In other words, reverts any changes to the active theme that haven't been saved.- Overrides:
restoreThemeValues
in classThemeManager
-
restoreColor
Description copied from class:ThemeManager
Restores the current color value for the given color id to the value established by the current theme.- Overrides:
restoreColor
in classThemeManager
- Parameters:
id
- the color id to restore back to the original theme value
-
restoreFont
Description copied from class:ThemeManager
Restores the current font value for the given font id to the value established by the current theme.- Overrides:
restoreFont
in classThemeManager
- Parameters:
id
- the font id to restore back to the original theme value
-
restoreIcon
Description copied from class:ThemeManager
Restores the current icon value for the given icon id to the value established by the current theme.- Overrides:
restoreIcon
in classThemeManager
- Parameters:
id
- the icon id to restore back to the original theme value
-
isChangedColor
Description copied from class:ThemeManager
Returns true if the color associated with the given id has been changed from the current theme value for that id.- Overrides:
isChangedColor
in classThemeManager
- Parameters:
id
- the color id to check if it has been changed- Returns:
- true if the color associated with the given id has been changed from the current theme value for that id.
-
isChangedFont
Description copied from class:ThemeManager
Returns true if the font associated with the given id has been changed from the current theme value for that id.- Overrides:
isChangedFont
in classThemeManager
- Parameters:
id
- the font id to check if it has been changed- Returns:
- true if the font associated with the given id has been changed from the current theme value for that id.
-
isChangedIcon
Description copied from class:ThemeManager
Returns true if the Icon associated with the given id has been changed from the current theme value for that id.- Overrides:
isChangedIcon
in classThemeManager
- Parameters:
id
- the Icon id to check if it has been changed- Returns:
- true if the Icon associated with the given id has been changed from the current theme value for that id.
-
setTheme
Description copied from class:ThemeManager
Sets the application's active theme to the given theme.- Overrides:
setTheme
in classThemeManager
- Parameters:
theme
- the theme to make active
-
setLookAndFeel
Description copied from class:ThemeManager
Sets the currentLookAndFeel
. This is used by theme editors to allow users to see the effects of changing LookAndFeels when configuring a theme. Setting this different from the activeTheme's LookAndFeel setting means the the current theme is in an unsaved state and causes theThemeManager.hasThemeChanges()
method to return true.- Overrides:
setLookAndFeel
in classThemeManager
- Parameters:
lafType
- theLafType
to set the LookAndFeel touseDarkDefaults
- true if the application should used dark defaults with this LookAndFeel
-
setBlinkingCursors
public void setBlinkingCursors(boolean b) Description copied from class:ThemeManager
Sets application's blinking cursor state. This will affect all JTextFields, JTextAreas, JTextPanes viaUIDefaults
. Custom components can also respect this setting by either adding aThemeListener
or overridingJComponent.updateUI()
NOTE: This method is a bit odd here as it doesn't really apply to a theme. But it requires manipulation of the look and feel which is managed by the theme. If other application level properties come along and also require changing the UIDefaults, perhaps a more general solution might be to add a way for clients to register a callback so that they get a chance to change the UIDefaults map as the look and feel is loaded.
- Overrides:
setBlinkingCursors
in classThemeManager
- Parameters:
b
- true for blinking text cursors, false for non-blinking text cursors
-
isBlinkingCursors
public boolean isBlinkingCursors()Description copied from class:ThemeManager
Returns true if the application should allow blinking cursors, false otherwise. Custom components can use this method to determine if they should have a blinking cursor or not.- Overrides:
isBlinkingCursors
in classThemeManager
- Returns:
- true if the application should allow blinking cursors, false otherwise.
-
addTheme
Description copied from class:ThemeManager
Adds the given theme to set of all themes.- Overrides:
addTheme
in classThemeManager
- Parameters:
newTheme
- the theme to add
-
deleteTheme
Description copied from class:ThemeManager
Removes the theme from the set of all themes. Also, if the theme has an associated file, the file will be deleted.- Overrides:
deleteTheme
in classThemeManager
- Parameters:
theme
- the theme to delete
-
getAllThemes
Description copied from class:ThemeManager
Returns a set of all known themes.- Overrides:
getAllThemes
in classThemeManager
- Returns:
- a set of all known themes.
-
getSupportedThemes
Description copied from class:ThemeManager
Returns a set of all known themes that are supported on the current platform.- Overrides:
getSupportedThemes
in classThemeManager
- Returns:
- a set of all known themes that are supported on the current platform.
-
getTheme
Description copied from class:ThemeManager
Returns the known theme that has the given name.- Overrides:
getTheme
in classThemeManager
- Parameters:
themeName
- the name of the theme to retrieve- Returns:
- the known theme that has the given name
-
setFont
Description copied from class:ThemeManager
Updates the current value for the font id in the newValue- Overrides:
setFont
in classThemeManager
- Parameters:
newValue
- the newFontValue
to install in the current values.
-
setColor
Description copied from class:ThemeManager
Updates the current value for the color id in the newValue- Overrides:
setColor
in classThemeManager
- Parameters:
newValue
- the newColorValue
to install in the current values.
-
setIcon
Description copied from class:ThemeManager
Updates the current value for theIcon
id in the newValue- Overrides:
setIcon
in classThemeManager
- Parameters:
newValue
- the newIconValue
to install in the current values.
-
getGColorUiResource
Gets a UIResource version of the GColor for the given id. Using this method ensures that the same instance is used for a given id. This fixes an issue with someLookAndFeel
s that internally use '==' comparisons.- Parameters:
id
- the id to get a GColorUIResource for- Returns:
- a GColorUIResource for the given id
-
setJavaDefaults
Sets the map of Java default UI values. These are the UI values defined by the current Java Look and Feel.- Parameters:
map
- the default theme values defined by theLookAndFeel
-
hasThemeChanges
public boolean hasThemeChanges()Description copied from class:ThemeManager
Returns true if there are any unsaved changes to the current theme.- Overrides:
hasThemeChanges
in classThemeManager
- Returns:
- true if there are any unsaved changes to the current theme.
-
hasThemeValueChanges
public boolean hasThemeValueChanges()Description copied from class:ThemeManager
Returns true if any theme values have changed. This does not take into account the current Look and Feel. UseThemeManager.hasThemeChanges()
to also account for changes to the Look and Feel.- Overrides:
hasThemeValueChanges
in classThemeManager
- Returns:
- true if any theme values have changed
-
registerFont
Description copied from class:ThemeManager
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.- Overrides:
registerFont
in classThemeManager
- Parameters:
component
- the component to set/update the fontfontId
- the id of the font to register with the given component
-
registerFont
Description copied from class:ThemeManager
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.This method is fairly niche and should not be called by most clients. Instead, call
ThemeManager.registerFont(Component, String)
.- Overrides:
registerFont
in classThemeManager
- Parameters:
component
- the component to set/update the fontfontId
- the id of the font to register with the given componentfontStyle
- the font style
-
unRegisterFont
Description copied from class:ThemeManager
Removes the component and font id binding made in a previous call toThemeManager.registerFont(Component, String)
.- Overrides:
unRegisterFont
in classThemeManager
- Parameters:
component
- the component to removefontId
- the id of the font previously registered
-
buildCurrentValues
protected void buildCurrentValues()Description copied from class:ThemeManager
This method is called to create the internal set of theme value used by the application. To do this, we use a layered approach to install values, with the last values added overwriting any pre-existing values with the same key. The values are added in the following order:java defaults -> light values -> dark values -> look and feel values -> property file values -> theme values
At the point this method is called, this is the state of these various values:
- The 'javaValues' are normalized in the form of 'laf.font.TextArea'
- The 'applicationDefaults' contains values loaded from the
theme.properties
files:font.listing.base font.monospaced [color]Viewport.background = color.bg [laf.font]TextArea.font = font.monospaced [laf.boolean]Button.rollover = true
- The 'activeTheme' values are those loaded by the current theme, which has any changes made to the default values
- Overrides:
buildCurrentValues
in classThemeManager
-
loadThemeFiles
-
refreshGThemeValues
public void refreshGThemeValues()
-