Search this API

y.layout
Class BendConverter

java.lang.Object
  extended by y.layout.BendConverter
All Implemented Interfaces:
Layouter, LayoutStage

public class BendConverter
extends java.lang.Object
implements LayoutStage

BendConverter replaces edge bends with dummy nodes for the core layout algorithm.

Concept

Replacing the bends works in three steps:

  1. Replacing the bends and the edge segments between them with dummy nodes and edges
  2. Invoking the core layout algorithm on the altered graph
  3. Recreating the bends and removing all dummy elements

When the dummy elements have been inserted, edge information about port constraints, edge groups and selection state can be adopted from the original edges. That way, the core layout algorithm can access the mentioned information.

 

Field Summary
static java.lang.Object SCOPE_DPKEY
          A DataProvider key for specifying the set of edges for which this stage will replace bends Only the bends of the marked edges will be replaced with dummy nodes.
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, NODE_TYPE_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
BendConverter()
          Creates a new BendConverter instance with default settings.
BendConverter(double size)
          Creates a new BendConverter instance with the given size as the width and height for the dummy nodes.
BendConverter(Layouter core)
          Creates a new instance of BendConverter with the given core layout algorithm.
 
Method Summary
protected  void addedPathForEdge(LayoutGraph graph, Edge edge, NodeList dummyNodes)
          Adds information to newly created dummy nodes.
 boolean canLayout(LayoutGraph graph)
          Accepts all graphs that can be handled by the core layout algorithm.
 void doLayout(LayoutGraph graph)
          Replaces all bends in the current scope with dummy nodes before invoking the core layout algorithm.
 Layouter getCoreLayouter()
          Returns the core layout algorithm that is wrapped by this LayoutStage.
 java.lang.Object getSelectedEdgesDpKey()
          Returns the key to register a DataProvider which identifies edges as selected.
 boolean isAdoptEdgeGroupsEnabled()
          Returns whether or not edge grouping information of the original edge should be adopted by its replacement edges.
 boolean isAdoptPortConstraintsEnabled()
          Returns whether or not the associated PortConstraints of the original edge should be adopted by its replacement edges.
 boolean isAdoptSelectionEnabled()
          Returns whether or not the selection state of the original edge should be adopted by its replacement edges.
protected  void prepare(LayoutGraph graph)
          Prepares the graph before calling the core layout algorithm.
 void setAdoptEdgeGroupsEnabled(boolean adoptEdgeGroupsEnabled)
          Specifies whether or not edge grouping information of the original edge should be adopted by its replacement edges.
 void setAdoptPortConstraintsEnabled(boolean adoptPortConstraintsEnabled)
          Specifies whether or not the associated PortConstraints of the original edge should be adopted by its replacement edges.
 void setAdoptSelectionEnabled(boolean adoptSelectionEnabled)
          Specifies whether or not the selection state of the original edge should be adopted by its replacement edges.
 void setCoreLayouter(Layouter layouter)
          Specifies the core layout algorithm that is wrapped by this LayoutStage.
 void setSelectedEdgesDpKey(java.lang.Object key)
          Specifies the key to register a DataProvider which identifies edges as selected.
protected  void unprepare(LayoutGraph graph)
          Restores the structure of the graph after the core layout algorithm has finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCOPE_DPKEY

public static final java.lang.Object SCOPE_DPKEY
A DataProvider key for specifying the set of edges for which this stage will replace bends

Only the bends of the marked edges will be replaced with dummy nodes.

 
If no DataProvider is registered with this key, the bends of all edges are replaced.
Constructor Detail

BendConverter

public BendConverter()
Creates a new BendConverter instance with default settings.


BendConverter

public BendConverter(Layouter core)
Creates a new instance of BendConverter with the given core layout algorithm.

Parameters:
core - the core layout algorithm

BendConverter

public BendConverter(double size)
Creates a new BendConverter instance with the given size as the width and height for the dummy nodes.

Parameters:
size - the size for the dummy nodes
Throws:
java.lang.IllegalArgumentException - if the given size is negative
Method Detail

canLayout

public boolean canLayout(LayoutGraph graph)
Accepts all graphs that can be handled by the core layout algorithm.

If there is no core layout algorithm, all graphs are accepted.

Specified by:
canLayout in interface Layouter
Parameters:
graph - the input graph
Returns:
true if there is no core layout algorithm or the core layout algorithm accepts the graph, false otherwise
See Also:
Layouter.doLayout(LayoutGraph)

doLayout

public void doLayout(LayoutGraph graph)
Replaces all bends in the current scope with dummy nodes before invoking the core layout algorithm.

After the core layout algorithm has finished, the edges between the dummy nodes are reconnected and the dummy nodes are replaced by bends again.

Specified by:
doLayout in interface Layouter
Parameters:
graph - the input graph
See Also:
Layouter.canLayout(LayoutGraph)

prepare

protected void prepare(LayoutGraph graph)
Prepares the graph before calling the core layout algorithm.

The bends of the edges belonging to the current scope are replaced by dummy nodes and the segments between those dummy nodes are replaced by dummy edges.

Edge-specific information like PortConstraints, edge groups or selection state can be applied to the dummy edges to keep this information for the core layout algorithm.

This method is called by doLayout(LayoutGraph) before invoking the core layout algorithm. It may be overridden to extend the edge-specific information that should be adopted by the dummy edges.

 
All changes to the graph should be reverted in unprepare(LayoutGraph).
Parameters:
graph - the input graph
See Also:
unprepare(LayoutGraph), setAdoptSelectionEnabled(boolean), setAdoptPortConstraintsEnabled(boolean), setAdoptEdgeGroupsEnabled(boolean)

unprepare

protected void unprepare(LayoutGraph graph)
Restores the structure of the graph after the core layout algorithm has finished.

This method is called by doLayout(LayoutGraph) after invoking the core layout algorithm. It may be overridden to clean up all additional information added in prepare(LayoutGraph).

 
All changes to the graph made in prepare(LayoutGraph) should be reverted by this method.
Parameters:
graph - the graph arranged by the core layout algorithm
See Also:
prepare(LayoutGraph), setAdoptSelectionEnabled(boolean), setAdoptPortConstraintsEnabled(boolean), setAdoptEdgeGroupsEnabled(boolean)

getCoreLayouter

public Layouter getCoreLayouter()
Returns the core layout algorithm that is wrapped by this LayoutStage.

Specified by:
getCoreLayouter in interface LayoutStage
Returns:
the core layout routine
See Also:
setCoreLayouter(Layouter)

setCoreLayouter

public void setCoreLayouter(Layouter layouter)
Specifies the core layout algorithm that is wrapped by this LayoutStage.

Specified by:
setCoreLayouter in interface LayoutStage
Default Value:
The default value is null.
Parameters:
layouter - the core layout routine

isAdoptEdgeGroupsEnabled

public boolean isAdoptEdgeGroupsEnabled()
Returns whether or not edge grouping information of the original edge should be adopted by its replacement edges.

Returns:
true if dummy edges get the edge grouping information from their corresponding originals, false otherwise
See Also:
setAdoptEdgeGroupsEnabled(boolean), PortConstraintKeys.SOURCE_GROUPID_KEY, PortConstraintKeys.TARGET_GROUPID_KEY

setAdoptEdgeGroupsEnabled

public void setAdoptEdgeGroupsEnabled(boolean adoptEdgeGroupsEnabled)
Specifies whether or not edge grouping information of the original edge should be adopted by its replacement edges.

Default Value:
The default value is true. Original edge grouping information is applied to the dummy edges.
Parameters:
adoptEdgeGroupsEnabled - true if dummy edges should get the edge grouping information from their corresponding originals, false otherwise
See Also:
PortConstraintKeys.SOURCE_GROUPID_KEY, PortConstraintKeys.TARGET_GROUPID_KEY

isAdoptPortConstraintsEnabled

public boolean isAdoptPortConstraintsEnabled()
Returns whether or not the associated PortConstraints of the original edge should be adopted by its replacement edges.

Returns:
true if dummy edges get the PortConstraints of their corresponding originals, false otherwise
See Also:
setAdoptPortConstraintsEnabled(boolean), PortConstraintKeys.SOURCE_PORT_CONSTRAINT_KEY, PortConstraintKeys.TARGET_PORT_CONSTRAINT_KEY

setAdoptPortConstraintsEnabled

public void setAdoptPortConstraintsEnabled(boolean adoptPortConstraintsEnabled)
Specifies whether or not the associated PortConstraints of the original edge should be adopted by its replacement edges.

Default Value:
The default value is true. PortConstraints of the original edges are applied to the dummy edges.
Parameters:
adoptPortConstraintsEnabled - true if dummy edges should get the PortConstraints of their corresponding originals, false otherwise
See Also:
PortConstraintKeys.SOURCE_PORT_CONSTRAINT_KEY, PortConstraintKeys.TARGET_PORT_CONSTRAINT_KEY

isAdoptSelectionEnabled

public boolean isAdoptSelectionEnabled()
Returns whether or not the selection state of the original edge should be adopted by its replacement edges.

The selection state is looked up in a DataProvider registered with the key returned by getSelectedEdgesDpKey().

Returns:
true if dummy edges get the selection state of their corresponding original edge, false otherwise
See Also:
setAdoptSelectionEnabled(boolean), getSelectedEdgesDpKey()

setAdoptSelectionEnabled

public void setAdoptSelectionEnabled(boolean adoptSelectionEnabled)
Specifies whether or not the selection state of the original edge should be adopted by its replacement edges.

The selection state is looked up in a DataProvider registered with the key returned by getSelectedEdgesDpKey().

Default Value:
The default value is true. The selection state of the original edge is applied to all corresponding dummy edges.
Parameters:
adoptSelectionEnabled - true if dummy edges should get the selection state of their corresponding original edge, false otherwise
See Also:
getSelectedEdgesDpKey()

addedPathForEdge

protected void addedPathForEdge(LayoutGraph graph,
                                Edge edge,
                                NodeList dummyNodes)
Adds information to newly created dummy nodes.

This is a callback method that will be invoked after new elements for the given edge have been added to the given graph by prepare(LayoutGraph). At this point, the original edge is still in the graph.

The current implementation does nothing.

Parameters:
graph - the input graph
edge - the edge whose bends were replaced by the given dummy nodes
dummyNodes - the dummy nodes representing the bends of the edge

getSelectedEdgesDpKey

public java.lang.Object getSelectedEdgesDpKey()
Returns the key to register a DataProvider which identifies edges as selected.

If the selection is conserved, the selection state described by the DataProvider registered with this key is applied to the according dummy edges.

Returns:
the DataProvider key
See Also:
setSelectedEdgesDpKey(Object), setAdoptSelectionEnabled(boolean)

setSelectedEdgesDpKey

public void setSelectedEdgesDpKey(java.lang.Object key)
Specifies the key to register a DataProvider which identifies edges as selected.

If the selection is conserved, the selection state described by the DataProvider registered with this key is applied to the according dummy edges.

Default Value:
The default value is Layouter.SELECTED_EDGES
Parameters:
key - the DataProvider key
Throws:
java.lang.IllegalArgumentException - if the specified key is null
See Also:
setAdoptSelectionEnabled(boolean)

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