|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.salespointframework.core.ResourceManager
public class ResourceManager
The global manager for all resources. The ResourceManager is responsible for managing all binary resources
of the framework. This can be images, videos, text ...
Resources are managed as follows:
The root directory is a directory ending with the name "resource". Here it is just the directory
"resource". Starting from this directory all resources are given back relative to this path.
There can be multiple resouces to manage: gif-images, jpeg-images, text and others.
For all of these resources there should exist one resource module.
There is already one module for gif-resources
.
Resources are requested as follows:
URL url = ResourceManager.getInstance().getResource (String type, String path);
The "type" is the name of the resource module. The path string is the path relative to the directory
of the requested type and is separated with a dot.
Example:
An icon of the size 16x16 should be requested. It is located in the directory "resource/gif/icon".
The icon's name is "document.gif".
So the call is:
URL url = ResourceManager.getInstance().getResource (RESOURCE_GIF, "icon.document");
Nested Class Summary | |
---|---|
static interface |
ResourceManager.ResourceModule
Interface for a resource module. |
private static class |
ResourceManager.ResourceModuleGIF
Predefined module for .gif-resources. |
private static class |
ResourceManager.ResourceModulePNG
Predefined module for .png-resources. |
static class |
ResourceManager.StandardResource
Standard resources |
Field Summary | |
---|---|
private java.util.Map<java.lang.String,java.awt.image.BufferedImage> |
imageCache
Image Cache |
private static ResourceManager |
instance
The singleton instance of the resource manager. |
private java.util.HashMap<java.lang.String,ResourceManager.ResourceModule> |
moduls
Map of all resource modules. |
static java.lang.String |
RESOURCE_GIF
Type name for resource module: GIF |
static java.lang.String |
RESOURCE_PNG
|
protected java.lang.String |
resourceRootPath
The root path of all resources. |
protected java.util.Map<ResourceManager.StandardResource,java.awt.image.BufferedImage> |
standardResources
Map of all standard resources |
Constructor Summary | |
---|---|
protected |
ResourceManager()
Creates a new instance of ResourceManager. |
Method Summary | |
---|---|
void |
addResourceModule(ResourceManager.ResourceModule rm)
Adds a resource module to the ResourceManager. |
static java.awt.image.BufferedImage |
createImageFromByteArray(byte[] data)
creates an optimized image from a byte array |
java.awt.image.BufferedImage |
getCachedImageRessource(java.lang.String type,
java.lang.String path)
Returns a resource as BufferedImage. |
java.awt.image.BufferedImage |
getCachedImageRessource(java.net.URL url)
get a cached and optimized image from given url |
java.lang.String |
getFullPath(java.lang.String type,
java.lang.String path)
Returns the full path of a resource.. |
static ResourceManager |
getInstance()
Returns the singleton instance of the ResourceManager. |
java.net.URL |
getResource(java.lang.String type,
java.lang.String path)
Returns a resource as URL. |
java.awt.image.BufferedImage |
getStandardResource(ResourceManager.StandardResource stdres)
get a specific standard resource |
static byte[] |
loadImageAsByteArray(java.net.URI uri)
loads the specified image and returns an byte array |
static byte[] |
loadImageAsByteArray(java.net.URI uri,
int maxdim)
loads the specified image. resizes it and returns an byte array |
static java.awt.image.BufferedImage |
optimizeImage(java.awt.Image img,
boolean forceOpaque)
Optimize Image for Screen |
void |
removeResourceModule(ResourceManager.ResourceModule rm)
Removes a resource module from the ResourceManager. |
void |
setStandardResource(ResourceManager.StandardResource stdres,
java.awt.image.BufferedImage bi)
Set a standard resource |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.Map<ResourceManager.StandardResource,java.awt.image.BufferedImage> standardResources
private java.util.HashMap<java.lang.String,ResourceManager.ResourceModule> moduls
protected java.lang.String resourceRootPath
private static ResourceManager instance
private java.util.Map<java.lang.String,java.awt.image.BufferedImage> imageCache
public static final java.lang.String RESOURCE_GIF
public static final java.lang.String RESOURCE_PNG
Constructor Detail |
---|
protected ResourceManager()
Method Detail |
---|
public static ResourceManager getInstance()
public void addResourceModule(ResourceManager.ResourceModule rm)
rm
- the resource module to be added.public void removeResourceModule(ResourceManager.ResourceModule rm)
rm
- the resource module to be removed.public java.net.URL getResource(java.lang.String type, java.lang.String path)
getResource ("RESOURCE_GIF", "icon.16x16.document)
(without file extension).
type
- the logical type namepath
- the relative path + file name without extension
public void setStandardResource(ResourceManager.StandardResource stdres, java.awt.image.BufferedImage bi)
stdres
- Resource to setbi
- image resourcepublic java.awt.image.BufferedImage getStandardResource(ResourceManager.StandardResource stdres)
stdres
- resource to get
public static java.awt.image.BufferedImage createImageFromByteArray(byte[] data)
data
-
public static byte[] loadImageAsByteArray(java.net.URI uri)
uri
- loaction of imagepublic static byte[] loadImageAsByteArray(java.net.URI uri, int maxdim)
uri
- location of imageif
- width or height exceeds this value, the image will be scaled down by aspect ratiopublic static java.awt.image.BufferedImage optimizeImage(java.awt.Image img, boolean forceOpaque)
img
-
public java.awt.image.BufferedImage getCachedImageRessource(java.lang.String type, java.lang.String path)
getResource(String, String)
type
- path
-
public java.awt.image.BufferedImage getCachedImageRessource(java.net.URL url)
url
-
public java.lang.String getFullPath(java.lang.String type, java.lang.String path)
type
- the logical type namepath
- der relative path + file name without extension
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |