org.opensourcephysics.tools
Class ResourceLoader

java.lang.Object
  extended by org.opensourcephysics.tools.ResourceLoader

public class ResourceLoader
extends java.lang.Object

This defines static methods for loading resources.

Version:
1.0
Author:
Douglas Brown

Field Summary
protected static boolean cacheEnabled
           
protected static java.util.ArrayList<java.lang.String> extractExtensions
           
protected static int maxPaths
           
protected static java.util.Hashtable<java.lang.String,Resource> resources
           
protected static java.util.ArrayList<java.lang.String> searchPaths
           
protected static java.net.URLClassLoader xsetZipLoader
           
protected static java.util.Map<java.lang.String,java.net.URLClassLoader> zipLoaders
           
 
Method Summary
static void addExtractExtension(java.lang.String extension)
          Adds an extension to the end of the extractExtensions list.
static void addSearchPath(java.lang.String base)
          Adds a path at the beginning of the searchPaths list.
static java.applet.AudioClip getAudioClip(java.lang.String path)
           
static java.awt.image.BufferedImage getBufferedImage(java.lang.String path)
           
static javax.swing.ImageIcon getIcon(java.lang.String path)
           
static java.awt.Image getImage(java.lang.String path)
           
static Resource getResource(java.lang.String name)
          Gets a resource specified by name.
static Resource getResource(java.lang.String name, boolean searchFiles)
          Gets a resource specified by name and Class.
static Resource getResource(java.lang.String name, java.lang.Class<?> type)
          Gets a resource specified by name and Class.
static Resource getResource(java.lang.String name, java.lang.Class<?> type, boolean searchFiles)
          Gets a resource specified by name and Class.
static Resource getResource(java.lang.String basePath, java.lang.String name)
          Gets a resource specified by base path and name.
static Resource getResource(java.lang.String basePath, java.lang.String name, boolean searchFiles)
          Gets a resource specified by base path and name.
static Resource getResource(java.lang.String basePath, java.lang.String name, java.lang.Class<Resource> type)
          Gets a resource specified by base path, name and class.
static Resource getResource(java.lang.String basePath, java.lang.String name, java.lang.Class<Resource> type, boolean searchFiles)
          Gets a resource specified by base path, name and class.
static java.lang.String getString(java.lang.String path)
           
static boolean isCacheEnabled()
          Gets the cacheEnabled property.
static java.io.InputStream openInputStream(java.lang.String path)
           
static java.io.Reader openReader(java.lang.String path)
           
static void removeSearchPath(java.lang.String base)
          Removes a path from the searchPaths list.
static void setCacheEnabled(boolean enabled)
          Sets the cacheEnabled property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

searchPaths

protected static java.util.ArrayList<java.lang.String> searchPaths

maxPaths

protected static int maxPaths

resources

protected static java.util.Hashtable<java.lang.String,Resource> resources

cacheEnabled

protected static boolean cacheEnabled

zipLoaders

protected static java.util.Map<java.lang.String,java.net.URLClassLoader> zipLoaders

xsetZipLoader

protected static java.net.URLClassLoader xsetZipLoader

extractExtensions

protected static java.util.ArrayList<java.lang.String> extractExtensions
Method Detail

getResource

public static Resource getResource(java.lang.String name)
Gets a resource specified by name. If no resource is found using the name alone, the searchPaths are searched.

Parameters:
name - the file or URL name
Returns:
the Resource, or null if none found

getResource

public static Resource getResource(java.lang.String name,
                                   boolean searchFiles)
Gets a resource specified by name and Class. If no resource is found using the name alone, the searchPaths are searched. Files are searched only if searchFile is true.

Parameters:
name - the file or URL name
searchFiles - true to search files
Returns:
the Resource, or null if none found

getResource

public static Resource getResource(java.lang.String name,
                                   java.lang.Class<?> type)
Gets a resource specified by name and Class. If no resource is found using the name alone, the searchPaths are searched.

Parameters:
name - the file or URL name
type - the Class providing default ClassLoader resource loading
Returns:
the Resource, or null if none found

getResource

public static Resource getResource(java.lang.String name,
                                   java.lang.Class<?> type,
                                   boolean searchFiles)
Gets a resource specified by name and Class. If no resource is found using the name alone, the searchPaths are searched. Files are searched only if searchFile is true.

Parameters:
name - the file or URL name
type - the Class providing default ClassLoader resource loading
searchFiles - true to search files
Returns:
the Resource, or null if none found

getResource

public static Resource getResource(java.lang.String basePath,
                                   java.lang.String name)
Gets a resource specified by base path and name. If base path is relative and no resource is found using the base alone, the searchPaths are searched.

Parameters:
basePath - the base path
name - the file or URL name
Returns:
the Resource, or null if none found

getResource

public static Resource getResource(java.lang.String basePath,
                                   java.lang.String name,
                                   boolean searchFiles)
Gets a resource specified by base path and name. If base path is relative and no resource is found using the base alone, the searchPaths are searched. Files are searched only if searchFile is true.

Parameters:
basePath - the base path
name - the file or URL name
searchFiles - true to search files
Returns:
the Resource, or null if none found

getResource

public static Resource getResource(java.lang.String basePath,
                                   java.lang.String name,
                                   java.lang.Class<Resource> type)
Gets a resource specified by base path, name and class. If base path is relative and no resource is found using the base alone, the searchPaths are searched.

Parameters:
basePath - the base path
name - the file or URL name
type - the Class providing ClassLoader resource loading
Returns:
the Resource, or null if none found

getResource

public static Resource getResource(java.lang.String basePath,
                                   java.lang.String name,
                                   java.lang.Class<Resource> type,
                                   boolean searchFiles)
Gets a resource specified by base path, name and class. If base path is relative and no resource is found using the base alone, the searchPaths are searched. Files are searched only if searchFile is true.

Parameters:
basePath - the base path
name - the file or URL name
type - the Class providing ClassLoader resource loading
searchFiles - true to search files
Returns:
the Resource, or null if none found

addSearchPath

public static void addSearchPath(java.lang.String base)
Adds a path at the beginning of the searchPaths list.

Parameters:
base - the base path to add

removeSearchPath

public static void removeSearchPath(java.lang.String base)
Removes a path from the searchPaths list.

Parameters:
base - the base path to remove

setCacheEnabled

public static void setCacheEnabled(boolean enabled)
Sets the cacheEnabled property.

Parameters:
enabled - true to enable the cache

isCacheEnabled

public static boolean isCacheEnabled()
Gets the cacheEnabled property.

Returns:
true if the cache is enabled

addExtractExtension

public static void addExtractExtension(java.lang.String extension)
Adds an extension to the end of the extractExtensions list. Files with this extension found inside jars are extracted before loading.

Parameters:
extension - the extension to add

openInputStream

public static java.io.InputStream openInputStream(java.lang.String path)

openReader

public static java.io.Reader openReader(java.lang.String path)

getString

public static java.lang.String getString(java.lang.String path)

getIcon

public static javax.swing.ImageIcon getIcon(java.lang.String path)

getImage

public static java.awt.Image getImage(java.lang.String path)

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(java.lang.String path)

getAudioClip

public static java.applet.AudioClip getAudioClip(java.lang.String path)