Class LinkingBaseTool

Extends Tool. This abstract class is the base class for the LinkingTool and RelinkingTool classes.

This class includes properties for defining and accessing any temporary nodes and temporary link that are used during any linking operation, as well as access to the existing diagram's nodes and link (if any) that are involved with the linking operation.

For a general discussion of link routing, see: Introduction to Links, Introduction to Link Labels, and Introduction to Link Connection Points. For customizing the linking tools, see Introduction to the Linking Tools. For customizing the reshaping of Links, see Introduction to the LinkReshapingTool. For a general discussion of validation, see Introduction to Validation.

Constructor Summary Details

Name Description
LinkingBaseTool()

Don't construct this directly -- this is an abstract class.

Properties Summary Details

Name, Value Type Description
isForwards
{boolean}

Gets whether the linking operation is in the forwards direction, connecting from the "From" port to the "To" port.

isUnconnectedLinkValid
{boolean} 1.3

Gets or sets whether it is valid to have partly or completely unconnected links.More...

The default value is false -- the user cannot draw or reconnect a link to "nowhere". Setting this property does not raise any events.

linkValidation
{function(Node, GraphObject, Node, GraphObject, Link):boolean | null}

Gets or sets a predicate that determines whether or not a new link between two ports would be valid.More... This predicate is called in addition to the normal link checking performed by isValidLink and any Node.linkValidation predicates on the "from" and "to" nodes. When relinking, the Link being considered for reconnection is passed as the fifth argument. The default predicate is null, which is equivalent to simply returning true.

For a more general discussion of validation, see Introduction to Validation.

The function, if supplied, must not have any side-effects.

originalFromNode
{Node}

Gets or sets the original Node from which the new link is being drawn or from which the originalLink was connected when being relinked.More... Setting this property does not raise any events.

originalFromPort

Gets or sets the GraphObject that is the port in the originalFromNode.More... Setting this property does not raise any events.

originalToNode
{Node}

Gets or sets the original Node to which the new link is being drawn or to which the originalLink was connected when being relinked.More... Setting this property does not raise any events.

originalToPort

Gets or sets the GraphObject that is the port in the originalToNode.More... Setting this property does not raise any events.

portGravity
{number}

Gets or sets the distance at which link snapping occurs.More... The default value is 100.0. The value must be non-negative. Setting this property does not raise any events.

portTargeted
{function(Node, GraphObject, Node, GraphObject, boolean) | null} 1.2

Gets or sets a function that is called as the tool targets the nearest valid port.More... The first two arguments specify the port by providing the Node that it is in and the GraphObject that is the actual port object. The next two arguments are the temporary port that has been moved and styled to be like the valid port. These values will be either the temporaryToNode and temporaryToPort or the temporaryFromNode and temporaryFromPort, depending on which end of the temporary link is being updated. The fifth argument is true if the target port represents a potential "to" end of a link; it is false if it is for the "from" end of a link.

When there is no valid port within the portGravity, the first two arguments are null.

The function, if supplied, must not add or remove any links or nodes or port objects, nor may it change the validity of any potential link connection.

targetPort

Gets or sets a proposed GraphObject port for connecting a link.More... Whether this is a "to" port or a "from" port depends on the direction (isForwards) in which the link is being drawn or reconnected.

This is set when the mouse is being dragged and when a mouse-up event occurs with the result of a call to findTargetPort. Setting this property does not raise any events.

temporaryFromNode
{Node}

Gets or sets the temporary Node at the "from" end of the temporaryLink while the user is drawing or reconnecting a link.More... Setting this property does not raise any events.

temporaryFromPort

Gets or sets the GraphObject that is the port at the "from" end of the temporaryLink while the user is drawing or reconnecting a link.More... Setting this property does not raise any events.

temporaryToNode
{Node}

Gets or sets the temporary Node at the "to" end of the temporaryLink while the user is drawing or reconnecting a link.More... Setting this property does not raise any events.

temporaryToPort

Gets or sets the GraphObject that is the port at the "to" end of the temporaryLink while the user is drawing or reconnecting a link.More... Setting this property does not raise any events.

Properties borrowed from class Tool:
diagram, isActive, isEnabled, name, transactionResult

Method Summary Details

Name, Return Type Description
copyPortProperties(realnode, realport, tempnode, tempport, toend)
1.2

Make a temporary port look and act like a real one.More...

This is called by doMouseMove as the tool finds new valid target ports. If findTargetPort returns null, it calls setNoTargetPortProperties instead.

If the portTargeted property is a function, that function is called. It is easier to customize the behavior by setting that functional property than it is to override this method and the setNoTargetPortProperties method. But you may want to call this method to get the standard behavior for dynamically adapting the temporary node/port to "act like" the target port. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{Node} realnode
{GraphObject} realport
{Node} tempnode
{GraphObject} tempport
{boolean} toend
doMouseMove()

Mouse movement results in a temporary node moving to where a valid target port is located, or to where the mouse is if there is no valid target port nearby.More...

This calls findTargetPort to update the targetPort given the new mouse point. If a valid target port is found this moves the temporary node/port and makes them appear like the target node/port by calling copyPortProperties. If no valid target port is found, this moves the temporary node to where the mouse currently is and removes any node/port appearance, by calling setNoTargetPortProperties.

This method may be overridden, but we recommend that you call this base method.

findTargetPort(toend)

Find a port with which the user could complete a valid link.More...

This finds objects near to the current mouse point for which a valid link connection is possible.

For each port element found, this calls isValidLink to find out if a link between the original node/port and the found node/port would be valid. The result is saved in a cache for faster decisions later during operation of this tool. The closest valid port is returned.

This method may be overridden, but we recommend that you call this base method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{boolean} toend
true if looking for a "to" port.
Returns:
{GraphObject} a valid port, or null if no such port is near the current mouse point within the portGravity distance.
isInSameNode(fromport, toport)
{boolean}

This predicate is true if both argument ports are in the same Node.More... This is called by isValidLink.

This method may be overridden, but we recommend that you call this base method. It is rare that you will want to override this method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{GraphObject} fromport
{GraphObject} toport
Returns:
{boolean}
isLinked(fromport, toport)
{boolean}

This predicate is true if there is a link in the diagram going from the given port to the given port.More... This is called by isValidLink.

This method may be overridden, but we recommend that you call this base method. It is rare that you will want to override this method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{GraphObject} fromport
{GraphObject} toport
Returns:
{boolean}
isValidCycle(from, to, ignore)
{boolean} 1.5

Checks whether a proposed link would be valid according to Diagram.validCycle.More... This does not distinguish between different ports on a node, so this method does not need to take port arguments. This is called by isValidLink.

This method may be overridden, but we recommend that you call this base method. It is rare that you will want to override this method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{Node} from
{Node} to
{Link} ignore
may be null; this is useful during relinking to ignore the originalLink
Returns:
{boolean}
isValidFrom(fromnode, fromport)
{boolean}

This predicate is true if it is permissible to connect a link from a given node/port.More... This is called by isValidLink.

For a more general discussion of validation, see Introduction to Validation.

This method may be overridden, but we recommend that you call this base method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{Node} fromnode
{GraphObject} fromport
Returns:
{boolean} False if the node is in a Layer that does not Layer.allowLink. False if the port's GraphObject.fromLinkable is either false or null. False if the number of links connected to the port would exceed the port's GraphObject.fromMaxLinks. Otherwise true.
isValidTo(tonode, toport)
{boolean}

This predicate is true if it is permissible to connect a link to a given node/port.More... This is called by isValidLink.

For a more general discussion of validation, see Introduction to Validation.

This method may be overridden, but we recommend that you call this base method. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{Node} tonode
{GraphObject} toport
Returns:
{boolean} False if the node is in a Layer that does not Layer.allowLink. False if the port's GraphObject.toLinkable is either false or null. False if the number of links connected from the port would exceed the port's GraphObject.toMaxLinks. Otherwise true.
setNoTargetPortProperties(tempnode, tempport, toend)
1.2

Reset a temporary port's properties to neutral values when there is no target port.More...

This is called by doMouseMove when the tool finds no new valid target port. If findTargetPort returns non-null, it calls copyPortProperties instead.

If the portTargeted property is a function, that function is called with null values as the first two arguments. It is easier to customize the behavior by setting that functional property than it is to override this method and the copyPortProperties method. But you may want to call this method to get the standard behavior for dynamically adapting the temporary node/port to "act like" it is not connecting with any target port. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{Node} tempnode
{GraphObject} tempport
{boolean} toend
Methods borrowed from class Tool:
cancelWaitAfter, canStart, canStartMultiTouch, doActivate, doCancel, doDeactivate, doKeyDown, doKeyUp, doMouseDown, doMouseUp, doMouseWheel, doStart, doStop, doWaitAfter, findToolHandleAt, isBeyondDragSize, standardMouseClick, standardMouseOver, standardMouseSelect, standardMouseWheel, standardPinchZoomMove, standardPinchZoomStart, standardWaitAfter, startTransaction, stopTool, stopTransaction, updateAdornments