Tool class
Tools handle mouse, keyboard, and touch events. The currently running tool, Diagram#currentTool, receives all input events from the Diagram via canonicalized InputEvents.
For more discussion, see Introduction to Tools. See samples that make use of tools in the samples index.
Most tools are "mode-less" tools that are managed by the ToolManager, which chooses the current tool based on the kind and position of the mouse event and the parts in the diagram. The ToolManager has properties holding instances of most of the pre-defined Tool classes. These classes include:
- In the ToolManager#mouseDownTools List:
- ActionTool
- RelinkingTool
- LinkReshapingTool
- RotatingTool
- ResizingTool
- In the ToolManager#mouseMoveTools List:
- LinkingTool
- DraggingTool
- DragSelectingTool
- PanningTool
- In the ToolManager#mouseUpTools List:
- ContextMenuTool
- TextEditingTool
- ClickCreatingTool
- ClickSelectingTool
The ToolManager chooses a tool to run as the diagram's current tool by finding in its lists of tools the first tool whose #canStart method returns true. The ToolManager then sets Diagram#currentTool to be that tool.
A tool is in the "running" state when it is the value of Diagram#currentTool. The Diagram#currentTool property setter will call #doStop on the old tool and then call #doStart on the new tool.
A tool can then go into the "active" state once it decides it can actually do something. This happens with a call to #doActivate, normally called by the ToolManager. Later it is deactivated (#doDeactivate) and then stopped. #isActive should be true when the tool is "active". Often tools should ignore certain common events, such as calls to #doMouseMove, unless the tool #isActive.
You can prevent a "mode-less" tool (i.e. one managed by the ToolManager) from being started by the ToolManager by setting #isEnabled to false.
You can also go into a particular "mode" by setting Diagram#currentTool explicitly, thereby circumventing the normal operation of the ToolManager. This ignores the #isEnabled property and does not call the #canStart predicate. The behavior will depend on the tool -- not all of the predefined tools support operating as a "modal" tool.
Tools cannot be shared amongst multiple Diagrams.
If you define a Tool subclass, you may override any of the methods whose names start with "do" and any other methods that are documented to be overridable, such as #canStart. However you must seriously consider calling the base method in order to gets its default behavior. There may be situations where not calling the base method may cause subtle bugs. But that depends on the method and the tool. Please read the Introduction page on Extensions for how to override methods and how to call the base method.
- Implementers
- Available extensions
- Annotations
-
- @JS()
- @staticInterop
Constructors
- Tool()
-
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited