Search this API

y.layout.router
Class OrthogonalSegmentDistributionStage

java.lang.Object
  extended by y.layout.AbstractLayoutStage
      extended by y.layout.router.OrthogonalSegmentDistributionStage
All Implemented Interfaces:
Layouter, LayoutStage

public class OrthogonalSegmentDistributionStage
extends AbstractLayoutStage

This class can be used to distribute overlapping edge segments of orthogonally routed edges. The edge segments will then be distributed in their so called channel according to the given settings. The channel in which the segments can be distributed is defined by the surrounding graph elements, which will form borderlines for the channel.

The distance between the distributed edge segments can be determined by method setPreferredDistance(double).

The edge segments can also be forced to be distributed on a given grid (setGridEnabled(boolean) ) whose origin ( setGridOffset(double,double) ) and grid width ( setGridWidth(double) ) can be set.

Note: this LayoutStage is not capable of moving nodes. If the set conditions like preferred distance or the grid width can not be satisfied, for example, because there is not enough space inside the channel, the set values will by default be adjusted (reduced). Concerning the grid, it will be divided by 2 until all segments will fit. The preferred distance will be adjusted so that the maximum possible distance near the given value will be taken. Also, segments that are directly at a node (source or target) will be distributed, so that they are placed equidistant all along the node's side.

Settings setGridWidthAdjustable(boolean) and setPreferredDistanceAdjustable(boolean) can be used to force the algorithm to distribute the edges with the exact given distances. If the segments will not fit into the given channel, they then will not be distributed at all. So there is a guarantee that they will match the settings if they are routed.

setLockFirstAndLastSegment(boolean) can be used to guarantee that the first and last segment of an edge (connected to source or target), won't be distributed. So ports can easily be kept without setting explicit strong port constraints or fixed PortCandidates.

The algorithm will not distribute the segments, whose end connect to a node at a strong port constraint or fixed port candidate.


Field Summary
static Object AFFECTED_EDGES
          DataProvider key that can be used to determine which edges the distribution stage will route.
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
OrthogonalSegmentDistributionStage()
           
 
Method Summary
 boolean canLayout(LayoutGraph graph)
          Returns true iff the given graph can be laid out by this algorithm.
 void doLayout(LayoutGraph graph)
          Main layout routine that assigns new layout information to the given graph.
 Object getAffectedEdgesDPKey()
          Returns the DataProvider key, which determines the edges, that shall be distributed by the algorithm.
 double getGridOffsetX()
          Returns the grid offset in x direction. by default this will be 0.
 double getGridOffsetY()
          Returns the grid offset in y direction. by default this will be 0.
 double getGridWidth()
          Returns the grid width that shall be used if grid distribution is enabled.
 double getPreferredDistance()
          Returns the preferred distance, segments shall have to each other and to the channel's border.
 boolean isGridEnabled()
          Returns whether grid distribution is enabled or not.
 boolean isGridWidthAdjustable()
          Returns whether or not the algorithm is allowed to reduce the grid width, if segments cannot be distributed using the previously given grid width.
 boolean isLockFirstAndLastSegment()
          Returns whether the first and last segment of an edge (connected to source or target), will be distributed.
 boolean isPreferredDistanceAdjustable()
          Returns what happens if the preferred distance can not be kept, because there is not enough space for the segments to be distributed in that distance.
 void setAffectedEdgesDPKey(Object key)
          Sets the DataProvider key, which determines the edges, that shall be distributed by the algorithm.
 void setGridEnabled(boolean gridEnabled)
          Determines whether grid distribution is enabled or not.
 void setGridOffset(double offsetX, double offsetY)
          Can be used to set the grid origin.
 void setGridWidth(double gridWidth)
          Sets the grid width that shall be used if grid distribution is enabled.
 void setGridWidthAdjustable(boolean gridWidthAdjustable)
          Specifies whether or not the algorithm is allowed to reduce the grid width, if segments cannot be distributed using the previously given grid width.
 void setLockFirstAndLastSegment(boolean lockFirstAndLastSegment)
          Determines whether the first and last segment of an edge (connected to source or target), will be distributed.
 void setPreferredDistance(double minimumDistance)
          Specifies the preferred distance, segments shall have to each other and to the channel's border.
 void setPreferredDistanceAdjustable(boolean preferredDistanceAdjustable)
          Determines what happens if the preferred distance can not be kept, because there is not enough space for the segments to be distributed in that distance.
 
Methods inherited from class y.layout.AbstractLayoutStage
canLayoutCore, doLayoutCore, getCoreLayouter, setCoreLayouter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AFFECTED_EDGES

public static final Object AFFECTED_EDGES
DataProvider key that can be used to determine which edges the distribution stage will route.

Constructor Detail

OrthogonalSegmentDistributionStage

public OrthogonalSegmentDistributionStage()
Method Detail

canLayout

public boolean canLayout(LayoutGraph graph)
Description copied from interface: Layouter
Returns true iff the given graph can be laid out by this algorithm. Calling doLayout with the given graph as its argument will only success if this method returns true.


doLayout

public void doLayout(LayoutGraph graph)
Description copied from interface: Layouter
Main layout routine that assigns new layout information to the given graph.


setAffectedEdgesDPKey

public void setAffectedEdgesDPKey(Object key)
Sets the DataProvider key, which determines the edges, that shall be distributed by the algorithm.

By default, AFFECTED_EDGES is used.

Parameters:
key - the key, which determines the edges, that shall be distributed by the algorithm.

getAffectedEdgesDPKey

public Object getAffectedEdgesDPKey()
Returns the DataProvider key, which determines the edges, that shall be distributed by the algorithm.

By default, AFFECTED_EDGES is used.

Returns:
the DataProvider key which determines the edges, that shall be distributed by the algorithm.

isPreferredDistanceAdjustable

public boolean isPreferredDistanceAdjustable()
Returns what happens if the preferred distance can not be kept, because there is not enough space for the segments to be distributed in that distance. If set to true the algorithm is allowed to reduce the distance to the next best value, that is possible. If set to false the algorithm will not at all distribute those segments. By default the setting is true and therefore segments will be distributed.

Returns:
true - if the preferred distance will be adjusted by the algorithm, if needed false - if the algorithm will not distribute segments, if their preferred distance can not be kept.

setPreferredDistanceAdjustable

public void setPreferredDistanceAdjustable(boolean preferredDistanceAdjustable)
Determines what happens if the preferred distance can not be kept, because there is not enough space for the segments to be distributed in that distance. If set to true the algorithm is allowed to reduce the distance to the next best value, that is possible. If set to false the algorithm will not at all distribute those segments. By default the setting is true and therefore segments will be distributed. Note: Preferred distances will not be kept for segments connecting to nodes (first and last segment of an edge). The segments are distributed equidistant all along the node side, thus may lead to bigger distances between segments.

Parameters:
preferredDistanceAdjustable - determines if the algorithm is allowed to reduce the preferred distance

isGridWidthAdjustable

public boolean isGridWidthAdjustable()
Returns whether or not the algorithm is allowed to reduce the grid width, if segments cannot be distributed using the previously given grid width. The algorithm will divide the given grid width by 2 as long as the segments will not fit and thus will lead to nicer results than taking some other value. Note: The grid width will only be adjusted for segments that cannot keep the originally set grid width.

By default, the algorithm is allowed to reduce the grid width.

Returns:
whether or not the set grid width can be reduced, if segments can't be distributed using this grid.

setGridWidthAdjustable

public void setGridWidthAdjustable(boolean gridWidthAdjustable)
Specifies whether or not the algorithm is allowed to reduce the grid width, if segments cannot be distributed using the previously given grid width. The algorithm will divide the given grid width by 2 as long as the segments will not fit and thus will lead to nicer results than taking some other value. Note: The grid width will only be adjusted for segments that cannot keep the originally set grid width.

By default, the algorithm is allowed to reduce the grid width.

Parameters:
gridWidthAdjustable - whether or not the algorithm is allowed to reduce the grid width.

isGridEnabled

public boolean isGridEnabled()
Returns whether grid distribution is enabled or not. If so, all segments will be distributed onto the grid. By default grid distribution is not enabled.

Returns:
whether grid distribution is enabled or not.

setGridEnabled

public void setGridEnabled(boolean gridEnabled)
Determines whether grid distribution is enabled or not. If so, all segments will be distributed onto the grid. By default grid distribution is not enabled.

Parameters:
gridEnabled - whether to enable grid distribution or not.

getGridWidth

public double getGridWidth()
Returns the grid width that shall be used if grid distribution is enabled. By default the grid width is 10.0.

Returns:
the grid width.

setGridWidth

public void setGridWidth(double gridWidth)
Sets the grid width that shall be used if grid distribution is enabled. By default the grid width is 10.0.

Parameters:
gridWidth - the grid width that shall be set.

setGridOffset

public void setGridOffset(double offsetX,
                          double offsetY)
Can be used to set the grid origin. By default the offset is (0, 0), so there is no offset.

Parameters:
offsetX - the offset in x direction.
offsetY - the offset in y direction

getGridOffsetX

public double getGridOffsetX()
Returns the grid offset in x direction. by default this will be 0.

Returns:
the grid offset in x direction.

getGridOffsetY

public double getGridOffsetY()
Returns the grid offset in y direction. by default this will be 0.

Returns:
the grid offset in x direction.

isLockFirstAndLastSegment

public boolean isLockFirstAndLastSegment()
Returns whether the first and last segment of an edge (connected to source or target), will be distributed. Defaults to false, i.e. first and last segments are not locked.

Returns:
whether the first and last segment of an edge (connected to source or target), will be distributed.

setLockFirstAndLastSegment

public void setLockFirstAndLastSegment(boolean lockFirstAndLastSegment)
Determines whether the first and last segment of an edge (connected to source or target), will be distributed. So ports can easily be kept without setting explicit strong port constraints or fixed PortCandidates. Defaults to false, i.e. first and last segments are not locked.

Parameters:
lockFirstAndLastSegment - whether to lock the first and last segments of edges, and therefore not distribute them.

getPreferredDistance

public double getPreferredDistance()
Returns the preferred distance, segments shall have to each other and to the channel's border.

Default value is 10.0.

Note: if setPreferredDistanceAdjustable(boolean) is set to true (which is the default), the preferred distance might be adjusted so that the maximum possible distance near the given value will be taken. This happens if the channel is not big enough to fit in all segments with the desired preferred distance.

Returns:
the preferred distance, segments shall have to each other and to the channel's border.

setPreferredDistance

public void setPreferredDistance(double minimumDistance)
Specifies the preferred distance, segments shall have to each other and to the channel's border.

Default value is 10.0.

Note: if setPreferredDistanceAdjustable(boolean) is set to true (which is the default), the preferred distance might be adjusted so that the maximum possible distance near the given value will be taken. This happens if the channel is not big enough to fit in all segments with the desired preferred distance.

Parameters:
minimumDistance - the preferred distance, segments shall have to each other and to the channel's border.

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