- All Known Implementing Classes:
ClasspathResources,EmptyResources,ModulepathResources
A resources object may reference a parent resources object using the resource key "$parent".
Placeholders
On top of the functionality provided by ResourceBundle, a property value can
include text from another property, by specifying the desired property name
and format type between "${" and "}".
For example, if there is a "imagedir" property with the value
"/org/jhotdraw8/undo/images", then this could be used in an attribute
like this: ${imagedir}/editUndo.png. This is resolved at
run-time as /org/jhotdraw8/undo/images/editUndo.png.
Property names in placeholders can contain modifiers. Modifiers are written
between @code "[$"} and "]". Each modifier has a fallback chain.
For example, if the property name modifier "os" has the value "win",
and its fallback chain is "mac","default", then the property name
${preferences.text.[$os]} is first evaluated to
preferences.text.win, and - if no property with this name exists - it is
evaluated to preferences.text.mac, and then to
preferences.text.default.
The property name modifier "os" is defined by default. It can assume the values "win", "mac" and "other". Its fallback chain is "default".
The format type can be optionally specified after a comma. The following format types are supported:
stringThis is the default format.acceleratorThis format replaces all occurrences of the keywords shift, control, ctrl, meta, alt, altGraph by properties which start withaccelerator.. For example, shift is replaced byaccelerator.shift.
- Author:
- Werner Randelshofer
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddDecoder(ResourceDecoder decoder) Adds a decoder.default voidconfigureAction(@NonNull Action action, String argument) default voiddefault voidconfigureButton(@NonNull javafx.scene.control.ButtonBase button, String argument) default voidconfigureButton(@NonNull javafx.scene.control.ButtonBase button, String argument, @NonNull Class<?> baseClass) default voidconfigureMenu(@NonNull javafx.scene.control.Menu menu, String argument) Configures a menu item with a text, an accelerator, a mnemonic and a menu icon.default voidconfigureMenuItem(@NonNull javafx.scene.control.MenuItem menu, String argument) Configures a menu item with a text, an accelerator, a mnemonic and a menu icon.default voidconfigureToolBarButton(@NonNull javafx.scene.control.ButtonBase button, String argument) default voidconfigureToolBarButton(@NonNull javafx.scene.control.ButtonBase button, String argument, @NonNull Class<?> baseClass) booleancontainsKey(String key) Returns a formatted string usingFormatter.default @Nullable javafx.scene.input.KeyCombinationGets a KeyStroke for a JavaBeans "accelerator" property from the ResourceBundle.Class<?> getFormatted(@NonNull String key, Object... arguments) Returns a formatted string using javax.text.MessageFormat.getInteger(@NonNull String key) Get an Integer from the ResourceBundle.default @Nullable javafx.scene.input.KeyCombinationGet a KeyStroke from the ResourceBundle.getKeys()default @Nullable javafx.scene.NodegetLargeIconProperty(String key, @NonNull Class<?> baseClass) Get a large image icon from the ResourceBundle for use on aJButton.default chargetMnemonic(@NonNull String key) Get a Mnemonic from the ResourceBundle.default @Nullable javafx.scene.input.KeyCombinationGets a char for a JavaBeans "mnemonic" property from the ResourceBundle.Returns a java.lang.Module if the resources have been created with named Java module on a Java VM that supports modules.getResources(String moduleName, @NonNull String resourceBundle) getRoot()default @Nullable javafx.scene.NodegetSmallIconProperty(String key, @NonNull Class<?> baseClass) Get a small image icon from the ResourceBundle for use on aJMenuItem.getTextProperty(String key) Get a String for a JavaBeans "text" property from the ResourceBundle.Get a String for a JavaBeans "toolTipText" property from the ResourceBundle.messageFormat(@NonNull String key, Object... arguments) Returns a formatted string usingMessageFormat.static voidputPropertyNameModifier(String name, String... fallbackChain) Puts a property name modifier along with a fallback chain.static voidRemoves a property name modifier.voidsubstitutePlaceholders(String key, @NonNull String value) Translate a String defining ajavax.swing.KeyStrokeinto a String forjavafx.input.KeyCombination.
-
Field Details
-
PARENT_RESOURCE_KEY
- See Also:
-
-
Method Details
-
addDecoder
Adds a decoder.- Parameters:
decoder- the resource decoder
-
putPropertyNameModifier
Puts a property name modifier along with a fallback chain.- Parameters:
name- The name of the modifier.fallbackChain- The fallback chain of the modifier.
-
removePropertyNameModifier
Removes a property name modifier.- Parameters:
name- The name of the modifier.
-
getResources
-
asResourceBundle
ResourceBundle asResourceBundle() -
configureAction
-
configureAction
-
configureButton
-
configureButton
-
configureMenu
Configures a menu item with a text, an accelerator, a mnemonic and a menu icon.- Parameters:
menu- the menuargument- the argument
-
configureMenuItem
Configures a menu item with a text, an accelerator, a mnemonic and a menu icon.- Parameters:
menu- the menu itemargument- the argument
-
configureToolBarButton
-
configureToolBarButton
-
containsKey
-
format
Returns a formatted string usingFormatter.- Parameters:
key- the keyarguments- the arguments- Returns:
- formatted String
-
messageFormat
Returns a formatted string usingMessageFormat.- Parameters:
key- the keyarguments- the arguments- Returns:
- formatted String
-
getAcceleratorProperty
Gets a KeyStroke for a JavaBeans "accelerator" property from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property. This method adds ".accelerator" to the key.- Returns:
javax.swing.KeyStroke.getKeyStroke(value). Returns null if the property is missing.
-
getBaseClass
Class<?> getBaseClass() -
getModule
Object getModule()Returns a java.lang.Module if the resources have been created with named Java module on a Java VM that supports modules.- Returns:
- java.lang.Module
-
getBaseName
-
getFormatted
Returns a formatted string using javax.text.MessageFormat.- Parameters:
key- the keyarguments- the arguments- Returns:
- formatted String
-
getInteger
Get an Integer from the ResourceBundle.
Convenience method to save casting.- Parameters:
key- The key of the property.- Returns:
- The value of the property. Returns -1 if the property is missing.
-
getKeyCombination
Get a KeyStroke from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property.- Returns:
javax.swing.KeyStroke.getKeyStroke(value). Returns null if the property is missing.
-
getLargeIconProperty
Get a large image icon from the ResourceBundle for use on aJButton.
Convenience method .- Parameters:
key- The key of the property. This method appends ".largeIcon" to the key.baseClass- the base class used to retrieve the image resource- Returns:
- The value of the property. Returns null if the property is missing.
-
getLocale
-
getMnemonic
Get a Mnemonic from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property.- Returns:
- The first char of the value of the property. Returns '\0' if the property is missing.
-
getMnemonicProperty
Gets a char for a JavaBeans "mnemonic" property from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property. This method appends ".mnemonic" to the key.- Returns:
- The first char of the value of the property. Returns '\0' if the property is missing.
-
getSmallIconProperty
Get a small image icon from the ResourceBundle for use on aJMenuItem.
Convenience method .- Parameters:
key- The key of the property. This method appends ".smallIcon" to the key.baseClass- the base class used to retrieve the image resource- Returns:
- The value of the property. Returns null if the property is missing.
-
getString
-
getTextProperty
Get a String for a JavaBeans "text" property from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property. This method appends ".text" to the key.- Returns:
- The ToolTip. Returns null if no tooltip is defined.
-
getToolTipTextProperty
Get a String for a JavaBeans "toolTipText" property from the ResourceBundle.
Convenience method.- Parameters:
key- The key of the property. This method appends ".toolTipText" to the key.- Returns:
- The ToolTip. Returns null if no tooltip is defined.
-
substitutePlaceholders
default @NonNull String substitutePlaceholders(String key, @NonNull String value) throws MissingResourceException - Throws:
MissingResourceException
-
translateKeyStrokeToKeyCombination
Translate a String defining ajavax.swing.KeyStrokeinto a String forjavafx.input.KeyCombination.- Parameters:
s- The KeyStroke String- Returns:
- The KeyCombination String
-
handleGetObjectRecursively
-
getKeys
@NonNull Enumeration<String> getKeys() -
getParent
-
setParent
-
getRoot
-