public class StyleGroup extends Style implements java.lang.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.Modifier and Type | Class and Description |
---|---|
static class |
StyleGroup.ElementEvents
Description of an element that is actually modified by one or more events
occurring on it.
|
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
Modifier and Type | Field and Description |
---|---|
java.util.HashMap<java.lang.String,GraphicElement.SwingElementRenderer> |
renderers
Associated renderers.
|
Constructor and Description |
---|
StyleGroup(java.lang.String identifier,
java.util.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.
|
Modifier and Type | Method and Description |
---|---|
void |
activateEventsFor(Element element)
Before drawing an element that has events, use this method to activate the
events, the style values will be modified accordingly.
|
void |
addElement(Element element)
Add a new graph element to the group.
|
void |
addRenderer(java.lang.String id,
GraphicElement.SwingElementRenderer renderer)
Add a renderer to this group.
|
java.lang.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.
|
boolean |
contains(Element element)
True if the group contains the element given.
|
boolean |
contains(java.lang.String elementId)
True if the group contains the element whose identifier is given.
|
void |
deactivateEvents()
De-activate any events activated for an element.
|
java.lang.Iterable<Element> |
dynamicElements()
Subset of elements that have dynamic style values and therefore must be
rendered one by one, not in groups like others.
|
boolean |
elementHasEvents(Element element)
True if the given element actually has active events.
|
boolean |
elementIsDynamic(Element element)
True if the given element has dynamic style values provided by specific
attributes.
|
java.lang.Iterable<? extends Element> |
elements()
Iterable set of elements.
|
java.lang.Iterable<StyleGroup.ElementEvents> |
elementsEvents()
Subset of elements that are actually modified by one or more events.
|
Element |
getElement(java.lang.String id)
Return an element of the group, knowing its identifier.
|
int |
getElementCount()
The number of elements of the group.
|
java.util.Iterator<? extends Element> |
getElementIterator()
Iterator on the set of graph elements of this group.
|
StyleGroup.ElementEvents |
getEventsFor(Element element)
Set of events for a given element or null if the element has not currently
occurring events.
|
java.lang.String |
getId()
The group unique identifier.
|
GraphicElement.SwingElementRenderer |
getRenderer(java.lang.String id)
The associated renderers.
|
Selector.Type |
getType()
Type of graph element concerned by this style (node, edge, sprite, graph).
|
java.lang.Object |
getValue(java.lang.String property,
java.lang.String... events)
Get the value of a given property.
|
boolean |
hasDynamicElements()
True if at least one of the style properties is dynamic (set according to an
attribute of the element to draw).
|
boolean |
hasEventElements()
If true this group contains some elements that are actually changed by an
event.
|
boolean |
isElementDynamic(Element element)
Test if an element is pushed as dynamic.
|
boolean |
isEmpty()
True if there are no elements in the group.
|
java.util.Iterator<Element> |
iterator() |
void |
release()
Remove all graph elements of this group, and remove this group from the group
list of each style rule.
|
Element |
removeElement(Element element)
Remove a graph element from the group.
|
GraphicElement.SwingElementRenderer |
removeRenderer(java.lang.String id)
Remove a renderer.
|
void |
setValue(java.lang.String property,
java.lang.Object value)
Redefinition of the
Style to forbid changing the values. |
java.lang.String |
toString() |
java.lang.String |
toString(int level) |
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, setDefaults
convertColor, convertLabel, convertValue, convertWidth
public java.util.HashMap<java.lang.String,GraphicElement.SwingElementRenderer> renderers
public StyleGroup(java.lang.String identifier, java.util.Collection<Rule> rules, Element firstElement, StyleGroupSet.EventSet eventSet)
identifier
- The unique group identifier (see
StyleSheet.getStyleGroupIdFor(Element, ArrayList)
).rules
- The set of style rules for the style group (see
StyleSheet.getRulesFor(Element)
).firstElement
- The first element to construct the group.public java.lang.String getId()
public Selector.Type getType()
public boolean hasDynamicElements()
public boolean hasEventElements()
public boolean elementHasEvents(Element element)
element
- The element to test.public boolean elementIsDynamic(Element element)
element
- The element to test.public java.lang.Object getValue(java.lang.String property, java.lang.String... events)
Style
to consider the fact a
style group aggregates several style rules.public boolean isEmpty()
public boolean contains(java.lang.String elementId)
elementId
- The element to search.public boolean contains(Element element)
element
- The element to search.public Element getElement(java.lang.String id)
id
- The searched element identifier.public int getElementCount()
public java.util.Iterator<? extends Element> getElementIterator()
public java.lang.Iterable<? extends Element> elements()
elementHasEvents(Element)
and are not dynamic by using
elementIsDynamic(Element)
and then draw modified elements using
elementsEvents()
and dynamicElements()
. But the easiest way
of drawing is to use first bulkElements()
for all non dynamic non
event elements, then the dynamicElements()
and
elementsEvents()
to draw all dynamic and event elements.public java.lang.Iterable<? extends Element> bulkElements()
public java.lang.Iterable<StyleGroup.ElementEvents> elementsEvents()
StyleGroup.ElementEvents
class contains the element and an array of events that
can be pushed on the style group set.public java.lang.Iterable<Element> dynamicElements()
public java.util.Iterator<Element> iterator()
iterator
in interface java.lang.Iterable<Element>
public GraphicElement.SwingElementRenderer getRenderer(java.lang.String id)
public StyleGroup.ElementEvents getEventsFor(Element element)
public boolean isElementDynamic(Element element)
public void addElement(Element element)
element
- The new graph element to add.public Element removeElement(Element element)
element
- The element to remove.public void activateEventsFor(Element element)
pushEventFor(Element, String)
.
After rendering the deactivateEvents()
MUST be called.element
- The element to push events for.public void deactivateEvents()
activateEventsFor(Element)
has been called.public void release()
public void setValue(java.lang.String property, java.lang.Object value)
Style
to forbid changing the values.public void addRenderer(java.lang.String id, GraphicElement.SwingElementRenderer renderer)
id
- The renderer identifier.renderer
- The renderer.public GraphicElement.SwingElementRenderer removeRenderer(java.lang.String id)
id
- The renderer identifier.