Add two features our multi-locale yohoho is going to need:

- Ability to set a locale prefix in which to search for locale-specific images.
- Ability to clear the image cache (we want to do this when we switch locales, otherwise we end up with wrong-language images cached.)


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@83 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mike Thomas
2006-12-01 18:49:09 +00:00
parent 4c61406ea8
commit 5fda18ef31
2 changed files with 54 additions and 0 deletions
@@ -136,6 +136,16 @@ public class ImageManager
this(rmgr, new AWTImageCreator(context));
}
/**
* Clears all images out of the cache.
*/
public void clearCache ()
{
Log.info("Clearing image manager cache.");
_ccache.clear();
}
/**
* Creates a buffered image, optimized for display on our graphics
* device.
@@ -193,6 +193,14 @@ public class ResourceManager
}
}
/**
* Set where we should look for locale-specific resources.
*/
public void setLocalePrefix (String prefix)
{
_localePrefix = prefix;
}
/**
* Initializes the bundle sets to be made available by this resource
* manager. Applications that wish to make use of resource bundles
@@ -419,6 +427,23 @@ public class ResourceManager
}
// if we still didn't find anything, try the classloader
// First try a locale-specific file
if (_localePrefix != null) {
final String rpath = PathUtil.appendPath(_rootPath,
PathUtil.appendPath(_localePrefix, path));
in = (InputStream)AccessController.doPrivileged(
new PrivilegedAction() {
public Object run () {
return _loader.getResourceAsStream(rpath);
}
});
if (in != null) {
return in;
}
}
// But if we didn't find that, try locale-neutral.
final String rpath = PathUtil.appendPath(_rootPath, path);
in = (InputStream)AccessController.doPrivileged(new PrivilegedAction() {
public Object run () {
@@ -462,6 +487,22 @@ public class ResourceManager
return new FileImageInputStream(file);
}
// First try a locale-specific file
if (_localePrefix != null) {
final String rpath = PathUtil.appendPath(_rootPath,
PathUtil.appendPath(_localePrefix, path));
InputStream in = (InputStream)AccessController.doPrivileged(
new PrivilegedAction() {
public Object run () {
return _loader.getResourceAsStream(rpath);
}
});
if (in != null) {
return new MemoryCacheImageInputStream(
new BufferedInputStream(in));
}
}
// if we still didn't find anything, try the classloader
final String rpath = PathUtil.appendPath(_rootPath, path);
InputStream in = (InputStream)
@@ -686,6 +727,9 @@ public class ResourceManager
/** A table of our resource sets. */
protected HashMap _sets = new HashMap();
/** Locale to search for locale-specific resources, if any. */
protected String _localePrefix = null;
/** The prefix of configuration entries that describe a resource
* set. */
protected static final String RESOURCE_SET_PREFIX = "resource.set.";