public class DragSourceContext extends Object implements DragSourceListener, DragSourceMotionListener, Serializable
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(java.awt.Cursor) 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, 
Serialized Form| Modifier and Type | Field and Description | 
|---|---|
| protected static int | CHANGEDAn  intused by updateCurrentCursor()
 indicating that the user operation has changed. | 
| protected static int | DEFAULTAn  intused by updateCurrentCursor()
 indicating that theCursorshould change
 to the default (no drop)Cursor. | 
| protected static int | ENTERAn  intused by updateCurrentCursor()
 indicating that theCursorhas entered aDropTarget. | 
| protected static int | OVERAn  intused by updateCurrentCursor()
 indicating that theCursoris
 over aDropTarget. | 
| Constructor and Description | 
|---|
| DragSourceContext(java.awt.dnd.peer.DragSourceContextPeer dscp,
                 DragGestureEvent trigger,
                 Cursor dragCursor,
                 Image dragImage,
                 Point offset,
                 Transferable t,
                 DragSourceListener dsl)Called from  DragSource, this constructor creates a newDragSourceContextgiven theDragSourceContextPeerfor this Drag, theDragGestureEventthat triggered the Drag, the initialCursorto use for the Drag, an (optional)Imageto display while the Drag is taking place, the offset
 of theImageorigin from the hotspot at the instant of the
 triggering event, theTransferablesubject data, and theDragSourceListenerto use during the Drag and Drop
 operation. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | addDragSourceListener(DragSourceListener dsl)Add a  DragSourceListenerto thisDragSourceContextif one has not already been added. | 
| void | dragDropEnd(DragSourceDropEvent dsde)Calls  dragDropEndon theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDropEvent. | 
| void | dragEnter(DragSourceDragEvent dsde)Calls  dragEnteron theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDragEvent. | 
| void | dragExit(DragSourceEvent dse)Calls  dragExiton theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceEvent. | 
| void | dragMouseMoved(DragSourceDragEvent dsde)Calls  dragMouseMovedon theDragSourceMotionListeners registered with theDragSourceassociated with thisDragSourceContext, and them passes the specifiedDragSourceDragEvent. | 
| void | dragOver(DragSourceDragEvent dsde)Calls  dragOveron theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDragEvent. | 
| void | dropActionChanged(DragSourceDragEvent dsde)Calls  dropActionChangedon theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDragEvent. | 
| Component | getComponent()Returns the  Componentassociated with thisDragSourceContext. | 
| Cursor | getCursor()Returns the current drag  Cursor. | 
| DragSource | getDragSource()Returns the  DragSourcethat instantiated thisDragSourceContext. | 
| int | getSourceActions()Returns a bitwise mask of  DnDConstantsthat
 represent the set of drop actions supported by the drag source for the
 drag operation associated with thisDragSourceContext. | 
| Transferable | getTransferable()Returns the  Transferableassociated with
 thisDragSourceContext. | 
| DragGestureEvent | getTrigger()Returns the  DragGestureEventthat initially triggered the drag. | 
| void | removeDragSourceListener(DragSourceListener dsl)Removes the specified  DragSourceListenerfrom  thisDragSourceContext. | 
| void | setCursor(Cursor c)Sets the cursor for this drag operation to the specified
  Cursor. | 
| void | transferablesFlavorsChanged()Notifies the peer that the  Transferable'sDataFlavors have changed. | 
| protected 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. | 
protected static final int DEFAULT
int used by updateCurrentCursor()
 indicating that the Cursor should change
 to the default (no drop) Cursor.protected static final int ENTER
int used by updateCurrentCursor()
 indicating that the Cursor
 has entered a DropTarget.protected static final int OVER
int used by updateCurrentCursor()
 indicating that the Cursor is
 over a DropTarget.protected static final int CHANGED
int used by updateCurrentCursor()
 indicating that the user operation has changed.public DragSourceContext(java.awt.dnd.peer.DragSourceContextPeer dscp,
                         DragGestureEvent trigger,
                         Cursor dragCursor,
                         Image dragImage,
                         Point offset,
                         Transferable t,
                         DragSourceListener dsl)
DragSource, this constructor creates a new
 DragSourceContext given the
 DragSourceContextPeer for this Drag, the
 DragGestureEvent that triggered the Drag, the initial
 Cursor to use for the Drag, an (optional)
 Image to display while the Drag is taking place, the offset
 of the Image origin from the hotspot at the instant of the
 triggering event, the Transferable subject data, and the
 DragSourceListener to use during the Drag and Drop
 operation.
 DragSourceContextPeer is null
 NullPointerException is thrown.
 DragGestureEvent is null
 NullPointerException is thrown.
 Cursor is null no exception is thrown and
 the default drag cursor behavior is activated for this drag operation.
 Image is null no exception is thrown.
 Image is not null and the offset is
 null NullPointerException is thrown.
 Transferable is null
 NullPointerException is thrown.
 DragSourceListener is null no exception
 is thrown.dscp - the DragSourceContextPeer for this dragtrigger - the triggering eventdragCursor - the initial 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 dropdragImage - the Image to drag (or null)offset - the offset of the image origin from the hotspot at the
                   instant of the triggering eventt - the Transferabledsl - the DragSourceListenerIllegalArgumentException - if the Component associated
         with the trigger event is null.IllegalArgumentException - if the DragSource for the
         trigger event is null.IllegalArgumentException - if the drag action for the
         trigger event is DnDConstants.ACTION_NONE.IllegalArgumentException - if the source actions for the
         DragGestureRecognizer associated with the trigger
         event are equal to DnDConstants.ACTION_NONE.NullPointerException - if dscp, trigger, or t are null, or
         if dragImage is non-null and offset is nullpublic DragSource getDragSource()
DragSource
 that instantiated this DragSourceContext.DragSource that
   instantiated this DragSourceContextpublic Component getComponent()
Component associated with this
 DragSourceContext.Component that started the dragpublic DragGestureEvent getTrigger()
DragGestureEvent
 that initially triggered the drag.public int getSourceActions()
DnDConstants that
 represent the set of drop actions supported by the drag source for the
 drag operation associated with this DragSourceContext.public void setCursor(Cursor c)
Cursor.  If the specified Cursor
 is null, the default drag cursor behavior is
 activated for this drag operation, otherwise it is deactivated.c - the initial 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 droppublic Cursor getCursor()
Cursor.
 Cursorpublic void addDragSourceListener(DragSourceListener dsl) throws TooManyListenersException
DragSourceListener to this
 DragSourceContext if one has not already been added.
 If a DragSourceListener already exists,
 this method throws a TooManyListenersException.
 dsl - the DragSourceListener to add.
 Note that while null is not prohibited,
 it is not acceptable as a parameter.
 TooManyListenersException - if
 a DragSourceListener has already been addedpublic void removeDragSourceListener(DragSourceListener dsl)
DragSourceListener
 from  this DragSourceContext.dsl - the DragSourceListener to remove;
     note that while null is not prohibited,
     it is not acceptable as a parameterpublic void transferablesFlavorsChanged()
Transferable's
 DataFlavors have changed.public void dragEnter(DragSourceDragEvent dsde)
dragEnter on the
 DragSourceListeners registered with this
 DragSourceContext and with the associated
 DragSource, and passes them the specified
 DragSourceDragEvent.dragEnter in interface DragSourceListenerdsde - the DragSourceDragEventpublic void dragOver(DragSourceDragEvent dsde)
dragOver on the
 DragSourceListeners registered with this
 DragSourceContext and with the associated
 DragSource, and passes them the specified
 DragSourceDragEvent.dragOver in interface DragSourceListenerdsde - the DragSourceDragEventpublic void dragExit(DragSourceEvent dse)
dragExit on the
 DragSourceListeners registered with this
 DragSourceContext and with the associated
 DragSource, and passes them the specified
 DragSourceEvent.dragExit in interface DragSourceListenerdse - the DragSourceEventpublic void dropActionChanged(DragSourceDragEvent dsde)
dropActionChanged on the
 DragSourceListeners registered with this
 DragSourceContext and with the associated
 DragSource, and passes them the specified
 DragSourceDragEvent.dropActionChanged in interface DragSourceListenerdsde - the DragSourceDragEventpublic void dragDropEnd(DragSourceDropEvent dsde)
dragDropEnd on the
 DragSourceListeners registered with this
 DragSourceContext and with the associated
 DragSource, and passes them the specified
 DragSourceDropEvent.dragDropEnd in interface DragSourceListenerdsde - the DragSourceDropEventpublic void dragMouseMoved(DragSourceDragEvent dsde)
dragMouseMoved on the
 DragSourceMotionListeners registered with the
 DragSource associated with this
 DragSourceContext, and them passes the specified
 DragSourceDragEvent.dragMouseMoved in interface DragSourceMotionListenerdsde - the DragSourceDragEventpublic Transferable getTransferable()
Transferable associated with
 this DragSourceContext.Transferableprotected void updateCurrentCursor(int sourceAct,
                                   int targetAct,
                                   int status)
sourceAct - the actions supported by the drag sourcetargetAct - the drop target actionstatus - one of the fields DEFAULT,
               ENTER, OVER,
               CHANGED Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2017, Oracle and/or its affiliates.  All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.