6. SwingResource interface.
- By Mike Mannion
- March 23, 2000
Listing 6. SwingResource interface.
public class SwingResource implements Resource
{
...
// Base name of resource file to be used
private String baseName;
public SwingResource(String baseName)
{
Assert.pre(baseName != null,
"Parameter baseName is not null");
this.baseName = baseName;
}
public Icon getIcon(String key)
{
ResourceBundle bundle = getBundle();
String iconName = bundle.getString(
key + ".icon");
Icon icon = new ImageIcon(iconName);
return icon;
}
...
public char getMnemonic(String key)
{
ResourceBundle bundle = getBundle();
String mnenonicString = bundle.getString(
key + ".mnemonic");
Assert.assert(mnenonicString.length() == 1,
"Resource for key "+key +
".mnemonic is valid char");
return (mnenonicString.toCharArray())[0];
}
protected ResourceBundle getBundle()
{
return ResourceBundle.getBundle(
baseName, Locale.getDefault());
}
}