Package: java.awt.dnd
Overview
This package defines the classes and interfaces necessary to perform Drag and Drop operations in Java. It defines classes for the drag-source and the drop-target, as well as events for transferring the data being dragged. This package also provides a means for giving visual feedback to the user throughout the duration of the Drag and Drop operation.
A typical Drag and Drop operation can be decomposed into the following states (not entirely sequentially):
- A
DragSourcecomes into existence, associated with some presentation element (Component) in the GUI, to initiate a Drag and Drop of some potentiallyTransferabledata. - 1 or more
DropTarget(s) come into/go out of existence, associated with presentation elements in the GUI (Components), potentially capable of consumingTransferabledata types. - A
DragGestureRecognizeris obtained from theDragSourceand is associated with aComponentin order to track and identify any Drag initiating gesture by the user over theComponent. - A user makes a Drag gesture over the
Component, which the registeredDragGestureRecognizerdetects, and notifies itsDragGestureListenerof.Note: Although this API consistently refers to the stimulus for a drag and drop operation being a physical gesture by a human user, this does not preclude a programmatically driven DnD operation given the appropriate implementation of a
DragSource. This package contains the abstract classMouseDragGestureRecognizerfor recognizing mouse device gestures. Other abstract subclasses may be provided by the platform to support other input devices or particularComponentclass semantics. - The
DragGestureListenercauses theDragSourceto initiate the Drag and Drop operation on behalf of the user, perhaps animating the GUI Cursor and/or rendering anImageof the item(s) that are the subject of the operation. - As the user gestures navigate over
Component(s) in the GUI with associatedDropTarget(s), theDragSourcereceives notifications in order to provide "Drag Over" feedback effects, and theDropTarget(s) receive notifications in order to provide "Drag Under" feedback effects based upon the operation(s) supported and the data type(s) involved.
The gesture itself moves a logical cursor across the GUI hierarchy,
intersecting the geometry of GUI Component(s), possibly resulting in
the logical "Drag" cursor entering, crossing, and subsequently
leaving Component(s) and associated DropTarget(s).
The DragSource object manifests "Drag Over" feedback to the user, in the typical case by animating the GUI Cursor associated with the
logical cursor.
DropTarget objects manifest "Drag Under" feedback to the user, in
the typical case, by rendering animations into their associated GUI
Component(s) under the GUI Cursor.
The determination of the feedback effects, and the ultimate success or failure of the data transfer, should one occur, is parameterized as follows:
- By the transfer "operation" selected by the user, and supported by
both the
DragSourceandDropTarget: Copy, Move or Reference(link). - By the intersection of the set of data types provided by the
DragSourceand the set of data types comprehensible by theDropTarget. - When the user terminates the drag operation, normally resulting in a
successful Drop, both the
DragSourceandDropTargetreceive notifications that include, and result in the type negotiation and transfer of, the information associated with theDragSourcevia aTransferableobject.
