org.PingOO.DLAI.lib.util
Class IconManager

java.lang.Object
  |
  +--org.PingOO.DLAI.lib.util.Manager
        |
        +--org.PingOO.DLAI.lib.util.IconManager

public final class IconManager
extends Manager

Manages the icon for the DLAI.

Since:
PingOO 2.0
Version:
2.0
Author:
Fabrice Bouyé (bouye@cur-archamps.fr)

Field Summary
private static java.util.Hashtable BIG_ICON_TABLE
          Cache for big icons.
private static java.lang.String DEFAULT_MODULE
          Default module.
private static java.lang.String[] ICON_EXTENSION
          By default all icons are gif files.
private static java.util.Hashtable SMALL_ICON_TABLE
          Cache for small icons.
 
Fields inherited from class org.PingOO.DLAI.lib.util.Manager
classLoader
 
Constructor Summary
private IconManager()
          Hides the constructor from the outside.
 
Method Summary
static void clearCache()
          Clears the cache used in this manager.
static javax.swing.Icon compoundIcon(javax.swing.Icon bottomIcon, javax.swing.Icon topIcon)
          Creates a new Icon by composing the two icon passed within parameters.
private static javax.swing.ImageIcon findIcon(java.lang.String baseDirectory, java.lang.String module, java.lang.String fileName, java.lang.String extension)
          Returns an icon from a file.
static javax.swing.Icon getBigIcon(java.lang.String identifier)
          Return a icon with the defautl size of a big icon.
static javax.swing.Icon getBigIcon(java.lang.String module, java.lang.String identifier)
          Return a icon with the defautl size of a big icon.
private static java.util.Hashtable getCache(java.lang.String module, java.util.Hashtable parentTable)
          Return the correct cache.
static javax.swing.ImageIcon getDefaultIcon()
          Constructs a (small) default icon.
static javax.swing.ImageIcon getDefaultIcon(java.awt.Dimension dimension)
          Constructs a default icon.
static javax.swing.ImageIcon getEmptyIcon()
          Constructs a (small) default icon.
static javax.swing.ImageIcon getEmptyIcon(java.awt.Dimension dimension)
          Constructs a default icon.
static javax.swing.Icon getIcon(java.lang.String identifier)
          Returns an icon from the default set.
static javax.swing.Icon getIcon(java.lang.String module, java.lang.String identifier)
          Returns an icon from a different set.
static java.awt.Image getImage(javax.swing.Icon icon)
          Returns the image of the icon.
static javax.swing.Icon getSmallIcon(java.lang.String identifier)
          Return a icon with the defautl size of a small icon.
static javax.swing.Icon getSmallIcon(java.lang.String module, java.lang.String identifier)
          Return a icon with the defautl size of a small icon.
private static void initialize()
          Initializes caches.
protected static javax.swing.ImageIcon loadIcon(java.lang.String baseDirectory, java.lang.String module, java.lang.String fileName)
          Tries to find an icon scanning various file extension.
static javax.swing.Icon resizeIcon(javax.swing.Icon icon, java.awt.Dimension dimension)
          Returns an icon that have been resized to the correct dimension.
static javax.swing.Icon toBig(javax.swing.Icon icon)
          Returns an icon with the default big icon size.
static javax.swing.Icon toSmall(javax.swing.Icon icon)
          Returns an icon with the default small icon size.
 
Methods inherited from class org.PingOO.DLAI.lib.util.Manager
findFile, findFile, findFile, findFile
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

ICON_EXTENSION

private static final java.lang.String[] ICON_EXTENSION
By default all icons are gif files.

BIG_ICON_TABLE

private static java.util.Hashtable BIG_ICON_TABLE
Cache for big icons.

SMALL_ICON_TABLE

private static java.util.Hashtable SMALL_ICON_TABLE
Cache for small icons.

DEFAULT_MODULE

private static final java.lang.String DEFAULT_MODULE
Default module.
Constructor Detail

IconManager

private IconManager()
Hides the constructor from the outside.
Method Detail

initialize

private static final void initialize()
Initializes caches.

getCache

private static final java.util.Hashtable getCache(java.lang.String module,
                                                  java.util.Hashtable parentTable)
Return the correct cache.
Parameters:
module - The module to use.
parentTable - The parent cache of the desired cache.
Returns:
The correct cache.

clearCache

public static void clearCache()
Clears the cache used in this manager.

getSmallIcon

public static final javax.swing.Icon getSmallIcon(java.lang.String identifier)
Return a icon with the defautl size of a small icon.
The icon might be resized if needed.
In case the icon is not found the program will then try to retrieve it by removing the default extension, the search will also occur in the big icon directory.
Parameters:
identifier - The identifier need to get the icon from its file. You do not need to provide the .gif extension.
Returns:
The expected icon, or the default icon if the file was not found.

getSmallIcon

public static final javax.swing.Icon getSmallIcon(java.lang.String module,
                                                  java.lang.String identifier)
Return a icon with the defautl size of a small icon.
The icon might be resized if needed.
In case the icon is not found the program will then try to retrieve it by removing the default extension, the search will also occur in the big icon directory.
If the icon is still not found then the search will continue in the default set, using the same way as with the specific module.
Parameters:
module - The appli's name.
identifier - The identifier need to get the icon from its file. You do not need to provide the .gif extension.
Returns:
The expected icon, or the default if the file was not found.

getBigIcon

public static final javax.swing.Icon getBigIcon(java.lang.String identifier)
Return a icon with the defautl size of a big icon.
The icon might be resized if needed.
In case the icon is not found the program will then try to retrieve it by removing the default extension, the search will also occur in the mini icon directory.
Parameters:
identifier - The identifier need to get the icon from its file. You do not need to provide the .gif extension.
Returns:
The expected icon, or the default icon if the file was not found.

getBigIcon

public static final javax.swing.Icon getBigIcon(java.lang.String module,
                                                java.lang.String identifier)
Return a icon with the defautl size of a big icon.
The icon might be resized if needed.
In case the icon is not found the program will then try to retrieve it by removing the default extensio, the search will also occur in the mini icon directoryn.
If the icon is still not found then the search will continue in the default set, using the same way as with the specific module.
Parameters:
module - The appli's name.
identifier - The identifier need to get the icon from its file. You do not need to provide the .gif extension.
Returns:
The expected icon, or the default icon if the file was not found.

getIcon

public static final javax.swing.Icon getIcon(java.lang.String identifier)
Returns an icon from the default set.
In case the icon is not found the program will then try to retrieve it by removing the default extension.
By default the search occurs in the big icon directory, then if the icon is still not found it will take place in the mini icon directory.
Parameters:
identifier - The identifier need to get the icon from its file. You do not need to provide the .gif extension.
Returns:
The expected icon, or the defautl icon if the file was not found.

getIcon

public static final javax.swing.Icon getIcon(java.lang.String module,
                                             java.lang.String identifier)
Returns an icon from a different set.
In case the icon is not found the program will then try to retrieve it by removing the default extension.
If the icon is still not found then the search will continue in the default set, using the same way as with the specific module.
By default the search occurs in the big icon directory, then if the icon is still not found it will take place in the mini icon directory.
Parameters:
module - The appli's name.
identifier - The identifier need to get the icon from its file. You do not need to provide the .gif extension.
Returns:
The expected icon, or the default icon if the file was not found.

loadIcon

protected static final javax.swing.ImageIcon loadIcon(java.lang.String baseDirectory,
                                                      java.lang.String module,
                                                      java.lang.String fileName)
Tries to find an icon scanning various file extension.
Could use ".jpeg" icon as well in future.
Parameters:
baseDirectory - It could be either the big icon directory or the mini icon directory.
module - The appli's name.
fileName - The name of the icon's file.
Returns:
The expected icon, or null if the file was not found.

findIcon

private static javax.swing.ImageIcon findIcon(java.lang.String baseDirectory,
                                              java.lang.String module,
                                              java.lang.String fileName,
                                              java.lang.String extension)
Returns an icon from a file.
Parameters:
baseDirectory - it could be either the big icon directory or the mini icon directory.
module - The appli's name.
fileName - The name of the icon's file.
extension - One of the existing extension for this file.
Returns:
The expected icon, or null if the file was not found.

resizeIcon

public static final javax.swing.Icon resizeIcon(javax.swing.Icon icon,
                                                java.awt.Dimension dimension)
Returns an icon that have been resized to the correct dimension.
Provides a convienient way to resize icons to their correct size.
Parameters:
icon - The original icon that needs to be resized.
dimension - the new dimension to apply.
Returns:
An icon with the correcte size, or the old icon if the dimension has a zero value,or null if the icon is null.

toBig

public static final javax.swing.Icon toBig(javax.swing.Icon icon)
Returns an icon with the default big icon size.
Parameters:
icon - the original icon.

toSmall

public static final javax.swing.Icon toSmall(javax.swing.Icon icon)
Returns an icon with the default small icon size.
Parameters:
icon - the original icon.

getImage

public static final java.awt.Image getImage(javax.swing.Icon icon)
Returns the image of the icon.
Returns:
The image of the icon, or null if the icon has no image.

getEmptyIcon

public static final javax.swing.ImageIcon getEmptyIcon()
Constructs a (small) default icon.
Returns:
The default icon.

getEmptyIcon

public static final javax.swing.ImageIcon getEmptyIcon(java.awt.Dimension dimension)
Constructs a default icon.
Parameters:
dimension - The dimension of this icon.
Returns:
The default icon.

getDefaultIcon

public static final javax.swing.ImageIcon getDefaultIcon()
Constructs a (small) default icon.
Returns:
The default icon.

getDefaultIcon

public static final javax.swing.ImageIcon getDefaultIcon(java.awt.Dimension dimension)
Constructs a default icon.
Parameters:
dimension - The dimension of this icon.
Returns:
The default icon.

compoundIcon

public static javax.swing.Icon compoundIcon(javax.swing.Icon bottomIcon,
                                            javax.swing.Icon topIcon)
Creates a new Icon by composing the two icon passed within parameters.
This function will be expanded in future wiht possible use of (not-yet defined) methods in ImageManager.
Parameters:
bottomIcon - The icon to be placed at the lower plane in the result icon.
topIcon - The icon to be placed at the higher plane in the result icon
Returns:
A new icon.