|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.colossus.util.StaticResourceLoader
public final class StaticResourceLoader
Class ResourceLoader is an utility class to load a resource from a filename and a list of directory.
Nested Class Summary | |
---|---|
private static class |
StaticResourceLoader.ColossusClassLoader
Class ColossusClassLoader allows for class loading outside the CLASSPATH, i.e. |
Field Summary | |
---|---|
private static java.lang.ClassLoader |
baseCL
|
private static StaticResourceLoader.ColossusClassLoader |
cl
|
static java.awt.Font |
DEFAULT_FONT
|
private static java.lang.String |
DEFAULT_FONT_NAME
|
private static int |
DEFAULT_FONT_SIZE
|
private static int |
DEFAULT_FONT_STYLE
|
private static java.util.Map<java.lang.String,byte[]> |
fileCache
|
static java.lang.String |
FILESERVER_IGNOREFAIL_SIGNAL
|
private static java.util.Map<java.lang.String,java.lang.Object> |
imageCache
|
private static java.lang.String[] |
imageExtension
|
static java.lang.String |
KEY_CONTENT_TYPE
|
private static java.util.logging.Logger |
LOGGER
|
private static java.lang.String |
pathSeparator
|
static java.lang.String |
REQUEST_TOKEN_SEPARATOR
|
private static java.lang.String |
server
|
private static int |
serverPort
|
Constructor Summary | |
---|---|
StaticResourceLoader()
|
Method Summary | |
---|---|
private static java.awt.Color |
colorFromFilename(java.lang.String filename,
java.lang.String prefix)
Extract a color from a filename, ignoring a prefix. |
private static java.lang.String |
colorNameFromFilename(java.lang.String filename,
java.lang.String prefix)
Extract a color name from a filename, ignoring a prefix |
private static java.awt.Image |
createColorizedImage(java.lang.String filename,
java.awt.Color color,
java.util.List<java.lang.String> directories,
int width,
int height)
Create a colorized version of the image contained in the given file. |
private static java.awt.Image |
createNameImage(int width,
int height,
java.lang.String name,
boolean down,
java.awt.Color color)
Create an Image with only the given String on it. |
private static java.awt.Image |
createNumberImage(int width,
int height,
int value,
boolean right,
java.awt.Color color)
Create an Image with only the given number on it. |
private static java.awt.Image |
createPlainImage(int width,
int height,
java.awt.Color color)
Create an Image that is only a plain rectangle. |
private static java.awt.Image |
createPlainImage(int width,
int height,
java.awt.Color color,
boolean border)
Create an Image that is only a plain rectangle, with an optional border. |
private static java.awt.Image |
createPlainImage(int width,
int height,
java.awt.Color color,
int t_x,
int t_y,
int t_w,
int t_h,
boolean border)
Create an Image that only contains a colored rectangle, with an optional border. |
private static java.lang.String |
fixFilename(java.lang.String filename)
Fix a filename by replacing space with underscore. |
static byte[] |
getBytesFromFile(java.lang.String filename,
java.util.List<java.lang.String> directories,
boolean cachedOnly,
boolean ignoreFail)
Return the content of the specified file as an array of byte. |
private static byte[] |
getBytesFromInputStream(java.io.InputStream is)
Return the content of the specified InputStream as an array of byte. |
static java.awt.Image |
getCompositeImage(java.lang.String[] filenames,
java.util.List<java.lang.String> directories,
int width,
int height)
Return the composite image made from blending the given filenames from the given directories. |
static javax.swing.text.Document |
getDocument(java.lang.String filename,
java.util.List<java.lang.String> directories)
Return the first Document from file of name filename in the list of directories. |
static java.util.List<org.jdom.Element> |
getFileCacheDump()
Dump the file cache as a List of XML "DataFile" Element, with the file key as attribute "DataFileKey", and the file data as a CDATA content. |
static java.awt.Image |
getImage(java.lang.String filename,
java.util.List<java.lang.String> directories,
int width,
int height)
Return the first Image of name filename in the list of directories. |
static javax.swing.ImageIcon |
getImageIcon(java.lang.String filename,
java.util.List<java.lang.String> directories,
int width,
int height)
Return the first ImageIcon of name filename in the list of directories. |
static java.io.InputStream |
getInputStream(java.lang.String filename,
java.util.List<java.lang.String> directories)
Return the first InputStream from file of name filename in the list of directories. |
private static java.io.InputStream |
getInputStream(java.lang.String filename,
java.util.List<java.lang.String> directories,
boolean remote,
boolean cachedOnly,
boolean ignoreFail)
Return the first InputStream from file of name filename in the list of directories. |
private static java.io.InputStream |
getInputStreamFromBytes(byte[] data)
Return the content of the specified byte array as an InputStream. |
static java.io.InputStream |
getInputStreamIgnoreFail(java.lang.String filename,
java.util.List<java.lang.String> directories)
Return the first InputStream from file of name filename in the list of directories, tell the getInputStream not to complain if not found. |
private static java.lang.String |
getMapKey(java.lang.String[] filenames,
java.util.List<java.lang.String> directories)
Return the key to use in the image cache. |
private static java.lang.String |
getMapKey(java.lang.String filename,
java.util.List<java.lang.String> directories)
Return the key to use in the image and file caches. |
static java.lang.Object |
getNewObject(java.lang.String className,
java.util.List<java.lang.String> directories)
Create an instance of the class whose name is in parameter. |
static java.lang.Object |
getNewObject(java.lang.String className,
java.util.List<java.lang.String> directories,
java.lang.Object[] parameter)
Create an instance of the class whose name is in parameter, using parameters. |
static java.io.OutputStream |
getOutputStream(java.lang.String filename,
java.util.List<java.lang.String> directories)
Return the first OutputStream from file of name filename in the list of directories. |
static java.lang.String |
getPathSeparator()
Give the String to mark directories. |
private static int |
numberFromFilename(java.lang.String filename,
java.lang.String prefix)
Extract a number from a filename, ignoring a prefix. |
static void |
purgeFileCache()
empty the cache so that all files have to be reloaded |
static void |
purgeImageCache()
empty the cache so that all Chits have to be redrawn |
static void |
putIntoFileCache(java.lang.String mapKey,
byte[] data)
Force adding the given data as belonging to the given key in the file cache. |
static void |
resetDataServer()
|
static void |
setDataServer(java.lang.String server,
int port)
|
private static java.awt.Image |
tryBuildingNonexistentImage(java.lang.String filename,
int width,
int height,
java.util.List<java.lang.String> directories)
Try to build an image when there is no source file to create it. |
private static java.awt.Image |
tryLoadImageFromFile(java.lang.String filename,
java.lang.String path,
int width,
int height)
Try loading the file with the given filename in the given path as an Image. |
private static javax.swing.ImageIcon |
tryLoadImageIconFromResource(java.lang.String filename,
java.lang.String path,
int width,
int height)
Try loading the file file with the given filename in the given path as an ImageIcon, through a Class loader. |
private static void |
waitOnImage(java.awt.Image image)
Wait until the Image in parameter is fully drawn. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.util.logging.Logger LOGGER
public static final java.lang.String FILESERVER_IGNOREFAIL_SIGNAL
public static final java.lang.String KEY_CONTENT_TYPE
private static final java.lang.String DEFAULT_FONT_NAME
private static final int DEFAULT_FONT_STYLE
private static final int DEFAULT_FONT_SIZE
public static final java.awt.Font DEFAULT_FONT
private static final java.lang.String pathSeparator
private static final java.lang.String[] imageExtension
private static final java.lang.ClassLoader baseCL
private static final StaticResourceLoader.ColossusClassLoader cl
private static final java.util.Map<java.lang.String,java.lang.Object> imageCache
private static final java.util.Map<java.lang.String,byte[]> fileCache
public static final java.lang.String REQUEST_TOKEN_SEPARATOR
private static java.lang.String server
private static int serverPort
Constructor Detail |
---|
public StaticResourceLoader()
Method Detail |
---|
public static void setDataServer(java.lang.String server, int port)
public static void resetDataServer()
public static java.lang.String getPathSeparator()
public static void purgeImageCache()
public static void purgeFileCache()
public static java.awt.Image getImage(java.lang.String filename, java.util.List<java.lang.String> directories, int width, int height)
filename
- Name of the Image file to load (without extension).directories
- List of directories to search (in order).
public static javax.swing.ImageIcon getImageIcon(java.lang.String filename, java.util.List<java.lang.String> directories, int width, int height)
filename
- Name of the ImageIcon file to load (without extension).directories
- List of directories to search (in order).
private static java.awt.Image tryLoadImageFromFile(java.lang.String filename, java.lang.String path, int width, int height)
filename
- Name of the file to load.path
- Path to search for the file
private static javax.swing.ImageIcon tryLoadImageIconFromResource(java.lang.String filename, java.lang.String path, int width, int height)
filename
- Name of the file to load.path
- Path to search for the file
public static java.io.InputStream getInputStreamIgnoreFail(java.lang.String filename, java.util.List<java.lang.String> directories)
filename
- Name of the file to load.directories
- List of directories to search (in order).
public static java.io.InputStream getInputStream(java.lang.String filename, java.util.List<java.lang.String> directories)
filename
- Name of the file to load.directories
- List of directories to search (in order).
private static java.io.InputStream getInputStream(java.lang.String filename, java.util.List<java.lang.String> directories, boolean remote, boolean cachedOnly, boolean ignoreFail)
filename
- Name of the file to load.directories
- List of directories to search (in order).remote
- Ask the server for the stream.cachedOnly
- Only look in the cache file,
do not try to load the file from permanent storage.ignoreFail
- (=don't complain) if file not found
public static byte[] getBytesFromFile(java.lang.String filename, java.util.List<java.lang.String> directories, boolean cachedOnly, boolean ignoreFail)
filename
- Name of the file to load.directories
- List of directories to search (in order).cachedOnly
- Only look in the cache file,
do not try to load the file from permanent storage.
private static byte[] getBytesFromInputStream(java.io.InputStream is)
InputStream
- The InputStream to use.
private static java.io.InputStream getInputStreamFromBytes(byte[] data)
data
- The byte array to convert.
public static java.io.OutputStream getOutputStream(java.lang.String filename, java.util.List<java.lang.String> directories)
filename
- Name of the file to load.directories
- List of directories to search (in order).
public static javax.swing.text.Document getDocument(java.lang.String filename, java.util.List<java.lang.String> directories)
filename
- Name of the file to load.directories
- List of directories to search (in order).
private static java.lang.String getMapKey(java.lang.String filename, java.util.List<java.lang.String> directories)
filename
- Name of the file.directories
- List of directories.
private static java.lang.String getMapKey(java.lang.String[] filenames, java.util.List<java.lang.String> directories)
filenames
- Array of name of files.directories
- List of directories.
public static java.awt.Image getCompositeImage(java.lang.String[] filenames, java.util.List<java.lang.String> directories, int width, int height)
filenames
- Names of the Images files to load (without extension).directories
- List of directories to search (in order).
private static java.awt.Image tryBuildingNonexistentImage(java.lang.String filename, int width, int height, java.util.List<java.lang.String> directories)
filename
- The name of the missing file.width
- Width of the image to create.height
- Height of the image to create.directories
- List of searched directories.
#getCompositeImage(String[], List)
private static java.awt.Image createNumberImage(int width, int height, int value, boolean right, java.awt.Color color)
width
- Width of the image to create.height
- Height of the image to create.value
- The number to draw on the image.right
- The number is on the right side (default is left side).color
- The color to use to draw the number.
private static java.awt.Image createNameImage(int width, int height, java.lang.String name, boolean down, java.awt.Color color)
width
- Width of the image to create.height
- Height of the image to create.name
- The String to draw on the image.down
- The name is on the bottom (default is top).color
- The color to use to draw the String.
private static java.awt.Image createPlainImage(int width, int height, java.awt.Color color)
width
- Width of the image to create.height
- Height of the image to create.color
- The color to use to fill the rectangle.
private static java.awt.Image createPlainImage(int width, int height, java.awt.Color color, boolean border)
width
- Width of the image to create.height
- Height of the image to create.color
- The color to use to fill the rectangle.border
- Whether to add a black border.
private static java.awt.Image createPlainImage(int width, int height, java.awt.Color color, int t_x, int t_y, int t_w, int t_h, boolean border)
width
- Width of the image to create.height
- Height of the image to createcolor
- The color to use to fill the rectangle.t_x
- Left border of the rectangle.t_y
- Top border of the rectangle.t_w
- Width of the rectangle.t_h
- Height of the rectangle.border
- Whether to add a black border.
private static java.awt.Image createColorizedImage(java.lang.String filename, java.awt.Color color, java.util.List<java.lang.String> directories, int width, int height)
filename
- Name of the Image file to load.directories
- List of directories to search (in order).color
- Color to use.
private static void waitOnImage(java.awt.Image image)
image
- Image to wait upon.private static int numberFromFilename(java.lang.String filename, java.lang.String prefix)
filename
- File name to extract from.prefix
- Prefix to ignore. Has to match the prefix of the file name, otherwise
0 will be returned.
private static java.lang.String colorNameFromFilename(java.lang.String filename, java.lang.String prefix)
filename
- File name to extract from.prefix
- Prefix to ignore. Has to match the beginning of the file
name, otherwise "black" will be used as default value.
private static java.awt.Color colorFromFilename(java.lang.String filename, java.lang.String prefix)
filename
- File name to extract from.prefix
- Prefix to ignore.
private static java.lang.String fixFilename(java.lang.String filename)
filename
- Filename to fix.
public static java.lang.Object getNewObject(java.lang.String className, java.util.List<java.lang.String> directories) throws ObjectCreationException
className
- The name of the class to use.directories
- List of directories to search (in order).
ObjectCreationException
- iff the object could not be createdpublic static java.lang.Object getNewObject(java.lang.String className, java.util.List<java.lang.String> directories, java.lang.Object[] parameter) throws ObjectCreationException
className
- The name of the class to use, must not be null.directories
- List of directories to search (in order), must not be null.parameter
- Array of parameters to pass to the constructor, can be null.
ObjectCreationException
- iff the object could not be created for some reasonpublic static void putIntoFileCache(java.lang.String mapKey, byte[] data)
mapKey
- Key to use in the cache.data
- File content to add.getMapKey(String, List)
,
getMapKey(String[], List)
public static java.util.List<org.jdom.Element> getFileCacheDump()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |