public class LayoutExecutor extends Object
ILayoutAlgorithm
and optionally animates the transition to the calculated layout.
This class is the preferred way to execute a layout. It supports calculating the layout in a separate thread
and its animation can be customized in various ways.
If no fine-grain control of the animation is required, the convenience methods IGraph.applyLayout(ILayoutAlgorithm, LayoutData)
and GraphControl.morphLayout(ILayoutAlgorithm, Duration, LayoutData, IEventHandler)
can be used instead.
LayoutUtilities
,
LayoutGraphAdapter
Constructor and Description |
---|
LayoutExecutor(GraphControl graphControl,
IGraph graph,
ILayoutAlgorithm layout)
Initializes a new instance of the
LayoutExecutor class. |
LayoutExecutor(GraphControl graphControl,
ILayoutAlgorithm layout)
Initializes a new instance of the
LayoutExecutor class. |
Modifier and Type | Method and Description |
---|---|
void |
addLayoutFinishedListener(IEventHandler<LayoutEventArgs> layoutFinishedEvent)
Adds the given listener for the
LayoutFinished
event. |
void |
cancel()
Cancels a currently running layout calculation or animation.
|
protected AbortHandler |
createAbortHandler()
Creates an instance of
AbortHandler . |
protected IAnimation |
createAnimation()
Factory method that creates the
IAnimation that will be used by this instance after the layout has been
calculated. |
protected IAnimation |
createMorphAnimation()
Factory method that creates the animation for the
IGraph . |
protected IAnimation |
createTableAnimations()
Creates an animation that morphs the layout of all
ITable s in the graph. |
protected TableLayoutConfigurator |
createTableLayoutConfigurator()
Create a new instance of
TableLayoutConfigurator that is used if TableLayoutConfiguratorEnabled
is enabled. |
protected IAnimation |
createViewportAnimation(RectD targetBounds)
Factory method that creates the animation for the
Viewport . |
protected void |
execute(Runnable threadStart)
Callback method that executes the specified
threadStart . |
AbortHandler |
getAbortHandler()
Gets the
AbortHandler that is used during the layout calculation. |
Duration |
getDuration()
Gets the duration of the animation.
|
protected IGraph |
getGraph()
Gets the graph this instance is working on.
|
protected GraphControl |
getGraphControl()
Gets the control this instance has been created for.
|
protected ILayoutAlgorithm |
getLayout()
Gets the
ILayoutAlgorithm this instance is using. |
LayoutData |
getLayoutData()
Gets the layout data that is applied when
starting the executor. |
protected CopiedLayoutGraph |
getLayoutGraph()
Gets the layout graph that is used by this instance to calculate the layout.
|
ISelectionModel<IModelItem> |
getSelectionModel()
Gets the
ISelectionModel to use for the automatically registered IDataProvider instances for LayoutKeys.AFFECTED_NODES_DPKEY
and LayoutKeys.AFFECTED_EDGES_DPKEY . |
TableLayoutConfigurator |
getTableLayoutConfigurator()
Gets the
TableLayoutConfigurator that is used if TableLayoutConfiguratorEnabled
is enabled. |
protected RectD |
getTargetBounds()
Calculate the target bounds to be used for the
ContentRect
as well as the ViewportAnimation after the layout has finished. |
InsetsD |
getTargetBoundsInsets()
Gets the insets (in world coordinates) that will be added to the content rectangle when calculating the target
viewport.
|
boolean |
isAutomaticEdgeGrouping()
Gets a value indicating whether edge groups are automatically created for edges that are connected to the same port.
|
boolean |
isContentRectUpdatingEnabled()
Gets a value indicating whether the content rectangle property of the
CanvasControl
should be updated upon completion. |
boolean |
isEasedAnimationEnabled()
Gets a value indicating whether to use eased animation.
|
boolean |
isFixPorts()
Controls whether strong port constraints are automatically created.
|
boolean |
isRunning()
Gets a value indicating whether this instance is currently running.
|
boolean |
isRunningInThread()
Gets a value indicating whether to run the layout in a separate thread.
|
boolean |
isSequentialExecutionEnabled()
Gets a value indicating whether this instance waits for other instances to finish their operations before it executes.
|
boolean |
isTableLayoutConfiguratorEnabled()
Gets a value indicating whether to automatically perform calls to
TableLayoutConfigurator.prepare(IGraph) and TableLayoutConfigurator.restore(IGraph)
in order to layout table nodes. |
boolean |
isUserInteractionAllowed()
Gets a value indicating whether user interaction should be allowed during the animation.
|
boolean |
isViewportAnimationEnabled()
Gets a value indicating whether to animate the viewport.
|
boolean |
isViewportLimiterConsiderationEnabled()
Gets a value indicating whether to respect the
ViewportLimiter
of the GraphControl of this instance. |
protected void |
prepareTableLayout()
Set up
TableLayoutConfigurator for a layout. |
void |
removeLayoutFinishedListener(IEventHandler<LayoutEventArgs> layoutFinishedEvent)
Removes the given listener for the
LayoutFinished
event. |
protected void |
restoreTableLayout()
Writes the table layout information provided through
TableLayoutConfigurator back
to all tables. |
void |
setAutomaticEdgeGrouping(boolean value)
Sets a value indicating whether edge groups are automatically created for edges that are connected to the same port.
|
void |
setContentRectUpdatingEnabled(boolean value)
Sets a value indicating whether the content rectangle property of the
CanvasControl
should be updated upon completion. |
void |
setDuration(Duration value)
Sets the duration of the animation.
|
void |
setEasedAnimationEnabled(boolean value)
Sets a value indicating whether to use eased animation.
|
void |
setFixPorts(boolean value)
Controls whether strong port constraints are automatically created.
|
void |
setLayoutData(LayoutData value)
Sets the layout data that is applied when
starting the executor. |
void |
setRunningInThread(boolean value)
Sets a value indicating whether to run the layout in a separate thread.
|
void |
setSelectionModel(ISelectionModel<IModelItem> value)
Sets the
ISelectionModel to use for the automatically registered IDataProvider instances for LayoutKeys.AFFECTED_NODES_DPKEY
and LayoutKeys.AFFECTED_EDGES_DPKEY . |
void |
setSequentialExecutionEnabled(boolean value)
Sets a value indicating whether this instance waits for other instances to finish their operations before it executes.
|
void |
setTableLayoutConfiguratorEnabled(boolean value)
Sets a value indicating whether to automatically perform calls to
TableLayoutConfigurator.prepare(IGraph) and TableLayoutConfigurator.restore(IGraph)
in order to layout table nodes. |
void |
setTargetBoundsInsets(InsetsD value)
Sets the insets (in world coordinates) that will be added to the content rectangle when calculating the target
viewport.
|
void |
setUserInteractionAllowed(boolean value)
Sets a value indicating whether user interaction should be allowed during the animation.
|
void |
setViewportAnimationEnabled(boolean value)
Sets a value indicating whether to animate the viewport.
|
void |
setViewportLimiterConsiderationEnabled(boolean value)
Sets a value indicating whether to respect the
ViewportLimiter
of the GraphControl of this instance. |
void |
start()
Actually starts the layout process and the optional animation.
|
void |
stop()
Stops a currently running layout calculation or animation.
|
public LayoutExecutor(GraphControl graphControl, IGraph graph, ILayoutAlgorithm layout)
LayoutExecutor
class.graphControl
- The control which will be animated and provides the IGraph
instance.graph
- The graph to layout.layout
- The ILayoutAlgorithm
to use.public LayoutExecutor(GraphControl graphControl, ILayoutAlgorithm layout)
LayoutExecutor
class.
Use the start()
method to actually execute the task. This will disable animation and content rect updates.
graphControl
- The control which will be animated and provides the IGraph
instance.layout
- The ILayoutAlgorithm
to use.public final void addLayoutFinishedListener(IEventHandler<LayoutEventArgs> layoutFinishedEvent)
LayoutFinished
event.
The event will be raised upon completion or upon an exception. In the case of an exception the LayoutEventArgs
contain the Exception
the exception instance.
Event handlers need to set the event as handled
to prevent further processing in
both the exception and the normal case.
layoutFinishedEvent
- The listener to add.start()
,
removeLayoutFinishedListener(IEventHandler)
public final void cancel()
If a layout calculation is still running, it will be canceled immediately via AbortHandler.cancel()
and the
animation will not run. If the layout calculation was already completed, the animation will be aborted and the layout
result will be shown immediately.
Note that when canceling an ILayoutAlgorithm
via AbortHandler
may leave the ILayoutAlgorithm
instance in an undefined state. The respective ILayoutAlgorithm
instance should no longer be used.
The LayoutFinished
event will be raised as soon as the layout
algorithm aborts.
protected AbortHandler createAbortHandler()
AbortHandler
.
This method is called upon first access to the AbortHandler
property.
AbortHandler
instance to use during layout calculation.protected IAnimation createAnimation()
IAnimation
that will be used by this instance after the layout has been
calculated.getDuration()
,
isViewportAnimationEnabled()
,
createMorphAnimation()
,
createViewportAnimation(RectD)
protected IAnimation createMorphAnimation()
IGraph
.createAnimation()
protected IAnimation createTableAnimations()
ITable
s in the graph.TableAnimation
,
isTableLayoutConfiguratorEnabled()
protected TableLayoutConfigurator createTableLayoutConfigurator()
TableLayoutConfigurator
that is used if TableLayoutConfiguratorEnabled
is enabled.
This method is called upon first access to the TableLayoutConfigurator
property.
TableLayoutConfigurator
class.protected IAnimation createViewportAnimation(RectD targetBounds)
Viewport
.targetBounds
- The target bounds of the animation.createAnimation()
protected void execute(Runnable threadStart)
threadStart
.
This implementation will either start a new Thread
if RunningInThread
is set to
true
, or directly invoke the threadStart
.
threadStart
- The thread start delegate to execute.public final AbortHandler getAbortHandler()
AbortHandler
that is used during the layout calculation.AbortHandler
that is used during the layout calculation.createAbortHandler()
public final Duration getDuration()
The default value is Duration.ZERO
.
Duration.ZERO
will prevent the animation from
happening. Instead, the result is applied immediately. A positive value will effectively force the execution to be
performed asynchronously.setDuration(Duration)
protected final IGraph getGraph()
protected final GraphControl getGraphControl()
protected final ILayoutAlgorithm getLayout()
ILayoutAlgorithm
this instance is using.public final LayoutData getLayoutData()
starting
the executor.setLayoutData(LayoutData)
protected final CopiedLayoutGraph getLayoutGraph()
public final ISelectionModel<IModelItem> getSelectionModel()
ISelectionModel
to use for the automatically registered IDataProvider
instances for LayoutKeys.AFFECTED_NODES_DPKEY
and LayoutKeys.AFFECTED_EDGES_DPKEY
.
If this value is null
and Graph
is the same instance as
GraphControl
's IGraph
instance, the selection model from GraphControl
is used instead.
setSelectionModel(ISelectionModel)
public final TableLayoutConfigurator getTableLayoutConfigurator()
TableLayoutConfigurator
that is used if TableLayoutConfiguratorEnabled
is enabled.createTableLayoutConfigurator()
protected RectD getTargetBounds()
ContentRect
as well as the ViewportAnimation
after the layout has finished.
By default, the value is computed with LayoutGraphUtilities.getBoundingBox(com.yworks.yfiles.layout.LayoutGraph, com.yworks.yfiles.algorithms.INodeCursor, com.yworks.yfiles.algorithms.IEdgeCursor, boolean)
with labels and TargetBoundsInsets
taken into account.
public final InsetsD getTargetBoundsInsets()
The default value is InsetsD.EMPTY
.
setTargetBoundsInsets(InsetsD)
public final boolean isAutomaticEdgeGrouping()
If this property is enabled and no edge groups are explicitly created (no IMapper
are
registered for the keys PortConstraintKeys.SOURCE_GROUP_ID_DPKEY
and
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
), for each port with multiple outgoing
resp. incoming edges these edges will be assigned to the same edge group. The necessary
IDataProvider
s will be created automatically.
Without an ILayoutAlgorithm
that supports edge groups, this property ahs no visual effect.
The default value is true
.
PortConstraintKeys.SOURCE_GROUP_ID_DPKEY
,
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
,
LayoutGraphAdapter.isAutomaticEdgeGrouping()
,
isFixPorts()
,
setAutomaticEdgeGrouping(boolean)
public final boolean isContentRectUpdatingEnabled()
CanvasControl
should be updated upon completion.
The default value is false
.
true
if the content rectangle should be updated; false
otherwise.setContentRectUpdatingEnabled(boolean)
public final boolean isEasedAnimationEnabled()
The default value is false
.
true
if the animation should be done with eased; false
otherwise.setEasedAnimationEnabled(boolean)
public final boolean isFixPorts()
If this property is enabled and no edge groups are explicitly created (no IMapper
are
registered for the keys PortConstraintKeys.SOURCE_GROUP_ID_DPKEY
and
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
), for all edges strong source and target
point constraints with PortSide.ANY
are created. The necessary
IDataProvider
s will be created automatically.
This ensures that view IPort
s are not moved during the layout, if the ILayoutAlgorithm
supports port constraints.
The default value is false
.
PortConstraintKeys.SOURCE_GROUP_ID_DPKEY
,
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
,
LayoutGraphAdapter.isFixPorts()
,
isAutomaticEdgeGrouping()
,
setFixPorts(boolean)
public final boolean isRunning()
public final boolean isRunningInThread()
The default value is true
.
true
if the layout is run in separate thread; otherwise, false
. A separate thread will make start()
perform the work asynchronously and return immediately.#execute(ThreadStart)
,
setRunningInThread(boolean)
public final boolean isSequentialExecutionEnabled()
The default value is true
. In this case, this instance waits for other instances of LayoutExecutor
that
handle the same instance of GraphControl
to finish their operation before it executes.
If set to
false
, this instance ignores other potentially running instances, and doesn't try to stop them but rather
executes immediately. Also it will not be stopped by other instances. This should only be used under special
circumstances since it can result in race conditions if multiple animations or calculations are performed on the same
graph instance.
setSequentialExecutionEnabled(boolean)
public final boolean isTableLayoutConfiguratorEnabled()
TableLayoutConfigurator.prepare(IGraph)
and TableLayoutConfigurator.restore(IGraph)
in order to layout table nodes.
The default value is true
.
true
if table layout should be configured automatically; false
otherwise.setTableLayoutConfiguratorEnabled(boolean)
public final boolean isUserInteractionAllowed()
If false
, the WaitInputMode
is queried from the CanvasControl
and Waiting
is enabled during the animation.
The default value is false
.
setUserInteractionAllowed(boolean)
public final boolean isViewportAnimationEnabled()
The default value is false
.
true
if the viewport should be animated; false
otherwise.setViewportAnimationEnabled(boolean)
public final boolean isViewportLimiterConsiderationEnabled()
ViewportLimiter
of the GraphControl
of this instance.
The default value is false
.
true
if the ViewportLimiter
should be
considered, otherwise false
.setViewportLimiterConsiderationEnabled(boolean)
protected void prepareTableLayout()
TableLayoutConfigurator
for a layout.
This implementation configures HorizontalLayoutEnabled
according to the LayoutOrientation
and calls
TableLayoutConfigurator.prepare(IGraph)
public final void removeLayoutFinishedListener(IEventHandler<LayoutEventArgs> layoutFinishedEvent)
LayoutFinished
event.
The event will be raised upon completion or upon an exception. In the case of an exception the LayoutEventArgs
contain the Exception
the exception instance.
Event handlers need to set the event as handled
to prevent further processing in
both the exception and the normal case.
layoutFinishedEvent
- The listener to remove.start()
,
addLayoutFinishedListener(IEventHandler)
protected void restoreTableLayout()
TableLayoutConfigurator
back
to all tables.
This method is only called when the layout is not animated.
prepareTableLayout()
public final void setAutomaticEdgeGrouping(boolean value)
If this property is enabled and no edge groups are explicitly created (no IMapper
are
registered for the keys PortConstraintKeys.SOURCE_GROUP_ID_DPKEY
and
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
), for each port with multiple outgoing
resp. incoming edges these edges will be assigned to the same edge group. The necessary
IDataProvider
s will be created automatically.
Without an ILayoutAlgorithm
that supports edge groups, this property ahs no visual effect.
The default value is true
.
value
- The AutomaticEdgeGrouping to set.PortConstraintKeys.SOURCE_GROUP_ID_DPKEY
,
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
,
LayoutGraphAdapter.isAutomaticEdgeGrouping()
,
isFixPorts()
,
isAutomaticEdgeGrouping()
public final void setContentRectUpdatingEnabled(boolean value)
CanvasControl
should be updated upon completion.
The default value is false
.
value
- true
if the content rectangle should be updated; false
otherwise.isContentRectUpdatingEnabled()
public final void setDuration(Duration value)
The default value is Duration.ZERO
.
value
- The duration of the animation. A value smaller than or equal to Duration.ZERO
will prevent the animation from
happening. Instead, the result is applied immediately. A positive value will effectively force the execution to be
performed asynchronously.getDuration()
public final void setEasedAnimationEnabled(boolean value)
The default value is false
.
value
- true
if the animation should be done with eased; false
otherwise.isEasedAnimationEnabled()
public final void setFixPorts(boolean value)
If this property is enabled and no edge groups are explicitly created (no IMapper
are
registered for the keys PortConstraintKeys.SOURCE_GROUP_ID_DPKEY
and
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
), for all edges strong source and target
point constraints with PortSide.ANY
are created. The necessary
IDataProvider
s will be created automatically.
This ensures that view IPort
s are not moved during the layout, if the ILayoutAlgorithm
supports port constraints.
The default value is false
.
value
- The FixPorts to set.PortConstraintKeys.SOURCE_GROUP_ID_DPKEY
,
PortConstraintKeys.TARGET_GROUP_ID_DPKEY
,
LayoutGraphAdapter.isFixPorts()
,
isAutomaticEdgeGrouping()
,
isFixPorts()
public final void setLayoutData(LayoutData value)
starting
the executor.value
- The LayoutData to set.getLayoutData()
public final void setRunningInThread(boolean value)
The default value is true
.
value
- true
if the layout is run in separate thread; otherwise, false
. A separate thread will make start()
perform the work asynchronously and return immediately.#execute(ThreadStart)
,
isRunningInThread()
public final void setSelectionModel(ISelectionModel<IModelItem> value)
ISelectionModel
to use for the automatically registered IDataProvider
instances for LayoutKeys.AFFECTED_NODES_DPKEY
and LayoutKeys.AFFECTED_EDGES_DPKEY
.
If this value is null
and Graph
is the same instance as
GraphControl
's IGraph
instance, the selection model from GraphControl
is used instead.
value
- The SelectionModel to set.getSelectionModel()
public final void setSequentialExecutionEnabled(boolean value)
The default value is true
. In this case, this instance waits for other instances of LayoutExecutor
that
handle the same instance of GraphControl
to finish their operation before it executes.
If set to
false
, this instance ignores other potentially running instances, and doesn't try to stop them but rather
executes immediately. Also it will not be stopped by other instances. This should only be used under special
circumstances since it can result in race conditions if multiple animations or calculations are performed on the same
graph instance.
value
- The SequentialExecutionEnabled to set.isSequentialExecutionEnabled()
public final void setTableLayoutConfiguratorEnabled(boolean value)
TableLayoutConfigurator.prepare(IGraph)
and TableLayoutConfigurator.restore(IGraph)
in order to layout table nodes.
The default value is true
.
value
- true
if table layout should be configured automatically; false
otherwise.isTableLayoutConfiguratorEnabled()
public final void setTargetBoundsInsets(InsetsD value)
The default value is InsetsD.EMPTY
.
value
- The target bounds insets.getTargetBoundsInsets()
public final void setUserInteractionAllowed(boolean value)
If false
, the WaitInputMode
is queried from the CanvasControl
and Waiting
is enabled during the animation.
The default value is false
.
value
- The UserInteractionAllowed to set.isUserInteractionAllowed()
public final void setViewportAnimationEnabled(boolean value)
The default value is false
.
value
- true
if the viewport should be animated; false
otherwise.isViewportAnimationEnabled()
public final void setViewportLimiterConsiderationEnabled(boolean value)
ViewportLimiter
of the GraphControl
of this instance.
The default value is false
.
value
- true
if the ViewportLimiter
should be
considered, otherwise false
.isViewportLimiterConsiderationEnabled()
public void start()
This method will ultimately call the #execute(ThreadStart)
method. If the Duration
is
zero and RunningInThread
is false
, the call will be blocking (synchronous),
otherwise it will return before LayoutFinished
is called, which
happens asynchronously.
If this instance is already running
, this method returns immedetaly without doing anything.
#execute(ThreadStart)
public final void stop()
If a layout calculation is still running, it will be requested to stopped via AbortHandler.stop()
and the
animation will not run. If the layout calculation was already completed, the animation will be aborted immediately and
the layout result will be shown immediately.
To just skip the animation but let the calculation finish normally, the Duration
can be set to
zero at any time before the animation was started.
The LayoutFinished
event will be raised as soon as the layout
algorithm stops.