public class OrthogonalEdgeEditingContext extends Object
This class will be queried from the IInputModeContext
of implementations of IPositionHandler
,
IHandle
, and IReshapeHandler
that support orthogonal editing of edges.
In a first step, the edit (which is a movement of one or more IPort
s, IBend
s, edge ends
,
or IPortOwner
s) is being initialized
before anything has been
changed. Then, client code that seeks to modify the graph, uses the methods
addExplicitlyMovedBend(MovementInfo)
, addMovedEdgeEnd(MovementInfo, boolean)
,
addMovedPort(MovementInfo)
, and addTransformedPortOwner(IPortOwner)
. In the next step, the drag is being initialized
and all affected edges will be prepared
so that the editing will not destroy the
orthogonality. Interested editors now get the chance to register and negotiate implicitly moved
bends. Then the actual editing is performed and the edit is either canceled
, in which case the added bends are removed
or the edit is finished
and the affected edges are being cleaned up
.
IOrthogonalEdgeHelper
,
isEnabled()
,
isPortMovingEnabled()
Constructor and Description |
---|
OrthogonalEdgeEditingContext()
Initializes a new instance of the
OrthogonalEdgeEditingContext class that is initially
Enabled . |
Modifier and Type | Method and Description |
---|---|
void |
addCleanedUpListener(IEventHandler<InputModeEventArgs> cleanedUpEvent)
Adds the given listener for the
CleanedUp event that occurs when the recent edit operation has been cleaned up. |
void |
addExplicitlyMovedBend(MovementInfo movementInfo)
Registers the provided bend with this instance so that it will be considered explicitly moved for this edit.
|
MovementInfo |
addImplicitlyMovedBend(MovementInfo movementInfo)
Registers the provided bend as being moved implicitly for this edit.
|
void |
addInitializedListener(IEventHandler<InputModeEventArgs> initializedEvent)
Adds the given listener for the
Initialized event that occurs when the edit has been initialized. |
void |
addInitializingListener(IEventHandler<InputModeEventArgs> initializingEvent)
Adds the given listener for the
Initializing event that occurs when the edit is about to be initialized. |
void |
addMovedEdgeEnd(MovementInfo movementInfo,
boolean sourceEnd)
Registers the provided end of the edge with this instance so that it will be considered explicitly moved for this edit.
|
void |
addMovedPort(MovementInfo movementInfo)
Registers the provided port with this instance so that it will be considered explicitly moved for this edit.
|
void |
addTransformedPortOwner(IPortOwner owner)
Adds an
IPortOwner that is being transformed somehow during the edit so that the attached ports
will be moved in an irregular (non-linear ) way. |
void |
cancelDrag()
Called by client edit code when a drag has been canceled.
|
protected void |
cleanUp()
Performs clean up procedures.
|
protected void |
cleanUpEdgePath(IGraph graph,
IEdge edge)
Cleans up the edge's path after a successfully
finished drag . |
protected void |
cleanupEdgePaths(IGraph graph)
Called after a successfully
finished drag to clean up artifacts of modified edges. |
MovementInfo |
createImplicitlyMovedBendInfo(IBend bend,
MovementInfo horizontalAdjacentInfo,
MovementInfo verticalAdjacentInfo)
Creates or obtains a previously created
MovementInfo for the provided implicitly moved bend. |
void |
dragFinished()
Called when a drag has been successfully finished.
|
void |
dragInitialized()
Needs to be called by client editing code after
initializeDrag(IInputModeContext) has been called and all
IDragHandler s have been initialized. |
protected IEnumerable<IBend> |
getAddedBends()
Gets the previously
registered added bends. |
protected IInputModeContext |
getCurrentInputModeContext()
Gets the current input mode context that is in effect for the current edit.
|
protected Iterable<IEdge> |
getLockedPortEdges()
Provides access to the enumeration of
IEdge instances whose ports have been locked at source and target end. |
protected IListEnumerable<MovementInfo> |
getMovementInfos(IEdge edge)
Gets the
movement infos that describe the orthogonal path of the edge. |
protected IOrthogonalEdgeHelper |
getOrthogonalEdgeHelper(IEdge edge)
Callback method that gets the
IOrthogonalEdgeHelper instance associated with the given edge. |
SegmentOrientation |
getSegmentOrientation(IEdge edge,
int segmentIndex)
Gets the declared segment orientation for the provided segment at the given edge.
|
protected Iterable<IPortOwner> |
getTransformedPortOwners()
Provides access to the enumeration of
IPortOwner instances that are being transformed during the edit. |
void |
initializeDrag(IInputModeContext context)
Called by client code when a drag is started about to be started.
|
boolean |
isEnabled()
Gets a value indicating whether orthogonal edge editing is enabled at all.
|
boolean |
isInitialized()
Whether the context is initialized.
|
boolean |
isInitializing()
Gets a value indicating whether this instance is currently initializing.
|
boolean |
isOrthogonallyEditedEdge(IInputModeContext context,
IEdge edge)
Callback that can be used by
IDragHandler s and the like to determines whether the given edge is orthogonally
edited edge in the specified input mode context. |
boolean |
isPortMovingEnabled()
Gets a value indicating ports are allowed to be moved at all.
|
void |
lockPortMovement(IEdge edge)
Locks the movement of the ports of the edges so that
shouldMoveEndImplicitly(IEdge, boolean) will yield false
for the provided edge during the current edit. |
protected void |
onCleanedUp(InputModeEventArgs eventArgs)
Raises the
CleanedUp event. |
protected void |
onInitialized(InputModeEventArgs eventArgs)
Raises the
Initialized event. |
protected void |
onInitializing(InputModeEventArgs eventArgs)
Raises the
Initializing event. |
protected void |
prepareEdgePaths(IGraph graph)
Called during
dragInitialized() to prepare the edge paths for orthogonal editing. |
protected void |
prepareOrthogonalEdge(IGraph graph,
IEdge edge,
IListEnumerable<SegmentOrientation> orientations,
IListEnumerable<MovementInfo> infos)
Helper method that inspects and prepares an orthogonal edge for the upcoming edit process.
|
protected void |
registerAddedBend(IBend bend)
Can be used by subclasses during
prepareOrthogonalEdge(IGraph, IEdge, IListEnumerable, IListEnumerable) to
register added bends that can later be removed in case the operation is
canceled. |
protected void |
removeAddedBends(IGraph graph,
Iterable<IBend> addedBends)
Removes previously
registered added bends. |
void |
removeCleanedUpListener(IEventHandler<InputModeEventArgs> cleanedUpEvent)
Removes the given listener for the
CleanedUp event that occurs when the recent edit operation has been cleaned
up. |
void |
removeInitializedListener(IEventHandler<InputModeEventArgs> initializedEvent)
Removes the given listener for the
Initialized event that occurs when the edit has been initialized. |
void |
removeInitializingListener(IEventHandler<InputModeEventArgs> initializingEvent)
Removes the given listener for the
Initializing event that occurs when the edit is about to be initialized. |
void |
setEnabled(boolean value)
Sets a value indicating whether orthogonal edge editing is enabled at all.
|
void |
setPortMovingEnabled(boolean value)
Sets a value indicating ports are allowed to be moved at all.
|
boolean |
shouldMoveEndImplicitly(IEdge edge,
boolean sourceSide)
Callback that can be used by
IDragHandler s and the like to determines whether the
specified end of the provided edge should be moved implicitly. |
public OrthogonalEdgeEditingContext()
OrthogonalEdgeEditingContext
class that is initially
Enabled
.public final void addCleanedUpListener(IEventHandler<InputModeEventArgs> cleanedUpEvent)
CleanedUp
event that occurs when the recent edit operation has been cleaned up.cleanedUpEvent
- The listener to add.cleanUp()
,
onCleanedUp(InputModeEventArgs)
,
removeCleanedUpListener(IEventHandler)
public final void addExplicitlyMovedBend(MovementInfo movementInfo)
IDragHandler
implementations that are being used to explicitly move a bend during
the edit should use this method to register their edit while they are being
initialized
.
movementInfo
- The movement info that describes the movement of the bend.public final MovementInfo addImplicitlyMovedBend(MovementInfo movementInfo)
The instance will be returned by createImplicitlyMovedBendInfo(IBend, MovementInfo, MovementInfo)
and the MoveType
will be combined with the requested move type.
movementInfo
- The movement info for the bend.public final void addInitializedListener(IEventHandler<InputModeEventArgs> initializedEvent)
Initialized
event that occurs when the edit has been initialized.initializedEvent
- The listener to add.dragInitialized()
,
onInitialized(InputModeEventArgs)
,
removeInitializedListener(IEventHandler)
public final void addInitializingListener(IEventHandler<InputModeEventArgs> initializingEvent)
Initializing
event that occurs when the edit is about to be initialized.initializingEvent
- The listener to add.initializeDrag(IInputModeContext)
,
onInitializing(InputModeEventArgs)
,
removeInitializingListener(IEventHandler)
public final void addMovedEdgeEnd(MovementInfo movementInfo, boolean sourceEnd)
IDragHandler
implementations that are being used to explicitly move the end of an
edge during the edit should use this method to register their edit while they are being
initialized
.
movementInfo
- The movement info that describes the movement of the end of the edge. The MovedItem
must be an IEdge
.sourceEnd
- true
if the movementInfo
represents the source end of the edge.IEdgePortHandleProvider
public final void addMovedPort(MovementInfo movementInfo)
IDragHandler
implementations that are being used to explicitly move a bend during
the edit should use this method to register their edit while they are being
initialized
.
movementInfo
- The movement info that describes the movement of the port.public final void addTransformedPortOwner(IPortOwner owner)
IPortOwner
that is being transformed somehow during the edit so that the attached ports
will be moved in an irregular (non-linear
) way.
Normally this will be nodes that are being resized or moved in a non-linear way, or edges, whose bends or ports are being changed.
owner
- The item that will be transformed.public void cancelDrag()
Resets all internal state lists and sets IsInitialized
back to false
. Also temporarily added bends are removed
and CleanedUp
will be triggered.
protected void cleanUp()
This is called in response to cancelDrag()
and dragFinished()
as well as initially during
initializeDrag(IInputModeContext)
.
protected void cleanUpEdgePath(IGraph graph, IEdge edge)
finished drag
.
This implementations delegates to the IOrthogonalEdgeHelper
's IOrthogonalEdgeHelper.cleanUpEdge(IInputModeContext, IGraph, IEdge)
method.
graph
- The graph in which the edge resides.edge
- The modified edge.getOrthogonalEdgeHelper(IEdge)
protected void cleanupEdgePaths(IGraph graph)
finished drag
to clean up artifacts of modified edges.graph
- The graph.cleanUpEdgePath(IGraph, IEdge)
public final MovementInfo createImplicitlyMovedBendInfo(IBend bend, MovementInfo horizontalAdjacentInfo, MovementInfo verticalAdjacentInfo)
MovementInfo
for the provided implicitly moved bend.
This method is queried by client IDragHandler
implementations that have been
initialized for the current edit that need to move adjacent bends implicitly. Implementations should pass as the
parameters the movement information that controls the vertical or horizontal movement of the bend implicitly.
bend
- The implicitly moved bend.verticalAdjacentInfo
- The movement info that implicitly constrains the vertical movement of the bend or null
.horizontalAdjacentInfo
- The movement info that implicitly constrains the horizontal movement of the bend or null
.public void dragFinished()
This method will perform the necessary clean up and clean up edge paths
.
addCleanedUpListener(IEventHandler)
public void dragInitialized()
initializeDrag(IInputModeContext)
has been called and all
IDragHandler
s have been initialized.
This method will update the IsInitializing
and IsInitialized
properties accordingly and will prepare
the edge paths. Finally, the Initialized
event is raised so that registered handlers can perform their post-initialization process.
protected final IEnumerable<IBend> getAddedBends()
registered added
bends.registerAddedBend(IBend)
.protected final IInputModeContext getCurrentInputModeContext()
Initializing
or Initialized
.protected final Iterable<IEdge> getLockedPortEdges()
IEdge
instances whose ports have been locked at source and target end.
For elements in the enumerable the end points should not be moved and thus shouldMoveEndImplicitly(IEdge, boolean)
returns false for these edges. Note that this collection is reset for each edit.
MoveTypes.ARBITRARY_MOVE
protected IListEnumerable<MovementInfo> getMovementInfos(IEdge edge)
movement infos
that describe the orthogonal path of the edge.edge
- The edge to obtain the infos for.null
values if nothing is known about the bend, yet.protected IOrthogonalEdgeHelper getOrthogonalEdgeHelper(IEdge edge)
IOrthogonalEdgeHelper
instance associated with the given edge.
This implementation obtains the helper instance from the ILookup.lookup(java.lang.Class)
of the edge.
edge
- The edge to obtain the helper instance for.null
, in which case the default behavior will be used.OrthogonalEdgeHelper
public SegmentOrientation getSegmentOrientation(IEdge edge, int segmentIndex)
This implementation uses the GetOrthogonalEdgeHelper()
.GetSegmentOrientation
method to yield the orientation.
edge
- The edge to determine the orientation of the segment.segmentIndex
- Index of the segment.protected final Iterable<IPortOwner> getTransformedPortOwners()
IPortOwner
instances that are being transformed during the edit.
For elements in the enumerable the attached Ports
are considered to be moved in an
irregular way during the edit.
MoveTypes.ARBITRARY_MOVE
public void initializeDrag(IInputModeContext context)
This code needs to be called before any of the IDragHandler
implementations are
initialized so that they can then register the items they are going to modify with this instance. After this method has
been called, the handlers that perform the actual edit need to be initialized and as soon as this has been done, dragInitialized()
should be called.
IllegalStateException
- If this context is already Initialized
or currently
Initializing
.context
- The context in which the edit is going to be performed.dragInitialized()
public final boolean isEnabled()
The default value is true
.
true
if orthogonal edge editing is enabled at all; false
otherwise.isOrthogonallyEditedEdge(IInputModeContext, IEdge)
,
IOrthogonalEdgeHelper.shouldEditOrthogonally(IInputModeContext, IEdge)
,
setEnabled(boolean)
public final boolean isInitialized()
The context is initialized between the calls to initializeDrag(IInputModeContext)
and dragFinished()
or cancelDrag()
.
public final boolean isInitializing()
true
if this instance is Initializing
but not yet
Initialized
; false
otherwise.public boolean isOrthogonallyEditedEdge(IInputModeContext context, IEdge edge)
IDragHandler
s and the like to determines whether the given edge is orthogonally
edited edge in the specified input mode context.
This implementation will always yield false
if it is disabled
. Otherwise getOrthogonalEdgeHelper(IEdge)
will be used to delegate the query to IOrthogonalEdgeHelper.shouldEditOrthogonally(IInputModeContext, IEdge)
.
context
- The input mode context which is editing the edge.edge
- The edge that will be edited.true
if this edge should be orthogonally edited for the specified input mode context; false
otherwise.isEnabled()
,
IOrthogonalEdgeHelper.shouldEditOrthogonally(IInputModeContext, IEdge)
public final boolean isPortMovingEnabled()
The default value is true
.
true
(the default) if bends adjacent to ports should try to move the port to stay perpendicular to the bend, false
otherwise.shouldMoveEndImplicitly(IEdge, boolean)
,
IOrthogonalEdgeHelper.shouldMoveEndImplicitly(IInputModeContext, IEdge, boolean)
,
setPortMovingEnabled(boolean)
public final void lockPortMovement(IEdge edge)
shouldMoveEndImplicitly(IEdge, boolean)
will yield false
for the provided edge during the current edit.
This state will be reset after the current edit.
edge
- The edge to lock the ports of.getLockedPortEdges()
protected void onCleanedUp(InputModeEventArgs eventArgs)
CleanedUp
event.eventArgs
- The InputModeEventArgs
instance containing the event data.protected void onInitialized(InputModeEventArgs eventArgs)
Initialized
event.eventArgs
- The InputModeEventArgs
instance containing the event data.addInitializedListener(IEventHandler)
,
dragInitialized()
protected void onInitializing(InputModeEventArgs eventArgs)
Initializing
event.eventArgs
- The InputModeEventArgs
instance containing the event data.addInitializingListener(IEventHandler)
,
initializeDrag(IInputModeContext)
protected void prepareEdgePaths(IGraph graph)
dragInitialized()
to prepare the edge paths for orthogonal editing.graph
- The graph that contains the edges to be edited.prepareOrthogonalEdge(IGraph, IEdge, IListEnumerable, IListEnumerable)
protected void prepareOrthogonalEdge(IGraph graph, IEdge edge, IListEnumerable<SegmentOrientation> orientations, IListEnumerable<MovementInfo> infos)
This method inspects an edge and possibly inserts new bends into an edge to assure that during editing the orthogonality won't be lost.
graph
- The graph to use for modifying the bends.edge
- The edge to inspect.orientations
- The orientations of the segments - the array is of length (edge.Bends.Count + 1).infos
- The MovementInfo
instances for the source end, the bends, and the target end. This array contains MovementInfo
instances representing either edge ends or ports at the first and last position and MovementInfo
s or null
entries for the bends. The length thus is (edge.Bends.Count + 2) and null
entries indicate that there is no
information about the movement (in case the bend will only be moved implicitly later, if at all).protected final void registerAddedBend(IBend bend)
prepareOrthogonalEdge(IGraph, IEdge, IListEnumerable, IListEnumerable)
to
register added bends that can later be removed
in case the operation is
canceled.
This method will only record the addition of bends if this instance is initialized
or
still initializing
.
bend
- The bend that has been added to guarantee orthogonality.protected void removeAddedBends(IGraph graph, Iterable<IBend> addedBends)
registered
added bends.graph
- The graph to use for removing the bends.addedBends
- The added bends.getAddedBends()
,
registerAddedBend(IBend)
public final void removeCleanedUpListener(IEventHandler<InputModeEventArgs> cleanedUpEvent)
CleanedUp
event that occurs when the recent edit operation has been cleaned
up.cleanedUpEvent
- The listener to remove.cleanUp()
,
onCleanedUp(InputModeEventArgs)
,
addCleanedUpListener(IEventHandler)
public final void removeInitializedListener(IEventHandler<InputModeEventArgs> initializedEvent)
Initialized
event that occurs when the edit has been initialized.initializedEvent
- The listener to remove.dragInitialized()
,
onInitialized(InputModeEventArgs)
,
addInitializedListener(IEventHandler)
public final void removeInitializingListener(IEventHandler<InputModeEventArgs> initializingEvent)
Initializing
event that occurs when the edit is about to be initialized.initializingEvent
- The listener to remove.initializeDrag(IInputModeContext)
,
onInitializing(InputModeEventArgs)
,
addInitializingListener(IEventHandler)
public final void setEnabled(boolean value)
The default value is true
.
value
- true
if orthogonal edge editing is enabled at all; false
otherwise.isOrthogonallyEditedEdge(IInputModeContext, IEdge)
,
IOrthogonalEdgeHelper.shouldEditOrthogonally(IInputModeContext, IEdge)
,
isEnabled()
public final void setPortMovingEnabled(boolean value)
The default value is true
.
value
- true
(the default) if bends adjacent to ports should try to move the port to stay perpendicular to the bend, false
otherwise.shouldMoveEndImplicitly(IEdge, boolean)
,
IOrthogonalEdgeHelper.shouldMoveEndImplicitly(IInputModeContext, IEdge, boolean)
,
isPortMovingEnabled()
public boolean shouldMoveEndImplicitly(IEdge edge, boolean sourceSide)
IDragHandler
s and the like to determines whether the
specified end of the provided edge
should be moved implicitly.
If an item is next to the end of an edge and the last segment should be kept orthogonal, this may only be possible if
the end of the edge is moved, too. This can be achieved by moving the edge to another IPort
, or by moving the
port instance itself. This depends on the implementation of the IEdgePortHandleProvider
for the given edge. This implementation will delegate to the IOrthogonalEdgeHelper.shouldMoveEndImplicitly(IInputModeContext, IEdge, boolean)
method of the IOrthogonalEdgeHelper
instance returned by getOrthogonalEdgeHelper(IEdge)
unless the side
of the edge is connected to an IPortOwner
instance that is marked as transformed
during the edit.
edge
- The edge for which it should be determined whether the edge end can be moved.sourceSide
- if set to true
the source side of the end is queried, else the target side.true
if the specified side of the edge can be moved; false
otherwise, in which case the segment should
be split to maintain orthogonality.getOrthogonalEdgeHelper(IEdge)
,
IOrthogonalEdgeHelper.shouldMoveEndImplicitly(IInputModeContext, IEdge, boolean)
,
isPortMovingEnabled()