There are several ways to control user actions on the document as a whole or on the separate items.
The Behavior property provides several predefined sets of rules specifying how user input with the mouse/keyboard is interpreted . If set to LinkShapes, drawing over an empty document area is processed as a ShapeNode creation request and drawing over a node creates a link. Note that such behavior leads to some extra work when creating overlaying nodes - users need to draw the second node on an empty area and move it over the first one afterwards. If you want to avoid that you should use the DrawShapes behavior. If LinkTables is set, drawing over an empty area creates a table, and dragging over a table creates an link. Behavior options also include DrawLinks, DrawTables and Modify.
Document size can be get or set with the getBounds and setBounds methods respectively. By default, users are able to move items outside document bounds. To prevent this use setRestrictItemsToBounds method. It provides three RestrictToBounds options to restrict item positions. They might not be restricted at all. The most restrictive option is to keep items entirely inside the document area. Another option allows items to be partially outside the document area but having at least a small visible part inside.
Constraints upon how users are allowed to modify a node are set through the setConstraints and setEnabledHandles methods. The former can be used to constrain the move direction, node size and aspect ratio. The latter enables or disables specific manipulation handles of a node. That allows making the node non-moveable, non-resizable, or resizable only horizontally/vertically.
Items can be locked by the setLocked method. Locked items are excluded from selection and users cannot select, move or modify them.
You can specify whether a DiagramNode accepts incoming and outgoing links by using the setAllowIncomingLinks and setAllowOutgoingLinks methods respectively.
Anchor points define where link's ends should be placed when a user attaches a link to a node. A pattern of anchor points can be assigned to a node by calling the node's setAnchorPattern method. To specify whether link ends are aligned to anchor points when creating or modifying links use the setSnapToAnchor method.
You can forbid users to move links' end points by calling setLinkEndsMovable passing false. This can also be controlled on a per-link basis through setAllowMoveEnd and setAllowMoveStart methods.
The setAllowSelfLoops method enables or disables drawing of reflexive links. They are allowed by default, but can be disabled if you consider them meaningless for your application. The setAllowLinksRepeat method can be used to control if two nodes can be linked more than once in the same direction.
The text of nodes and tables can be edited in-place by double-clicking the respective items. To enable the feature invoke the setAllowInplaceEdit method passing true as its argument. For tables, both captions and cells can be edited in this way. Call the cellTextEditing method to enable/disable in-place editing per cell. Depending on the type of item being edited, one of these events can be fired when editing completes: nodeTextEdited, cellTextEdited.
In-place editing mode is exited when users click outside the text entry control or by pressing the ENTER or ESC keys if respectively setInplaceEditAcceptOnEnter and setInplaceEditCancelOnEsc are called.
When users try to create, delete or select an item one of the following events is fired. To ban the action, set corresponding event boolean argument to false:
Event | Description |
---|---|
Raised while a user draws a new node. | |
Raised while a user draws a new link. | |
Raised when the user is trying to select a node. | |
Raised when the user is trying to select a link. | |
Raised when the user is trying to delete a node. | |
Raised when the user is trying to delete a link. | |
Raised while a user modifies an existing node. | |
Raised while a user modifies an existing link. | |
Raised while a user makes changes to the text of a node. | |
Raised while a user makes changes to the text of a link. |
For more events that can be fired by user's actions, please, visit the DiagramListener section of the documentation.