public class SpriteManager extends Object implements 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.
Modifier and Type | Field and Description |
---|---|
(package private) boolean |
attributeLock
this acts as a lock when we are adding a sprite since we are also
listener of the graph, and when we receive an "add" event, we
automatically create a sprite.
|
protected SpriteFactory |
factory
Factory to create new sprites.
|
protected Graph |
graph
The graph to add sprites to.
|
protected HashMap<String,Sprite> |
sprites
The set of sprites.
|
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(String identifier)
Add a sprite with the given identifier.
|
<T extends Sprite> |
addSprite(String identifier,
Class<T> spriteClass)
Add a sprite of a given subclass of Sprite with the given identifier.
|
<T extends Sprite> |
addSprite(String identifier,
Class<T> spriteClass,
Values position)
Same as
addSprite(String, Class) but also allows to specify an
initial position. |
protected Sprite |
addSprite(String identifier,
Values position)
Add a sprite with the given identifier and position.
|
void |
detach()
Detach this manager from its graph.
|
void |
edgeAttributeAdded(String graphId,
long time,
String edgeId,
String attribute,
Object value)
A edge attribute was added.
|
void |
edgeAttributeChanged(String graphId,
long time,
String edgeId,
String attribute,
Object oldValue,
Object newValue)
A edge attribute was changed.
|
void |
edgeAttributeRemoved(String graphId,
long time,
String edgeId,
String attribute)
A edge attribute was removed.
|
protected static Values |
getPositionValue(Object value) |
Sprite |
getSprite(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(String graphId,
long time,
String attribute,
Object value)
A graph attribute was added.
|
void |
graphAttributeChanged(String graphId,
long time,
String attribute,
Object oldValue,
Object newValue)
A graph attribute was changed.
|
void |
graphAttributeRemoved(String graphId,
long time,
String attribute)
A graph attribute was removed.
|
boolean |
hasSprite(String identifier)
True if the manager contains a sprite corresponding to the given
identifier.
|
Iterator<Sprite> |
iterator()
Iterator on the set of sprites.
|
protected void |
lookForExistingSprites() |
void |
nodeAttributeAdded(String graphId,
long time,
String nodeId,
String attribute,
Object value)
A node attribute was added.
|
void |
nodeAttributeChanged(String graphId,
long time,
String nodeId,
String attribute,
Object oldValue,
Object newValue)
A node attribute was changed.
|
void |
nodeAttributeRemoved(String graphId,
long time,
String nodeId,
String attribute)
A node attribute was removed.
|
void |
removeSprite(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.
|
Iterator<? extends Sprite> |
spriteIterator()
Iterator on the set of sprites.
|
Iterable<? extends Sprite> |
sprites()
Iterable set of sprites in no particular order.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
protected SpriteFactory factory
boolean attributeLock
public SpriteManager(Graph graph) throws InvalidSpriteIDException
graph
- The graph to associate with this manager;InvalidSpriteIDException
protected void lookForExistingSprites() throws InvalidSpriteIDException
InvalidSpriteIDException
public int getSpriteCount()
public boolean hasSprite(String identifier)
identifier
- The sprite identifier to search for.public Sprite getSprite(String identifier)
identifier
- The sprite identifier.public Iterable<? extends Sprite> sprites()
public Iterator<? extends Sprite> spriteIterator()
public SpriteFactory getSpriteFactory()
public void detach()
public void setSpriteFactory(SpriteFactory factory)
factory
- The new factory to use.public void resetSpriteFactory()
public Sprite addSprite(String identifier) throws InvalidSpriteIDException
identifier
- The identifier of the new sprite to add.InvalidSpriteIDException
- If the given identifier contains a dot.protected Sprite addSprite(String identifier, Values position) throws InvalidSpriteIDException
identifier
- The sprite identifier.position
- The sprite position (or null for (0,0,0)).InvalidSpriteIDException
- If the given identifier contains a dot.public <T extends Sprite> T addSprite(String identifier, 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(String identifier, 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(String identifier)
identifier
- The identifier of the sprite to remove.protected static Values getPositionValue(Object value)
public void graphAttributeAdded(String graphId, long time, String attribute, 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(String graphId, long time, String attribute, Object oldValue, 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(String graphId, long time, 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(String graphId, long time, String edgeId, String attribute, 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(String graphId, long time, String edgeId, String attribute, Object oldValue, 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(String graphId, long time, String edgeId, 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(String graphId, long time, String nodeId, String attribute, 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(String graphId, long time, String nodeId, String attribute, Object oldValue, 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(String graphId, long time, String nodeId, 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.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses