dsto.dfc.swt.icons
Class IconCache

java.lang.Object
  extended by dsto.dfc.swt.icons.IconCache

public class IconCache
extends Object

A system-wide cache of rendered SWT images for Icon instances. This class is not thread-safe: it is assumed that all accesses come from the SWT GUI thread. Icons used in the cache must implement equals () and hashCode ().

Author:
Matthew Phillips

Field Summary
protected  HashMap cache
           
 
Constructor Summary
IconCache()
           
 
Method Summary
 void clear()
          Clear and dispose of all icons in the cache.
 org.eclipse.swt.graphics.Image get(Icon icon)
          Retrieve the image for a cached icon.
static IconCache getDefault()
          Get the default instance.
 org.eclipse.swt.graphics.Image getOrPut(Icon icon)
          Like get (), but put ()'s the icon if not in the cache.
 org.eclipse.swt.graphics.Image put(Icon icon)
          Put icon into the cache.
 void remove(Icon icon)
          Reverse of put (): decrements an icon's reference count in the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected HashMap cache
Constructor Detail

IconCache

public IconCache()
Method Detail

getDefault

public static IconCache getDefault()
Get the default instance.


clear

public void clear()
Clear and dispose of all icons in the cache. Only call this if you know all SWT clients have been disposed (i.e. after the event loop has exited).


put

public org.eclipse.swt.graphics.Image put(Icon icon)
Put icon into the cache. If the icon is not already there, its image is rendered with Icon.createImage(org.eclipse.swt.graphics.Device) and placed in the cache. If the icon is already there, its reference count is incremented.

Parameters:
icon - The icon to cache.
Returns:
The image for icon.
See Also:
get(Icon), remove(Icon)

get

public org.eclipse.swt.graphics.Image get(Icon icon)
Retrieve the image for a cached icon.

Parameters:
icon - The icon to query.
Returns:
The icon image, or null if not in the cache.
See Also:
put(Icon), getOrPut(Icon)

getOrPut

public org.eclipse.swt.graphics.Image getOrPut(Icon icon)
Like get (), but put ()'s the icon if not in the cache.

See Also:
get(Icon), put(Icon)

remove

public void remove(Icon icon)
Reverse of put (): decrements an icon's reference count in the cache. If the count falls to zero, the image is disposed, EXCEPT for ImageResourceIcon's, which remain cached permanently to avoid the overhead associated with reloading them.



Copyright © 2008 Commonwealth of Australia