Class ToolManager

Extends Tool. This special Tool is responsible for managing all of the Diagram's mode-less tools, which you can access as the Diagram.toolManager.

Mode-less tools are tools that are present in one of the following lists: mouseDownTools, mouseMoveTools, or mouseUpTools. This ToolManager tool is normally the Diagram.defaultTool, so it is also usually the Diagram.currentTool when the user is doing "nothing".

When this tool is running as the current tool, it handles mouse-down, mouse-move, and mouse-up events and the corresponding touch events. For each event it iterates over each of the tools in the corresponding list, calling the tool's Tool.canStart predicate. If that predicate returns true, it starts that tool by making it the diagram's current tool. It then activates the tool and passes on the event to the tool by calling the corresponding method (either Tool.doMouseDown, Tool.doMouseMove, or Tool.doMouseUp).

Because this tool is typically the one running as the diagram's current tool when the user isn't "doing" anything, this tool can also handle other events, such as mouse wheel events and keyboard commands.

Keyboard events are just passed on to the Diagram.commandHandler's CommandHandler.doKeyDown or CommandHandler.doKeyUp method.

This tool also is responsible for showing tooltips. Tooltip Adornments may be declared as any GraphObject.toolTip, or as the Diagram.toolTip if the mouse or finger remains motionless in the background of the diagram. You can set toolTipDuration to control how long the tooltip remains visible after being motionless.

This tool does not utilize any tool handles. This tool does not conduct any transactions. But of course some of the tools that the ToolManager starts can show tool handles and/or conduct their own transactions.

Constructor Summary Details

Name Description
ToolManager()

You do not normally need to create an instance of this tool because one already exists as the Diagram.toolManager, which you can modify.More...

The Tool.name of this tool is "ToolManager".

The constructor produces a ToolManager that manages no tools. Call initializeStandardTools to create various tools, initialize the tool properties such as draggingTool, and initialize the three mouse tool lists with those newly created tools.

Properties Summary Details

Name, Value Type Description
actionTool

Gets or sets the mode-less ActionTool, normally one of the mouseDownTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

clickCreatingTool

Gets or sets the mode-less ClickCreatingTool, normally one of the mouseUpTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

clickSelectingTool

Gets or sets the mode-less ClickSelectingTool, normally one of the mouseUpTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

contextMenuTool

Gets or sets the mode-less ContextMenuTool, normally one of the mouseUpTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

currentToolTip

This read-only property returns the currently showing tooltip, or null if there is none.

draggingTool

Gets or sets the mode-less DraggingTool, normally one of the mouseMoveTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

dragSelectingTool

Gets or sets the mode-less DragSelectingTool, normally one of the mouseMoveTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

dragSize
{Size} 1.2

Gets or sets the distance in view coordinates within which a mouse down-and-up is considered a click and beyond which a mouse movement is considered a drag.More... The default value is 2 pixels horizontally and vertically for mouse events, and increases by 6 pixels for touch events. This value is used by Tool.isBeyondDragSize.

gestureBehavior
{EnumValue} 1.5

Gets or sets the ToolManager's default gestureBehavior behavior.More... Allowed values are ToolManager.GestureZoom and ToolManager.GestureCancel and ToolManager.GestureNone.

The default value is ToolManager.GestureZoom.

holdDelay
{number}

Gets or sets the time between when the mouse stops moving and a hold event, in milliseconds.More... The default value is 850 milliseconds.

hoverDelay
{number}

Gets or sets the time between when the mouse stops moving and a hover event, in milliseconds.More... This value affects the delay before GraphObject.toolTips are shown. The default value is 850 milliseconds.

linkingTool

Gets or sets the mode-less LinkingTool, normally one of the mouseMoveTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

linkReshapingTool

Gets or sets the mode-less LinkReshapingTool, normally one of the mouseDownTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

mouseDownTools
{List.}

This read-only property returns the list of Tools that might be started upon a mouse or finger press event.More... When the ToolManager handles a mouse-down or touch-down event in doMouseDown, it searches this list in order, starting the first tool for which Tool.canStart returns true.

This list may be modified, but it must not be modified while any tool is handling events.

initializeStandardTools installs the following tools, in order:

mouseMoveTools
{List.}

This read-only property returns the list of Tools that might be started upon a mouse or finger move event.More... When the ToolManager handles a mouse-move or touch-move event in doMouseMove, it searches this list in order, starting the first tool for which Tool.canStart returns true.

This list may be modified, but it must not be modified while any tool is handling events.

initializeStandardTools installs the following tools, in order:

mouseUpTools
{List.}

This read-only property returns the list of Tools that might be started upon a mouse or finger up event.More... When the ToolManager handles a mouse-up or touch-up event in doMouseUp, it searches this list in order, starting the first tool for which Tool.canStart returns true.

This list may be modified, but it must not be modified while any tool is handling events.

initializeStandardTools installs the following tools, in order:

mouseWheelBehavior
{EnumValue}

Gets or sets the ToolManager's mouse wheel behavior.More... Allowed values are ToolManager.WheelScroll and ToolManager.WheelZoom and ToolManager.WheelNone.

The default value is ToolManager.WheelScroll.

panningTool

Gets or sets the mode-less PanningTool, normally one of the mouseMoveTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

relinkingTool

Gets or sets the mode-less RelinkingTool, normally one of the mouseDownTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

resizingTool

Gets or sets the mode-less ResizingTool, normally one of the mouseDownTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

rotatingTool

Gets or sets the mode-less RotatingTool, normally one of the mouseDownTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

textEditingTool

Gets or sets the mode-less TextEditingTool, normally one of the mouseUpTools.More...

You can disable this tool by setting its Tool.isEnabled property to false.

toolTipDuration
{number}

Gets or sets how long a tool tip is visible.More... The default value is 5000 milliseconds.

This is used by showToolTip to determine how long to wait before calling hideToolTip.

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

Method Summary Details

Name, Return Type Description
doKeyDown()

This just calls CommandHandler.doKeyDown on the diagram's Diagram.commandHandler.More...

This method may be overridden, but you should consider calling this base method in order to get all of its functionality.

doKeyUp()

This just calls CommandHandler.doKeyUp on the diagram's Diagram.commandHandler.More...

This method may be overridden, but you should consider calling this base method in order to get all of its functionality.

doMouseDown()

Iterate over the mouseDownTools list and start the first tool for which its Tool.canStart predicate returns true.More...

Starting a tool replaces the Diagram.currentTool with the new tool. Successfully doing so also activates the new tool by calling Tool.doActivate and passes on the mouse-down event to it by calling Tool.doMouseDown.

Not finding any startable tools causes this tool manager to activate, thereby enabling the mouse-move and mouse-up behaviors and starts detection of a mouse-hold event after holdDelay milliseconds.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

doMouseHover()

Implement the standard behavior for mouse hover and mouse hold events, called by doWaitAfter when the mouse has not moved for a period of time.More...

If there has been no mouse down, the timer is set for hoverDelay milliseconds. If it executes, it calls any GraphObject.mouseHover function on the object at the mouse or on any of its containing panels, or it calls any Diagram.mouseHover function for a background mouse-hover event.

If there had been a mouse down, the timer is set for holdDelay milliseconds. If it executes, it calls any GraphObject.mouseHold function on the object at the mouse or on any of its containing panels, or it calls any Diagram.mouseHold function for a background mouse-held-down event.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

doMouseMove()

Iterate over the mouseMoveTools list and start the first tool for which its Tool.canStart predicate returns true.More...

Starting a tool replaces the Diagram.currentTool with the new tool. Successfully doing so also activates the new tool by calling Tool.doActivate and passes on the mouse-move event to it by calling Tool.doMouseMove.

If no tool is found and activated, this:

This method may be overridden, but you should consider calling this base method in order to get all of its functionality.

doMouseUp()

Iterate over the mouseUpTools list and start the first tool for which its Tool.canStart predicate returns true.More...

Starting a tool replaces the Diagram.currentTool with the new tool. Successfully doing so also activates the new tool by calling Tool.doActivate and passes on the mouse-up event to it by calling Tool.doMouseUp.

If no startable tool is found it deactivates this tool manager, to get ready for a mouse-down and ignore mouse-move and mouse-up events.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality.

doMouseWheel()

The diagram will call this method as the mouse wheel is rotated.More...

By default this just calls Tool.standardMouseWheel. This method may be overridden, but you should consider calling this base method in order to get all of its functionality.

doToolTip()

Implement the standard behavior for tooltips, called by doWaitAfter when the mouse has not moved for a period of time.More...

This looks for a GraphObject at the latest mouse point. If it finds an object, it checks for a GraphObject.toolTip. If it has none, this method searches up the visual tree for a containing Panel that does have a tooltip.

If it didn't find any object, this looks for a Diagram.toolTip.

If it eventually finds a tooltip, this calls showToolTip. Otherwise this calls hideToolTip.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

doWaitAfter(event)

Implement the standard behavior for when the mouse has not moved for a period of time.More... This is due to an expired timer started by calling Tool.standardWaitAfter.

This calls doMouseHover and, if not mouse-down, doToolTip. Afterwards, if the event that called Tool.standardWaitAfter was a touch event, this simulates a right click, enabling context menu functionality and other actions on touch devices.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality.

Parameters:
{InputEvent=} event
The event that caused standardWaitAfter. In this override, if it is a touch event and the Diagram.lastInput event is not handled (InputEvent.handled set to false), then this method will simulate a right click.
findTool(name)
{Tool}

Find a mouse tool of a given name.More... This searches the mouseDownTools, mouseMoveTools, and mouseUpTools lists. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{string} name
the type of tool, such as "Dragging" or "ClickSelecting".
Returns:
{Tool} a Tool whose Tool.name exactly matches the given name, or null if no such tool is found in any of the three lists.
hideToolTip()

Hide any tooltip.More...

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

initializeStandardTools()

Initialize the three mouse tool lists with instances of the standard tools.More... This adds new instances of tools to the following three mouse tool lists: mouseDownTools, mouseMoveTools, or mouseUpTools. This also sets the various tool properties of this ToolManager to those newly created tools. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

positionToolTip(tooltip, obj)

This is called by showToolTip to position the part within the viewport.More... It normally goes just below the cursor. But if the mouse is too close to the right edge or the bottom edge of the viewport, it is positioned left and/or above the cursor.

This method only operates if the tooltip, an Adornment, does not have a Adornment.placeholder. When there is a Placeholder in the tooltip, that Adornment is automatically positioned so that the Placeholder is positioned at the adorned object, the second argument to this method.

This method may be overridden. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

If you override this method to position the tooltip, the tooltip has already been measured but not arranged, so you can use its GraphObject.measuredBounds width and height but not its GraphObject.actualBounds.

Parameters:
{Adornment} tooltip
{GraphObject} obj
The GraphObject getting the tooltip, or null if the tooltip is for the diagram background.
replaceTool(name, newtool)
{Tool}

Replace a mouse tool of a given name with a new tool, or remove an existing tool (if the newtool is null).More... This searches the mouseDownTools, mouseMoveTools, and mouseUpTools lists. The new tool is inserted into the same list in which the same-named tool is found, at the same position as the old tool. However, if no existing tool with the given name is present, this does not add the new tool to any list, since it cannot know where it should be added. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{string} name
the type of tool, such as "Dragging" or "ClickSelecting".
{Tool} newtool
If null, any tool that the search finds will just be removed from the list in which it was found.
Returns:
{Tool} the old tool that was replaced by the new one; this is null if none was found and the new tool was not added to any mouse tool list
showToolTip(tooltip, obj)

Show a tooltip Adornment or HTMLInfo.More... This is called by doToolTip once that method has found a tooltip to display.

This calls positionToolTip to make it easier to customize how the tooltip is positioned relative to the object with the tooltip.

This method may be overridden, but you should consider calling this base method in order to get all of its functionality. Please read the Introduction page on Extensions for how to override methods and how to call this base method.

Parameters:
{Adornment|HTMLInfo} tooltip
{GraphObject} obj
The GraphObject getting the tooltip; this is null if the tooltip is being shown for the diagram background.
Methods borrowed from class Tool:
cancelWaitAfter, canStart, canStartMultiTouch, doActivate, doCancel, doDeactivate, doStart, doStop, findToolHandleAt, isBeyondDragSize, standardMouseClick, standardMouseOver, standardMouseSelect, standardMouseWheel, standardPinchZoomMove, standardPinchZoomStart, standardWaitAfter, startTransaction, stopTool, stopTransaction, updateAdornments

Constants Summary Details

Name Description
GestureCancel 1.5 {EnumValue}

This value for gestureBehavior indicates that the pointer/touch pinch gestures on the canvas intend to have no effect on the Diagram, but also no effect on the page.

GestureNone 1.5 {EnumValue}

This value for gestureBehavior indicates that the pointer/touch pinch gestures on the canvas intend to have no effect on the Diagram, but will not be prevented, and may bubble up the page to have other effects (such as zooming the page).

GestureZoom 1.5 {EnumValue}

This value for gestureBehavior indicates that the pointer/touch pinch gestures on the canvas intend to zoom the Diagram.

WheelNone 1.2 {EnumValue}

This value for mouseWheelBehavior indicates that the mouse wheel events are ignored, although scrolling or zooming by other means may still be allowed.

WheelScroll {EnumValue}

This default value for mouseWheelBehavior indicates that mouse wheel events scroll the diagram.

WheelZoom {EnumValue}

This value for mouseWheelBehavior indicates that the mouse wheel events change the scale of the diagram.