com.threerings.media
Class IconManager

java.lang.Object
  extended by com.threerings.media.IconManager

public class IconManager
extends Object

Manages the creation of icons from tileset images. The icon manager is provided with a configuration file, which maps icon set identifiers to uniform tilesets and provides the metric information for said tilesets. UI code can subsequently request icons from the icon manager based on icon set identifier and index.

The configuration might look like the following:

 arrows.path = /rsrc/media/icons/arrows.png
 arrows.metrics = 20, 25  # icons that are 20 pixels wide and 25 pixels tall

 smileys.path = /rsrc/media/icons/smileys.png
 smileys.metrics = 16, 16  # icons that are 16 pixels square
 
A user could then request an arrows icon like so:
 Icon icon = iconmgr.getIcon("arrows", 2);
 


Field Summary
protected  Properties _config
          Our configuration information.
protected  Map<String,TileSet> _icons
          A cache of our icon tilesets.
protected  String _rsrcSet
          The resource bundle from which we load icon images, or null if they should be loaded from the classpath.
protected  TileManager _tilemgr
          The tile manager we use to load tilesets.
protected static int ICON_CACHE_SIZE
          The maximum number of icon tilesets that may be cached at once.
protected static String METRICS_SUFFIX
          The suffix we append to an icon set name to obtain the tileset metrics configuration parameter.
protected static String PATH_SUFFIX
          The suffix we append to an icon set name to obtain the tileset image path configuration parameter.
 
Constructor Summary
IconManager(TileManager tmgr, Properties config)
          Creates an icon manager that will obtain tilesets from the supplied tile manager and which will read its configuration information from the supplied properties file.
IconManager(TileManager tmgr, String configPath)
          Creates an icon manager that will obtain tilesets from the supplied tile manager and which will load its configuration information from the specified properties file.
 
Method Summary
 Icon getIcon(String iconSet, int index)
          Fetches the icon with the specified index from the named icon set.
 void setSource(String resourceSet)
          If icon images should be loaded from a set of resource bundles rather than the classpath, that set can be set here.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_tilemgr

protected TileManager _tilemgr
The tile manager we use to load tilesets.


_config

protected Properties _config
Our configuration information.


_rsrcSet

protected String _rsrcSet
The resource bundle from which we load icon images, or null if they should be loaded from the classpath.


_icons

protected Map<String,TileSet> _icons
A cache of our icon tilesets.


PATH_SUFFIX

protected static final String PATH_SUFFIX
The suffix we append to an icon set name to obtain the tileset image path configuration parameter.

See Also:
Constant Field Values

METRICS_SUFFIX

protected static final String METRICS_SUFFIX
The suffix we append to an icon set name to obtain the tileset metrics configuration parameter.

See Also:
Constant Field Values

ICON_CACHE_SIZE

protected static final int ICON_CACHE_SIZE
The maximum number of icon tilesets that may be cached at once.

See Also:
Constant Field Values
Constructor Detail

IconManager

public IconManager(TileManager tmgr,
                   String configPath)
            throws IOException
Creates an icon manager that will obtain tilesets from the supplied tile manager and which will load its configuration information from the specified properties file.

Parameters:
tmgr - the tile manager to use when fetching tilesets.
configPath - the path (relative to the classpath) from which the icon manager configuration can be loaded.
Throws:
IOException - thrown if an error occurs loading the configuration file.

IconManager

public IconManager(TileManager tmgr,
                   Properties config)
Creates an icon manager that will obtain tilesets from the supplied tile manager and which will read its configuration information from the supplied properties file.

Method Detail

setSource

public void setSource(String resourceSet)
If icon images should be loaded from a set of resource bundles rather than the classpath, that set can be set here.


getIcon

public Icon getIcon(String iconSet,
                    int index)
Fetches the icon with the specified index from the named icon set.