Package diva.resource

Class RelativeBundle

  • Direct Known Subclasses:
    DefaultBundle

    public class RelativeBundle
    extends java.util.ResourceBundle
    A class for managing resources. This class is an extension to the standard ResourceBundle that allows you to construct ResourceBundles that
    • are relative to a specified class -- this means that you can let the class-loaders find the resource for you.
    • "override" other resource bundles. Thus, an abstract application could have a set of default resources, and a particular application could add its own resources to override the defaults where appropriate.
    Version:
    $Id$
    Author:
    John Reekie
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.ResourceBundle

        java.util.ResourceBundle.Control
    • Field Summary

      • Fields inherited from class java.util.ResourceBundle

        parent
    • Constructor Summary

      Constructors 
      Constructor Description
      RelativeBundle​(java.lang.String baseName, java.lang.Class loader, java.util.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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.Image getImage​(java.lang.String key)
      Get a resource as an image.
      javax.swing.ImageIcon getImageIcon​(java.lang.String key)
      Get a resource as an image icon.
      java.util.Enumeration getKeys()
      Get an enumeration over the keys
      java.net.URL getResource​(java.lang.String key)
      Get a resource as an absolute URL.
      java.io.InputStream getResourceAsStream​(java.lang.String key)
      Get a resource as an input stream.
      protected java.lang.Object handleGetObject​(java.lang.String key)
      Get an object from a ResourceBundle.
      • Methods inherited from class java.util.ResourceBundle

        clearCache, clearCache, containsKey, getBaseBundleName, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getLocale, getObject, getString, getStringArray, handleKeySet, keySet, setParent
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RelativeBundle

        public RelativeBundle​(java.lang.String baseName,
                              java.lang.Class loader,
                              java.util.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 java.net.URL getResource​(java.lang.String key)
        Get a resource as an absolute URL.
      • getResourceAsStream

        public java.io.InputStream getResourceAsStream​(java.lang.String key)
        Get a resource as an input stream.
      • getImageIcon

        public javax.swing.ImageIcon getImageIcon​(java.lang.String key)
        Get a resource as an image icon. Return null if not found. (Or should this throw an exception?)
      • getImage

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

        protected java.lang.Object handleGetObject​(java.lang.String key)
                                            throws java.util.MissingResourceException
        Get an object from a ResourceBundle.
        Specified by:
        handleGetObject in class java.util.ResourceBundle
        Throws:
        java.util.MissingResourceException
      • getKeys

        public java.util.Enumeration getKeys()
        Get an enumeration over the keys
        Specified by:
        getKeys in class java.util.ResourceBundle