public class PortRelocationHandle extends Object implements IHandle
IHandle
interface that lets the user change an edge's source
and target port
.
This handle will move one of the edge's end points visually to another IPort
or IPortCandidate
and upon
finalization of the gesture will set the new ports
for the
edge. This class heavily relies on the implementation of the IEdgeReconnectionPortCandidateProvider
that is
queried from the IEdge
this handle is acting on.
Constructor and Description |
---|
PortRelocationHandle(IGraph graph,
IEdge edge,
boolean sourceEnd)
Creates a new instance of the
PortRelocationHandle class. |
Modifier and Type | Method and Description |
---|---|
void |
cancelDrag(IInputModeContext context,
PointD originalLocation)
Called by clients to indicate that the dragging has been canceled by the user.
|
protected ICanvasObjectDescriptor |
createCurrentPortCandidateDescriptor()
Factory method that creates the
ICanvasObjectDescriptor that will be used to paint the "current"
IPortCandidate . |
protected SimpleEdge |
createDummyEdge(IEdge edge)
Factory method that creates the dummy edge that will be shown during the drag operation.
|
protected IVisualCreator |
createDummyEdgeVisualCreator(SimpleEdge dummy)
Factory method that creates a dummy paintable for the dummy edge during the drag operation.
|
protected IPortCandidate |
createExistingPortCandidate(IPort port)
Factory method that creates the candidate for the existing port.
|
protected ICanvasObjectDescriptor |
createPortCandidateDescriptor()
Factory method that creates the
ICanvasObjectDescriptor that will be used to paint the IPortCandidate s. |
void |
dragFinished(IInputModeContext context,
PointD originalLocation,
PointD newLocation)
Called by clients to indicate that the repositioning has just been finished.
|
protected IPortCandidate |
getClosestCandidate(IInputModeContext context,
PointD location,
Iterable<IPortCandidate> candidates)
Finds the closest candidate from the given set of candidates.
|
Cursor |
getCursor()
Provides the cursor to display when the mouse hovers over or drags this handle.
|
protected SimpleEdge |
getDummyEdge()
Gets the dummy edge this instance uses during the edit.
|
protected IEdge |
getEdge()
Gets the edge this instance acts upon.
|
protected IGraph |
getGraph(IInputModeContext context)
Gets the graph to use from the context.
|
protected IInputModeContext |
getInputModeContext()
Gets the context to operate on.
|
IPoint |
getLocation()
Returns a view of the location of the item.
|
double |
getMaximumSnapDistance()
Gets the maximum distance the pointer may be away of a candidate in order to be snapped to the candidate.
|
protected IPort |
getPort(IInputModeContext context,
IPortCandidate portCandidate,
PointD suggestedLocation)
Callback used during
dragFinished(IInputModeContext, PointD, PointD) to actually get the new port from the
chosen candidate. |
IEventRecognizer |
getPortCandidateResolutionRecognizer()
Gets the event recognizer that determines whether a
dynamic port candidate should
be resolved. |
protected Iterable<IPortCandidate> |
getPortCandidates(IInputModeContext context,
IEdge edge,
boolean sourcePort)
Gets the possible candidates for the given edge.
|
HandleTypes |
getType()
Returns the type of the handle that can be used by the rendering engine to render types differently.
|
void |
handleMove(IInputModeContext context,
PointD originalLocation,
PointD newLocation)
Called by clients to indicate that the element has been dragged and its position should be updated.
|
protected void |
hideOriginalEdge(IInputModeContext context,
IEdge edge)
Hides the original edge that during the drag operation.
|
void |
initializeDrag(IInputModeContext context)
Called by clients to indicate that the element is going to be dragged.
|
boolean |
isCyclicPortDependenciesAllowed()
Determines whether or not cyclic port dependencies are allowed.
|
boolean |
isDummyEdgeDisplayEnabled()
Gets a value indicating whether to show a dummy edge during the drag operation.
|
boolean |
isEdgeToEdgeConnectionsAllowed()
Determines whether or not edges are allowed to connect to other edges.
|
boolean |
isExistingPortAddingEnabled()
Gets a property that determines whether the existing port should be available as a possible port candidate, too.
|
protected boolean |
isPortCandidateResolutionEnabled(IInputModeContext context)
Determines whether
port candidate resolution is
enabled for the current gesture. |
boolean |
isPortCandidateResolvingEnabled()
Gets a value indicating whether a
dynamic port candidate should be resolved for
the current mouse location. |
boolean |
isShowingHitPortOwnerCandidatesOnlyEnabled()
Gets a value indicating whether to show the candidates of hit
IPortOwner s only. |
protected boolean |
isSourceEnd()
Gets a value indicating whether the source end of the edge is handled by this instance.
|
protected IPortCandidate |
resolveCandidate(IInputModeContext context,
IPortCandidate portCandidate,
PointD location)
Tries to
resolve a dynamic port candidate for the
given location. |
protected void |
setClosestCandidate(IPortCandidate portCandidate)
Updates the closest candidate for visual feedback.
|
void |
setCursor(Cursor value)
Provides the cursor to display when the mouse hovers over or drags this handle.
|
void |
setCyclicPortDependenciesAllowed(boolean value)
Determines whether or not cyclic port dependencies are allowed.
|
void |
setDummyEdgeDisplayEnabled(boolean value)
Sets a value indicating whether to show a dummy edge during the drag operation.
|
void |
setEdgeToEdgeConnectionsAllowed(boolean value)
Determines whether or not edges are allowed to connect to other edges.
|
void |
setExistingPortAddingEnabled(boolean value)
Sets a property that determines whether the existing port should be available as a possible port candidate, too.
|
protected void |
setInputModeContext(IInputModeContext value)
Sets the context to operate on.
|
void |
setMaximumSnapDistance(double value)
Sets the maximum distance the pointer may be away of a candidate in order to be snapped to the candidate.
|
protected void |
setPort(IInputModeContext context,
IEdge edge,
boolean setSourcePort,
IPortCandidate portCandidate,
PointD suggestedLocation)
Callback that is triggered by
dragFinished(IInputModeContext, PointD, PointD) to actually change the port. |
void |
setPortCandidateResolutionRecognizer(IEventRecognizer value)
Sets the event recognizer that determines whether a
dynamic port candidate should
be resolved. |
void |
setPortCandidateResolvingEnabled(boolean value)
Sets a value indicating whether a
dynamic port candidate should be resolved for
the current mouse location. |
protected void |
setPorts(IInputModeContext context,
IEdge edge,
IPort sourcePort,
IPort targetPort)
Finally sets the ports for the edge to the new values.
|
protected void |
setPosition(PointD location)
Updates the position of the handle.
|
void |
setShowingHitPortOwnerCandidatesOnlyEnabled(boolean value)
Sets a value indicating whether to show the candidates of hit
IPortOwner s only. |
protected void |
setToPortCandidate(SimpleEdge dummy,
boolean source,
IPortCandidate portCandidate)
Updates the dummy edge's visual appearance to reflect the new port candidate.
|
void |
setType(HandleTypes value)
Returns the type of the handle that can be used by the rendering engine to render types differently.
|
protected void |
unhideOriginalEdge(IEdge edge,
CanvasControl canvas)
Unhides the original edge that was hidden during the drag operation.
|
public PortRelocationHandle(IGraph graph, IEdge edge, boolean sourceEnd)
PortRelocationHandle
class.graph
- The graph or null
. If the graph instance is not specified, the handle will try to receive the graph from the IInputModeContext
it is passed in during initializeDrag(IInputModeContext)
.edge
- The edge.sourceEnd
- if set to true
the source end will be subject to relocation, otherwise it will be the target port.public void cancelDrag(IInputModeContext context, PointD originalLocation)
IDragHandler
This method may be called after the initial IDragHandler.initializeDrag(IInputModeContext)
and zero or more invocations of
IDragHandler.handleMove(IInputModeContext, PointD, PointD)
. Implementations should reset the position of the items they
modify to their initial state. Alternatively to this method the IDragHandler.dragFinished(IInputModeContext, PointD, PointD)
method might be called.
cancelDrag
in interface IDragHandler
context
- The context to retrieve information about the drag from.originalLocation
- The value of the coordinate of the Location
property at the time of
IDragHandler.initializeDrag(IInputModeContext)
.protected ICanvasObjectDescriptor createCurrentPortCandidateDescriptor()
ICanvasObjectDescriptor
that will be used to paint the "current"
IPortCandidate
.CanvasControl
.protected final SimpleEdge createDummyEdge(IEdge edge)
edge
- The edge to be represented by the dummy edge.isDummyEdgeDisplayEnabled()
protected IVisualCreator createDummyEdgeVisualCreator(SimpleEdge dummy)
dummy
- The dummy to create a paintable for.isDummyEdgeDisplayEnabled()
protected IPortCandidate createExistingPortCandidate(IPort port)
port
- The port to create a candidate for.null
.getPortCandidates(IInputModeContext, IEdge, boolean)
,
isExistingPortAddingEnabled()
protected ICanvasObjectDescriptor createPortCandidateDescriptor()
ICanvasObjectDescriptor
that will be used to paint the IPortCandidate
s.CanvasControl
.public void dragFinished(IInputModeContext context, PointD originalLocation, PointD newLocation)
IDragHandler
This method may be called after the initial IDragHandler.initializeDrag(IInputModeContext)
and zero or more invocations of
IDragHandler.handleMove(IInputModeContext, PointD, PointD)
. Alternatively to this method the IDragHandler.cancelDrag(IInputModeContext, PointD)
method might be called.
dragFinished
in interface IDragHandler
context
- The context to retrieve information about the drag from.originalLocation
- The value of the Location
property at the time of IDragHandler.initializeDrag(IInputModeContext)
.newLocation
- The coordinates in the world coordinate system that the client wants the handle to be at. Depending on the
implementation the Location
may or may not be modified to reflect the new value. This is the same
value as delivered in the last invocation of IDragHandler.handleMove(IInputModeContext, PointD, PointD)
protected IPortCandidate getClosestCandidate(IInputModeContext context, PointD location, Iterable<IPortCandidate> candidates)
context
- The context in for which the closest handle candidate is sought.location
- The location for which to find a candidate.candidates
- The list of possible candidates.null
.public Cursor getCursor()
IHandle
protected final SimpleEdge getDummyEdge()
isDummyEdgeDisplayEnabled()
protected final IEdge getEdge()
protected IGraph getGraph(IInputModeContext context)
context
- The input mode context.null
.protected final IInputModeContext getInputModeContext()
setInputModeContext(IInputModeContext)
public IPoint getLocation()
This implementation returns this
.
getLocation
in interface IDragHandler
public final double getMaximumSnapDistance()
The distance is measured in view coordinates. The default value is 50.0
.
setMaximumSnapDistance(double)
protected IPort getPort(IInputModeContext context, IPortCandidate portCandidate, PointD suggestedLocation)
dragFinished(IInputModeContext, PointD, PointD)
to actually get the new port from the
chosen candidate.
This implementation returns the result of IPortCandidate.createPort(IInputModeContext)
or calls IGraph.addPort(IPortOwner, com.yworks.yfiles.graph.portlocationmodels.IPortLocationModelParameter, com.yworks.yfiles.graph.styles.IPortStyle, Object)
if the result was null
.
portCandidate
- The candidate to get a port instance from.suggestedLocation
- The suggested location for the port.null
port instance.setPorts(IInputModeContext, IEdge, IPort, IPort)
public final IEventRecognizer getPortCandidateResolutionRecognizer()
dynamic port candidate
should
be resolved.
Note that this property has no effect if PortCandidateResolvingEnabled
is set
to false
.
By default this is set to IEventRecognizer.SHIFT_PRESSED
.
setPortCandidateResolutionRecognizer(IEventRecognizer)
protected Iterable<IPortCandidate> getPortCandidates(IInputModeContext context, IEdge edge, boolean sourcePort)
This implementation uses the IEdgeReconnectionPortCandidateProvider
from the edge's ILookup.lookup(Class)
to retrieve the candidate sets. If ExistingPortAddingEnabled
is enabled, the
existing port will be part of the candidates.
context
- The context that is used to retrieve the candidates for.edge
- The edge.sourcePort
- Whether to look for source port candidates.null
enumerable over the candidates.public HandleTypes getType()
IHandle
public void handleMove(IInputModeContext context, PointD originalLocation, PointD newLocation)
IDragHandler
This method may be called more than once after an initial IDragHandler.initializeDrag(IInputModeContext)
and will the final
call will be followed by either one IDragHandler.dragFinished(IInputModeContext, PointD, PointD)
or one IDragHandler.cancelDrag(IInputModeContext, PointD)
call.
handleMove
in interface IDragHandler
context
- The context to retrieve information about the drag from.originalLocation
- The value of the Location
property at the time of IDragHandler.initializeDrag(IInputModeContext)
.newLocation
- The coordinates in the world coordinate system that the client wants the handle to be at. Depending on the
implementation the Location
may or may not be modified to reflect the new value.protected void hideOriginalEdge(IInputModeContext context, IEdge edge)
edge
- The edge to hide.context
- The context to get the canvas the edge should be hidden from.unhideOriginalEdge(IEdge, CanvasControl)
,
isDummyEdgeDisplayEnabled()
public void initializeDrag(IInputModeContext context)
IDragHandler
This call will be followed by one or more calls to IDragHandler.handleMove(IInputModeContext, PointD, PointD)
, and a final IDragHandler.dragFinished(IInputModeContext, PointD, PointD)
or IDragHandler.cancelDrag(IInputModeContext, PointD)
.
initializeDrag
in interface IDragHandler
context
- The context to retrieve information about the drag from.public final boolean isCyclicPortDependenciesAllowed()
If edge to edge connections
are allowed by this instance, this property
determines whether getClosestCandidate(IInputModeContext, PointD, Iterable)
s are will yield candidates that
would result in the edge being modified would create a cyclic dependency. The default is false
.
setCyclicPortDependenciesAllowed(boolean)
public final boolean isDummyEdgeDisplayEnabled()
The default is true
.
setDummyEdgeDisplayEnabled(boolean)
public final boolean isEdgeToEdgeConnectionsAllowed()
The default is true
.
setEdgeToEdgeConnectionsAllowed(boolean)
public final boolean isExistingPortAddingEnabled()
The default is true
. If this property is set to false
, getPortCandidates(IInputModeContext, IEdge, boolean)
will return only the ports provided by the IPortCandidateProvider
in the node's
lookup.
setExistingPortAddingEnabled(boolean)
protected boolean isPortCandidateResolutionEnabled(IInputModeContext context)
port candidate resolution
is
enabled for the current gesture.
This implementation checks whether the the parent input mode is an instance of HandleInputMode
, the PortCandidateResolutionRecognizer
recognizes its Mouse2DEvent
, and the
CurrentHandle
's location is equal to this
Location
.
context
- The context to inspect.true
if port candidates may be resolved; false
otherwise.public final boolean isPortCandidateResolvingEnabled()
dynamic port candidate
should be resolved for
the current mouse location.
By default this feature is enabled and the PortCandidateResolutionRecognizer
is configured so that the resolution mechanism is used if the user holds the shift modifier
during the gesture.
getPortCandidateResolutionRecognizer()
,
resolveCandidate(IInputModeContext, IPortCandidate, PointD)
,
setPortCandidateResolvingEnabled(boolean)
public final boolean isShowingHitPortOwnerCandidatesOnlyEnabled()
IPortOwner
s only.true
if only candidates of hit nodes and edges are shown; false
otherwise.setShowingHitPortOwnerCandidatesOnlyEnabled(boolean)
protected final boolean isSourceEnd()
true
if the source end is handled; false
otherwise.protected IPortCandidate resolveCandidate(IInputModeContext context, IPortCandidate portCandidate, PointD location)
resolve
a dynamic port candidate for the
given location.context
- The context in which the candidate is resolved.portCandidate
- The candidate.location
- The current location.protected void setClosestCandidate(IPortCandidate portCandidate)
public void setCursor(Cursor value)
value
- The Cursor to set.getCursor()
public final void setCyclicPortDependenciesAllowed(boolean value)
If edge to edge connections
are allowed by this instance, this property
determines whether getClosestCandidate(IInputModeContext, PointD, Iterable)
s are will yield candidates that
would result in the edge being modified would create a cyclic dependency. The default is false
.
value
- The CyclicPortDependenciesAllowed to set.isCyclicPortDependenciesAllowed()
public final void setDummyEdgeDisplayEnabled(boolean value)
The default is true
.
value
- The DummyEdgeDisplayEnabled to set.isDummyEdgeDisplayEnabled()
public final void setEdgeToEdgeConnectionsAllowed(boolean value)
The default is true
.
value
- The EdgeToEdgeConnectionsAllowed to set.isEdgeToEdgeConnectionsAllowed()
public final void setExistingPortAddingEnabled(boolean value)
The default is true
. If this property is set to false
, getPortCandidates(IInputModeContext, IEdge, boolean)
will return only the ports provided by the IPortCandidateProvider
in the node's
lookup.
value
- The ExistingPortAddingEnabled to set.isExistingPortAddingEnabled()
protected final void setInputModeContext(IInputModeContext value)
value
- The InputModeContext to set.getInputModeContext()
public final void setMaximumSnapDistance(double value)
The distance is measured in view coordinates. The default value is 50.0
.
value
- The MaximumSnapDistance to set.getMaximumSnapDistance()
protected void setPort(IInputModeContext context, IEdge edge, boolean setSourcePort, IPortCandidate portCandidate, PointD suggestedLocation)
dragFinished(IInputModeContext, PointD, PointD)
to actually change the port.context
- The context.edge
- The edge to change ports.setSourcePort
- Whether to set the source port. false
for target ports.portCandidate
- The candidate that has been chosen.suggestedLocation
- The suggested location for the port.public final void setPortCandidateResolutionRecognizer(IEventRecognizer value)
dynamic port candidate
should
be resolved.
Note that this property has no effect if PortCandidateResolvingEnabled
is set
to false
.
By default this is set to IEventRecognizer.SHIFT_PRESSED
.
value
- The PortCandidateResolutionRecognizer to set.getPortCandidateResolutionRecognizer()
public final void setPortCandidateResolvingEnabled(boolean value)
dynamic port candidate
should be resolved for
the current mouse location.
By default this feature is enabled and the PortCandidateResolutionRecognizer
is configured so that the resolution mechanism is used if the user holds the shift modifier
during the gesture.
value
- The PortCandidateResolvingEnabled to set.getPortCandidateResolutionRecognizer()
,
resolveCandidate(IInputModeContext, IPortCandidate, PointD)
,
isPortCandidateResolvingEnabled()
protected void setPorts(IInputModeContext context, IEdge edge, IPort sourcePort, IPort targetPort)
context
- The context in which the ports are set.edge
- The edge to set the ports for.sourcePort
- The (possibly) new source port.targetPort
- The (possibly) new target port.protected void setPosition(PointD location)
location
- The new location of the handle.public final void setShowingHitPortOwnerCandidatesOnlyEnabled(boolean value)
IPortOwner
s only.value
- true
if only candidates of hit nodes and edges are shown; false
otherwise.isShowingHitPortOwnerCandidatesOnlyEnabled()
protected void setToPortCandidate(SimpleEdge dummy, boolean source, IPortCandidate portCandidate)
dummy
- The dummy edge.source
- Whether to update the source or target port.portCandidate
- The new candidate to indicate.public void setType(HandleTypes value)
value
- The Type to set.getType()
protected void unhideOriginalEdge(IEdge edge, CanvasControl canvas)
edge
- The edge to unhide.canvas
- The canvas the edge was hidden from.hideOriginalEdge(IInputModeContext, IEdge)
,
isDummyEdgeDisplayEnabled()