Search this API

y.view.hierarchy
Class GroupNodePainter

java.lang.Object
  extended by y.view.hierarchy.GroupNodePainter
All Implemented Interfaces:
GenericNodeRealizer.ContainsTest, GenericNodeRealizer.GenericMouseInputEditorProvider, GenericNodeRealizer.Initializer, GenericNodeRealizer.Painter

public class GroupNodePainter
extends java.lang.Object
implements GenericNodeRealizer.Painter, GenericNodeRealizer.GenericMouseInputEditorProvider, GenericNodeRealizer.Initializer, GenericNodeRealizer.ContainsTest

A decorator GenericNodeRealizer.Painter for group/folder nodes that adds a state label that display whether the node is an opened group node or a closed folder node.

The state label can be clicked to toggle the open/close state of the node if the decorator is registered as GenericNodeRealizer.GenericMouseInputEditorProvider.
The icons displayed by the state label can be exchanged using methods setOpenGroupIcon(javax.swing.Icon) and setClosedGroupIcon(javax.swing.Icon). Moreover, overwriting method getStateLabel(y.view.NodeRealizer) allows for exhaustive customization of the state label.

Method setInnerGraphDisplayEnabled(boolean) can be used to determine whether the inner graph of the group node shall be painted or not.

Method setGroupDepthFillColorEnabled(boolean) can be used to determine whether deeper nested graphs shall get darker fill colors for deeper nested group nodes to achieve a better outline.

 

Nested Class Summary
static class GroupNodePainter.GroupStateEditor
          A MouseInputEditor implementation that closes group nodes and opens folder nodes in response to state change gestures (that is a mouse click at an appropriate location).
static class GroupNodePainter.GroupStateStyle
          A GroupStateStyle provides opacity information for painting group state icons.
 
Field Summary
static java.lang.String GROUP_STATE_STYLE_ID
          Style property key for style information used to render group state icons.
 
Constructor Summary
GroupNodePainter()
          Creates a new instance of GroupNodePainter that uses a ShapeNodePainter to paint the node itself.
GroupNodePainter(GenericNodeRealizer.Painter painterDelegate)
          Creates a new instance of GroupNodePainter that uses the given GenericNodeRealizer.Painter implementation to paint node itself and adds the state label and the ability to open/close this node to it.
 
Method Summary
protected  void configureDefaultLabel(NodeRealizer context, NodeLabel label)
          Configures the given label as default group label.
 boolean contains(NodeRealizer context, double x, double y)
          Determines whether the point given by the specified coordinates lies within the (visual) bounds of the specified realizer or within the bounds of the specified realizer's default label (if it exists).
 MouseInputEditor findMouseInputEditor(NodeRealizer context, Graph2DView view, double x, double y, HitInfo hitInfo)
          Returns an editor to handle mouse events for group/folder nodes that are configured to use this GroupNodePainter instance as their GenericNodeRealizer.GenericMouseInputEditorProvider.
 javax.swing.Icon getClosedGroupIcon()
          Returns the icon that is used for the state label when the group is closed.
protected  float getGroupStateOpacity(NodeRealizer context)
          Returns the state icon's opacity value for the given NodeRealizer.
protected  HierarchyManager getHierarchyManager(Graph graph)
          Returns the hierarchy manager responsibly for managing the node represented by this realizer.
protected  YInsets getInnerGraphInsets(NodeRealizer context)
          Returns the insets for painting inner graphs.
 javax.swing.Icon getOpenGroupIcon()
          Returns the icon that is used for the state label when the group is opened.
 GenericNodeRealizer.Painter getPainterDelegate()
          Returns the delegate painter that paints the node itself.
protected  NodeLabel getStateLabel(NodeRealizer context)
          Returns the state label of this realizer.
 void initialize(NodeRealizer context)
          Configures the given realizer's default label as default group label.
 boolean isGroupDepthFillColorEnabled()
          Whether or not the fill color of this node gets adapted to reflect the local group depth of this node within the graph hierarchy.
 boolean isInnerGraphDisplayEnabled()
          Returns whether or not the inner graph of a folder node should be displayed.
 void paint(NodeRealizer context, java.awt.Graphics2D graphics)
          Used as a callback for the GenericNodeRealizer.paint(Graphics2D) method.
protected  void paintGroupState(NodeRealizer context, java.awt.Graphics2D graphics, boolean sloppy)
          Paints an icon representing the context realizer's group state.
protected  void paintInnerGraph(NodeRealizer context, java.awt.Graphics2D gfx)
          Used to paint the inner graph of a folder node when innerGraphDisplay is enabled.
 void paintSloppy(NodeRealizer context, java.awt.Graphics2D graphics)
          Used as a callback for the GenericNodeRealizer.paintSloppy(Graphics2D) method.
 void setClosedGroupIcon(javax.swing.Icon icon)
          Sets the icon to be used for the state label when the group is closed.
 void setGroupDepthFillColorEnabled(boolean enabled)
          Whether or not the fill color of this node should be adapted to reflect the local group depth of this node within the graph hierarchy.
 void setInnerGraphDisplayEnabled(boolean innerGraphDisplayEnabled)
          Sets whether or not the inner graph of a folder node should be displayed.
 void setOpenGroupIcon(javax.swing.Icon icon)
          Sets the icon to be used for the state label when the group is open.
protected  boolean shouldChangeState(NodeRealizer context, double x, double y)
          Determines whether or not a state change gesture at the specified point should result in a group state change for the node represented by the specified node realizer.
protected  boolean shouldConfigureDefaultLabel(NodeRealizer context, NodeLabel label)
          Determines if the given label should be configured as default group label.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROUP_STATE_STYLE_ID

public static final java.lang.String GROUP_STATE_STYLE_ID
Style property key for style information used to render group state icons. Property values have to be of type GroupNodePainter.GroupStateStyle. Style properties registered for this key are considered transient and will not be serialized.

See Also:
paintGroupState(y.view.NodeRealizer, java.awt.Graphics2D, boolean), GenericNodeRealizer.setStyleProperty(String, Object), Constant Field Values
Constructor Detail

GroupNodePainter

public GroupNodePainter()
Creates a new instance of GroupNodePainter that uses a ShapeNodePainter to paint the node itself.


GroupNodePainter

public GroupNodePainter(GenericNodeRealizer.Painter painterDelegate)
Creates a new instance of GroupNodePainter that uses the given GenericNodeRealizer.Painter implementation to paint node itself and adds the state label and the ability to open/close this node to it.

Parameters:
painterDelegate - an implementation of GenericNodeRealizer.Painter that will be used for painting the node itself.
Method Detail

getPainterDelegate

public GenericNodeRealizer.Painter getPainterDelegate()
Returns the delegate painter that paints the node itself.

Returns:
the delegate painter that paints the node itself.
See Also:
GroupNodePainter(y.view.GenericNodeRealizer.Painter)

paint

public void paint(NodeRealizer context,
                  java.awt.Graphics2D graphics)
Description copied from interface: GenericNodeRealizer.Painter
Used as a callback for the GenericNodeRealizer.paint(Graphics2D) method.

Specified by:
paint in interface GenericNodeRealizer.Painter

paintSloppy

public void paintSloppy(NodeRealizer context,
                        java.awt.Graphics2D graphics)
Description copied from interface: GenericNodeRealizer.Painter
Used as a callback for the GenericNodeRealizer.paintSloppy(Graphics2D) method.

Specified by:
paintSloppy in interface GenericNodeRealizer.Painter

paintGroupState

protected void paintGroupState(NodeRealizer context,
                               java.awt.Graphics2D graphics,
                               boolean sloppy)
Paints an icon representing the context realizer's group state. Called from paint(y.view.NodeRealizer, java.awt.Graphics2D) and paintSloppy(y.view.NodeRealizer, java.awt.Graphics2D). The default implementation calls the state label's paint method.

Parameters:
context - the context node.
graphics - the graphics context to use.
sloppy - whether or not to paint in sloppy mode.

getGroupStateOpacity

protected float getGroupStateOpacity(NodeRealizer context)
Returns the state icon's opacity value for the given NodeRealizer.

The default implementation checks the style property GROUP_STATE_STYLE_ID for the opacity value to be set.

Parameters:
context - The node realizer where the opacity value is set for
Returns:
a value between 0 (transparent) and 1 (opaque)
See Also:
GroupNodePainter.GroupStateStyle.getOpacity()

paintInnerGraph

protected void paintInnerGraph(NodeRealizer context,
                               java.awt.Graphics2D gfx)
Used to paint the inner graph of a folder node when innerGraphDisplay is enabled.

Parameters:
context - the node realizer that this painter is associated with.
gfx - the graphics context to paint to.

getInnerGraphInsets

protected YInsets getInnerGraphInsets(NodeRealizer context)
Returns the insets for painting inner graphs.

Parameters:
context - the node realizer for which an inner graph is painted.
Returns:
the insets for painting inner graphs.
See Also:
paintInnerGraph(y.view.NodeRealizer, java.awt.Graphics2D)

getClosedGroupIcon

public javax.swing.Icon getClosedGroupIcon()
Returns the icon that is used for the state label when the group is closed.

Returns:
the icon used to illustrate a closed state.

setClosedGroupIcon

public void setClosedGroupIcon(javax.swing.Icon icon)
Sets the icon to be used for the state label when the group is closed.

Parameters:
icon - used to illustrate a closed state.

getOpenGroupIcon

public javax.swing.Icon getOpenGroupIcon()
Returns the icon that is used for the state label when the group is opened.

Returns:
the icon used to illustrate an open state.

setOpenGroupIcon

public void setOpenGroupIcon(javax.swing.Icon icon)
Sets the icon to be used for the state label when the group is open.

Parameters:
icon - used to illustrate an open state.

setGroupDepthFillColorEnabled

public void setGroupDepthFillColorEnabled(boolean enabled)
Whether or not the fill color of this node should be adapted to reflect the local group depth of this node within the graph hierarchy. By default this feature is enabled.

Parameters:
enabled - whether the group depth shall be reflected by the groups fill color. Default is true.

isGroupDepthFillColorEnabled

public boolean isGroupDepthFillColorEnabled()
Whether or not the fill color of this node gets adapted to reflect the local group depth of this node within the graph hierarchy.

Returns:
true whether deeper nested groups will have darker fill colors, false otherwise.
See Also:
setGroupDepthFillColorEnabled(boolean)

getStateLabel

protected NodeLabel getStateLabel(NodeRealizer context)
Returns the state label of this realizer.

Parameters:
context - the node realizer that this painter is associated with.
Returns:
the state label for the current state.

getHierarchyManager

protected HierarchyManager getHierarchyManager(Graph graph)
Returns the hierarchy manager responsibly for managing the node represented by this realizer.

Parameters:
graph - the graph for whom the HierarchyManager shall be returned.
Returns:
the HierarchyManager for the given graph.

isInnerGraphDisplayEnabled

public boolean isInnerGraphDisplayEnabled()
Returns whether or not the inner graph of a folder node should be displayed.

Returns:
whether or not the inner graph of a folder node should be displayed.

setInnerGraphDisplayEnabled

public void setInnerGraphDisplayEnabled(boolean innerGraphDisplayEnabled)
Sets whether or not the inner graph of a folder node should be displayed. The node represented by this painter must be a folder node in the graph hierarchy and the realizer must be in closed mode.

Parameters:
innerGraphDisplayEnabled - whether or not the inner graph of a folder node should be displayed.

findMouseInputEditor

public MouseInputEditor findMouseInputEditor(NodeRealizer context,
                                             Graph2DView view,
                                             double x,
                                             double y,
                                             HitInfo hitInfo)
Returns an editor to handle mouse events for group/folder nodes that are configured to use this GroupNodePainter instance as their GenericNodeRealizer.GenericMouseInputEditorProvider.

By default, a GroupNodePainter.GroupStateEditor instance that closes groups/opens folders when shouldChangeState yields true is returned.

Specified by:
findMouseInputEditor in interface GenericNodeRealizer.GenericMouseInputEditorProvider
Parameters:
context - the node context.
view - the component that received the mouse event.
x - the x-component of the world (graph) coordinate of the event.
y - the y-component of the world (graph) coordinate of the event.
hitInfo - the elements of the specified view's graph at the event location.
Returns:
a MouseInputEditor instance that handles mouse events at the given coordinates or null if events at the given coordinates are ignored.
See Also:
GroupNodePainter.GroupStateEditor

shouldChangeState

protected boolean shouldChangeState(NodeRealizer context,
                                    double x,
                                    double y)
Determines whether or not a state change gesture at the specified point should result in a group state change for the node represented by the specified node realizer.

The default implementation returns true if the specified point lies in the group node's state label and false otherwise.

Called from findMouseInputEditor.

Parameters:
context - the node context.
x - the x-coordinate of the state change gesture.
y - the y-coordinate of the state change gesture.
Returns:
true if the group state should be changed when the appropriate gesture is received at the specified coordinates; false otherwise.

initialize

public void initialize(NodeRealizer context)
Configures the given realizer's default label as default group label.

Calls shouldConfigureDefaultLabel and configureDefaultLabel.

Specified by:
initialize in interface GenericNodeRealizer.Initializer
See Also:
shouldConfigureDefaultLabel(NodeRealizer, NodeLabel), configureDefaultLabel(NodeRealizer, NodeLabel)

shouldConfigureDefaultLabel

protected boolean shouldConfigureDefaultLabel(NodeRealizer context,
                                              NodeLabel label)
Determines if the given label should be configured as default group label.

Called from initialize.

Parameters:
context - the node context.
label - the label to be checked
Returns:
true if the given label should be configured as default group label and false otherwise.
See Also:
initialize(NodeRealizer), configureDefaultLabel(NodeRealizer, NodeLabel)

configureDefaultLabel

protected void configureDefaultLabel(NodeRealizer context,
                                     NodeLabel label)
Configures the given label as default group label.

Called from initialize.

Parameters:
context - the node context.
label - the label to be configured
See Also:
initialize(NodeRealizer), shouldConfigureDefaultLabel(NodeRealizer, NodeLabel)

contains

public boolean contains(NodeRealizer context,
                        double x,
                        double y)
Determines whether the point given by the specified coordinates lies within the (visual) bounds of the specified realizer or within the bounds of the specified realizer's default label (if it exists).

Specified by:
contains in interface GenericNodeRealizer.ContainsTest

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.