6. SwingResource interface.

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());
   }
}