com.motorola.iden.micro3d
Class MultiTexture

java.lang.Object
  |
  +--com.motorola.iden.micro3d.Texture
        |
        +--com.motorola.iden.micro3d.MultiTexture

public class MultiTexture
extends Texture

MultiTexture class contains and manages multiple textures.

A multi-texture is a texture composed of several separate Texture objects. The MultiTexture is used for figures that were created with support for multiple textures. When such figure is rendered, its texture is created from the separate Texture objects contained in this MultiTexture. If this MultiTexture contains more Texture object than were originally created for that particular figure, the additional textures will be ignored and will not affect the rendering. If the MultiTexture does not contain all the textures that form the multi-texture for that particular figure, then some (or all) parts of the figure will not render correctly or will not render at all.

MultiTexture also maintains an index that points to one of the Texture objects contained in this MultiTexture. This index can be accessed and modified with the getCurrentIndex() and setCurrentIndex() methods respectivelly. Specifying the index enables the use of the MultiTexture for figures and primitives that were not created to support multiple textures. For those figure and primitives, the texture that will be used will be the Texture that is found at the location pointed to by the current index.


MOTOROLA and the Stylized M Logo are registered trademarks of Motorola, Inc. Reg. U.S. Pat. & Tm. Off.
© COPYRIGHT 2003-2004 MOTOROLA, Inc. All Rights Reserved.


Field Summary
static int MAX_TEXTURES
          Defines the maximum amount of textures a MultiTexture can hold.
 
Constructor Summary
MultiTexture()
          Constructs an empty MultiTexture.
MultiTexture(int capacity)
          Constructs a MultiTexture capable of holding the specified amount of Texture objects.
 
Method Summary
 boolean addTexture(Texture texture)
          Adds the specified Texture to the end of the list.
 int capacity()
          Returns the current capacity of this MultiTexture.
 boolean contains(Texture texture)
          Tests if the specified Texture is contained in this MultiTexture.
 int getCurrentIndex()
          Returns the current index for this MultiTexture.
 Texture getCurrentTexture()
          Returns the Texture reference by the current index.
 int indexOf(Texture texture)
          Searches for the first occurence of the given Texture, testing for equality using the equals method.
 int indexOf(Texture texture, int index)
          Searches for the first occurence of the given Texture, beginning the search at index, and testing for equality using the equals method.
 boolean insertTextureAt(Texture texture, int index)
          Inserts the specified texture as a component in this MultiTexture at the specified index.
 boolean isEmpty()
          Tests if this MultiTexture has no textures.
 int lastIndexOf(Texture texture)
          Returns the index of the last occurrence of the specified texture in this MultiTexture.
 int lastIndexOf(Texture texture, int index)
          Searches backwards for the specified texture, starting from the specified index, and returns an index to it.
 void removeAllTextures()
          Removes all components from this MultiTexture and sets its size to zero.
 boolean removeTexture(Texture texture)
          Removes the first occurrence of the specified texture from this MultiTexture.
 void removeTextureAt(int index)
          Deletes the Texture at the specified index.
 void setCurrentIndex(int index)
          Sets the Texture at the index specified as the current Texture for this MultiTexture.
 void setTextureAt(Texture texture, int index)
          Sets the texture at the specified index of this MultiTexture to be the specified Texture.
 int size()
          Returns the number of textures in this MultiTexture.
 Texture textureAt(int index)
          Returns the Texture at the specified index.
 java.util.Enumeration textures()
          Returns an enumeration of the textures of this MultiTexture.
 
Methods inherited from class com.motorola.iden.micro3d.Texture
createTexture, createTexture, isSphereTexture
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_TEXTURES

public static final int MAX_TEXTURES
Defines the maximum amount of textures a MultiTexture can hold. This value is defined as 16.
Constructor Detail

MultiTexture

public MultiTexture()
Constructs an empty MultiTexture. The capacity of this MultiTexture is set to MAX_TEXTURES.
See Also:
MAX_TEXTURES

MultiTexture

public MultiTexture(int capacity)
Constructs a MultiTexture capable of holding the specified amount of Texture objects. If specified capacity is greater than the maximum amount of textures for a MultiTexture the value will be adjusted to the maximum value.

Parameters:
capacity - the initial capacity of the MultiTexture.
Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative.
See Also:
MAX_TEXTURES
Method Detail

addTexture

public boolean addTexture(Texture texture)
Adds the specified Texture to the end of the list. The capacity of this MultiTexture is increased if its size becomes greater than its capacity unless MAX_TEXTURES has been reached.

Parameters:
texture - the Texture to be added.
Returns:
true if the MultiTexture had space to accommodate the new Texture; false otherwise.
Throws:
java.lang.NullPointerException - if texture is null.
java.lang.IllegalArgumentException - if the specified parameter is a sphere texture or a MultiTexture.

capacity

public int capacity()
Returns the current capacity of this MultiTexture.

Returns:
the current capacity of this MultiTexture.

contains

public boolean contains(Texture texture)
Tests if the specified Texture is contained in this MultiTexture.

Parameters:
texture - texture to test for.
Returns:
true if the specified Texture is a component in this MultiTexture; false otherwise.

textureAt

public Texture textureAt(int index)
Returns the Texture at the specified index.

Parameters:
index - an index into this MultiTexture.
Returns:
the Texture at the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if an invalid index was given.

textures

public java.util.Enumeration textures()
Returns an enumeration of the textures of this MultiTexture.

Returns:
an enumeration of the components of this MultiTexture.

indexOf

public int indexOf(Texture texture)
Searches for the first occurence of the given Texture, testing for equality using the equals method.

Parameters:
texture - the Texture to search for.
Returns:
the index of the first occurrence of the Texture in this MultiTexture; returns -1 if the Texture is not found.

indexOf

public int indexOf(Texture texture,
                   int index)
Searches for the first occurence of the given Texture, beginning the search at index, and testing for equality using the equals method.

Parameters:
texture - the Texture to search for.
index - the index to start searching from.
Returns:
the index of the first occurrence of the Texture in this MultiTexture at position index or later in the vector; returns -1 if the Texture is not found.

lastIndexOf

public int lastIndexOf(Texture texture)
Returns the index of the last occurrence of the specified texture in this MultiTexture.

Parameters:
texture - the Texture to search for.
Returns:
the index of the last occurrence of the specified texture in this MultiTexture; returns -1 if the specified texture is not found.

lastIndexOf

public int lastIndexOf(Texture texture,
                       int index)
Searches backwards for the specified texture, starting from the specified index, and returns an index to it.

Parameters:
texture - the Texture to search for.
index - the index to start searching from.
Returns:
the index of the last occurrence of the specified texture in this MultiTexture at position less than index in the MultiTexture; returns -1 if the texture is not found.

insertTextureAt

public boolean insertTextureAt(Texture texture,
                               int index)
                        throws java.lang.NullPointerException,
                               java.lang.IllegalArgumentException
Inserts the specified texture as a component in this MultiTexture at the specified index. Each texture in this MultiTexture with an index greater or equal to the specified index is shifted upward to have an index one greater than the value it had previously.

The index must be a value greater than or equal to 0 and less than or equal to the current size of the MultiTexture.

Parameters:
texture - the Texture to insert.
index - where to insert the new texture.
Returns:
true if the MultiTexture had space to accommodate the new Texture; false otherwise.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the specified index was invalid.
java.lang.NullPointerException - if Texture is null
java.lang.IllegalArgumentException - if the specified parameter is a sphere texture or a MultiTexture

isEmpty

public boolean isEmpty()
Tests if this MultiTexture has no textures.

Returns:
true if this MultiTexture has no textures; false otherwise.

removeTexture

public boolean removeTexture(Texture texture)
Removes the first occurrence of the specified texture from this MultiTexture. If the texture is found in this MultiTexture, each component in the MultiTexture with an index greater or equal to the texture's index is shifted downward to have an index one smaller than the value it had previously.

Parameters:
texture - the Texture to be removed.
Returns:
true if the Texture was a component of this MultiTexture; false otherwise.
Throws:
java.lang.NullPointerException - if Texture is null.

removeTextureAt

public void removeTextureAt(int index)
Deletes the Texture at the specified index. Each Texture in this MultiTexture with an index greater or equal to the specified index is shifted downward to have an index one smaller than the value it had previously.

Parameters:
index - the index of the Texture to remove.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

removeAllTextures

public void removeAllTextures()
Removes all components from this MultiTexture and sets its size to zero.

setTextureAt

public void setTextureAt(Texture texture,
                         int index)
                  throws java.lang.NullPointerException,
                         java.lang.IllegalArgumentException,
                         java.lang.ArrayIndexOutOfBoundsException
Sets the texture at the specified index of this MultiTexture to be the specified Texture. The previous Texture at that position is discarded.

Parameters:
texture - what the Texture is to be set to.
index - the index of the Texture to remove.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.
java.lang.NullPointerException - if Texture is null.
java.lang.IllegalArgumentException - if Texture is a sphere texture or a MultiTexture.

size

public int size()
Returns the number of textures in this MultiTexture.

Returns:
the number of textures in this MultiTexture.

getCurrentIndex

public int getCurrentIndex()
Returns the current index for this MultiTexture.

Returns:
current index in this MultiTexture.

setCurrentIndex

public void setCurrentIndex(int index)
Sets the Texture at the index specified as the current Texture for this MultiTexture.

Parameters:
index - the index of the Texture to be specified as the current Texture.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the specified index is invalid.

getCurrentTexture

public Texture getCurrentTexture()
Returns the Texture reference by the current index.

Returns:
the Texture serving as the current Texture or null if the current Texture is not set.