org.bs.mdi
Class Resources

java.lang.Object
  extended byorg.bs.mdi.Resources
Direct Known Subclasses:
CompositeResources, DefaultResources

public abstract class Resources
extends Object

Manages program resources such as localized strings or icons.


Field Summary
static int BUTTON_ICON
           
static int CUSTOM_ICON
           
static int MENU_ICON
           
static int MESSAGEBOX_ICON
           
static int TOOLBAR_ICON
           
 
Constructor Summary
Resources()
          Resources is an abstract class and therefore cannot be instantiated.
 
Method Summary
abstract  Icon getIcon(String key, int size)
          Returns an icon for the specified key and in the given size
 Locale getLocale()
          Returns the currently used locale.
 int getMnemonic(String key)
          Returns the Mnemonic for the given key.
abstract  String getString(String key)
          Returns a localized string for the given key.
 String i18n(String key)
          Returns a localized string for the given key, stripping ampersand characters which are meant for marking mnemonics.
abstract  void loadResources()
          Re-loads the resources from storage.
 void setLocale(Locale locale)
          Sets the locale used for getting translated/localized resources.
protected  String stripMnemonic(String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CUSTOM_ICON

public static final int CUSTOM_ICON
See Also:
Constant Field Values

MENU_ICON

public static final int MENU_ICON
See Also:
Constant Field Values

BUTTON_ICON

public static final int BUTTON_ICON
See Also:
Constant Field Values

TOOLBAR_ICON

public static final int TOOLBAR_ICON
See Also:
Constant Field Values

MESSAGEBOX_ICON

public static final int MESSAGEBOX_ICON
See Also:
Constant Field Values
Constructor Detail

Resources

public Resources()
Resources is an abstract class and therefore cannot be instantiated. The default implementation sets the system-default locale and calls loadResources().

Method Detail

setLocale

public void setLocale(Locale locale)
Sets the locale used for getting translated/localized resources.

Parameters:
locale - the locale to be used

getLocale

public Locale getLocale()
Returns the currently used locale.

Returns:
the current locale

loadResources

public abstract void loadResources()
Re-loads the resources from storage. This method should take the currently selected locale (see getLocale()) into account.


getString

public abstract String getString(String key)
Returns a localized string for the given key.

Parameters:
key - the key
Returns:
the localized string, or null in case of error

getIcon

public abstract Icon getIcon(String key,
                             int size)
Returns an icon for the specified key and in the given size

Parameters:
key - the key
size - the size of the icon: pre-defined values are: CUSTOM_ICON, MENU_ICON, BUTTON_ICON, TOOLBAR_ICON, MESSAGEBOX_ICON.
Returns:
the icon, or null in case of error

i18n

public String i18n(String key)
Returns a localized string for the given key, stripping ampersand characters which are meant for marking mnemonics. For a detailed description of the mnemonic feature, see getMnemonic(java.lang.String).

Parameters:
key - the key
Returns:
the localized string, or key in case of error

stripMnemonic

protected String stripMnemonic(String s)

getMnemonic

public int getMnemonic(String key)
Returns the Mnemonic for the given key. A mnemonic is a key shortcut for accessing GUI elements such as menu items, buttons, or labels.

Example: For accessing the file menu, the keystroke "F" may be used as the mnemonic of this menu. The letter "F" then usually appears underligned, and the user can press a key combination such as STRG-F or ALT-F for activating the menu.

Using the jmdiframework resource system, mnemonics are usually marked using the prefix "&" (ampersand). In the above example, the file menu label would be saved in the resource files as "&File".

This method first looks for a translation of the given key using the getString(java.lang.String) method, then scans the result for the appearance of an ampersand character, and returns the following character as the mnemonic.

Parameters:
key - the key
Returns:
the mnemonic, or 0 if no mnemonic is set