public class OrientationLayout extends AbstractLayoutStage
OrientationLayout
is a ILayoutStage
that changes the orientation of the layout.
Changing the layout orientation is useful for layout styles that show a main direction.
LayoutOrientation.TOP_TO_BOTTOM
layout
LayoutOrientation.BOTTOM_TO_TOP
layout with mirroring
LayoutOrientation.LEFT_TO_RIGHT
layout
LayoutOrientation.RIGHT_TO_LEFT
layout
OrientationLayout
performs three basic steps.
PortConstraint
s are
transformed to the LayoutOrientation.TOP_TO_BOTTOM
orientation.
core layout algorithm
is invoked and calculates the layout
for orientation LayoutOrientation.TOP_TO_BOTTOM
.
core layout algorithm
is rotated and mirrored
to fit the desired layout orientation.
OrientationLayout
can either be used as a ILayoutStage
wrapping a
layout algorithm
. Then it will change the orientation of the result of the
core layout algorithm
.
If no core layout algorithm
is specified, OrientationLayout
can
work alone. It will just change the orientation of the layout without arranging nodes and edges.
MultiStageLayout
s it is highly recommended to use OrientationLayout
for layout orientation changes and not to wrap MultiStageLayout
with an OrientationLayout
instance. That
may cause unwanted artifacts.Constructor and Description |
---|
OrientationLayout()
Creates a new
OrientationLayout instance with default settings. |
OrientationLayout(ILayoutAlgorithm coreLayouter)
Creates a new
OrientationLayout instance using the given
core layout algorithm . |
OrientationLayout(LayoutOrientation orientation)
Creates a new
OrientationLayout instance using the given orientation. |
Modifier and Type | Method and Description |
---|---|
void |
applyLayout(LayoutGraph graph)
Prepares the graph for orientation change before calling the
core layout algorithm
and finishes the orientation change afterwards. |
protected void |
completeOrientationChange(LayoutGraph graph)
Applies the desired orientation to the graph.
|
protected YPoint |
completeTransform(YPoint point)
Transforms the given point during completion.
|
YInsets |
createOrientedInsets(YInsets insets)
|
NodeHalo |
createOrientedNodeHalo(NodeHalo halo)
|
YDimension |
createOrientedNodeSize(YDimension nodeSize)
Creates a
YDimension that is a geometric transformation of the given size. |
MirrorModes |
getMirrorMode()
Gets the mirror mask that defines which orientations this
OrientationLayout shall mirror. |
LayoutOrientation |
getOrientation()
Gets the main direction of the layout.
|
boolean |
isEdgeLabelConsiderationEnabled()
Gets whether or not the position of the edge labels should be changed during orientation change.
|
boolean |
isHorizontalOrientation()
Gets whether or not the current orientation is horizontal.
|
boolean |
isOrientationMirrored(LayoutOrientation orientation)
Returns whether or not this
OrientationLayout instance will mirror the graph for a given layout orientation. |
protected void |
prepareOrientationChange(LayoutGraph graph)
Prepares the layout for the desired orientation.
|
protected YPoint |
prepareTransform(YPoint point)
Transforms the given point during preparation.
|
void |
setEdgeLabelConsiderationEnabled(boolean value)
Sets whether or not the position of the edge labels should be changed during orientation change.
|
void |
setMirrorMode(MirrorModes value)
Sets the mirror mask that defines which orientations this
OrientationLayout shall mirror. |
void |
setOrientation(LayoutOrientation value)
Sets the main direction of the layout.
|
protected YPoint |
transform(YPoint point,
boolean prepare)
Transforms the given point during the preparation or completion step.
|
applyLayoutCore, getCoreLayout, setCoreLayout
public OrientationLayout()
OrientationLayout
instance with default settings.public OrientationLayout(ILayoutAlgorithm coreLayouter)
OrientationLayout
instance using the given
core layout algorithm
.coreLayouter
- the core layout routinepublic OrientationLayout(LayoutOrientation orientation)
OrientationLayout
instance using the given orientation.IllegalArgumentException
- if the specified orientation is unknownorientation
- the orientation specifiersetOrientation(LayoutOrientation)
public void applyLayout(LayoutGraph graph)
core layout algorithm
and finishes the orientation change afterwards.applyLayout
in interface ILayoutAlgorithm
applyLayout
in class AbstractLayoutStage
graph
- the input graphprotected void completeOrientationChange(LayoutGraph graph)
It performs the inverse coordinate transformation that has been applied to the layout by method
prepareOrientationChange(LayoutGraph)
.
This method is called by applyLayout(LayoutGraph)
after invoking the
core layout algorithm
. It may be overridden to extend the orientation
change to custom layout features.
graph
- the input graphprepareOrientationChange(LayoutGraph)
protected YPoint completeTransform(YPoint point)
The point is transformed from LayoutOrientation.TOP_TO_BOTTOM
orientation to the desired orientation.
point
- the calculated pointcompleteOrientationChange(LayoutGraph)
public YInsets createOrientedInsets(YInsets insets)
YInsets
that are a geometric transformation of the given YInsets
.
The transform will correspond to the currently set orientation.
insets
- the original insetssetOrientation(LayoutOrientation)
public NodeHalo createOrientedNodeHalo(NodeHalo halo)
NodeHalo
that is a geometric transformation of the given NodeHalo
.
The transform will correspond to the currently set orientation.
halo
- the original NodeHalo
NodeHalo
setOrientation(LayoutOrientation)
public YDimension createOrientedNodeSize(YDimension nodeSize)
YDimension
that is a geometric transformation of the given size.
The transform will correspond to the currently set orientation.
nodeSize
- the original node sizesetOrientation(LayoutOrientation)
public MirrorModes getMirrorMode()
OrientationLayout
shall mirror.
Setting a layout orientation
can be seen as rotating the graph by 90
,
180
or 270
degrees. Afterwards the graph can be mirrored at the x-axis (for horizontal layout
orientations) or y-axis (for vertical layout orientations).
Which directions are mirrored can be defined by the given mask. It can combine several mirrored directions with a
logical or
-operation.
IllegalArgumentException
- if an unknown mask is specifiedMirrorModes.BOTTOM_TO_TOP
setMirrorMode(MirrorModes)
public LayoutOrientation getOrientation()
IllegalArgumentException
- if the specified orientation is unknownLayoutOrientation.TOP_TO_BOTTOM
setOrientation(LayoutOrientation)
public boolean isEdgeLabelConsiderationEnabled()
core layout algorithm
should switch this off if it performs integrated
edge labeling.true
. The orientation of labels is handled by this OrientationLayout
.true
if the position of the edge labels are changed, false
otherwisesetEdgeLabelConsiderationEnabled(boolean)
public boolean isHorizontalOrientation()
The orientation is horizontal if it is LayoutOrientation.LEFT_TO_RIGHT
or
LayoutOrientation.RIGHT_TO_LEFT
.
true
if a horizontal orientation is currently used, false
otherwisesetOrientation(LayoutOrientation)
public boolean isOrientationMirrored(LayoutOrientation orientation)
OrientationLayout
instance will mirror the graph for a given layout orientation.
Horizontal orientations get mirrored at the x-axis while vertical orientations are mirrored at the y-axis.
orientation
- the layout orientation for which to check the mirror statetrue
if the layout algorithm will mirror the graph at the corresponding axis for the given layout orientation, false
otherwisesetOrientation(LayoutOrientation)
,
setMirrorMode(MirrorModes)
protected void prepareOrientationChange(LayoutGraph graph)
It will rotate and mirror the coordinates and bounds of the graph layout such that the core layout algorithm
can perform its calculations assuming the canonical LayoutOrientation.TOP_TO_BOTTOM
orientation.
This method is called by applyLayout(LayoutGraph)
before invoking the
core layout algorithm
. It might be overridden to extend the preparations
to custom layout features.
graph
- the input graphcompleteOrientationChange(LayoutGraph)
protected YPoint prepareTransform(YPoint point)
The point is transformed so it matches the LayoutOrientation.TOP_TO_BOTTOM
orientation.
point
- the original pointprepareOrientationChange(LayoutGraph)
public void setEdgeLabelConsiderationEnabled(boolean value)
core layout algorithm
should switch this off if it performs integrated
edge labeling.true
. The orientation of labels is handled by this OrientationLayout
.value
- true
if the position of the edge labels are changed, false
otherwiseisEdgeLabelConsiderationEnabled()
public void setMirrorMode(MirrorModes value)
OrientationLayout
shall mirror.
Setting a layout orientation
can be seen as rotating the graph by 90
,
180
or 270
degrees. Afterwards the graph can be mirrored at the x-axis (for horizontal layout
orientations) or y-axis (for vertical layout orientations).
Which directions are mirrored can be defined by the given mask. It can combine several mirrored directions with a
logical or
-operation.
IllegalArgumentException
- if an unknown mask is specifiedMirrorModes.BOTTOM_TO_TOP
value
- the mask that determines which layout orientations are mirroredgetMirrorMode()
public void setOrientation(LayoutOrientation value)
IllegalArgumentException
- if the specified orientation is unknownLayoutOrientation.TOP_TO_BOTTOM
value
- of the valid orientation specifiersgetOrientation()
protected YPoint transform(YPoint point, boolean prepare)
This method is called by prepareOrientationChange(LayoutGraph)
and completeOrientationChange(LayoutGraph)
to get the according point location.
point
- the original/calculated pointprepare
- true
if this method is called during preparation, false
if it is called during completionprepareOrientationChange(LayoutGraph)
,
completeOrientationChange(LayoutGraph)
,
prepareTransform(YPoint)
,
completeTransform(YPoint)