DragSourceContext class is responsible for managing the
initiator side of the Drag and Drop protocol. In particular, it is responsible
for managing drag event notifications to the
DragSourceListeners
and DragSourceMotionListeners, and providing the
Transferable representing the source data for the drag operation.
Note that the DragSourceContext itself
implements the DragSourceListener and
DragSourceMotionListener interfaces.
This is to allow the platform peer
(the DragSourceContextPeer instance)
created by the DragSource to notify
the DragSourceContext of
state changes in the ongoing operation. This allows the
DragSourceContext object to interpose
itself between the platform and the
listeners provided by the initiator of the drag operation.
By default, DragSourceContext sets the cursor as appropriate
for the current state of the drag and drop operation. For example, if
the user has chosen the move action,
and the pointer is over a target that accepts
the move action, the default move cursor is shown. When
the pointer is over an area that does not accept the transfer,
the default "no drop" cursor is shown.
This default handling mechanism is disabled when a custom cursor is set
by the setCursor method. When the default handling is disabled,
it becomes the responsibility
of the developer to keep the cursor up to date, by listening
to the DragSource events and calling the setCursor() method.
Alternatively, you can provide custom cursor behavior by providing
custom implementations of the DragSource
and the DragSourceContext classes.
DragSourceListener, DragSourceMotionListener, DnDConstants
| Modifier and Type | Field and Description |
|---|---|
| protected static final int | CHANGED
An |
| private Cursor | cursor
The current drag cursor. |
| protected static final int | DEFAULT
An |
| private static Transferable | |
| protected static final int | ENTER
An |
| private transient DragSourceListener | |
| protected static final int | OVER
An |
| private final transient DragSourceContextPeer | |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.4 for interoperability. |
| private int | sourceActions
A bitwise mask of |
| private transient Transferable | |
| private DragGestureEvent | trigger
The event which triggered the start of the drag. |
| private boolean | useCustomCursor
|
| Access | Constructor and Description |
|---|---|
| public | DragSourceContext(DragGestureEvent
the triggering event trigger, Cursor the initial dragCursor, Image Cursor for this drag operation
or null for the default cursor handling;
see class level documentation
for more details on the cursor handling mechanism during drag and dropthe dragImage, Point Image to drag (or null)the offset of the image origin from the hotspot at the
instant of the triggering event offset, Transferable the t, DragSourceListener Transferablethe dsl)DragSourceListenerCalled from |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized void | addDragSourceListener(DragSourceListener
the dsl)DragSourceListener to add.
Note that while null is not prohibited,
it is not acceptable as a parameter.Add a |
| public void | dragDropEnd(DragSourceDropEvent
the dsde)DragSourceDropEventImplements java. Calls |
| public void | dragEnter(DragSourceDragEvent
the dsde)DragSourceDragEventImplements java. Calls |
| public void | dragExit(DragSourceEvent
the dse)DragSourceEventImplements java. Calls |
| public void | dragMouseMoved(DragSourceDragEvent
the dsde)DragSourceDragEventImplements java. Calls |
| public void | dragOver(DragSourceDragEvent
the dsde)DragSourceDragEventImplements java. Calls |
| public void | dropActionChanged(DragSourceDragEvent
the dsde)DragSourceDragEventImplements java. Calls |
| public Component | Returns: theComponent that started the dragReturns the |
| public Cursor | Returns: the current custom dragCursor, if it was set
otherwise returns null.Returns the current custom drag |
| public DragSource | Returns: theDragSource that
instantiated this DragSourceContextReturns the |
| public int | Returns: the drop actions supported by the drag sourceReturns a bitwise mask of |
| public Transferable | Returns: theTransferableReturns the |
| public DragGestureEvent | Returns: the Event that triggered the dragReturns the |
| private void | |
| public synchronized void | removeDragSourceListener(DragSourceListener
the dsl)DragSourceListener to remove;
note that while null is not prohibited,
it is not acceptable as a parameterRemoves the specified |
| public synchronized void | setCursor(Cursor
the initial c)Cursor for this drag operation,
or null for the default cursor handling;
see class
level documentation for more details
on the cursor handling during drag and dropSets the custom cursor for this drag operation to the specified
|
| private void | |
| public void | |
| protected synchronized void | updateCurrentCursor(int
the actions supported by the drag source sourceAct, int the drop target action targetAct, int one of the fields status)DEFAULT,
ENTER, OVER,
CHANGEDIf the default drag cursor behavior is active, this method sets the default drag cursor for the specified actions supported by the drag source, the drop target action, and status, otherwise this method does nothing. |
| private void |
| CHANGED | back to summary |
|---|---|
| protected static final int CHANGED An | |
| cursor | back to summary |
|---|---|
| private Cursor cursor The current drag cursor. | |
| DEFAULT | back to summary |
|---|---|
| protected static final int DEFAULT An | |
| emptyTransferable | back to summary |
|---|---|
| private static Transferable emptyTransferable | |
| ENTER | back to summary |
|---|---|
| protected static final int ENTER An | |
| listener | back to summary |
|---|---|
| private transient DragSourceListener listener | |
| OVER | back to summary |
|---|---|
| protected static final int OVER An | |
| peer | back to summary |
|---|---|
| private final transient DragSourceContextPeer peer | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Use serialVersionUID from JDK 1.4 for interoperability. | |
| sourceActions | back to summary |
|---|---|
| private int sourceActions A bitwise mask of | |
| transferable | back to summary |
|---|---|
| private transient Transferable transferable | |
| trigger | back to summary |
|---|---|
| private DragGestureEvent trigger The event which triggered the start of the drag. | |
| useCustomCursor | back to summary |
|---|---|
| private boolean useCustomCursor
| |
| DragSourceContext | back to summary |
|---|---|
| public DragSourceContext(DragGestureEvent trigger, Cursor dragCursor, Image dragImage, Point offset, Transferable t, DragSourceListener dsl) Called from
| |
| addDragSourceListener | back to summary |
|---|---|
| public synchronized void addDragSourceListener(DragSourceListener dsl) throws TooManyListenersException Add a
| |
| dragDropEnd | back to summary |
|---|---|
| public void dragDropEnd(DragSourceDropEvent dsde) Implements java. Calls
| |
| dragEnter | back to summary |
|---|---|
| public void dragEnter(DragSourceDragEvent dsde) Implements java. Calls
| |
| dragExit | back to summary |
|---|---|
| public void dragExit(DragSourceEvent dse) Implements java. Calls
| |
| dragMouseMoved | back to summary |
|---|---|
| public void dragMouseMoved(DragSourceDragEvent dsde) Implements java. Calls
| |
| dragOver | back to summary |
|---|---|
| public void dragOver(DragSourceDragEvent dsde) Implements java. Calls
| |
| dropActionChanged | back to summary |
|---|---|
| public void dropActionChanged(DragSourceDragEvent dsde) Implements java. Calls
| |
| getComponent | back to summary |
|---|---|
| public Component getComponent() Returns the
| |
| getCursor | back to summary |
|---|---|
| public Cursor getCursor() Returns the current custom drag | |
| getDragSource | back to summary |
|---|---|
| public DragSource getDragSource() Returns the
| |
| getSourceActions | back to summary |
|---|---|
| public int getSourceActions() Returns a bitwise mask of
| |
| getTransferable | back to summary |
|---|---|
| public Transferable getTransferable() Returns the
| |
| getTrigger | back to summary |
|---|---|
| public DragGestureEvent getTrigger() Returns the
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException Deserializes this
| |
| removeDragSourceListener | back to summary |
|---|---|
| public synchronized void removeDragSourceListener(DragSourceListener dsl) Removes the specified
| |
| setCursor | back to summary |
|---|---|
| public synchronized void setCursor(Cursor c) Sets the custom cursor for this drag operation to the specified
| |
| setCursorImpl | back to summary |
|---|---|
| private void setCursorImpl(Cursor c) | |
| transferablesFlavorsChanged | back to summary |
|---|---|
| public void transferablesFlavorsChanged() Notifies the peer that the | |
| updateCurrentCursor | back to summary |
|---|---|
| protected synchronized void updateCurrentCursor(int sourceAct, int targetAct, int status) If the default drag cursor behavior is active, this method sets the default drag cursor for the specified actions supported by the drag source, the drop target action, and status, otherwise this method does nothing.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Serializes this
| |