org.jrabbit.base.graphics.layers.grouped
Class DefaultLayeredRenderList

java.lang.Object
  extended by org.jrabbit.base.graphics.layers.grouped.DefaultLayeredRenderList
All Implemented Interfaces:
java.lang.Iterable<Layer>, Renderable, Factory<Layer>, Accepter<Layer>, Container<Layer>, KeyedContainer<Layer>, Remover<Layer>, LayeredRenderList

public class DefaultLayeredRenderList
extends java.lang.Object
implements LayeredRenderList

DefaultLayeredRenderList provides a standard implementation of the LayeredRenderList interface. Basically, it manages Layers via a LinkedHashMap and creates DefaultLayers from Strings when required. A DefaultLayeredRenderList is intended to have at least one Layer at all times; if all layers are ever removed it will create a new Layer with an empty String as a reference. Additionally, DefaultLayeredRenderList maintains a "default" layer; this is intended to always be the "top" layer. If a Renderable is added without an indicated Layer, it is added to this default.

Author:
Chris Molini

Field Summary
private  Layer defaultLayer
          The current Layer accepting default add methods.
protected  java.util.LinkedHashMap<java.lang.String,Layer> layers
          The list of Layers, keyed to their references.
 
Constructor Summary
DefaultLayeredRenderList()
          Creates a DefaultLayeredRenderList with no Layers in it.
DefaultLayeredRenderList(Layer... layers)
          Creates a DefaultLayeredRenderList with the indicated Layers in it.
DefaultLayeredRenderList(java.lang.String... layers)
          Creates a DefaultLayeredRenderList with the indicated Layers in it.
 
Method Summary
 void add(Layer... layers)
          Attempts to add the indicated series of Layers to the list.
 boolean add(Layer layer)
          Attempts to add the indicated Layer on top of those already present in the list.
 boolean add(Renderable renderable)
          Attempts to add the indicated Renderable to the default Layer.
 boolean add(Renderable renderable, java.lang.String layerName)
          Attempts to add the indicated Renderable object to the Layer in the list with an identical reference to the one supplied.
 void add(java.lang.String... layerNames)
          Attempts to create and add Layers corresponding to every supplied layer name.
 boolean add(java.lang.String layerName)
          Adds a new Layer with the indicated reference.
protected  void adjustDefault()
          Ensures that the default layer is the last Layer in the list (the one "on top").
 void clear()
          Removes all Layers; this effectively "empties" the list.
 Layer containing(Renderable renderable)
          Finds and retrieves the Layer that contains the indicated Renderable.
 boolean contains(Layer layer)
          Checks to see if the list contains the indicated layer.
 boolean contains(java.lang.String layerName)
          Checks to see if the list contains a layer with the indicated String as a reference.
 Layer create(java.lang.String reference)
          Creates a DefaultLayer with the indicated String as an identifier.
 Layer get(java.lang.String reference)
          Attempts to find the Layer with the indicated reference.
 java.util.Iterator<Layer> iterator()
          Gets an iterator that moves through all Layers in the list, in order.
 void remove(Layer... layers)
          Attempts to remove the indicated series of Layers from the list.
 boolean remove(Layer layer)
          Attempts to remove the indicated Layer from the list.
 boolean remove(Renderable renderable)
          Attempts to remove the indicated Renderable object from the list of Layers.
 boolean remove(Renderable renderable, java.lang.String layerName)
          Attempts to remove the indicated Renderable from the Layer in the list with an identical reference.
 java.util.LinkedList<Layer> remove(java.lang.String... layerNames)
          Attempts to remove and return all Layers with the supplied names.
 Layer remove(java.lang.String layerName)
          Removes the Layer (if any) on the list with the indicated reference.
 void render()
          Renders every Layer in the list, in order.
 int size()
          Determines how many Layers are in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

layers

protected java.util.LinkedHashMap<java.lang.String,Layer> layers
The list of Layers, keyed to their references.


defaultLayer

private Layer defaultLayer
The current Layer accepting default add methods.

Constructor Detail

DefaultLayeredRenderList

public DefaultLayeredRenderList()
Creates a DefaultLayeredRenderList with no Layers in it.


DefaultLayeredRenderList

public DefaultLayeredRenderList(java.lang.String... layers)
Creates a DefaultLayeredRenderList with the indicated Layers in it.

Parameters:
layers - The identifiers of the DefaultLayers to put into the list.

DefaultLayeredRenderList

public DefaultLayeredRenderList(Layer... layers)
Creates a DefaultLayeredRenderList with the indicated Layers in it.

Parameters:
layers - The Layers to place into the list.
Method Detail

add

public boolean add(Layer layer)
Attempts to add the indicated Layer on top of those already present in the list. The operation fails if another layer is in the list with an identical reference. Additionally, if the addition succeeds, this sets the default layer to the supplied one.

Specified by:
add in interface Accepter<Layer>
Parameters:
layer - The Layer to add.
Returns:
True if the Layer was added successfully, false if not.

add

public void add(Layer... layers)
Attempts to add the indicated series of Layers to the list.

Specified by:
add in interface Accepter<Layer>
Parameters:
layers - The Layers to add.
See Also:
add(Layer)

add

public boolean add(java.lang.String layerName)
Adds a new Layer with the indicated reference. This operation will fail if a Layer is already on the list with an identical reference. Additionally, if the addition succeeds, this sets the default layer to the new one.

Specified by:
add in interface KeyedContainer<Layer>
Parameters:
reference - The String to identify the new Layer.
Returns:
True if the add succeeded, false if not.

add

public void add(java.lang.String... layerNames)
Attempts to create and add Layers corresponding to every supplied layer name.

Specified by:
add in interface KeyedContainer<Layer>
Parameters:
layerNames - The Strings to identify the new Layers.

remove

public boolean remove(Layer layer)
Attempts to remove the indicated Layer from the list. If different Layer with the same reference is on the list, nothing happens.

Specified by:
remove in interface Remover<Layer>
Parameters:
layer - The Layer to remove.
Returns:
True if the removal operation succeeded, false if not.

remove

public void remove(Layer... layers)
Attempts to remove the indicated series of Layers from the list.

Specified by:
remove in interface Remover<Layer>
Parameters:
layers - The Layers to remove.
See Also:
add(Layer)

remove

public Layer remove(java.lang.String layerName)
Removes the Layer (if any) on the list with the indicated reference. If no Layer has the reference, nothing changes. If the current default layer is removed, then the new "top" layer is set as the default.

Specified by:
remove in interface KeyedContainer<Layer>
Parameters:
reference - The String that identifies the target Layer.
Returns:
The Layer that was removed. If no layer was removed, returns null.

remove

public java.util.LinkedList<Layer> remove(java.lang.String... layerNames)
Attempts to remove and return all Layers with the supplied names.

Specified by:
remove in interface KeyedContainer<Layer>
Parameters:
layerNames - The Strings indicating which Layers to remove.
Returns:
A LinkedList containing all Layers removed. If no Layers are removed successfully, an empty list is returned.

get

public Layer get(java.lang.String reference)
Attempts to find the Layer with the indicated reference.

Specified by:
get in interface KeyedContainer<Layer>
Parameters:
reference - The String that identifies the target Layer.
Returns:
The Layer in the list with the indicated reference, or (if none exist) returns the "default" Layer.

contains

public boolean contains(Layer layer)
Checks to see if the list contains the indicated layer.

Specified by:
contains in interface Container<Layer>
Parameters:
layer - The Layer to check for.
Returns:
True if the layer is contained, false if not.

contains

public boolean contains(java.lang.String layerName)
Checks to see if the list contains a layer with the indicated String as a reference.

Specified by:
contains in interface KeyedContainer<Layer>
Parameters:
layerName - The String that identifies the target Layer.
Returns:
True if a Layer is contained whose reference matches the supplied String.

clear

public void clear()
Removes all Layers; this effectively "empties" the list. NOTE: It's recommended that a new, empty Layer should be added to the list after this method, so that it's still possible to add Renderable objects.

Specified by:
clear in interface Container<Layer>

size

public int size()
Determines how many Layers are in the list.

Specified by:
size in interface Container<Layer>
Returns:
The number of Layers contained.

create

public Layer create(java.lang.String reference)
Creates a DefaultLayer with the indicated String as an identifier.

Specified by:
create in interface Factory<Layer>
Parameters:
reference - The String to identify the new Layer.
Returns:
A new DefaultLayer created from the reference.

adjustDefault

protected void adjustDefault()
Ensures that the default layer is the last Layer in the list (the one "on top"). If no Layers are currently in the list, a new Layer with an empty String as an identifier is created and added.


render

public void render()
Renders every Layer in the list, in order.

Specified by:
render in interface Renderable

add

public boolean add(Renderable renderable,
                   java.lang.String layerName)
Attempts to add the indicated Renderable object to the Layer in the list with an identical reference to the one supplied. If no Layer with the indicated reference is in the list, the addition fails.

Specified by:
add in interface LayeredRenderList
Parameters:
renderable - The Renderable object to add to the Layer.
layerName - The reference that identifies the Layer to add to.
Returns:
True if the add succeeded, false if not.

add

public boolean add(Renderable renderable)
Attempts to add the indicated Renderable to the default Layer.

Specified by:
add in interface LayeredRenderList
Parameters:
renderable - The Renderable object to add.
Returns:
True if the add succeeded, false if not.

remove

public boolean remove(Renderable renderable,
                      java.lang.String layerName)
Attempts to remove the indicated Renderable from the Layer in the list with an identical reference. If no Layer with the indicated reference is in the list, the removal fails.

Specified by:
remove in interface LayeredRenderList
Parameters:
renderable - The Renderable object to remove from the Layer.
layerName - The reference that identifies the Layer to remove from.
Returns:
True if the removal succeeded, false if not.

remove

public boolean remove(Renderable renderable)
Attempts to remove the indicated Renderable object from the list of Layers. This method searches through all Layers in an attempt to find the Layer to remove from.

Specified by:
remove in interface LayeredRenderList
Parameters:
renderable - The Renderable object to remove.
Returns:
True if the removal succeeded, false if not.

containing

public Layer containing(Renderable renderable)
Description copied from interface: LayeredRenderList
Finds and retrieves the Layer that contains the indicated Renderable.

Specified by:
containing in interface LayeredRenderList
Parameters:
renderable - The Renderable object to search for.
Returns:
The Layer that contains the object; or if none do, null.

iterator

public java.util.Iterator<Layer> iterator()
Gets an iterator that moves through all Layers in the list, in order.

Specified by:
iterator in interface java.lang.Iterable<Layer>
Returns:
An iterator through all the Layers.