uic.model
Class IconFactory

java.lang.Object
  extended by uic.model.IconFactory

public class IconFactory
extends Object

Icon factory creates Icon objects from image files found in one of the registered repositories. This class keeps a jvm-wide list of icon repositories. Repositories have to be registered in order to find the images, see the different add methods add a jar like jlfgr , addRepository on path, add custom repositories.

Example usage:

      IconFactory icons = new IconFactory();
      icons.addRepository("/usr/share/icons/default.kde"); // for debian systems
      icons.addRepository("/opt/kde3/share/icons/default.kde"); // for suse systems
      myExitButton.setIcon(icons.getIcon("actions/exit"));

Since:
1.2
See Also:
ActionFactory

Nested Class Summary
static class IconFactory.ClasspathRepository
          A repository that will load images from the classpath.
protected static class IconFactory.IconRepository
          An IconRepository class that uses known formats from http://kdelook.org icon packages.
static interface IconFactory.Repository
          This interface is used to query any repository for icons it might have to be used by the IconFactory.
static class IconFactory.SizeComperator
          This comperator is usable to sort image sizes in an existing collection for best quality.
protected static class IconFactory.ZipFileRepository
          A repository to allow things like the jlfg jar to be used.
 
Constructor Summary
IconFactory()
          Sole constructor, new instanciations made will reuse already registered repositories.
 
Method Summary
 boolean addJar(String path)
          Use the jar repository that follows the file layout as used in the java-look-and-feel-graphics jar.
 void addRepository(IconFactory.Repository repository)
          Add a repository that should be queried for images.
 boolean addRepository(String path)
          Add a repository layed out like the KDE Iconsets.
 ImageIcon getIcon(String name, int size)
          Create an icon with the name being the repository path like 'actions/exit'.
 ImageIcon getIcon(String name, int size, boolean canScale)
          Create an icon with the name being the repository path like 'actions/exit'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IconFactory

public IconFactory()
Sole constructor, new instanciations made will reuse already registered repositories.

Method Detail

addJar

public boolean addJar(String path)
Use the jar repository that follows the file layout as used in the java-look-and-feel-graphics jar.

Parameters:
path - path to the jar, if the path does not point to a correct jar the add will be silently ignored, and false will be returned.
Returns:
true if successfully added.

addRepository

public boolean addRepository(String path)
Add a repository layed out like the KDE Iconsets.

Parameters:
path - path to the respository directory, if the path is not correct the add will be silently ignored, and false will be returned.
Returns:
true if successfully added.

addRepository

public void addRepository(IconFactory.Repository repository)
Add a repository that should be queried for images.


getIcon

public ImageIcon getIcon(String name,
                         int size)
Create an icon with the name being the repository path like 'actions/exit'.

Parameters:
name - the name of the icon without filetype and including the path from the root of the repository.
size - the size the widget should be in. If icon found does not matched it will be scaled to fit.
Returns:
a new ImageIcon of the width and height as specified with size, or null when no image was found.

getIcon

public ImageIcon getIcon(String name,
                         int size,
                         boolean canScale)
Create an icon with the name being the repository path like 'actions/exit'.

Parameters:
name - the name of the icon without filetype and including the path from the root of the repository.
size - the size the widget should be in.
canScale - when true and the icon found does not match argument size it will be scaled to fit.
Returns:
a new ImageIcon of the width and height as specified with size, or null when no image was found.


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