net.sourceforge.java.feednread.backend.configuration
Class ImageManager

java.lang.Object
  extended bynet.sourceforge.java.feednread.backend.configuration.ImageManager

public class ImageManager
extends Object

Central application Image management class. Disposes of a memory cache for application Images which caches an Image in memory the first time it is requested. In addition an icon cache for Favorite icon Images is used which caches icons from a Favorite's host in a local persistent cache.

Don't forget to call the dispose() method on application exit to clear off the memory cache.

Author:
Sebastian Machhausen

Field Summary
private static int DEFAULT_ICON_HEIGHT
           The default icon Image height
private static int DEFAULT_ICON_WIDTH
           The default icon Image width
private static ImageRegistry DEFAULT_REGISTRY
           The default ImageRegistry to cache all requested Images.
 
Constructor Summary
ImageManager()
           
 
Method Summary
private static void cacheIcon(String hostUrl)
           Puts the icon deposited at the specified hostUrl in the local icon cache.
private static ImageDescriptor createImageDescriptor(String key)
           Gets the ImageDescriptor matching the specified key.
static void dispose()
           Disposes all Image resources created by this ImageManager.
static Image getIcon(String favoriteUrl)
           Gets the icon Image denoted by the specified favoriteUrl from the cache using both cache levels, i.e.
static Image getIcon(String favoriteUrl, boolean useSecondLevelCache)
           Gets the icon Image denoted by the specified favoriteUrl from the cache.
static Image getImage(String key)
           Gets the Image denoted by the specified key from the internal ImageRegistry.
private static Image getImage(String key, boolean returnMissingOnError, boolean scaleImage)
           Gets the Image denoted by the specified key from the internal ImageRegistry.
static ImageDescriptor getImageDescriptor(String key)
           Gets the ImageDescriptor denoted by the specified key from the internal ImageRegistry.
static Image getNewsFeedTypeImage(String type)
           Gets the newsfeed type Image based on the specified syndication type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_REGISTRY

private static final ImageRegistry DEFAULT_REGISTRY

The default ImageRegistry to cache all requested Images.


DEFAULT_ICON_WIDTH

private static final int DEFAULT_ICON_WIDTH

The default icon Image width

See Also:
Constant Field Values

DEFAULT_ICON_HEIGHT

private static final int DEFAULT_ICON_HEIGHT

The default icon Image height

See Also:
Constant Field Values
Constructor Detail

ImageManager

public ImageManager()
Method Detail

dispose

public static void dispose()

Disposes all Image resources created by this ImageManager.


getImage

public static Image getImage(String key)

Gets the Image denoted by the specified key from the internal ImageRegistry. An Image is initialized and cached the first time it is requested.

Parameters:
key - the key to query the Image for
Returns:
the Image denoted by the specified key

getImage

private static Image getImage(String key,
                              boolean returnMissingOnError,
                              boolean scaleImage)

Gets the Image denoted by the specified key from the internal ImageRegistry. An Image is initialized and cached the first time it is requested.

Parameters:
key - the key to query the Image for
returnMissingOnError - if true returns a default image; otherwise returns null
scaleImage - true to scale the Image to the default size; false to get it in original size
Returns:
the Image denoted by the specified key

getImageDescriptor

public static ImageDescriptor getImageDescriptor(String key)

Gets the ImageDescriptor denoted by the specified key from the internal ImageRegistry. An ImageDescriptor is initialized and cached the first time it is requested.

Parameters:
key - the key to query the ImageDescriptor for
Returns:
the ImageDescriptor denoted by the specified key

getNewsFeedTypeImage

public static Image getNewsFeedTypeImage(String type)

Gets the newsfeed type Image based on the specified syndication type.

Parameters:
type - String the syndication type

getIcon

public static Image getIcon(String favoriteUrl)

Gets the icon Image denoted by the specified favoriteUrl from the cache using both cache levels, i.e. first level and second cache.

Parameters:
favoriteUrl - the url of the Favorite to get the icon Image for
Returns:
the icon Image

getIcon

public static Image getIcon(String favoriteUrl,
                            boolean useSecondLevelCache)

Gets the icon Image denoted by the specified favoriteUrl from the cache.

Parameters:
favoriteUrl - the url of the Favorite to get the icon Image for
useSecondLevelCache - true to also use second level cache (web) if the icon Image is not found in the first level cache (local).
Returns:
the icon Image

cacheIcon

private static void cacheIcon(String hostUrl)

Puts the icon deposited at the specified hostUrl in the local icon cache.

Parameters:
hostUrl - the url of the host to get the icon Image from

createImageDescriptor

private static ImageDescriptor createImageDescriptor(String key)

Gets the ImageDescriptor matching the specified key.

Parameters:
key - the key that identifies the image to get the descriptor for
Returns:
the ImageDescriptor matching the specified key