public class SpriteManager extends java.lang.Object implements java.lang.Iterable<Sprite>, AttributeSink
The sprite manager acts as a set of sprite elements that are associated with a graph. There can be only one sprite manager per graph. The sprite manager only role is to allow to create, destroy and enumerate sprites of a graph.
See the Sprite
class for an explanation of what are sprites and how
to use them.
In case you need to refine the Sprite class, you can change the
SpriteFactory
of this manager so that it creates specific instances
of sprites instead of the default ones. This is mostly useful when all
sprites will pertain to the same subclass. If you need to create several
sprites of distinct subclasses, you can use the
addSprite(String, Class)
and
addSprite(String, Class, Values)
methods.
Constructor and Description |
---|
SpriteManager(Graph graph)
Create a new manager for sprite and bind it to the given graph.
|
Modifier and Type | Method and Description |
---|---|
Sprite |
addSprite(java.lang.String identifier)
Add a sprite with the given identifier.
|
<T extends Sprite> |
addSprite(java.lang.String identifier,
java.lang.Class<T> spriteClass)
Add a sprite of a given subclass of Sprite with the given identifier.
|
<T extends Sprite> |
addSprite(java.lang.String identifier,
java.lang.Class<T> spriteClass,
Values position)
Same as
addSprite(String, Class) but also allows to specify an
initial position. |
void |
detach()
Detach this manager from its graph.
|
void |
edgeAttributeAdded(java.lang.String graphId,
long time,
java.lang.String edgeId,
java.lang.String attribute,
java.lang.Object value)
A edge attribute was added.
|
void |
edgeAttributeChanged(java.lang.String graphId,
long time,
java.lang.String edgeId,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
A edge attribute was changed.
|
void |
edgeAttributeRemoved(java.lang.String graphId,
long time,
java.lang.String edgeId,
java.lang.String attribute)
A edge attribute was removed.
|
Sprite |
getSprite(java.lang.String identifier)
Sprite corresponding to the given identifier or null if no sprite is
associated with the given identifier.
|
int |
getSpriteCount()
Number of sprites in the manager.
|
SpriteFactory |
getSpriteFactory()
The current sprite factory.
|
void |
graphAttributeAdded(java.lang.String graphId,
long time,
java.lang.String attribute,
java.lang.Object value)
A graph attribute was added.
|
void |
graphAttributeChanged(java.lang.String graphId,
long time,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
A graph attribute was changed.
|
void |
graphAttributeRemoved(java.lang.String graphId,
long time,
java.lang.String attribute)
A graph attribute was removed.
|
boolean |
hasSprite(java.lang.String identifier)
True if the manager contains a sprite corresponding to the given identifier.
|
java.util.Iterator<Sprite> |
iterator()
Iterator on the set of sprites.
|
void |
nodeAttributeAdded(java.lang.String graphId,
long time,
java.lang.String nodeId,
java.lang.String attribute,
java.lang.Object value)
A node attribute was added.
|
void |
nodeAttributeChanged(java.lang.String graphId,
long time,
java.lang.String nodeId,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
A node attribute was changed.
|
void |
nodeAttributeRemoved(java.lang.String graphId,
long time,
java.lang.String nodeId,
java.lang.String attribute)
A node attribute was removed.
|
void |
removeSprite(java.lang.String identifier)
Remove a sprite knowing its identifier.
|
void |
resetSpriteFactory()
Reset the sprite factory to defaults.
|
void |
setSpriteFactory(SpriteFactory factory)
Specify the sprite factory to use.
|
java.util.Iterator<? extends Sprite> |
spriteIterator()
Iterator on the set of sprites.
|
java.lang.Iterable<? extends Sprite> |
sprites()
Iterable set of sprites in no particular order.
|
public SpriteManager(Graph graph) throws InvalidSpriteIDException
graph
- The graph to associate with this manager;InvalidSpriteIDException
public int getSpriteCount()
public boolean hasSprite(java.lang.String identifier)
identifier
- The sprite identifier to search for.public Sprite getSprite(java.lang.String identifier)
identifier
- The sprite identifier.public java.lang.Iterable<? extends Sprite> sprites()
public java.util.Iterator<? extends Sprite> spriteIterator()
public java.util.Iterator<Sprite> iterator()
iterator
in interface java.lang.Iterable<Sprite>
public SpriteFactory getSpriteFactory()
public void detach()
public void setSpriteFactory(SpriteFactory factory)
factory
- The new factory to use.public void resetSpriteFactory()
public Sprite addSprite(java.lang.String identifier) throws InvalidSpriteIDException
identifier
- The identifier of the new sprite to add.InvalidSpriteIDException
- If the given identifier contains a dot.public <T extends Sprite> T addSprite(java.lang.String identifier, java.lang.Class<T> spriteClass)
SpriteFactory
. Most
often you use a sprite factory when all sprites will pertain to the same
subclass. If some sprites pertain to distinct subclasses, you can use this
method.identifier
- The identifier of the new sprite to add.spriteClass
- The class of the new sprite to add.public <T extends Sprite> T addSprite(java.lang.String identifier, java.lang.Class<T> spriteClass, Values position)
addSprite(String, Class)
but also allows to specify an
initial position.identifier
- The identifier of the new sprite to add.spriteClass
- The class of the new sprite to add.position
- The sprite position, or null for position (0, 0, 0).public void removeSprite(java.lang.String identifier)
identifier
- The identifier of the sprite to remove.public void graphAttributeAdded(java.lang.String graphId, long time, java.lang.String attribute, java.lang.Object value)
AttributeSink
graphAttributeAdded
in interface AttributeSink
graphId
- Identifier of the graph where the attribute changed.attribute
- The attribute name.value
- The attribute new value.public void graphAttributeChanged(java.lang.String graphId, long time, java.lang.String attribute, java.lang.Object oldValue, java.lang.Object newValue)
AttributeSink
graphAttributeChanged
in interface AttributeSink
graphId
- Identifier of the graph where the attribute changed.attribute
- The attribute name.oldValue
- The attribute old value.newValue
- The attribute new value.public void graphAttributeRemoved(java.lang.String graphId, long time, java.lang.String attribute)
AttributeSink
graphAttributeRemoved
in interface AttributeSink
graphId
- Identifier of the graph where the attribute was removed.attribute
- The removed attribute name.public void edgeAttributeAdded(java.lang.String graphId, long time, java.lang.String edgeId, java.lang.String attribute, java.lang.Object value)
AttributeSink
edgeAttributeAdded
in interface AttributeSink
graphId
- Identifier of the graph where the change occurred.edgeId
- Identifier of the edge whose attribute changed.attribute
- The attribute name.value
- The attribute new value.public void edgeAttributeChanged(java.lang.String graphId, long time, java.lang.String edgeId, java.lang.String attribute, java.lang.Object oldValue, java.lang.Object newValue)
AttributeSink
edgeAttributeChanged
in interface AttributeSink
graphId
- Identifier of the graph where the change occurred.edgeId
- Identifier of the edge whose attribute changed.attribute
- The attribute name.oldValue
- The attribute old value.newValue
- The attribute new value.public void edgeAttributeRemoved(java.lang.String graphId, long time, java.lang.String edgeId, java.lang.String attribute)
AttributeSink
edgeAttributeRemoved
in interface AttributeSink
graphId
- Identifier of the graph where the attribute was removed.edgeId
- Identifier of the edge whose attribute was removed.attribute
- The removed attribute name.public void nodeAttributeAdded(java.lang.String graphId, long time, java.lang.String nodeId, java.lang.String attribute, java.lang.Object value)
AttributeSink
nodeAttributeAdded
in interface AttributeSink
graphId
- Identifier of the graph where the change occurred.nodeId
- Identifier of the node whose attribute changed.attribute
- The attribute name.value
- The attribute new value.public void nodeAttributeChanged(java.lang.String graphId, long time, java.lang.String nodeId, java.lang.String attribute, java.lang.Object oldValue, java.lang.Object newValue)
AttributeSink
nodeAttributeChanged
in interface AttributeSink
graphId
- Identifier of the graph where the change occurred.nodeId
- Identifier of the node whose attribute changed.attribute
- The attribute name.oldValue
- The attribute old value.newValue
- The attribute new value.public void nodeAttributeRemoved(java.lang.String graphId, long time, java.lang.String nodeId, java.lang.String attribute)
AttributeSink
nodeAttributeRemoved
in interface AttributeSink
graphId
- Identifier of the graph where the attribute was removed.nodeId
- Identifier of the node whose attribute was removed.attribute
- The removed attribute name.