Search this API

y.layout
Class LabelLayoutTranslator

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

public class LabelLayoutTranslator
extends java.lang.Object
implements LayoutStage

LabelLayoutTranslator automatically translates label layout information provided by the standard label layout classes EdgeLabelLayout and NodeLabelLayout to layout data of type LabelLayoutData that is accessible by the keys defined in class LabelLayoutKeys.

One can use this LayoutStage as label layout algorithm of a label-aware layout algorithm like IncrementalHierarchicLayouter. This can be done by assigning the stage by an appropriate call to setLabelLayouter.

When writing the LabelLayoutData, the boxes are set relative. In case of a node label, the box's anchor is relative to the center of the owning node. In case of an edge label the box's anchor is relative to the center of the source node of the owning edge.

If writing back node labels and/or writing back edge labels is enabled, the LabelLayoutData is transferred back to the NodeLabelLayouts and/or EdgeLabelLayouts.

By default, the boxes are now interpreted absolute but by activating isWriteBackRelativeNodeLabelLocationEnabled() and/or isWriteBackRelativeEdgeLabelLocationEnabled() this can be changed to interpret them relative as explained above.

Note that care must be taken on the choice of the label model that is used by the classes EdgeLabelLayout and NodeLabelLayout. The calculated label positions must be consistent with the label positions allowed by the label model. The best label layout results are achieved by choosing FreeEdgeLabelModel for edge layouts and FreeNodeLabelModel for node layouts.

 

Field Summary
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
LabelLayoutTranslator()
          Creates a new LabelLayoutTranslator instance with default settings.
 
Method Summary
 boolean canLayout(LayoutGraph graph)
          Accepts all graphs which the core layout algorithm can handle.
 void doLayout(LayoutGraph graph)
          Translates traditional LabelLayout information to DataProvider-based LabelLayoutData.
 Layouter getCoreLayouter()
          Returns the core layout algorithm that is wrapped by this LayoutStage.
 boolean isAutoFlippingEnabled()
          Returns whether or not this stage should automatically flip edge label content depending on the label's rotation angle.
 boolean isResettingEdgeLabelOrientation()
          Returns whether or not to reset the orientation of edge labels.
 boolean isResettingNodeLabelOrientation()
          Returns whether or not to reset the orientation of node labels.
 boolean isTranslateEdgeLabelsEnabled()
          Returns whether or not edge label information is translated.
 boolean isTranslateNodeLabelsEnabled()
          Returns whether or not node label information is translated.
 boolean isWriteBackEdgeLabelsEnabled()
          Returns whether or not edge label information is written back to the model after core layout.
 boolean isWriteBackNodeLabelsEnabled()
          Returns whether or not node label information is written back to the model after the core layout.
 boolean isWriteBackRelativeEdgeLabelLocationEnabled()
          Returns whether or not edge label boxes are interpreted relative to the edge when writing them back to the model.
 boolean isWriteBackRelativeNodeLabelLocationEnabled()
          Returns whether or not node label bounds are interpreted relative to the node when writing them back to the model.
 void setAutoFlippingEnabled(boolean enabled)
          Specifies whether or not this stage should automatically flip edge label content depending on the label's rotation angle.
 void setCoreLayouter(Layouter layouter)
          Specifies the core layout algorithm that is wrapped by this LayoutStage.
 void setResettingEdgeLabelOrientation(boolean resettingEdgeLabelOrientation)
          Specifies whether or not to reset the orientation of edge labels.
 void setResettingNodeLabelOrientation(boolean resettingNodeLabelOrientation)
          Specifies whether or not to reset the orientation of node labels.
 void setTranslateEdgeLabelsEnabled(boolean translateEdgeLabelsEnabled)
          Specifies whether or not edge label information is translated.
 void setTranslateNodeLabelsEnabled(boolean translateNodeLabelsEnabled)
          Specifies whether or not node label information is translated.
 void setWriteBackEdgeLabelsEnabled(boolean writeBack)
          Specifies whether or not edge label information is written back to the model after core layout.
 void setWriteBackNodeLabelsEnabled(boolean writeBack)
          Specifies whether or not node label information is written back to the model after the core layout.
 void setWriteBackRelativeEdgeLabelLocationEnabled(boolean writeBackRelativeEdgeLabelLocationEnabled)
          Specifies whether or not edge label boxes are interpreted relative to the edge when writing them back to the model.
 void setWriteBackRelativeNodeLabelLocationEnabled(boolean writeBackRelativeNodeLabelLocationEnabled)
          Specifies whether or not node label boxes are interpreted relative to the node when writing them back to the model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LabelLayoutTranslator

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

Method Detail

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

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)

doLayout

public void doLayout(LayoutGraph graph)
Translates traditional LabelLayout information to DataProvider-based LabelLayoutData. Afterwards, the calculated layout data will be written back to the original label layout.

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

isAutoFlippingEnabled

public boolean isAutoFlippingEnabled()
Returns whether or not this stage should automatically flip edge label content depending on the label's rotation angle.

More precisely, if this option is enabled and the up vector of the OrientedRectangle associated with an EdgeLabelLayout points downwards (upY > 0), this LayoutStage automatically flips the label. It rotates the label by 180 degrees without changing the label's center.

Returns:
true if this LayoutStage automatically flips edge label content depending on the label's rotation angle, false otherwise
See Also:
setAutoFlippingEnabled(boolean), LayoutTool.autoFlipBox(OrientedRectangle), LabelLayout.getOrientedBox()

setAutoFlippingEnabled

public void setAutoFlippingEnabled(boolean enabled)
Specifies whether or not this stage should automatically flip edge label content depending on the label's rotation angle.

More precisely, if this option is enabled and the up vector of the OrientedRectangle associated with an EdgeLabelLayout points downwards (upY > 0), this LayoutStage automatically flips the label. It rotates the label by 180 degrees without changing the label's center.

Default Value:
The default value is true. Labels are automatically flipped if they are upside down.
Parameters:
enabled - true if this LayoutStage should automatically flip edge label content depending on the label's rotation angle, false otherwise
See Also:
LayoutTool.autoFlipBox(OrientedRectangle), LabelLayout.getOrientedBox()
Sample Graphs:

false

true

isResettingNodeLabelOrientation

public boolean isResettingNodeLabelOrientation()
Returns whether or not to reset the orientation of node labels. If this option is enabled, the up vector of the corresponding oriented box is set to (0,-1) before adding it to the DataProvider.

 
If a layout algorithm just considers node labels, LabelLayoutTranslator should not reset their orientation. When it performs integrated node labeling, this option should be enabled.
Returns:
true if the orientation of node labels is reset, false otherwise
See Also:
setResettingNodeLabelOrientation(boolean)

setResettingNodeLabelOrientation

public void setResettingNodeLabelOrientation(boolean resettingNodeLabelOrientation)
Specifies whether or not to reset the orientation of node labels. If this option is enabled, the up vector of the corresponding oriented box is set to (0,-1) before adding it to the DataProvider.

 
If a layout algorithm just considers node labels, LabelLayoutTranslator should not reset their orientation. When it performs integrated node labeling, this option should be enabled.
Default Value:
The default value is false. The orientation of node labels is kept.
Parameters:
resettingNodeLabelOrientation - true if the orientation of node labels should be reset, false otherwise

isResettingEdgeLabelOrientation

public boolean isResettingEdgeLabelOrientation()
Returns whether or not to reset the orientation of edge labels. If this option is enabled, the up vector of the corresponding oriented box is set to (0,-1) before adding it to the DataProvider.

 
If a layout algorithm just considers edge labels, LabelLayoutTranslator should not reset their orientation. When it performs integrated edge labeling, this option should be enabled.
Returns:
true if the orientation of edge labels is reset, false otherwise
See Also:
setResettingEdgeLabelOrientation(boolean)

setResettingEdgeLabelOrientation

public void setResettingEdgeLabelOrientation(boolean resettingEdgeLabelOrientation)
Specifies whether or not to reset the orientation of edge labels. If this option is enabled, the up vector of the corresponding oriented box is set to (0,-1) before adding it to the DataProvider.

 
If a layout algorithm just considers edge labels, LabelLayoutTranslator should not reset their orientation. When it performs integrated edge labeling, this option should be enabled.
Default Value:
The default value is true. The orientation of edge labels is reset.
Parameters:
resettingEdgeLabelOrientation - true if the orientation of edge labels should be reset, false otherwise

canLayout

public boolean canLayout(LayoutGraph graph)
Accepts all graphs which the core layout algorithm can handle.

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

isWriteBackEdgeLabelsEnabled

public boolean isWriteBackEdgeLabelsEnabled()
Returns whether or not edge label information is written back to the model after core layout.

 
This option should only be enabled if the core layout algorithm performs integrated edge labeling.
Returns:
true if edge label information is written back, false otherwise
See Also:
setWriteBackEdgeLabelsEnabled(boolean)

setWriteBackEdgeLabelsEnabled

public void setWriteBackEdgeLabelsEnabled(boolean writeBack)
Specifies whether or not edge label information is written back to the model after core layout.

 
This option should only be enabled if the core layout algorithm performs integrated edge labeling.
Default Value:
The default value is true. Edge label information is transferred back to the label model.
Parameters:
writeBack - true if edge label information should be written back, false otherwise

isWriteBackRelativeEdgeLabelLocationEnabled

public boolean isWriteBackRelativeEdgeLabelLocationEnabled()
Returns whether or not edge label boxes are interpreted relative to the edge when writing them back to the model.

 
This option is only considered if setWriteBackEdgeLabelsEnabled(boolean) is enabled.
Returns:
true if the bounds are interpreted relative, false for absolute interpretation
See Also:
setWriteBackRelativeEdgeLabelLocationEnabled(boolean)

setWriteBackRelativeEdgeLabelLocationEnabled

public void setWriteBackRelativeEdgeLabelLocationEnabled(boolean writeBackRelativeEdgeLabelLocationEnabled)
Specifies whether or not edge label boxes are interpreted relative to the edge when writing them back to the model.

 
This option is only considered if setWriteBackEdgeLabelsEnabled(boolean) is enabled.
Default Value:
The default value is false. Edge label boxes are interpreted absolute.
Parameters:
writeBackRelativeEdgeLabelLocationEnabled - true if the boxes should be interpreted relative, false for absolute interpretation

isWriteBackNodeLabelsEnabled

public boolean isWriteBackNodeLabelsEnabled()
Returns whether or not node label information is written back to the model after the core layout.

 
This option should only be enabled if the core layout algorithm performs integrated node labeling.
Returns:
true if node label information is written back, false otherwise
See Also:
setWriteBackNodeLabelsEnabled(boolean)

setWriteBackNodeLabelsEnabled

public void setWriteBackNodeLabelsEnabled(boolean writeBack)
Specifies whether or not node label information is written back to the model after the core layout.

 
This option should only be enabled if the core layout algorithm performs integrated node labeling.
Default Value:
The default value is true. Node label information is transferred back to the label model.
Parameters:
writeBack - true if node label information should be written back, false otherwise

isWriteBackRelativeNodeLabelLocationEnabled

public boolean isWriteBackRelativeNodeLabelLocationEnabled()
Returns whether or not node label bounds are interpreted relative to the node when writing them back to the model.

 
This option is only considered if setWriteBackNodeLabelsEnabled(boolean) is enabled.
Returns:
true if the bounds are interpreted relative, false for absolute interpretation
See Also:
setWriteBackRelativeNodeLabelLocationEnabled(boolean)

setWriteBackRelativeNodeLabelLocationEnabled

public void setWriteBackRelativeNodeLabelLocationEnabled(boolean writeBackRelativeNodeLabelLocationEnabled)
Specifies whether or not node label boxes are interpreted relative to the node when writing them back to the model.

 
This option is only considered if setWriteBackNodeLabelsEnabled(boolean) is enabled.
Default Value:
The default value is false. Node label boxes are interpreted absolute.
Parameters:
writeBackRelativeNodeLabelLocationEnabled - true if the boxes should be interpreted relative, false for absolute interpretation

isTranslateNodeLabelsEnabled

public boolean isTranslateNodeLabelsEnabled()
Returns whether or not node label information is translated.

Returns:
true if node label information is translated, false otherwise
See Also:
setTranslateNodeLabelsEnabled(boolean)

setTranslateNodeLabelsEnabled

public void setTranslateNodeLabelsEnabled(boolean translateNodeLabelsEnabled)
Specifies whether or not node label information is translated.

Default Value:
The default value is false. The label information is not translated for node labels.
Parameters:
translateNodeLabelsEnabled - true if node label information should be translated, false otherwise

isTranslateEdgeLabelsEnabled

public boolean isTranslateEdgeLabelsEnabled()
Returns whether or not edge label information is translated.

Returns:
true if edge label information is translated, false otherwise
See Also:
setTranslateEdgeLabelsEnabled(boolean)

setTranslateEdgeLabelsEnabled

public void setTranslateEdgeLabelsEnabled(boolean translateEdgeLabelsEnabled)
Specifies whether or not edge label information is translated.

Default Value:
The default value is false. The label information is not translated for edge labels.
Parameters:
translateEdgeLabelsEnabled - true if edge label information should be translated, false otherwise

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