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
FieldsFields inherited from class generic.theme.ThemeManager
activeLafType, activeTheme, applicationDefaults, currentValues, INSTANCE, javaDefaults, THEME_DIR, useDarkDefaults -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given theme to set of all themes.protected voidThis method is called to create the internal set of theme value used by the application.voiddeleteTheme(GTheme theme) Removes the theme from the set of all themes.protected voidReturns 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.booleanReturns true if there are any unsaved changes to the current theme.booleanReturns true if any theme values have changed.static voidInitialized the Theme and its values for the application.booleanReturns true if the application should allow blinking cursors, false otherwise.booleanisChangedColor(String id) Returns true if the color associated with the given id has been changed from the current theme value for that id.booleanisChangedFont(String id) Returns true if the font associated with the given id has been changed from the current theme value for that id.booleanisChangedIcon(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> voidvoidregisterFont(Component component, String fontId) Binds the component to the font identified by the given font id.voidregisterFont(Component component, String fontId, int fontStyle) Binds the component to the font identified by the given font id.voidrestoreColor(String id) Restores the current color value for the given color id to the value established by the current theme.voidrestoreFont(String id) Restores the current font value for the given font id to the value established by the current theme.voidrestoreIcon(String id) Restores the current icon value for the given icon id to the value established by the current theme.voidRestores all the current application back to the values as specified by the active theme.voidsetBlinkingCursors(boolean b) Sets application's blinking cursor state.voidsetColor(ColorValue newValue) Updates the current value for the color id in the newValuevoidUpdates the current value for the font id in the newValuevoidUpdates the current value for theIconid in the newValuevoidSets the map of Java default UI values.voidsetLookAndFeel(LafType lafType, boolean useDarkDefaults) Sets the currentLookAndFeel.voidSets the application's active theme to the given theme.voidunRegisterFont(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, isUsingAquaUI, isUsingFlatUI, 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:ThemeManagerRestores 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:
restoreThemeValuesin classThemeManager
-
restoreColor
Description copied from class:ThemeManagerRestores the current color value for the given color id to the value established by the current theme.- Overrides:
restoreColorin classThemeManager- Parameters:
id- the color id to restore back to the original theme value
-
restoreFont
Description copied from class:ThemeManagerRestores the current font value for the given font id to the value established by the current theme.- Overrides:
restoreFontin classThemeManager- Parameters:
id- the font id to restore back to the original theme value
-
restoreIcon
Description copied from class:ThemeManagerRestores the current icon value for the given icon id to the value established by the current theme.- Overrides:
restoreIconin classThemeManager- Parameters:
id- the icon id to restore back to the original theme value
-
isChangedColor
Description copied from class:ThemeManagerReturns true if the color associated with the given id has been changed from the current theme value for that id.- Overrides:
isChangedColorin 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:ThemeManagerReturns true if the font associated with the given id has been changed from the current theme value for that id.- Overrides:
isChangedFontin 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:ThemeManagerReturns true if the Icon associated with the given id has been changed from the current theme value for that id.- Overrides:
isChangedIconin 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:ThemeManagerSets the application's active theme to the given theme.- Overrides:
setThemein classThemeManager- Parameters:
theme- the theme to make active
-
setLookAndFeel
Description copied from class:ThemeManagerSets 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 that the current theme is in an unsaved state and causes theThemeManager.hasThemeChanges()method to return true.- Overrides:
setLookAndFeelin classThemeManager- Parameters:
lafType- theLafTypeto 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:ThemeManagerSets application's blinking cursor state. This will affect all JTextFields, JTextAreas, JTextPanes viaUIDefaults. Custom components can also respect this setting by either adding aThemeListeneror 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:
setBlinkingCursorsin classThemeManager- Parameters:
b- true for blinking text cursors, false for non-blinking text cursors
-
isBlinkingCursors
public boolean isBlinkingCursors()Description copied from class:ThemeManagerReturns 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:
isBlinkingCursorsin classThemeManager- Returns:
- true if the application should allow blinking cursors, false otherwise.
-
addTheme
Description copied from class:ThemeManagerAdds the given theme to set of all themes.- Overrides:
addThemein classThemeManager- Parameters:
newTheme- the theme to add
-
deleteTheme
Description copied from class:ThemeManagerRemoves the theme from the set of all themes. Also, if the theme has an associated file, the file will be deleted.- Overrides:
deleteThemein classThemeManager- Parameters:
theme- the theme to delete
-
getAllThemes
Description copied from class:ThemeManagerReturns a set of all known themes.- Overrides:
getAllThemesin classThemeManager- Returns:
- a set of all known themes.
-
getSupportedThemes
Description copied from class:ThemeManagerReturns a set of all known themes that are supported on the current platform.- Overrides:
getSupportedThemesin classThemeManager- Returns:
- a set of all known themes that are supported on the current platform.
-
getTheme
Description copied from class:ThemeManagerReturns the known theme that has the given name.- Overrides:
getThemein classThemeManager- Parameters:
themeName- the name of the theme to retrieve- Returns:
- the known theme that has the given name
-
setFont
Description copied from class:ThemeManagerUpdates the current value for the font id in the newValue- Overrides:
setFontin classThemeManager- Parameters:
newValue- the newFontValueto install in the current values.
-
setColor
Description copied from class:ThemeManagerUpdates the current value for the color id in the newValue- Overrides:
setColorin classThemeManager- Parameters:
newValue- the newColorValueto install in the current values.
-
setIcon
Description copied from class:ThemeManagerUpdates the current value for theIconid in the newValue- Overrides:
setIconin classThemeManager- Parameters:
newValue- the newIconValueto 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 someLookAndFeels 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:ThemeManagerReturns true if there are any unsaved changes to the current theme.- Overrides:
hasThemeChangesin classThemeManager- Returns:
- true if there are any unsaved changes to the current theme.
-
hasThemeValueChanges
public boolean hasThemeValueChanges()Description copied from class:ThemeManagerReturns 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:
hasThemeValueChangesin classThemeManager- Returns:
- true if any theme values have changed
-
registerFont
Description copied from class:ThemeManagerBinds 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:
registerFontin 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:ThemeManagerBinds 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:
registerFontin 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:ThemeManagerRemoves the component and font id binding made in a previous call toThemeManager.registerFont(Component, String).- Overrides:
unRegisterFontin classThemeManager- Parameters:
component- the component to removefontId- the id of the font previously registered
-
buildCurrentValues
protected void buildCurrentValues()Description copied from class:ThemeManagerThis 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.propertiesfiles: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:
buildCurrentValuesin classThemeManager
-
loadThemeFiles
-
refreshGThemeValues
public void refreshGThemeValues()
-