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 SpriteaddSprite(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.voiddetach()Detach this manager from its graph.voidedgeAttributeAdded(String graphId, long time, String edgeId, String attribute, Object value)A edge attribute was added.voidedgeAttributeChanged(String graphId, long time, String edgeId, String attribute, Object oldValue, Object newValue)A edge attribute was changed.voidedgeAttributeRemoved(String graphId, long time, String edgeId, String attribute)A edge attribute was removed.SpritegetSprite(String identifier)Sprite corresponding to the given identifier or null if no sprite is associated with the given identifier.intgetSpriteCount()Number of sprites in the manager.SpriteFactorygetSpriteFactory()The current sprite factory.voidgraphAttributeAdded(String graphId, long time, String attribute, Object value)A graph attribute was added.voidgraphAttributeChanged(String graphId, long time, String attribute, Object oldValue, Object newValue)A graph attribute was changed.voidgraphAttributeRemoved(String graphId, long time, String attribute)A graph attribute was removed.booleanhasSprite(String identifier)True if the manager contains a sprite corresponding to the given identifier.Iterator<Sprite>iterator()Iterator on the set of sprites.voidnodeAttributeAdded(String graphId, long time, String nodeId, String attribute, Object value)A node attribute was added.voidnodeAttributeChanged(String graphId, long time, String nodeId, String attribute, Object oldValue, Object newValue)A node attribute was changed.voidnodeAttributeRemoved(String graphId, long time, String nodeId, String attribute)A node attribute was removed.voidremoveSprite(String identifier)Remove a sprite knowing its identifier.voidresetSpriteFactory()Reset the sprite factory to defaults.voidsetSpriteFactory(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:AttributeSinkA graph attribute was added.- Specified by:
graphAttributeAddedin 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:AttributeSinkA graph attribute was changed.- Specified by:
graphAttributeChangedin 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:AttributeSinkA graph attribute was removed.- Specified by:
graphAttributeRemovedin 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:AttributeSinkA edge attribute was added.- Specified by:
edgeAttributeAddedin 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:AttributeSinkA edge attribute was changed.- Specified by:
edgeAttributeChangedin 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:AttributeSinkA edge attribute was removed.- Specified by:
edgeAttributeRemovedin 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:AttributeSinkA node attribute was added.- Specified by:
nodeAttributeAddedin 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:AttributeSinkA node attribute was changed.- Specified by:
nodeAttributeChangedin 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:AttributeSinkA node attribute was removed.- Specified by:
nodeAttributeRemovedin 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.
-