public class UIManager extends Object
Modifier and Type | Method and Description |
---|---|
void |
addThemeProps(Hashtable themeProps)
Adds the given theme properties on top of the existing properties without
clearing the existing theme first
|
void |
addThemeRefreshListener(ActionListener l)
Adds a Theme refresh listener.
|
static UIManager |
createInstance()
This factory method allows creating a new UIManager instance, this is usefull where an application
has some screens with different context
|
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.
|
Style |
getComponentCustomStyle(String id,
String type)
Returns a custom style for the component with the given id, this method always returns a
new instance.
|
Style |
getComponentSelectedStyle(String id)
Returns the selected style of the component with the given id or a new instance of the default
style.
|
Style |
getComponentStyle(String id)
Returns the style of the component with the given id or a new instance of the default
style.
|
String |
getIconUIIDFor(String id)
Gets the IconUIID for the given UIID.
|
static UIManager |
getInstance()
Singleton instance method
|
LookAndFeel |
getLookAndFeel()
Returns the currently installed look and feel
|
Hashtable |
getResourceBundle()
Deprecated.
this method uses the old resource bundle hashtable, use the new getBundle() method
|
int |
getThemeConstant(String constantName,
int def)
Returns a theme constant defined in the resource editor
|
String |
getThemeConstant(String constantName,
String def)
Returns a theme constant defined in the resource editor
|
Image |
getThemeImageConstant(String constantName)
Returns a theme constant defined in the resource editor
|
Object |
getThemeMaskConstant(String constantName)
Returns a theme mask constant
|
String |
getThemeName() |
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.
|
static Resources |
initNamedTheme(String resourceFile,
String resName)
Same as the initFirstTheme method, but unlike that method this allows specifying the theme resource name
|
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
|
boolean |
isThemeConstant(String constantName,
boolean def)
Returns a theme constant defined in the resource editor as a boolean value
|
String |
localize(String key,
String defaultValue)
Localizes the given string from the resource bundle if such a String exists in the
resource bundle.
|
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.
|
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.
|
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.
|
void |
removeThemeRefreshListener(ActionListener l)
Removes a Theme refresh listener.
|
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.
|
void |
setComponentSelectedStyle(String id,
Style style)
Allows a developer to programmatically install a style into the UI manager
|
void |
setComponentStyle(String id,
Style style)
Allows a developer to programmatically install a style into the UI manager
|
void |
setComponentStyle(String id,
Style style,
String type)
Allows a developer to programmatically install a style into the UI manager
|
void |
setLookAndFeel(LookAndFeel plaf)
Sets the currently installed look and feel
|
void |
setResourceBundle(Hashtable resourceBundle)
Deprecated.
this method uses the old resource bundle hashtable, use the new setBundle() method
|
void |
setThemeProps(Hashtable themeProps)
Allows manual theme loading from a hashtable of key/value pairs
|
boolean |
wasThemeInstalled()
Indicates if a theme was previously installed since the last reset
|
public boolean wasThemeInstalled()
public static UIManager getInstance()
public static UIManager createInstance()
public LookAndFeel getLookAndFeel()
public void setLookAndFeel(LookAndFeel plaf)
plaf
- the look and feel for the applicationpublic void setComponentStyle(String id, Style style)
id
- the component id matching the given stylestyle
- the style object to installpublic void setComponentStyle(String id, Style style, String type)
id
- the component id matching the given stylestyle
- the style object to installtype
- press, dis or other custom typepublic void setComponentSelectedStyle(String id, Style style)
id
- the component id matching the given stylestyle
- the style object to installpublic Style getComponentStyle(String id)
id
- the component id whose style we wantpublic String getIconUIIDFor(String id)
id
- The UIID to check for a companion UIID.public Style parseComponentStyle(Resources theme, String baseStyle, String id, String... styleString)
theme
- Theme file used to retrieve images that are referenced by the styleStringbaseStyle
- 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
- 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 Style
and their associated values.public Style getComponentSelectedStyle(String id)
id
- the component id whose selected style we wantpublic Style parseComponentSelectedStyle(Resources theme, String baseStyle, String id, String... styleString)
theme
- Theme file used to retrieve images that are referenced by the styleStringbaseStyle
- 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
- 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 Style
and their associated values.public Style getComponentCustomStyle(String id, String type)
id
- the component id whose custom style we wanttype
- the style typepublic Style parseComponentCustomStyle(Resources theme, String baseStyle, String id, String type, String... styleString)
theme
- Theme file used to retrieve images that are referenced by the styleStringbaseStyle
- 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 typestyleString
- 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 Style
and their associated values.public String getThemeName()
public void setThemeProps(Hashtable themeProps)
themeProps
- the properties of the given themepublic void addThemeProps(Hashtable themeProps)
themeProps
- the properties of the given themepublic int getThemeConstant(String constantName, int def)
constantName
- the name of the constantdef
- default valuepublic String getThemeConstant(String constantName, String def)
constantName
- the name of the constantdef
- default valuepublic boolean isThemeConstant(String constantName, boolean def)
constantName
- the name of the constantdef
- default valuepublic Boolean isThemeConstant(String constantName)
constantName
- the name of the constantpublic Image getThemeImageConstant(String constantName)
constantName
- the name of the constantpublic Object getThemeMaskConstant(String constantName)
constantName
- the name of the constantpublic Hashtable getResourceBundle()
public Map<String,String> getBundle()
public void setBundle(Map<String,String> bundle)
resourceBundle
- the localization bundlepublic void setResourceBundle(Hashtable resourceBundle)
resourceBundle
- the localization bundlepublic String localize(String key, String defaultValue)
key
- The key used to lookup in the resource bundledefaultValue
- the value returned if no such key existspublic void addThemeRefreshListener(ActionListener l)
l
- an ActionListener to be addedpublic void removeThemeRefreshListener(ActionListener l)
l
- an ActionListener to be removedpublic static Resources initFirstTheme(String resourceFile)
try { theme = Resources.openLayered(resourceFile); UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0])); } catch(IOException e){ e.printStackTrace(); }
resourceFile
- the name of the resource file starting with / and without the res extensionpublic static Resources initNamedTheme(String resourceFile, String resName)
resourceFile
- the name of the resource file starting with / and without the res extensionresName
- the name of the theme to use from the file if it contains more than one theme