Package org.graphstream.ui.spriteManager
Class SpriteManager
java.lang.Object
org.graphstream.ui.spriteManager.SpriteManager
- All Implemented Interfaces:
Iterable<Sprite>
,AttributeSink
public class SpriteManager extends Object implements Iterable<Sprite>, AttributeSink
Set of sprites associated with a graph.
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 Summary
Constructors Constructor Description SpriteManager(Graph graph)
Create a new manager for sprite and bind it to the given graph. -
Method Summary
Modifier and Type Method Description Sprite
addSprite(String identifier)
Add a sprite with the given identifier.<T extends Sprite>
TaddSprite(String identifier, Class<T> spriteClass)
Add a sprite of a given subclass of Sprite with the given identifier.<T extends Sprite>
TaddSprite(String identifier, Class<T> spriteClass, Values position)
Same asaddSprite(String, Class)
but also allows to specify an initial 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.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.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.
-
Constructor Details
-
SpriteManager
Create a new manager for sprite and bind it to the given graph. If the graph already contains attributes describing sprites, the manager is automatically filled with the existing sprites.- Parameters:
graph
- The graph to associate with this manager;- Throws:
InvalidSpriteIDException
-
-
Method Details
-
getSpriteCount
public int getSpriteCount()Number of sprites in the manager.- Returns:
- The sprite count.
-
hasSprite
True if the manager contains a sprite corresponding to the given identifier.- Parameters:
identifier
- The sprite identifier to search for.
-
getSprite
Sprite corresponding to the given identifier or null if no sprite is associated with the given identifier.- Parameters:
identifier
- The sprite identifier.
-
sprites
Iterable set of sprites in no particular order.- Returns:
- The set of sprites.
-
spriteIterator
Iterator on the set of sprites.- Returns:
- An iterator on sprites.
-
iterator
Iterator on the set of sprites. -
getSpriteFactory
The current sprite factory.- Returns:
- A Sprite factory.
-
detach
public void detach()Detach this manager from its graph. This manager will no more be usable to create or remove sprites. However sprites not yet removed are still present as attributes in the graph and binding another sprite manager to this graph will retrieve all sprites. -
setSpriteFactory
Specify the sprite factory to use. This allows to use specific sprite classes (descendants of Sprite).- Parameters:
factory
- The new factory to use.
-
resetSpriteFactory
public void resetSpriteFactory()Reset the sprite factory to defaults. -
addSprite
Add a sprite with the given identifier. If the sprite already exists, nothing is done. The sprite identifier cannot actually contain dots. This character use is reserved by the sprite mechanism.- Parameters:
identifier
- The identifier of the new sprite to add.- Returns:
- The created sprite.
- Throws:
InvalidSpriteIDException
- If the given identifier contains a dot.
-
addSprite
Add a sprite of a given subclass of Sprite with the given identifier. If the sprite already exists, nothing is done. This method allows to add a sprite of a chosen subclass of Sprite, without using aSpriteFactory
. 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.- Parameters:
identifier
- The identifier of the new sprite to add.spriteClass
- The class of the new sprite to add.- Returns:
- The created sprite.
-
addSprite
Same asaddSprite(String, Class)
but also allows to specify an initial position.- Parameters:
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).- Returns:
- The created sprite.
-
removeSprite
Remove a sprite knowing its identifier. If no such sprite exists, this fails silently.- Parameters:
identifier
- The identifier of the sprite to remove.
-
graphAttributeAdded
Description copied from interface:AttributeSink
A graph attribute was added.- Specified by:
graphAttributeAdded
in interfaceAttributeSink
- Parameters:
graphId
- Identifier of the graph where the attribute changed.attribute
- The attribute name.value
- The attribute new value.
-
graphAttributeChanged
public void graphAttributeChanged(String graphId, long time, String attribute, Object oldValue, Object newValue)Description copied from interface:AttributeSink
A graph attribute was changed.- Specified by:
graphAttributeChanged
in interfaceAttributeSink
- Parameters:
graphId
- Identifier of the graph where the attribute changed.attribute
- The attribute name.oldValue
- The attribute old value.newValue
- The attribute new value.
-
graphAttributeRemoved
Description copied from interface:AttributeSink
A graph attribute was removed.- Specified by:
graphAttributeRemoved
in interfaceAttributeSink
- Parameters:
graphId
- Identifier of the graph where the attribute was removed.attribute
- The removed attribute name.
-
edgeAttributeAdded
public void edgeAttributeAdded(String graphId, long time, String edgeId, String attribute, Object value)Description copied from interface:AttributeSink
A edge attribute was added.- Specified by:
edgeAttributeAdded
in interfaceAttributeSink
- Parameters:
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.
-
edgeAttributeChanged
public void edgeAttributeChanged(String graphId, long time, String edgeId, String attribute, Object oldValue, Object newValue)Description copied from interface:AttributeSink
A edge attribute was changed.- Specified by:
edgeAttributeChanged
in interfaceAttributeSink
- Parameters:
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.
-
edgeAttributeRemoved
Description copied from interface:AttributeSink
A edge attribute was removed.- Specified by:
edgeAttributeRemoved
in interfaceAttributeSink
- Parameters:
graphId
- Identifier of the graph where the attribute was removed.edgeId
- Identifier of the edge whose attribute was removed.attribute
- The removed attribute name.
-
nodeAttributeAdded
public void nodeAttributeAdded(String graphId, long time, String nodeId, String attribute, Object value)Description copied from interface:AttributeSink
A node attribute was added.- Specified by:
nodeAttributeAdded
in interfaceAttributeSink
- Parameters:
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.
-
nodeAttributeChanged
public void nodeAttributeChanged(String graphId, long time, String nodeId, String attribute, Object oldValue, Object newValue)Description copied from interface:AttributeSink
A node attribute was changed.- Specified by:
nodeAttributeChanged
in interfaceAttributeSink
- Parameters:
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.
-
nodeAttributeRemoved
Description copied from interface:AttributeSink
A node attribute was removed.- Specified by:
nodeAttributeRemoved
in interfaceAttributeSink
- Parameters:
graphId
- Identifier of the graph where the attribute was removed.nodeId
- Identifier of the node whose attribute was removed.attribute
- The removed attribute name.
-