org.graphstream.ui.graphicGraph
Class StyleGroupSet

java.lang.Object
  extended by org.graphstream.ui.graphicGraph.StyleGroupSet
All Implemented Interfaces:
StyleSheetListener

public class StyleGroupSet
extends Object
implements StyleSheetListener

A set of style groups.

This class is in charge or storing all the style groups and to update them. Each time an element is added or removed the groups are updated. Each time the style sheet changes the groups are updated.

Author:
Antoine Dutot

Nested Class Summary
 class StyleGroupSet.EventSet
          Set of events (meta-classes) actually active.
 class StyleGroupSet.ShadowSet
          Set of groups that cast a shadow.
 class StyleGroupSet.ZIndex
          All the style groups sorted by their Z index.
 
Constructor Summary
StyleGroupSet(StyleSheet stylesheet)
          New empty style group set, using the given style sheet to create style groups.
 
Method Summary
 StyleGroup addElement(Element element)
          Add an element and bind it to its style group.
 void addListener(StyleGroupListener listener)
          Add a listener for element style changes.
 boolean areEmptyGroupRemoved()
          True if groups are removed when becoming empty.
 void checkElementStyleGroup(Element element)
          Check if an element need to change from a style group to another.
 void clear()
          Empties this style group set.
 boolean containsEdge(String id)
          True if the set contains and styles the edge whose identifier is given.
 boolean containsGraph(String id)
          True if the set contains and styles the graph whose identifier is given.
 boolean containsNode(String id)
          True if the set contains and styles the node whose identifier is given.
 boolean containsSprite(String id)
          True if the set contains and styles the sprite whose identifier is given.
 Iterable<? extends Edge> edges()
          Iterable set of edges.
 Edge getEdge(String id)
          Get an edge element knowing its identifier.
 int getEdgeCount()
          The number of edges referenced.
 Iterator<? extends Edge> getEdgeIterator()
          Iterator on the set of edges.
 String getElementGroup(Element element)
          Retrieve the group identifier of an element knowing the element identifier.
 Graph getGraph(String id)
          Get a graph element knowing its identifier.
 Iterator<? extends Graph> getGraphIterator()
          Iterator on the set of graphs.
 StyleGroup getGroup(String groupId)
          Return a group by its unique identifier.
 int getGroupCount()
          Number of groups.
 Iterator<? extends StyleGroup> getGroupIterator()
          Iterator on the set of groups in no particular order.
 Node getNode(String id)
          Get a node element knowing its identifier.
 int getNodeCount()
          The number of nodes referenced.
 Iterator<? extends Node> getNodeIterator()
          Iterator on the set of nodes.
 Iterator<StyleGroup> getShadowIterator()
          Iterator on the style groups that cast a shadow.
 StyleGroupSet.ShadowSet getShadowSet()
          The set of style groups that cast a shadow.
 GraphicSprite getSprite(String id)
          Get a sprite element knowing its identifier.
 int getSpriteCount()
          The number of sprites referenced.
 Iterator<? extends GraphicSprite> getSpriteIterator()
          Iterator on the set of sprite.
 StyleGroup getStyleFor(Edge edge)
          Get the style of a given edge.
 StyleGroup getStyleFor(Graph graph)
          Get the style of a given graph.
 StyleGroup getStyleFor(GraphicSprite sprite)
          Get the style of a given sprite.
 StyleGroup getStyleFor(Node node)
          Get the style of a given node.
 StyleGroup getStyleForElement(Element element)
          Get the style of an element.
 StyleGroupSet.ZIndex getZIndex()
          The Z index object.
 Iterator<HashSet<StyleGroup>> getZIterator()
          Iterator on the Z index.
 Iterable<? extends Graph> graphs()
          Iterable set of graphs.
 Iterable<? extends StyleGroup> groups()
          Iterable set of groups elements, in no particular order.
 Iterable<? extends Node> nodes()
          Iterable set of nodes.
 void popElementAsDynamic(Element element)
          Remove the given element from the subset of elements having dynamic style attribute values.
 void popEvent(String event)
          Pop a global event from the event set.
 void popEventFor(Element element, String event)
          Pop an event specifically for a given element.
 void pushElementAsDynamic(Element element)
          Specify the given element has dynamic style attribute values.
 void pushEvent(String event)
          Push a global event on the event stack.
 void pushEventFor(Element element, String event)
          Push an event specifically for a given element.
 void release()
          Release any dependency to the style sheet.
 void removeElement(Element element)
          Remove an element from the group set.
 void removeListener(StyleGroupListener listener)
          Remove a style change listener.
 void setRemoveEmptyGroups(boolean on)
          Remove or keep groups that becomes empty, if true the groups are removed.
 Iterable<StyleGroup> shadows()
          Iterable set of groups that cast shadow.
 Iterable<? extends GraphicSprite> sprites()
          Iterable set of sprites.
 void styleAdded(Rule oldRule, Rule newRule)
          A style was changed or added.
 void styleSheetCleared()
          The complete style sheet was cleared.
 String toString()
           
 Iterable<HashSet<StyleGroup>> zIndex()
          Iterable set of "subsets of groups" sorted by Z level.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StyleGroupSet

public StyleGroupSet(StyleSheet stylesheet)
New empty style group set, using the given style sheet to create style groups. The group set installs itself as a listener of the style sheet. So in order to completely stop using such a group, you must call release().

Parameters:
stylesheet - The style sheet to use to create groups.
Method Detail

getGroupCount

public int getGroupCount()
Number of groups.

Returns:
The number of groups.

getGroup

public StyleGroup getGroup(String groupId)
Return a group by its unique identifier. The way group identifier are constructed reflects their contents.

Parameters:
groupId - The group identifier.
Returns:
The corresponding group or null if not found.

getGroupIterator

public Iterator<? extends StyleGroup> getGroupIterator()
Iterator on the set of groups in no particular order.

Returns:
An iterator on the group set.

groups

public Iterable<? extends StyleGroup> groups()
Iterable set of groups elements, in no particular order.

Returns:
An iterable on the set of groups.

getZIterator

public Iterator<HashSet<StyleGroup>> getZIterator()
Iterator on the Z index.

Returns:
The z index iterator.

zIndex

public Iterable<HashSet<StyleGroup>> zIndex()
Iterable set of "subsets of groups" sorted by Z level. Each subset of groups is at the same Z level.

Returns:
The z levels.

getShadowIterator

public Iterator<StyleGroup> getShadowIterator()
Iterator on the style groups that cast a shadow.

Returns:
The shadow groups iterator.

shadows

public Iterable<StyleGroup> shadows()
Iterable set of groups that cast shadow.

Returns:
All the groups that cast a shadow.

containsNode

public boolean containsNode(String id)
True if the set contains and styles the node whose identifier is given.

Parameters:
id - The node identifier.
Returns:
True if the node is in this set.

containsEdge

public boolean containsEdge(String id)
True if the set contains and styles the edge whose identifier is given.

Parameters:
id - The edge identifier.
Returns:
True if the edge is in this set.

containsSprite

public boolean containsSprite(String id)
True if the set contains and styles the sprite whose identifier is given.

Parameters:
id - The sprite identifier.
Returns:
True if the sprite is in this set.

containsGraph

public boolean containsGraph(String id)
True if the set contains and styles the graph whose identifier is given.

Parameters:
id - The graph identifier.
Returns:
True if the graph is in this set.

getNode

public Node getNode(String id)
Get a node element knowing its identifier.

Parameters:
id - The node identifier.
Returns:
The node if it is in this set, else null.

getEdge

public Edge getEdge(String id)
Get an edge element knowing its identifier.

Parameters:
id - The edge identifier.
Returns:
The edge if it is in this set, else null.

getSprite

public GraphicSprite getSprite(String id)
Get a sprite element knowing its identifier.

Parameters:
id - The sprite identifier.
Returns:
The sprite if it is in this set, else null.

getGraph

public Graph getGraph(String id)
Get a graph element knowing its identifier.

Parameters:
id - The graph identifier.
Returns:
The graph if it is in this set, else null.

getNodeCount

public int getNodeCount()
The number of nodes referenced.

Returns:
The node count.

getEdgeCount

public int getEdgeCount()
The number of edges referenced.

Returns:
The edge count.

getSpriteCount

public int getSpriteCount()
The number of sprites referenced.

Returns:
The sprite count.

getNodeIterator

public Iterator<? extends Node> getNodeIterator()
Iterator on the set of nodes.

Returns:
An iterator on all node elements contained in style groups.

getGraphIterator

public Iterator<? extends Graph> getGraphIterator()
Iterator on the set of graphs.

Returns:
An iterator on all graph elements contained in style groups.

nodes

public Iterable<? extends Node> nodes()
Iterable set of nodes.

Returns:
The set of all nodes.

graphs

public Iterable<? extends Graph> graphs()
Iterable set of graphs.

Returns:
The set of all graphs.

getEdgeIterator

public Iterator<? extends Edge> getEdgeIterator()
Iterator on the set of edges.

Returns:
An iterator on all edge elements contained in style groups.

edges

public Iterable<? extends Edge> edges()
Iterable set of edges.

Returns:
The set of all edges.

getSpriteIterator

public Iterator<? extends GraphicSprite> getSpriteIterator()
Iterator on the set of sprite.

Returns:
An iterator on all sprite elements contained in style groups.

sprites

public Iterable<? extends GraphicSprite> sprites()
Iterable set of sprites.

Returns:
The set of all sprites.

getElementGroup

public String getElementGroup(Element element)
Retrieve the group identifier of an element knowing the element identifier.

Parameters:
element - The element to search for.
Returns:
Identifier of the group containing the element.

getStyleForElement

public StyleGroup getStyleForElement(Element element)
Get the style of an element.

Parameters:
element - The element to search for.
Returns:
The style group of the element (which is also a style).

getStyleFor

public StyleGroup getStyleFor(Node node)
Get the style of a given node.

Parameters:
node - The node to search for.
Returns:
The node style.

getStyleFor

public StyleGroup getStyleFor(Edge edge)
Get the style of a given edge.

Parameters:
edge - The edge to search for.
Returns:
The edge style.

getStyleFor

public StyleGroup getStyleFor(GraphicSprite sprite)
Get the style of a given sprite.

Parameters:
sprite - The node to search for.
Returns:
The sprite style.

getStyleFor

public StyleGroup getStyleFor(Graph graph)
Get the style of a given graph.

Parameters:
graph - The node to search for.
Returns:
The graph style.

areEmptyGroupRemoved

public boolean areEmptyGroupRemoved()
True if groups are removed when becoming empty. This setting allows to keep empty group when the set of elements is quite dynamic. This allows to avoid recreting groups when an element appears and disappears regularly.

Returns:
True if the groups are removed when empty.

getZIndex

public StyleGroupSet.ZIndex getZIndex()
The Z index object.

Returns:
The Z index.

getShadowSet

public StyleGroupSet.ShadowSet getShadowSet()
The set of style groups that cast a shadow.

Returns:
The set of shadowed style groups.

release

public void release()
Release any dependency to the style sheet.


clear

public void clear()
Empties this style group set. The style sheet is listener is not removed, use release() to do that.


setRemoveEmptyGroups

public void setRemoveEmptyGroups(boolean on)
Remove or keep groups that becomes empty, if true the groups are removed. If this setting was set to false, and is now true, the group set is purged of the empty groups.

Parameters:
on - If true the groups will be removed.

addElement

public StyleGroup addElement(Element element)
Add an element and bind it to its style group. The group is created if needed.

Parameters:
element - The element to add.
Returns:
The style group where the element was added.

removeElement

public void removeElement(Element element)
Remove an element from the group set. If the group becomes empty after the element removal, depending on the setting of areEmptyGroupRemoved(), the group is deleted or kept. Keeping groups allows to handle faster elements that constantly appear and disappear.

Parameters:
element - The element to remove.

checkElementStyleGroup

public void checkElementStyleGroup(Element element)
Check if an element need to change from a style group to another.

When an element can have potentially changed style due to some of its attributes (ui.class for example), instead of removing it then reading it, use this method to move the element from its current style group to a potentially different style group.

Explanation of this method : checking the style of an element may be done by removing it (removeElement(Element)) and then re-adding it ( addElement(Element)). This must be done by the element since it knows when to check this. However you cannot only remove and add, since the style group inside which the element is can have events occurring on it, and these events must be passed from its old style to its new style. This method does all this information passing.

Parameters:
element - The element to move.

pushEvent

public void pushEvent(String event)
Push a global event on the event stack. Events trigger the replacement of a style by an alternative style (or meta-class) when possible. If an event is on the event stack, each time a style has an alternative corresponding to the event, the alternative is used instead of the style.

Parameters:
event - The event to push.

pushEventFor

public void pushEventFor(Element element,
                         String event)
Push an event specifically for a given element. This is normally done automatically by the graphic element.

Parameters:
element - The element considered.
event - The event to push.

popEvent

public void popEvent(String event)
Pop a global event from the event set.

Parameters:
event - The event to remove.

popEventFor

public void popEventFor(Element element,
                        String event)
Pop an event specifically for a given element. This is normally done automatically by the graphic element.

Parameters:
element - The element considered.
event - The event to pop.

pushElementAsDynamic

public void pushElementAsDynamic(Element element)
Specify the given element has dynamic style attribute values. This is normally done automatically by the graphic element.

Parameters:
element - The element to add to the dynamic subset.

popElementAsDynamic

public void popElementAsDynamic(Element element)
Remove the given element from the subset of elements having dynamic style attribute values. This is normally done automatically by the graphic element.

Parameters:
element - The element to remove from the dynamic subset.

addListener

public void addListener(StyleGroupListener listener)
Add a listener for element style changes.

Parameters:
listener - The listener to add.

removeListener

public void removeListener(StyleGroupListener listener)
Remove a style change listener.

Parameters:
listener - The listener to remove.

styleAdded

public void styleAdded(Rule oldRule,
                       Rule newRule)
Description copied from interface: StyleSheetListener
A style was changed or added. To differentiate the addition of a new style from a change (augmentation) of an existing style, two values are passed, the old style if augmented and the new style. The first is set to null if the style is added. The old style is set to a value if is was augmented.

Specified by:
styleAdded in interface StyleSheetListener
Parameters:
oldRule - The style that changed.
newRule - The style that was added to the style sheet.

styleSheetCleared

public void styleSheetCleared()
Description copied from interface: StyleSheetListener
The complete style sheet was cleared.

Specified by:
styleSheetCleared in interface StyleSheetListener

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.