Interface Resources

All Known Implementing Classes:
ClasspathResources, EmptyResources, ModulepathResources

public interface Resources
This is a convenience wrapper for accessing resources stored in a ResourceBundle.

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:

  • string This is the default format.
  • accelerator This format replaces all occurrences of the keywords shift, control, ctrl, meta, alt, altGraph by properties which start with accelerator.. For example, shift is replaced by accelerator.shift.
Author:
Werner Randelshofer
  • Field Details

  • Method Details

    • addDecoder

      static void addDecoder(ResourceDecoder decoder)
      Adds a decoder.
      Parameters:
      decoder - the resource decoder
    • putPropertyNameModifier

      static void putPropertyNameModifier(String name, String... fallbackChain)
      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

      static void removePropertyNameModifier(String name)
      Removes a property name modifier.
      Parameters:
      name - The name of the modifier.
    • getResources

      static @NonNull Resources getResources(String moduleName, @NonNull String resourceBundle)
    • asResourceBundle

      ResourceBundle asResourceBundle()
    • configureAction

      default void configureAction(@NonNull Action action, String argument)
    • configureAction

      default void configureAction(@NonNull Action action, String argument, @NonNull Class<?> baseClass)
    • configureButton

      default void configureButton(@NonNull javafx.scene.control.ButtonBase button, String argument)
    • configureButton

      default void configureButton(@NonNull javafx.scene.control.ButtonBase button, String argument, @NonNull Class<?> baseClass)
    • configureMenu

      default void configureMenu(@NonNull javafx.scene.control.Menu menu, String argument)
      Configures a menu item with a text, an accelerator, a mnemonic and a menu icon.
      Parameters:
      menu - the menu
      argument - the argument
    • configureMenuItem

      default void configureMenuItem(@NonNull javafx.scene.control.MenuItem menu, String argument)
      Configures a menu item with a text, an accelerator, a mnemonic and a menu icon.
      Parameters:
      menu - the menu item
      argument - the argument
    • configureToolBarButton

      default void configureToolBarButton(@NonNull javafx.scene.control.ButtonBase button, String argument)
    • configureToolBarButton

      default void configureToolBarButton(@NonNull javafx.scene.control.ButtonBase button, String argument, @NonNull Class<?> baseClass)
    • containsKey

      boolean containsKey(String key)
    • format

      default @NonNull String format(@NonNull String key, Object... arguments)
      Returns a formatted string using Formatter.
      Parameters:
      key - the key
      arguments - the arguments
      Returns:
      formatted String
    • messageFormat

      default @NonNull String messageFormat(@NonNull String key, Object... arguments)
      Returns a formatted string using MessageFormat.
      Parameters:
      key - the key
      arguments - the arguments
      Returns:
      formatted String
    • getAcceleratorProperty

      default @Nullable javafx.scene.input.KeyCombination getAcceleratorProperty(String key)
      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

      @NonNull String getBaseName()
    • getFormatted

      default @NonNull String getFormatted(@NonNull String key, Object... arguments)
      Returns a formatted string using javax.text.MessageFormat.
      Parameters:
      key - the key
      arguments - the arguments
      Returns:
      formatted String
    • getInteger

      default @NonNull Integer getInteger(@NonNull String key)
      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

      default @Nullable javafx.scene.input.KeyCombination getKeyCombination(@NonNull String key)
      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

      default @Nullable javafx.scene.Node getLargeIconProperty(String key, @NonNull Class<?> baseClass)
      Get a large image icon from the ResourceBundle for use on a JButton.
      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

      @NonNull Locale getLocale()
    • getMnemonic

      default char getMnemonic(@NonNull String key)
      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

      default @Nullable javafx.scene.input.KeyCombination getMnemonicProperty(String key)
      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

      default @Nullable javafx.scene.Node getSmallIconProperty(String key, @NonNull Class<?> baseClass)
      Get a small image icon from the ResourceBundle for use on a JMenuItem.
      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

      @NonNull String getString(String s)
    • getTextProperty

      default @Nullable String getTextProperty(String key)
      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

      default @Nullable String getToolTipTextProperty(String key)
      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

      default @Nullable String translateKeyStrokeToKeyCombination(@Nullable String s)
      Translate a String defining a javax.swing.KeyStroke into a String for javafx.input.KeyCombination.
      Parameters:
      s - The KeyStroke String
      Returns:
      The KeyCombination String
    • handleGetObjectRecursively

      @Nullable Object handleGetObjectRecursively(@NonNull String key)
    • getKeys

    • getParent

      @Nullable Resources getParent()
    • setParent

      void setParent(@Nullable Resources newParent)
    • getRoot

      default @NonNull Resources getRoot()