org.xith3d.resources
Class ResourceBag

java.lang.Object
  extended by org.xith3d.resources.ResourceBag

public class ResourceBag
extends java.lang.Object

A ResourceBag holds references to all kinds of data to be used in Xith3D. Currently handled resource types are:

The resources are mapped to a user defined name and are accessible only through this name or the Map's Iterator.


Constructor Summary
ResourceBag()
          Creates a new ResourceBag.
 
Method Summary
 void addModel(java.lang.String name, Model model)
          Adds a Model resource to the ResourceBag.
 void addShader(java.lang.String name, Shader shader)
          Adds a Shader resource to the ResourceBag.
 void addSound(java.lang.String name, SoundContainer sound)
          Adds a Sound resource to the ResourceBag.
 void addTexture(java.lang.String name, Texture texture)
          Adds a Texture resource to the ResourceBag.
 void freeOpenGLResources(Canvas3D canvas)
          This method frees OpenGL resources (names) for all this NodeComponent and all child-components.
 void freeOpenGLResources(CanvasPeer canvasPeer)
          This method frees OpenGL resources (names) for all this NodeComponent and all child-components.
static ResourceBag getInstance()
          If you want to use one ResourceBag as a singleton, use this.
 Model getModel(java.lang.String name)
          Retrieves the given Model resource from the ResourceBag.
 Model getModelInstance(java.lang.String name)
          Retrieves a new shared instance of the given Model resource from the ResourceBag.
 java.util.Collection<Model> getModels()
          Returns a Collection of all Models stored in the ResourceBag.
 Shader getShader(java.lang.String name)
          Retrieves the given Shader resource from the ResourceBag.
 java.util.Collection<Shader> getShaders()
          Returns a Collection of all Shaders stored in the ResourceBag.
 SoundContainer getSound(java.lang.String name)
          Retrieves the given Sound resource from the ResourceBag.
 java.util.Collection<SoundContainer> getSounds()
          Returns a Collection of all Sounds stored in the ResourceBag.
 Texture getTexture(java.lang.String name)
          Retrieves the given Texture resource from the ResourceBag.
 java.util.Collection<Texture> getTextures()
          Returns a Collection of all Textures stored in the ResourceBag.
 int numModels()
          Returns the number of Model resources stored in this ResourceBag.
 int numResources()
          Return the total number of all resources stored in this ResourceBag.
 int numShaders()
          Return the number of Shader resources stored in this ResourceBag.
 int numSounds()
          Return the number of Sound resources stored in this ResourceBag.
 int numTextures()
          Returns the number of Texture resources stored in this ResourceBag.
static void setSingletonInstance(ResourceBag resBag)
          If you want to use one ResourceBag as a singleton, first invoke this and then use the getInstance() method to access the instance everywhere.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceBag

public ResourceBag()
Creates a new ResourceBag. Each supported resource type is stored in a HashMap each.

Method Detail

setSingletonInstance

public static void setSingletonInstance(ResourceBag resBag)
If you want to use one ResourceBag as a singleton, first invoke this and then use the getInstance() method to access the instance everywhere.

Parameters:
resBag - the ResourceBag instance to use as the singleton instance
See Also:
getInstance()

getInstance

public static ResourceBag getInstance()
If you want to use one ResourceBag as a singleton, use this. But remember to first (once) invoke the setSingletonInstance() method.

Returns:
the singleton instance (if already set)
See Also:
setSingletonInstance(ResourceBag)

addTexture

public void addTexture(java.lang.String name,
                       Texture texture)
Adds a Texture resource to the ResourceBag.

Parameters:
name - the name to access the resource at a later time
texture - the resource to add to the bag

getTexture

public Texture getTexture(java.lang.String name)
Retrieves the given Texture resource from the ResourceBag.

Parameters:
name - the name to use as the key
Returns:
the retrieved Texture resource or null, if the name does not exist in the bag

getTextures

public java.util.Collection<Texture> getTextures()
Returns a Collection of all Textures stored in the ResourceBag.

Returns:
the Collection of Textures

numTextures

public int numTextures()
Returns the number of Texture resources stored in this ResourceBag.

Returns:
the number of Texture resources

addModel

public void addModel(java.lang.String name,
                     Model model)
Adds a Model resource to the ResourceBag.

Parameters:
name - the name to access the resource at a later time
model - the resource to add to the bag

getModel

public Model getModel(java.lang.String name)
Retrieves the given Model resource from the ResourceBag.

Parameters:
name - the name to use as the key
Returns:
the retrieved Model resource or null, if the name does not exist in the bag

getModelInstance

public Model getModelInstance(java.lang.String name)
Retrieves a new shared instance of the given Model resource from the ResourceBag.

Parameters:
name - the name to use as the key
Returns:
a new shared instance of the Model resource or null, if the name does not exist in the bag.

getModels

public java.util.Collection<Model> getModels()
Returns a Collection of all Models stored in the ResourceBag.

Returns:
the Collection of Models

numModels

public int numModels()
Returns the number of Model resources stored in this ResourceBag.

Returns:
the number of Model resources

addSound

public void addSound(java.lang.String name,
                     SoundContainer sound)
Adds a Sound resource to the ResourceBag.

Parameters:
name - the name to access the resource at a later time
sound - the resource to add to the bag

getSound

public SoundContainer getSound(java.lang.String name)
Retrieves the given Sound resource from the ResourceBag.

Parameters:
name - the name to use as the key
Returns:
the retrieved Sound resource or null, if the name does not exist in the bag.

getSounds

public java.util.Collection<SoundContainer> getSounds()
Returns a Collection of all Sounds stored in the ResourceBag.

Returns:
the Collection of Sounds

numSounds

public int numSounds()
Return the number of Sound resources stored in this ResourceBag.

Returns:
the number of Sound resources

addShader

public void addShader(java.lang.String name,
                      Shader shader)
Adds a Shader resource to the ResourceBag.

Parameters:
name - the name to access the resource at a later time
shader - the resource to add to the bag

getShader

public Shader getShader(java.lang.String name)
Retrieves the given Shader resource from the ResourceBag.

Parameters:
name - the name to use as the key
Returns:
the retrieved Shader resource or null, if the name does not exist in the bag.

getShaders

public java.util.Collection<Shader> getShaders()
Returns a Collection of all Shaders stored in the ResourceBag.

Returns:
the Collection of Shaders

numShaders

public int numShaders()
Return the number of Shader resources stored in this ResourceBag.

Returns:
the number of Shader resources

numResources

public int numResources()
Return the total number of all resources stored in this ResourceBag.

Returns:
the number of all resources

freeOpenGLResources

public void freeOpenGLResources(CanvasPeer canvasPeer)
This method frees OpenGL resources (names) for all this NodeComponent and all child-components.

Parameters:
canvasPeer - the CanvasPeer for which to free the resources
See Also:
NodeComponent, CanvasPeer

freeOpenGLResources

public final void freeOpenGLResources(Canvas3D canvas)
This method frees OpenGL resources (names) for all this NodeComponent and all child-components.

Parameters:
canvas - the Canvas3D for which to free the resources
See Also:
NodeComponent, Canvas3D