Search this API

y.view.hierarchy
Class GroupLayoutConfigurator

java.lang.Object
  extended by y.view.hierarchy.GroupLayoutConfigurator

public class GroupLayoutConfigurator
extends java.lang.Object

This convenience class helps to prepare a hierarchically grouped Graph2D for an automatic assignment of layout information. Basically, it translates the hierarchy information maintained by an HierarchyManager to data provider-based hierarchy information that is understood by automatic layout algorithms (see GroupingKeys).
This class is used heavily by Graph2DLayoutExecutor but could be used on its own as well:

 // initialize grouping information
 GroupLayoutConfigurator glc = new GroupLayoutConfigurator(getGraph2D());
 try {
   // register grouping relevant DataProviders
   glc.prepareAll();
   // launch layouter in buffered mode
   new BufferedLayouter(getLayouter()).doLayout(getGraph2D());
 } finally {
   // make sure the DataProviders will always be unregistered
   glc.restoreAll();
 }
 

See Also:
Graph2DLayoutExecutor, HierarchyManager, GroupingKeys
 

Nested Class Summary
static class GroupLayoutConfigurator.MinNodeSizeDataProvider
          A data provider that returns minimal sizes of node realizers that are provided through the node realizer's SizeConstraintProvider, see NodeRealizer.getSizeConstraintProvider()
 
Constructor Summary
GroupLayoutConfigurator(Graph2D graph)
          Initializes a new GroupLayoutConfigurator instance for the given graph
 
Method Summary
protected  DataProvider createGroupDP(Graph2D graph)
          Creates a data provider that maps each node to a boolean flag indicating whether the node is a group node or not.
protected  DataProvider createGroupNodeInsetsProvider(Graph2D graph, HierarchyManager hierarchyManager)
          Returns a data provider for insets of group nodes from the given graph.
protected  DataProvider createGroupProvider(Graph2D graph, HierarchyManager hierarchyManager)
          Creates a data provider that maps each node to a boolean flag indicating whether or not the node is a group node.
protected  DataProvider createMinNodeSizesProvider(Graph2D graph, HierarchyManager hierarchyManager)
          Returns a data provider for minimal sizes of nodes from the given graph.
 Graph2D getGraph()
          Returns the graph associated to this GroupLayoutConfigurator instance.
protected  YInsets getGroupNodeInsets(Graph2D graph, Node node)
          Determines the group node insets that have to be taken into account by layout algorithms.
 HierarchyManager getHierarchyManager()
          Returns the hierarchy manager associated to this configurator's graph.
 boolean isTreatEmptyGroupNodesAsNormalNodesEnabled()
          Returns whether or not empty group nodes are handled like normal nodes.
 void prepareAll()
          Convenience method that performs all necessary layout preparations on the input graph.
 void prepareAutoBoundsFeatures()
          Disables the auto bounds feature in all NodeRealizers that implement AutoBoundsFeature.
 void prepareGroupDataProviders()
          Binds all data providers to the input graph, that define the hierarchically grouped structure of the graph.
 void prepareGroupNodeBounds()
          Makes sure that the current bounds of the group nodes are up to date, i.e.
 void prepareGroupNodeInsets()
          Makes the insets of group nodes that implement AutoBoundsFeature available for layout algorithms.
 void prepareMinGroupNodeSizes()
          Makes the minimum node bounds available for layout algorithms.
 void restoreAll()
          Cleanup method that undoes the steps performed by prepareAll().
 void restoreAutoBoundsFeatures()
          Cleanup method that undoes the steps performed by prepareAutoBoundsFeatures().
 void restoreGroupDataProviders()
          Cleanup method that undoes the steps performed by prepareGroupDataProviders().
 void restoreGroupNodeInsets()
          Cleanup method that undoes the steps performed by prepareGroupNodeInsets().
 void restoreMinGroupNodeSizes()
          Cleanup method that undoes the steps performed by prepareMinGroupNodeSizes().
 void setTreatEmptyGroupNodesAsNormalNodesEnabled(boolean enabled)
          If this option is enabled, empty group nodes are handled like normal nodes, that is they are not marked as group nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GroupLayoutConfigurator

public GroupLayoutConfigurator(Graph2D graph)
Initializes a new GroupLayoutConfigurator instance for the given graph

Parameters:
graph - the graph structure that will be processed by layout algorithms. May not be null.
Method Detail

getGraph

public final Graph2D getGraph()
Returns the graph associated to this GroupLayoutConfigurator instance.


getHierarchyManager

public final HierarchyManager getHierarchyManager()
Returns the hierarchy manager associated to this configurator's graph.

Returns:
the HierarchyManager instance associated to this configurator's graph or null if this configurator's graph does not support nesting.

isTreatEmptyGroupNodesAsNormalNodesEnabled

public boolean isTreatEmptyGroupNodesAsNormalNodesEnabled()
Returns whether or not empty group nodes are handled like normal nodes.

Returns:
true if empty group nodes are handled like normal nodes; false otherwise.
See Also:
setTreatEmptyGroupNodesAsNormalNodesEnabled(boolean), HierarchyManager.isGroupNode(y.base.Node), HierarchyManager.isNormalNode(y.base.Node)

setTreatEmptyGroupNodesAsNormalNodesEnabled

public void setTreatEmptyGroupNodesAsNormalNodesEnabled(boolean enabled)
If this option is enabled, empty group nodes are handled like normal nodes, that is they are not marked as group nodes. By default this option is enabled. Note that some layout algorithms may produce unsuitable results if this option is disabled.

Parameters:
enabled - whether or not this option should be enabled.
See Also:
isTreatEmptyGroupNodesAsNormalNodesEnabled(), HierarchyManager.isGroupNode(y.base.Node), HierarchyManager.isNormalNode(y.base.Node)

prepareGroupDataProviders

public void prepareGroupDataProviders()
Binds all data providers to the input graph, that define the hierarchically grouped structure of the graph.


createGroupDP

protected DataProvider createGroupDP(Graph2D graph)
Creates a data provider that maps each node to a boolean flag indicating whether the node is a group node or not. The returned data provider is bound to key GroupingKeys.GROUP_DPKEY.

Parameters:
graph - the Graph2D instance.
Returns:
the created data provider.

createGroupProvider

protected DataProvider createGroupProvider(Graph2D graph,
                                           HierarchyManager hierarchyManager)
Creates a data provider that maps each node to a boolean flag indicating whether or not the node is a group node.

Called from createGroupDP(Graph2D).


prepareGroupNodeInsets

public void prepareGroupNodeInsets()
Makes the insets of group nodes that implement AutoBoundsFeature available for layout algorithms.

The default implementation registers the data provider created by createGroupNodeInsetsProvider(Graph2D, HierarchyManager).

See Also:
restoreGroupNodeInsets()

createGroupNodeInsetsProvider

protected DataProvider createGroupNodeInsetsProvider(Graph2D graph,
                                                     HierarchyManager hierarchyManager)
Returns a data provider for insets of group nodes from the given graph.

The default implementation returns a data provider that delegates queries to getGroupNodeInsets(Graph2D, Node).

Called from prepareGroupNodeInsets().


getGroupNodeInsets

protected YInsets getGroupNodeInsets(Graph2D graph,
                                     Node node)
Determines the group node insets that have to be taken into account by layout algorithms.

Note: Unlike the other methods declared in this class, getGroupNodeInsets is queried during layout calculation.

Parameters:
graph - the graph for which this configurator is responsible.
node - the node whose insets have to be returned.
Returns:
the insets that layout algorithms have to take into account for the specified group node.

prepareMinGroupNodeSizes

public void prepareMinGroupNodeSizes()
Makes the minimum node bounds available for layout algorithms.

The default implementation registers the data provider created by createMinNodeSizesProvider(Graph2D, HierarchyManager).

See Also:
restoreMinGroupNodeSizes()

createMinNodeSizesProvider

protected DataProvider createMinNodeSizesProvider(Graph2D graph,
                                                  HierarchyManager hierarchyManager)
Returns a data provider for minimal sizes of nodes from the given graph.

Called from prepareMinGroupNodeSizes().

Returns:
a new instance of GroupLayoutConfigurator.MinNodeSizeDataProvider.

prepareGroupNodeBounds

public void prepareGroupNodeBounds()
Makes sure that the current bounds of the group nodes are up to date, i.e. if they still encompass their children, for example. This code will disable and reenable the AutoBoundsFeature of all nodes in the graph in order to trigger a recalculation of their bounds, if it is necessary

See Also:
GroupNodeRealizer.recalculateBounds()

restoreGroupDataProviders

public void restoreGroupDataProviders()
Cleanup method that undoes the steps performed by prepareGroupDataProviders().


prepareAutoBoundsFeatures

public void prepareAutoBoundsFeatures()
Disables the auto bounds feature in all NodeRealizers that implement AutoBoundsFeature. This way an automatic layout algorithm will be able to resize such nodes during the layout process.


restoreGroupNodeInsets

public void restoreGroupNodeInsets()
Cleanup method that undoes the steps performed by prepareGroupNodeInsets().


restoreMinGroupNodeSizes

public void restoreMinGroupNodeSizes()
Cleanup method that undoes the steps performed by prepareMinGroupNodeSizes().


restoreAutoBoundsFeatures

public void restoreAutoBoundsFeatures()
Cleanup method that undoes the steps performed by prepareAutoBoundsFeatures().


prepareAll

public void prepareAll()
Convenience method that performs all necessary layout preparations on the input graph.


restoreAll

public void restoreAll()
Cleanup method that undoes the steps performed by prepareAll().


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