Class UIManager
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddThemeProps(Hashtable themeProps) Adds the given theme properties on top of the existing properties without clearing the existing theme firstvoidAdds a Theme refresh listener.static UIManagerThis factory method allows creating a new UIManager instance, this is usefull where an application has some screens with different contextThe resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.getComponentCustomStyle(String id, String type) Returns a custom style for the component with the given id, this method always returns a new instance.Returns the selected style of the component with the given id or a new instance of the default style.final StyleReturns the style of the component with the given id or a new instance of the default style.getIconUIIDFor(String id) Gets the IconUIID for the given UIID.static UIManagerSingleton instance methodReturns the currently installed look and feelThe resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.intgetThemeConstant(String constantName, int def) Returns a theme constant defined in the resource editorfinal StringgetThemeConstant(String constantName, String def) Returns a theme constant defined in the resource editorgetThemeImageConstant(String constantName) Returns a theme constant defined in the resource editorgetThemeMaskConstant(String constantName) Returns a theme mask constantReturns
static ResourcesinitFirstTheme(String resourceFile) This is a shorthand notation for boilerplate code for initializing the first theme in the given resource file and catching/doing nothing with the IOException since this would be invoked too early in the program where we would be out of options if something like that happens.static ResourcesinitNamedTheme(String resourceFile, String resName) Same as the initFirstTheme method, but unlike that method this allows specifying the theme resource nameisThemeConstant(String constantName) Returns a theme constant defined in the resource editor as a boolean value or null if the constant isn't definedfinal booleanisThemeConstant(String constantName, boolean def) Returns a theme constant defined in the resource editor as a boolean valuebooleanChecks if larger text scaling is enabled.final StringLocalizes the given string from the resource bundle if such a String exists in the resource bundle.protected voidonLocalize(String key, String defaultValue) Callback for subclasses that wish to track localization invocations.parseComponentCustomStyle(Resources theme, String baseStyle, String id, String type, String... styleString) Returns the selected style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.parseComponentSelectedStyle(Resources theme, String baseStyle, String id, String... styleString) Returns the selected style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.parseComponentStyle(Resources theme, String baseStyle, String id, String... styleString) Returns the style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.voidRemoves a Theme refresh listener.voidThe resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.voidsetComponentSelectedStyle(String id, Style style) Allows a developer to programmatically install a style into the UI managervoidsetComponentStyle(String id, Style style) Allows a developer to programmatically install a style into the UI managervoidsetComponentStyle(String id, Style style, String type) Allows a developer to programmatically install a style into the UI managervoidsetLookAndFeel(LookAndFeel plaf) Sets the currently installed look and feelvoidsetResourceBundle(Hashtable resourceBundle) The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.voidsetThemeProps(Hashtable themeProps) Allows manual theme loading from a hashtable of key/value pairsvoidsetUseLargerTextScale(boolean useLargerTextScale) Enables or disables scaling fonts when larger text is enabled on the device.booleanIndicates if a theme was previously installed since the last reset
-
Method Details
-
getInstance
Singleton instance method
Returns
Instance of the ui manager
-
createInstance
This factory method allows creating a new UIManager instance, this is usefull where an application has some screens with different context
Returns
a new UIManager instance
-
initFirstTheme
This is a shorthand notation for boilerplate code for initializing the first theme in the given resource file and catching/doing nothing with the IOException since this would be invoked too early in the program where we would be out of options if something like that happens. Effectively this is the same as writing:
try { theme = Resources.openLayered(resourceFile); UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0])); } catch(IOException e){ e.printStackTrace(); }Parameters
resourceFile: the name of the resource file starting with / and without the res extension
Returns
the resource file or null in case of a failure
-
initNamedTheme
Same as the initFirstTheme method, but unlike that method this allows specifying the theme resource name
Parameters
-
resourceFile: the name of the resource file starting with / and without the res extension -
resName: the name of the theme to use from the file if it contains more than one theme
Returns
the resource file or null in case of a failure
-
-
isUseLargerTextScale
public boolean isUseLargerTextScale()Checks if larger text scaling is enabled.
Returns
true if larger text scaling should be applied.
-
setUseLargerTextScale
public void setUseLargerTextScale(boolean useLargerTextScale) Enables or disables scaling fonts when larger text is enabled on the device. This can also be enabled via the
useLargerTextScaleBooltheme constant.Parameters
useLargerTextScale: @param useLargerTextScale true to applyDisplay#getLargerTextScale()whenDisplay#isLargerTextEnabled()is true.
-
wasThemeInstalled
public boolean wasThemeInstalled()Indicates if a theme was previously installed since the last reset
Returns
true if setThemeProps was invoked
-
getLookAndFeel
Returns the currently installed look and feel
Returns
the currently installed look and feel
-
setLookAndFeel
Sets the currently installed look and feel
Parameters
plaf: the look and feel for the application
-
setComponentStyle
-
setComponentStyle
-
setComponentSelectedStyle
-
getComponentStyle
Returns the style of the component with the given id or a new instance of the default style. This method will always return a new style instance to prevent modification of the global style object.
Parameters
id: the component id whose style we want
Returns
the appropriate style (this method never returns null)
-
getIconUIIDFor
Gets the IconUIID for the given UIID. If the theme defines a style that is named ${id}Icon (i.e. the id with "Icon" suffix) such that it derives from id, then this style is deemed to be the icon style corresponding with id.
Parameters
id: The UIID to check for a companion UIID.
Returns
The IconUIID corresponding to the given ID - or null if none is defined in the theme.
Since
8.0
-
parseComponentStyle
public Style parseComponentStyle(Resources theme, String baseStyle, String id, String... styleString) Returns the style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.
This method will always return a new style instance to prevent modification of the global style object.
Parameters
-
theme: Theme file used to retrieve images that are referenced by the styleString -
baseStyle: @param baseStyle The component ID that serves as the base style for this style. These base styles are overridden by the styles provided in styleString. -
id: the component id into which the resulting style is to be cached. -
styleString: @param styleString Array of style strings to override the styles in baseStyle. Style string syntax is is key1:value1; key2:value2; key3:value3; etc.... While this is similar to CSS, it is not CSS. The keys and values correspond to properties ofStyleand their associated values.
Returns
the appropriate style (this method never returns null)
-
-
getComponentSelectedStyle
Returns the selected style of the component with the given id or a new instance of the default style. This method will always return a new style instance to prevent modification of the global style object.
Parameters
id: the component id whose selected style we want
Returns
the appropriate style (this method never returns null)
-
parseComponentSelectedStyle
public Style parseComponentSelectedStyle(Resources theme, String baseStyle, String id, String... styleString) Returns the selected style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.
This method will always return a new style instance to prevent modification of the global style object.
Parameters
-
theme: Theme file used to retrieve images that are referenced by the styleString -
baseStyle: @param baseStyle The component ID that serves as the base style for this style. These base styles are overridden by the styles provided in styleString. -
id: the component id into which the resulting style is to be cached. -
styleString: @param styleString Array of style strings to override the styles in baseStyle. Style string syntax is is key1:value1; key2:value2; key3:value3; etc.... While this is similar to CSS, it is not CSS. The keys and values correspond to properties ofStyleand their associated values.
Returns
the appropriate style (this method never returns null)
-
-
getComponentCustomStyle
Returns a custom style for the component with the given id, this method always returns a new instance. Custom styles allow us to install application specific or component specific style attributes such as pressed, disabled, hover etc.
Parameters
-
id: the component id whose custom style we want -
type: the style type
Returns
the appropriate style (this method never returns null)
-
-
parseComponentCustomStyle
public Style parseComponentCustomStyle(Resources theme, String baseStyle, String id, String type, String... styleString) Returns the selected style of the component with the given baseStyle or a new instance of the default style, but overrides styles based on the directives in the styleStrings.
This method will always return a new style instance to prevent modification of the global style object.
Parameters
-
theme: Theme file used to retrieve images that are referenced by the styleString -
baseStyle: @param baseStyle The component ID that serves as the base style for this style. These base styles are overridden by the styles provided in styleString. -
id: the component id into which the resulting style is to be cached. -
type: the style type -
styleString: @param styleString Array of style strings to override the styles in baseStyle. Style string syntax is is key1:value1; key2:value2; key3:value3; etc.... While this is similar to CSS, it is not CSS. The keys and values correspond to properties ofStyleand their associated values.
Returns
the appropriate style (this method never returns null)
-
-
getThemeName
Returns
the name of the current theme for theme switching UI's
-
setThemeProps
Allows manual theme loading from a hashtable of key/value pairs
Parameters
themeProps: the properties of the given theme
-
addThemeProps
Adds the given theme properties on top of the existing properties without clearing the existing theme first
Parameters
themeProps: the properties of the given theme
-
getThemeConstant
Returns a theme constant defined in the resource editor
Parameters
-
constantName: the name of the constant -
def: default value
Returns
the value of the constant or the default if the constant isn't in the theme
-
-
getThemeConstant
-
isThemeConstant
Returns a theme constant defined in the resource editor as a boolean value
Parameters
-
constantName: the name of the constant -
def: default value
Returns
the value of the constant or the default if the constant isn't in the theme
-
-
isThemeConstant
-
getThemeImageConstant
-
getThemeMaskConstant
-
getResourceBundle
The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.
Returns
the localization bundle
Deprecated
this method uses the old resource bundle hashtable, use the new getBundle() method
-
setResourceBundle
The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.
Parameters
resourceBundle: the localization bundle
Deprecated
this method uses the old resource bundle hashtable, use the new setBundle() method
-
getBundle
-
setBundle
The resource bundle allows us to implicitly localize the UI on the fly, once its installed all internal application strings query the resource bundle and extract their values from this table if applicable.
Parameters
resourceBundle: the localization bundle
-
localize
Localizes the given string from the resource bundle if such a String exists in the resource bundle. If no key exists in the bundle then or a bundle is not installed the default value is returned.
Parameters
-
key: The key used to lookup in the resource bundle -
defaultValue: the value returned if no such key exists
Returns
either default value or the appropriate value
-
-
onLocalize
-
addThemeRefreshListener
Adds a Theme refresh listener. The listenres will get a callback when setThemeProps method is invoked.
Parameters
l: an ActionListener to be added
-
removeThemeRefreshListener
Removes a Theme refresh listener.
Parameters
l: an ActionListener to be removed
-