Class StyleGroup
public class StyleGroup extends Style implements Iterable<Element>
The purpose of a style group is to allow retrieving all elements with the same style easily. Most of the time, with graphic engines, pushing the graphic state (the style, colors, line width, textures, gradients) is a costly operation. Doing it once for several elements can speed up things a lot. This is the purpose of the style group.
The action of drawing elements in group (first push style, then draw all elements) are called bulk drawing. All elements that can be drawn at once this way are called bulk elements.
In a style group it is not always possible do draw elements in a such a "bulk" operation. If the style contains "dynamic values" for example, that is value that depend on the value of an attribute stored on the element, or if the element is modified by an event (clicked, selected), the element will not be drawn the same as others.
The style group provides iterators on each of these categories of elements :
elements()allows to browse all elements contained in the group without exception.dynamicElements()allows to browse the subset of elements having a attribute that modify their style.elementsEvents()allows to browse the subset of elements modified by an event.bulkElements()allows to browse all remaining elements that have no dynamic attribute or event.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStyleGroup.ElementEventsDescription of an element that is actually modified by one or more events occurring on it.Nested classes/interfaces inherited from class org.graphstream.ui.graphicGraph.stylesheet.StyleConstants
StyleConstants.ArrowShape, StyleConstants.FillMode, StyleConstants.IconMode, StyleConstants.JComponents, StyleConstants.ShadowMode, StyleConstants.Shape, StyleConstants.ShapeKind, StyleConstants.SizeMode, StyleConstants.SpriteOrientation, StyleConstants.StrokeMode, StyleConstants.TextAlignment, StyleConstants.TextBackgroundMode, StyleConstants.TextMode, StyleConstants.TextStyle, StyleConstants.TextVisibilityMode, StyleConstants.Units, StyleConstants.VisibilityMode -
Field Summary
Fields Modifier and Type Field Description HashMap<String,GraphicElement.SwingElementRenderer>renderersAssociated renderers. -
Constructor Summary
Constructors Constructor Description StyleGroup(String identifier, Collection<Rule> rules, Element firstElement, StyleGroupSet.EventSet eventSet)New style group for a first graph element and the set of style rules that matches it. -
Method Summary
Modifier and Type Method Description voidactivateEventsFor(Element element)Before drawing an element that has events, use this method to activate the events, the style values will be modified accordingly.voidaddElement(Element element)Add a new graph element to the group.voidaddRenderer(String id, GraphicElement.SwingElementRenderer renderer)Add a renderer to this group.Iterable<? extends Element>bulkElements()Iterable set of elements that can be drawn in a bulk operation, that is the subset of all elements that are not dynamic or modified by an event.booleancontains(String elementId)True if the group contains the element whose identifier is given.booleancontains(Element element)True if the group contains the element given.voiddeactivateEvents()De-activate any events activated for an element.Iterable<Element>dynamicElements()Subset of elements that have dynamic style values and therefore must be rendered one by one, not in groups like others.booleanelementHasEvents(Element element)True if the given element actually has active events.booleanelementIsDynamic(Element element)True if the given element has dynamic style values provided by specific attributes.Iterable<? extends Element>elements()Iterable set of elements.Iterable<StyleGroup.ElementEvents>elementsEvents()Subset of elements that are actually modified by one or more events.ElementgetElement(String id)Return an element of the group, knowing its identifier.intgetElementCount()The number of elements of the group.Iterator<? extends Element>getElementIterator()Iterator on the set of graph elements of this group.StyleGroup.ElementEventsgetEventsFor(Element element)Set of events for a given element or null if the element has not currently occurring events.StringgetId()The group unique identifier.GraphicElement.SwingElementRenderergetRenderer(String id)The associated renderers.Selector.TypegetType()Type of graph element concerned by this style (node, edge, sprite, graph).ObjectgetValue(String property, String... events)Get the value of a given property.booleanhasDynamicElements()True if at least one of the style properties is dynamic (set according to an attribute of the element to draw).booleanhasEventElements()If true this group contains some elements that are actually changed by an event.booleanisElementDynamic(Element element)Test if an element is pushed as dynamic.booleanisEmpty()True if there are no elements in the group.Iterator<Element>iterator()voidrelease()Remove all graph elements of this group, and remove this group from the group list of each style rule.ElementremoveElement(Element element)Remove a graph element from the group.GraphicElement.SwingElementRendererremoveRenderer(String id)Remove a renderer.voidsetValue(String property, Object value)Redefinition of theStyleto forbid changing the values.StringtoString()StringtoString(int level)Methods inherited from class org.graphstream.ui.graphicGraph.stylesheet.Style
addAlternateStyle, augment, getArrowImage, getArrowShape, getArrowSize, getCanvasColor, getCanvasColor, getCanvasColorCount, getFillColor, getFillColorCount, getFillColors, getFillImage, getFillMode, getIcon, getIconMode, getJComponent, getPadding, getParent, getShadowColor, getShadowColorCount, getShadowColors, getShadowMode, getShadowOffset, getShadowWidth, getShape, getShapePoints, getSize, getSizeMode, getSpriteOrientation, getStrokeColor, getStrokeColor, getStrokeColorCount, getStrokeMode, getStrokeWidth, getTextAlignment, getTextBackgroundColor, getTextBackgroundColor, getTextBackgroundMode, getTextColor, getTextColor, getTextColorCount, getTextFont, getTextMode, getTextOffset, getTextPadding, getTextSize, getTextStyle, getTextVisibility, getTextVisibilityMode, getVisibility, getVisibilityMode, getZIndex, hasValue, reparent, setDefaultsMethods inherited from class org.graphstream.ui.graphicGraph.stylesheet.StyleConstants
convertColor, convertLabel, convertValue, convertWidth
-
Field Details
-
renderers
Associated renderers.
-
-
Constructor Details
-
StyleGroup
public StyleGroup(String identifier, Collection<Rule> rules, Element firstElement, StyleGroupSet.EventSet eventSet)New style group for a first graph element and the set of style rules that matches it. More graph elements can be added later.- Parameters:
identifier- The unique group identifier (seeStyleSheet.getStyleGroupIdFor(Element, ArrayList)).rules- The set of style rules for the style group (seeStyleSheet.getRulesFor(Element)).firstElement- The first element to construct the group.
-
-
Method Details
-
getId
The group unique identifier.- Returns:
- A style group identifier.
-
getType
Type of graph element concerned by this style (node, edge, sprite, graph).- Returns:
- The type of the style group elements.
-
hasDynamicElements
public boolean hasDynamicElements()True if at least one of the style properties is dynamic (set according to an attribute of the element to draw). Such elements cannot therefore be drawn in a group operation, but one by one.- Returns:
- True if one property is dynamic.
-
hasEventElements
public boolean hasEventElements()If true this group contains some elements that are actually changed by an event. Such elements cannot therefore be drawn in a group operation, but one by one.- Returns:
- True if the group contains some elements changed by an event.
-
elementHasEvents
True if the given element actually has active events.- Parameters:
element- The element to test.- Returns:
- True if the element has actually active events.
-
elementIsDynamic
True if the given element has dynamic style values provided by specific attributes.- Parameters:
element- The element to test.- Returns:
- True if the element has actually specific style attributes.
-
getValue
Get the value of a given property. This is a redefinition of the method inStyleto consider the fact a style group aggregates several style rules. -
isEmpty
public boolean isEmpty()True if there are no elements in the group.- Returns:
- True if the group is empty of elements.
-
contains
True if the group contains the element whose identifier is given.- Parameters:
elementId- The element to search.- Returns:
- true if the element is in the group.
-
contains
True if the group contains the element given.- Parameters:
element- The element to search.- Returns:
- true if the element is in the group.
-
getElement
Return an element of the group, knowing its identifier.- Parameters:
id- The searched element identifier.- Returns:
- The element corresponding to the identifier or null if not found.
-
getElementCount
public int getElementCount()The number of elements of the group.- Returns:
- The element count.
-
getElementIterator
Iterator on the set of graph elements of this group.- Returns:
- The elements iterator.
-
elements
Iterable set of elements. This the complete set of elements contained in this group without regard to the fact they are modified by an event or are dynamic. If you plan to respect events or dynamic elements, you must check the elements are not modified by events usingelementHasEvents(Element)and are not dynamic by usingelementIsDynamic(Element)and then draw modified elements usingelementsEvents()anddynamicElements(). But the easiest way of drawing is to use firstbulkElements()for all non dynamic non event elements, then thedynamicElements()andelementsEvents()to draw all dynamic and event elements.- Returns:
- All the elements in no particular order.
-
bulkElements
Iterable set of elements that can be drawn in a bulk operation, that is the subset of all elements that are not dynamic or modified by an event.- Returns:
- The iterable set of bulk elements.
-
elementsEvents
Subset of elements that are actually modified by one or more events. TheStyleGroup.ElementEventsclass contains the element and an array of events that can be pushed on the style group set.- Returns:
- The subset of elements modified by one or more events.
-
dynamicElements
Subset of elements that have dynamic style values and therefore must be rendered one by one, not in groups like others. Even though elements style can specify some dynamics, the elements must individually have attributes that specify the dynamic value. If the elements do not have these attributes they can be rendered in bulk operations.- Returns:
- The subset of dynamic elements of the group.
-
iterator
-
getRenderer
The associated renderers.- Returns:
- A renderer or null if not found.
-
getEventsFor
Set of events for a given element or null if the element has not currently occurring events.- Returns:
- A set of events or null if none occurring at that time.
-
isElementDynamic
Test if an element is pushed as dynamic. -
addElement
Add a new graph element to the group.- Parameters:
element- The new graph element to add.
-
removeElement
Remove a graph element from the group.- Parameters:
element- The element to remove.- Returns:
- The removed element, or null if the element was not found.
-
activateEventsFor
Before drawing an element that has events, use this method to activate the events, the style values will be modified accordingly. Events for this element must have been registered viapushEventFor(Element, String). After rendering thedeactivateEvents()MUST be called.- Parameters:
element- The element to push events for.
-
deactivateEvents
public void deactivateEvents()De-activate any events activated for an element. This method MUST be called ifactivateEventsFor(Element)has been called. -
release
public void release()Remove all graph elements of this group, and remove this group from the group list of each style rule. -
setValue
Redefinition of theStyleto forbid changing the values. -
addRenderer
Add a renderer to this group.- Parameters:
id- The renderer identifier.renderer- The renderer.
-
removeRenderer
Remove a renderer.- Parameters:
id- The renderer identifier.- Returns:
- The removed renderer or null if not found.
-
toString
-
toString
-