Use an LRUHashMap to cache icons.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2035 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2002-12-07 02:09:45 +00:00
parent acaf39b070
commit eda77a227d
@@ -1,10 +1,9 @@
// //
// $Id: IconManager.java,v 1.3 2002/10/17 17:43:21 mdb Exp $ // $Id: IconManager.java,v 1.4 2002/12/07 02:09:45 shaper Exp $
package com.threerings.media; package com.threerings.media;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Properties; import java.util.Properties;
import java.awt.Color; import java.awt.Color;
@@ -14,6 +13,7 @@ import java.awt.Graphics;
import javax.swing.Icon; import javax.swing.Icon;
import com.samskivert.util.ConfigUtil; import com.samskivert.util.ConfigUtil;
import com.samskivert.util.LRUHashMap;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import com.threerings.media.tile.NoSuchTileException; import com.threerings.media.tile.NoSuchTileException;
@@ -150,9 +150,8 @@ public class IconManager
* they should be loaded from the classpath. */ * they should be loaded from the classpath. */
protected String _rsrcSet; protected String _rsrcSet;
/** A cache of our icon tilesets. TODO: use a real LRU cache instead /** A cache of our icon tilesets. */
* of a hash map. */ protected LRUHashMap _icons = new LRUHashMap(ICON_CACHE_SIZE);
protected HashMap _icons = new HashMap();
/** The icon we return when we are unable to load a requested icon. */ /** The icon we return when we are unable to load a requested icon. */
protected Icon _errorIcon = new Icon() { protected Icon _errorIcon = new Icon() {
@@ -175,4 +174,7 @@ public class IconManager
/** The suffix we append to an icon set name to obtain the tileset /** The suffix we append to an icon set name to obtain the tileset
* metrics configuration parameter. */ * metrics configuration parameter. */
protected static final String METRICS_SUFFIX = ".metrics"; protected static final String METRICS_SUFFIX = ".metrics";
/** The maximum number of icons that may be cached at any one time. */
protected static final int ICON_CACHE_SIZE = 50;
} }