|
|
![]() |
The Docking Utility provides a simple, non-invasive means of adding runtime drag-n-drop docking functionality to otherwise standard components. Docking is accomplished by grabbing a component with the mouse cursor, dragging it to a desired location within the GUI, and dropping it into its new location.
There are three main parties involved in a docking operation; the Dockable, the DockingPort, and the DockingManager. A Dockable is any component that has docking capabilities (implements the Dockable interface). A DockingPort is any container that is capable of accepting a new child Dockable (implements the DockingPort interface). The DockingManager is the class responsible for detecting drag operations, maintaining the state of the Dockable while dragging, and initiating the docking operation into the DockingPort when dragging has ended.
Each DockingPort consists of five regions, which are analogous to the regions of a BorderLayout; NORTH, SOUTH, EAST, WEST, and CENTER.

When a drag operation is detected on a Dockable, the DockingManager class assumes responsibility for keeping track of the mouse coordinates. During dragging, the DockingManager maintains a rectangular outline of the Dockable component in concert with the mouse position. Additionally, the DockingManager queries any DockingPort instance beneath the current mouse cursor for the region enclosing the mouse location, updating the cursor icon accordingly. If docking is allowed within the current region by the DockingPort, the cursor icon reflects the current region. Otherwise, the cursor icon displays an image indicating that docking will not be allowed.
When the mouse is released, the drag operation ends and the DockingManager attempts to dock the selected Dockable within the DockingPort underneath the mouse cursor. If no DockingPort is underneath the mouse cursor, or the DockingPort underneath the mouse cursor doesn't allow docking within the current docking region, docking fails and the callback method dockingCanceled() is invoked on the selected Dockable. If docking is allowed, then the selected Dockable is removed from its parent component and is added to the target DockingPort with the specified Component, region, and resize policy as parameters to the dock() method. The method dockingComplete(String region) is invoked against the target DockingPort and the callback method dockingCompleted() is invoked against the selected Dockable.
|
|
|