public class UIManager
- Object
- UIManager
Methods
public static int getThemeGeneration() | The current theme generation; see themeGeneration. |
public static UIManager getInstance() | Singleton instance method |
public static UIManager createInstance() | This factory method allows creating a new UIManager instance, this is usefull where an application has some screens with different context |
public static Resources initFirstTheme(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. |
public static Resources initNamedTheme(String resourceFile, String resName) | Same as the initFirstTheme method, but unlike that method this allows specifying the theme resource name |
public boolean isUseLargerTextScale() | Checks if larger text scaling is enabled. |
public void setUseLargerTextScale(boolean useLargerTextScale) | Enables or disables scaling fonts when larger text is enabled on the device. |
public boolean wasThemeInstalled() | Indicates if a theme was previously installed since the last reset |
public LookAndFeel getLookAndFeel() | Returns the currently installed look and feel |
public void setLookAndFeel(LookAndFeel plaf) | Sets the currently installed look and feel |
public void setComponentStyle(String id, Style style) | Allows a developer to programmatically install a style into the UI manager |
public void setComponentStyle(String id, Style style, String type) | Allows a developer to programmatically install a style into the UI manager |
public void setComponentSelectedStyle(String id, Style style) | Allows a developer to programmatically install a style into the UI manager |
public final Style getComponentStyle(String id) | Returns the style of the component with the given id or a new instance of the default style. |
public String getIconUIIDFor(String id) | Gets the IconUIID for the given UIID. |
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. |
public Style getComponentSelectedStyle(String id) | Returns the selected style of the component with the given id or a new instance of the default style. |
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. |
public Style getComponentCustomStyle(String id, String type) | Returns a custom style for the component with the given id, this method always returns a new instance. |
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. |
public String getThemeName() | |
public void setThemeProps(Hashtable themeProps) | Allows manual theme loading from a hashtable of key/value pairs |
public void addThemeProps(Hashtable themeProps) | Adds the given theme properties on top of the existing properties without clearing the existing theme first |
public void zoomFonts(float factor) | Scales the font sizes of the current theme by the given factor, e.g. a factor of 1.2 increases all font sizes by 20% and a factor of 0.8 decreases them by 20%. |
public void refreshTheme() | Invalidates the cached Style instances and re-runs the theme build pass against the currently installed theme properties. |
public int getThemeConstant(String constantName, int def) | Returns a theme constant defined in the resource editor |
public final String getThemeConstant(String constantName, String def) | Returns a theme constant defined in the resource editor |
public final boolean isThemeConstant(String constantName, boolean def) | Returns a theme constant defined in the resource editor as a boolean value |
public Boolean isThemeConstant(String constantName) | Returns a theme constant defined in the resource editor as a boolean value or null if the constant isn’t defined |
public Image getThemeImageConstant(String constantName) | Returns a theme constant defined in the resource editor |
public Object getThemeMaskConstant(String constantName) | Returns a theme mask constant |
public Hashtable getResourceBundle() | Deprecated 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. |
public void setResourceBundle(Hashtable resourceBundle) | Deprecated 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. |
public Map<String, String> getBundle() | 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. |
public void setBundle(Map<String, String> bundle) | 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. |
public final String localize(String key, String defaultValue) | Localizes the given string from the resource bundle if such a String exists in the resource bundle. |
protected void onLocalize(String key, String defaultValue) | Callback for subclasses that wish to track localization invocations. |
public void addThemeRefreshListener(ActionListener l) | Adds a Theme refresh listener. |
public void removeThemeRefreshListener(ActionListener l) | Removes a Theme refresh listener. |
Inherited methods
Method details
getThemeGeneration
public static int getThemeGeneration()themeGeneration.getInstance
public static UIManager getInstance()Returns
createInstance
public static UIManager createInstance()Returns
initFirstTheme
public static Resources initFirstTheme(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. Effectively this is the same as writing:
Resources theme = null;
try {
theme = Resources.openLayered(resourceFile);
UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
} catch (IOException e) {
Log.e(e);
}
Parameters
resourceFileString- the name of the resource file starting with / and without the res extension
Returns
initNamedTheme
public static Resources initNamedTheme(String resourceFile, String resName)Parameters
resourceFileString- the name of the resource file starting with / and without the res extension
resNameString- the name of the theme to use from the file if it contains more than one theme
Returns
isUseLargerTextScale
public boolean isUseLargerTextScale()Returns
setUseLargerTextScale
public void setUseLargerTextScale(boolean useLargerTextScale)useLargerTextScaleBool theme constant.Parameters
useLargerTextScaleboolean- true to apply
Display#getLargerTextScale()whenDisplay#isLargerTextEnabled()is true.
wasThemeInstalled
public boolean wasThemeInstalled()Returns
getLookAndFeel
public LookAndFeel getLookAndFeel()Returns
setLookAndFeel
public void setLookAndFeel(LookAndFeel plaf)Parameters
plafLookAndFeel- the look and feel for the application
setComponentStyle
public void setComponentStyle(String id, Style style)Parameters
idString- the component id matching the given style
styleStyle- the style object to install
setComponentStyle
public void setComponentStyle(String id, Style style, String type)Parameters
idString- the component id matching the given style
styleStyle- the style object to install
typeString- press, dis or other custom type
setComponentSelectedStyle
public void setComponentSelectedStyle(String id, Style style)Parameters
idString- the component id matching the given style
styleStyle- the style object to install
getComponentStyle
public final Style getComponentStyle(String id)Parameters
idString- the component id whose style we want
Returns
getIconUIIDFor
public String getIconUIIDFor(String id)Parameters
idString- The UIID to check for a companion UIID.
Returns
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
themeResources- Theme file used to retrieve images that are referenced by the styleString
baseStyleString- The component ID that serves as the base style for this style. These base styles are overridden by the styles provided in styleString.
idString- the component id into which the resulting style is to be cached.
styleStringString...- 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 of
Styleand their associated values.
Returns
getComponentSelectedStyle
public Style getComponentSelectedStyle(String id)Parameters
idString- the component id whose selected style we want
Returns
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
themeResources- Theme file used to retrieve images that are referenced by the styleString
baseStyleString- The component ID that serves as the base style for this style. These base styles are overridden by the styles provided in styleString.
idString- the component id into which the resulting style is to be cached.
styleStringString...- 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 of
Styleand their associated values.
Returns
getComponentCustomStyle
public Style getComponentCustomStyle(String id, String type)Parameters
idString- the component id whose custom style we want
typeString- the style type
Returns
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
themeResources- Theme file used to retrieve images that are referenced by the styleString
baseStyleString- The component ID that serves as the base style for this style. These base styles are overridden by the styles provided in styleString.
idString- the component id into which the resulting style is to be cached.
typeString- the style type
styleStringString...- 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 of
Styleand their associated values.
Returns
getThemeName
public String getThemeName()Returns
setThemeProps
public void setThemeProps(Hashtable themeProps)Parameters
themePropsHashtable- the properties of the given theme
addThemeProps
public void addThemeProps(Hashtable themeProps)Parameters
themePropsHashtable- the properties of the given theme
zoomFonts
public void zoomFonts(float factor)Scales the font sizes of the current theme by the given factor, e.g.
a factor of 1.2 increases all font sizes by 20% and a factor of 0.8
decreases them by 20%. Only fonts that support scaling (TTF or native:
fonts, see Font.isTTFNativeFont()) are affected; system fonts are
skipped since their size is fixed by the underlying platform.
The zoom is applied relative to the current state of the theme, so calling this method repeatedly compounds the effect. To undo a zoom, either reapply the theme or call this method with the reciprocal factor.
Note: this updates the theme definitions and clears the cached
styles, but components already shown on a form continue to render
with the Font instances they captured before the call. To apply the
new sizes to a live form, invoke refreshTheme() on it (typically
CN.getCurrentForm().refreshTheme()) after calling this method.
Parameters
factorfloat- the multiplier applied to every scalable font size. Must be greater than zero.
refreshTheme
public void refreshTheme()Display.setDarkMode,
which makes $Dark<UIID> entries eligible) without reloading the theme
from a resource file. Components styled after this call resolve against
the refreshed theme; already-resolved Style references on existing
components keep their old values until those components re-fetch their
styles.getThemeConstant
public int getThemeConstant(String constantName, int def)Parameters
constantNameString- the name of the constant
defint- default value
Returns
getThemeConstant
public final String getThemeConstant(String constantName, String def)Parameters
constantNameString- the name of the constant
defString- default value
Returns
isThemeConstant
public final boolean isThemeConstant(String constantName, boolean def)Parameters
constantNameString- the name of the constant
defboolean- default value
Returns
isThemeConstant
public Boolean isThemeConstant(String constantName)Parameters
constantNameString- the name of the constant
Returns
getThemeImageConstant
public Image getThemeImageConstant(String constantName)Parameters
constantNameString- the name of the constant
Returns
getThemeMaskConstant
public Object getThemeMaskConstant(String constantName)Parameters
constantNameString- the name of the constant
Returns
getResourceBundle
public Hashtable getResourceBundle()Returns
setResourceBundle
public void setResourceBundle(Hashtable resourceBundle)Parameters
resourceBundleHashtable- the localization bundle
getBundle
public Map<String, String> getBundle()Returns
setBundle
public void setBundle(Map<String, String> bundle)localize
public final String localize(String key, String defaultValue)Parameters
keyString- The key used to lookup in the resource bundle
defaultValueString- the value returned if no such key exists
Returns
onLocalize
protected void onLocalize(String key, String defaultValue)Parameters
keyString- The key used to lookup in the resource bundle
defaultValueString- the value returned if no such key exists
addThemeRefreshListener
public void addThemeRefreshListener(ActionListener l)Parameters
lActionListener- an ActionListener to be added
removeThemeRefreshListener
public void removeThemeRefreshListener(ActionListener l)Parameters
lActionListener- an ActionListener to be removed