diva.resource
Class RelativeBundle

java.lang.Object
  extended by java.util.ResourceBundle
      extended by diva.resource.RelativeBundle
Direct Known Subclasses:
DefaultBundle

public class RelativeBundle
extends ResourceBundle

A class for managing resources. This class is an extension to the standard ResourceBundle that allows you to construct ResourceBundles that

Version:
$Revision: 1.6 $
Author:
John Reekie (johnr@eecs.berkeley.edu)

Field Summary
 
Fields inherited from class java.util.ResourceBundle
parent
 
Constructor Summary
RelativeBundle(String baseName, Class loader, ResourceBundle overrides)
          Create a new RelativeBundle using the given basename, with the given class as the loader for URL-based resources, and with the given ResourceBundle as the one that gets overridden.
 
Method Summary
 Image getImage(String key)
          Get a resource as an image.
 ImageIcon getImageIcon(String key)
          Get a resource as an image icon.
 Enumeration getKeys()
          Get an enumeration over the keys
 URL getResource(String key)
          Get a resource as an absolute URL.
 InputStream getResourceAsStream(String key)
          Get a resource as an input stream.
protected  Object handleGetObject(String key)
          Get an object from a ResourceBundle.
 
Methods inherited from class java.util.ResourceBundle
getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RelativeBundle

public RelativeBundle(String baseName,
                      Class loader,
                      ResourceBundle overrides)
Create a new RelativeBundle using the given basename, with the given class as the loader for URL-based resources, and with the given ResourceBundle as the one that gets overridden. The loader must be such that the resource paths in the properties file ("baseName.properties") are relative to the package containing that class. For example, you could create a default Bundle and override it as follows:
   RelativeBundle default = new diva.resource.Default();
   RelativeBundle resource = new RelativeBundle(
       "mypackage.resource.MyResources", getClass(), default);
 

 In this example, the file mypackage/resource/MyResource.properties
 would contain resource such as
 
    LoadImage = resources/load.gif
    SaveImage = resources/save.gif
 

If you don't mind cluttering up your source directory with resource files, then it's probably better to put the resource file in the same directory as the application classes, so the properties files doesn't need the "resources/" strings.

Method Detail

getResource

public URL getResource(String key)
Get a resource as an absolute URL.


getResourceAsStream

public InputStream getResourceAsStream(String key)
Get a resource as an input stream.


getImageIcon

public ImageIcon getImageIcon(String key)
Get a resource as an image icon. Return null if not found. (Or should this throw an exception?)


getImage

public Image getImage(String key)
Get a resource as an image. Return null if not found. (Or should this throw an exception?)


handleGetObject

protected Object handleGetObject(String key)
                          throws MissingResourceException
Get an object from a ResourceBundle.

Specified by:
handleGetObject in class ResourceBundle
Throws:
MissingResourceException

getKeys

public Enumeration getKeys()
Get an enumeration over the keys

Specified by:
getKeys in class ResourceBundle


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.