com.jeta.open.resources
Class AppResourceLoader

java.lang.Object
  extended by com.jeta.open.resources.AppResourceLoader
All Implemented Interfaces:
ResourceLoader

public class AppResourceLoader
extends Object
implements ResourceLoader

This class is an implementation of a ResourceLoader. It insulates the application code from having any need to know about the local file system directory structure. It is also useful for debugging and development so we can redirect resource request to debug files if needed.


Field Summary
 
Fields inherited from interface com.jeta.open.resources.ResourceLoader
COMPONENT_ID
 
Constructor Summary
AppResourceLoader()
           
 
Method Summary
 ClassLoader getClassLoader()
          Used to provide a custom class loader for certain cases.
static ImageIcon getEmptyIcon()
          Returns an icon with a red X to show an icon that could not be loaded.
static ImageIcon getImage(String imageName)
          Loads an image from disk.
 InputStream getResourceAsStream(String resourceName)
          Opens and returns an input stream for the given resourceName.
 ImageIcon loadImage(String imageName)
          Helper utility to load an image file from the application images directory
 void setClassLoader(ClassLoader loader)
          Used to provide a custom class loader for certain cases.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AppResourceLoader

public AppResourceLoader()
Method Detail

getClassLoader

public ClassLoader getClassLoader()
Description copied from interface: ResourceLoader
Used to provide a custom class loader for certain cases. This is especially useful during development when we want the resource bundles to be loaded from the source directories or if you want to provide a custom class loader.

Specified by:
getClassLoader in interface ResourceLoader
Returns:
a custom class loader for the application

getEmptyIcon

public static ImageIcon getEmptyIcon()
Returns an icon with a red X to show an icon that could not be loaded.


getResourceAsStream

public InputStream getResourceAsStream(String resourceName)
                                throws IOException
Opens and returns an input stream for the given resourceName. The resourceName is relative to the application CLASSPATH (i.e. JAR file).

Specified by:
getResourceAsStream in interface ResourceLoader
Parameters:
resourceName - the relative name of the resource to open
Returns:
an input stream for the given resourceName.
Throws:
IOException

getImage

public static ImageIcon getImage(String imageName)
Loads an image from disk. The image is loaded relative to the application directory.

To do:
we need to cache these images

loadImage

public ImageIcon loadImage(String imageName)
Helper utility to load an image file from the application images directory

Specified by:
loadImage in interface ResourceLoader
Parameters:
imageName - the name (and optional sub directory ) of the file to load

setClassLoader

public void setClassLoader(ClassLoader loader)
Description copied from interface: ResourceLoader
Used to provide a custom class loader for certain cases. This is especially useful during development when we want the resource bundles to be loaded from the source directories

Specified by:
setClassLoader in interface ResourceLoader


Copyright © 2005-2007 Jeff Tassin & Todd Viegut. All Rights Reserved.