Class StyleGroupSet
- All Implemented Interfaces:
StyleSheetListener
public class StyleGroupSet extends Object implements StyleSheetListener
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
Nested Classes Modifier and Type Class Description 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
Constructors Constructor Description StyleGroupSet(StyleSheet stylesheet)
New empty style group set, using the given style sheet to create style groups. -
Method Summary
Modifier and Type Method Description 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.Stream<Edge>
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(Node node)
Get the style of a given node.StyleGroup
getStyleFor(GraphicSprite sprite)
Get the style of a given sprite.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.Stream<Node>
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.Stream<GraphicSprite>
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.
-
Constructor Details
-
StyleGroupSet
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 callrelease()
.- Parameters:
stylesheet
- The style sheet to use to create groups.
-
-
Method Details
-
getGroupCount
public int getGroupCount()Number of groups.- Returns:
- The number of groups.
-
getGroup
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
Iterator on the set of groups in no particular order.- Returns:
- An iterator on the group set.
-
groups
Iterable set of groups elements, in no particular order.- Returns:
- An iterable on the set of groups.
-
getZIterator
Iterator on the Z index.- Returns:
- The z index iterator.
-
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
Iterator on the style groups that cast a shadow.- Returns:
- The shadow groups iterator.
-
shadows
Iterable set of groups that cast shadow.- Returns:
- All the groups that cast a shadow.
-
containsNode
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
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
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
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
Get a node element knowing its identifier.- Parameters:
id
- The node identifier.- Returns:
- The node if it is in this set, else null.
-
getEdge
Get an edge element knowing its identifier.- Parameters:
id
- The edge identifier.- Returns:
- The edge if it is in this set, else null.
-
getSprite
Get a sprite element knowing its identifier.- Parameters:
id
- The sprite identifier.- Returns:
- The sprite if it is in this set, else null.
-
getGraph
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
Iterator on the set of nodes.- Returns:
- An iterator on all node elements contained in style groups.
-
getGraphIterator
Iterator on the set of graphs.- Returns:
- An iterator on all graph elements contained in style groups.
-
nodes
-
edges
-
sprites
-
graphs
Iterable set of graphs.- Returns:
- The set of all graphs.
-
getEdgeIterator
Iterator on the set of edges.- Returns:
- An iterator on all edge elements contained in style groups.
-
getSpriteIterator
Iterator on the set of sprite.- Returns:
- An iterator on all sprite elements contained in style groups.
-
getElementGroup
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
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
Get the style of a given node.- Parameters:
node
- The node to search for.- Returns:
- The node style.
-
getStyleFor
Get the style of a given edge.- Parameters:
edge
- The edge to search for.- Returns:
- The edge style.
-
getStyleFor
Get the style of a given sprite.- Parameters:
sprite
- The node to search for.- Returns:
- The sprite style.
-
getStyleFor
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
The Z index object.- Returns:
- The Z index.
-
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, userelease()
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
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
Remove an element from the group set. If the group becomes empty after the element removal, depending on the setting ofareEmptyGroupRemoved()
, 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
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
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
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
Pop a global event from the event set.- Parameters:
event
- The event to remove.
-
popEventFor
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
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
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
Add a listener for element style changes.- Parameters:
listener
- The listener to add.
-
removeListener
Remove a style change listener.- Parameters:
listener
- The listener to remove.
-
styleAdded
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 interfaceStyleSheetListener
- 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 interfaceStyleSheetListener
-
toString
-