In order to move or modify a diagram element, users manipulate its modification handles. Modification handles appear around an item when it is selected. Each handle can be dragged to perform specific transformation on the item. The appearance and behavior of modification handles can be altered by calling the setHandlesStyle method. You can also invoke the setModificationStart method to make those handles appear automatically for non-selected items when the mouse pointer hovers over them.
If only one diagram item is selected, it is considered the 'active' item. One of the items in a multiple-selection is also regarded as active; it is usually the one selected last. The active item has white modification handles drawn around it, while other items in multiple-selection have gray handles. The active item is probably the one, users are most interested in while editing a diagram, and your program can update its state and user-interface according to that. Access to the active item is provided through the getActiveItem method of the Diagram class.
Selection of diagram objects in JDiagram is represented by an instance of the Selection class. This class provides methods to programmatically select or deselect items, as well as methods that modify how the selection looks and behaves. The selected items within the current document can be obtained through the getSelection method of the Diagram class. Multiple items can be selected, thus moved at the same time. To programmatically add or remove items to the multiple-selection invoke one of the addItem, toggle and removeItem methods. The clear method deselects all items and the change method selects a single item deselecting all other. To disable multiple selection, pass false to setAllowMultiple.
The visual style of multiple-selection can be modified by the setStyle method of the Selection class. For example selection might be painted as a dashed rectangle or a semi-transparent filled rectangle. Another method related to selection visualization is the Diagram's setSelectionOnTop, which can be used to specify whether selected items should be painted according to their Z-order position or they should be painted on top of the non-selected items.
The Selection class exposes the selected items as lists of items. The selected items from a particular class can be accessed through the corresponding method. To get the list of all selected nodes and links, use the getNodes and getLinks methods. You can obtain a list with all selected items, disregarding class, by invoking the getItems method. Alternatively you might enumerate all items in the diagram and call their getSelected method.
To enable automatic selection of newly created objects, call setSelectAfterCreate passing true.