uic.model
Class IconFactory.ClasspathRepository

java.lang.Object
  extended by uic.model.IconFactory.ClasspathRepository
All Implemented Interfaces:
IconFactory.Repository
Enclosing class:
IconFactory

public static class IconFactory.ClasspathRepository
extends Object
implements IconFactory.Repository

A repository that will load images from the classpath.


Constructor Summary
IconFactory.ClasspathRepository()
          This constructor will search for basic images.
IconFactory.ClasspathRepository(String[] extentions)
          This constructor create a repository that will search for images with the given extentions.
IconFactory.ClasspathRepository(String[] prefixes, String[] extentions)
          This constructor create a repository that will search for images with the given attributes.
 
Method Summary
 void addClassLoader(Class classForClassLoader)
           
 void addClassLoader(ClassLoader classLoader)
           
 void addPostfix(String post)
          Add a postfix.
 void addPostfix(String post, int sizeHint)
          Add a postfix.
 void addPrefix(String prefix)
          Add a prefix.
 void addPrefix(String prefix, int sizeHint)
          Add a prefix.
 InputStream getImage(String name, int size)
          Returns the input stream of the requested image, or null when none found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IconFactory.ClasspathRepository

public IconFactory.ClasspathRepository()
This constructor will search for basic images. Using this constructor you create a repository that will search the classpath for images with the given name and optionally will append a '.gif' or a '.png' to the name.


IconFactory.ClasspathRepository

public IconFactory.ClasspathRepository(String[] extentions)
This constructor create a repository that will search for images with the given extentions. Each name will be searched in the classath and all argument extentions will be tried to find a match.


IconFactory.ClasspathRepository

public IconFactory.ClasspathRepository(String[] prefixes,
                                       String[] extentions)
This constructor create a repository that will search for images with the given attributes. Each name will be searched in the classath and all argument extentions as well as the prefixes will be tried to find a match. All possible combinations between the two lists will be tried.
Note that it is perfectly legal to pass empty lists.

Method Detail

addPrefix

public void addPrefix(String prefix)
Add a prefix. Supply a path that goes before the image name on the path. This allows you to ask for an image in a subdir by only the image name, and you can supply any number of image directories here: '/images/' is a good example.

Parameters:
prefix - the path leading up to the image name you plan to supply; note that you will need to add a '/' at the end if the prefix is a directory. Only use slash ('/') as a directory-delimiter, this is portable to all OSes.

addPrefix

public void addPrefix(String prefix,
                      int sizeHint)
Add a prefix. Supply a path that goes before the image name on the path. This allows you to ask for an image in a subdir by only the image name, and you can supply any number of image directories here: '/images/' is a good example.

Parameters:
prefix - the path leading up to the image name you plan to supply; note that you will need to add a '/' at the end if the prefix is a directory. Only use slash ('/') as a directory-delimiter, this is portable to all OSes.
sizeHint - when using this prefix the size of the image will likely be the sizeHint.

addPostfix

public void addPostfix(String post)
Add a postfix. Supply the extention that follows your image name on the path. '.png' is a good example.

Parameters:
post - the part that follows the filename

addPostfix

public void addPostfix(String post,
                       int sizeHint)
Add a postfix. Supply the extention that follows your image name on the path. '.png' is a good example.

Parameters:
post - the part that follows the filename
sizeHint - when using this prefix the size of the image will likely be the sizeHint.

addClassLoader

public void addClassLoader(Class classForClassLoader)

addClassLoader

public void addClassLoader(ClassLoader classLoader)

getImage

public InputStream getImage(String name,
                            int size)
                     throws IOException
Description copied from interface: IconFactory.Repository
Returns the input stream of the requested image, or null when none found. All registered repositories will be asked to provide an image untill one returns a parsable image.

Specified by:
getImage in interface IconFactory.Repository
Parameters:
name - the name of the image, this is the name as specified in the getIcon method which again is the same name as registered in an action.
size - the requested size. If the wanted size is not found the returned size will be used to scale to the wanted size.
Returns:
an InputStream for the image, or null if nothing found.
Throws:
IOException


Copyright © 2002-2004 Thomas Zander Available under the Free Apache licence