net.jinx.video
Class TextureManager

java.lang.Object
  extended by net.jinx.video.TextureManager

public class TextureManager
extends java.lang.Object

TextureManager holds mappings of String names to BufferedImage objects. TextureManager also has utility methods for loading and using it's textures.

Textures are loaded via the load(Hierarchy) method, using a URL as the base directory that they are loaded from.

Textures are used with Model instances by calling the bind, unbind and activate methods.

API Stability: Stable.


Constructor Summary
TextureManager()
          Constructs an empty TextureManager.
TextureManager(java.net.URL baseURL)
          Constructs an empty TextureManager.
 
Method Summary
 void activate(java.lang.String name, Context opt)
          Activates the specified texture.
 void addImage(java.lang.String name, java.awt.image.BufferedImage img, float priority)
          Adds an image.
 void bind(Context opt)
          Binds all textures for rendering.
 java.net.URL getBaseURL()
          Provides the base URL used for loading images.
 java.awt.image.BufferedImage getImage(java.lang.String name)
          Provides the image for the given name.
 boolean hasImage(java.lang.String name)
          Provides the means to determine if a given name has been mapped to an image.
 boolean isBound()
          If true, then the add and remove methods will throw a java.lang.IllegalStateException when they're used.
 void load(Hierarchy h)
          Loads a set of images using the given Hierarchy object as a mapping of image names to image locations.
 void removeAll()
          Removes all images.
 void removeImage(java.lang.String name)
          Removes an image.
 void setBaseFile(java.io.File file)
          Utility method to set the base URL using a java.io.File object to produce the base URL.
 void setBaseURL(java.net.URL baseURL)
          Sets the base URL used for loading images.
 void unbind(Context opt)
          Unbinds all textures.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextureManager

public TextureManager()
Constructs an empty TextureManager. It must still be configured. The base URL is the current directory (".").


TextureManager

public TextureManager(java.net.URL baseURL)
               throws java.net.MalformedURLException
Constructs an empty TextureManager. It must still be configured. The base URL is as given.

Parameters:
baseURL - the URL object to use as a base.
Throws:
java.net.MalformedURLException
Method Detail

setBaseURL

public void setBaseURL(java.net.URL baseURL)
Sets the base URL used for loading images.

Parameters:
baseURL - the URL object to use as a base.

setBaseFile

public void setBaseFile(java.io.File file)
                 throws java.net.MalformedURLException
Utility method to set the base URL using a java.io.File object to produce the base URL. If its a file, its assumed to be a jar file. If its a directory, it is used as the base. If it doesn't exist then the base URL isn't set.

Parameters:
file - the File object.
Throws:
java.net.MalformedURLException - if file cannot be converted to a URL.

getBaseURL

public java.net.URL getBaseURL()
Provides the base URL used for loading images.

Returns:
the URL object to use as a base.

addImage

public void addImage(java.lang.String name,
                     java.awt.image.BufferedImage img,
                     float priority)
Adds an image.

Parameters:
name - the name of the image to add.
img - the image to add.

removeImage

public void removeImage(java.lang.String name)
Removes an image.

Parameters:
name - the name of the image to remove.

removeAll

public void removeAll()
Removes all images.


hasImage

public boolean hasImage(java.lang.String name)
Provides the means to determine if a given name has been mapped to an image.

Parameters:
name - the name of the image to check for.
Returns:
true if there is an image with that name.

getImage

public java.awt.image.BufferedImage getImage(java.lang.String name)
Provides the image for the given name.

Parameters:
name - the name of the image.
Returns:
the image for the given name or null if there is no image with that name.

isBound

public boolean isBound()
If true, then the add and remove methods will throw a java.lang.IllegalStateException when they're used.

Returns:
true if this TextureManager has been bound to a GLDrawable for rendering.

bind

public void bind(Context opt)
Binds all textures for rendering.

Parameters:
opt - the Context object holding rendering attributes.

unbind

public void unbind(Context opt)
Unbinds all textures.

Parameters:
opt - the Context object holding rendering attributes.

activate

public void activate(java.lang.String name,
                     Context opt)
Activates the specified texture. This makes it the currently active OpenGL texture.


load

public void load(Hierarchy h)
Loads a set of images using the given Hierarchy object as a mapping of image names to image locations.

Parameters:
h - the Hierachy object that describes the mappings.