| java.lang.Object java.awt.dnd.DragSourceContext
DragSourceContext | public class DragSourceContext implements DragSourceListener,DragSourceMotionListener,Serializable(Code) | | The 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
and
, 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
,
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
DragSourceContext.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.
See Also: DragSourceListener See Also: DragSourceMotionListener See Also: DnDConstants version: 1.62, 06/05/07 since: 1.2 |
Field Summary | |
final protected static int | CHANGED An int used by updateCurrentCursor()
indicating that the user operation has changed. | final protected static int | DEFAULT An int used by updateCurrentCursor()
indicating that the Cursor should change
to the default (no drop) Cursor . | final protected static int | ENTER An int used by updateCurrentCursor()
indicating that the Cursor
has entered a DropTarget . | final protected static int | OVER An int used by updateCurrentCursor()
indicating that the Cursor is
over a DropTarget . |
Constructor Summary | |
public | DragSourceContext(DragSourceContextPeer dscp, DragGestureEvent trigger, Cursor dragCursor, Image dragImage, Point offset, Transferable t, DragSourceListener dsl) Called from 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.
If DragSourceContextPeer is null
NullPointerException is thrown.
If DragGestureEvent is null
NullPointerException is thrown.
If Cursor is null no exception is thrown and
the default drag cursor behavior is activated for this drag operation.
If Image is null no exception is thrown.
If Image is not null and the offset is
null NullPointerException is thrown.
If Transferable is null
NullPointerException is thrown.
If DragSourceListener is null no exception
is thrown.
Parameters: dscp - the DragSourceContextPeer for this drag Parameters: trigger - the triggering event Parameters: dragCursor - the initial Cursor for this drag operationor null for the default cursor handling;see class level documentationfor more details on the cursor handling mechanism during drag and drop Parameters: dragImage - the Image to drag (or null ) Parameters: offset - the offset of the image origin from the hotspot at theinstant of the triggering event Parameters: t - the Transferable Parameters: dsl - the DragSourceListener throws: IllegalArgumentException - if the Component associatedwith the trigger event is null . throws: IllegalArgumentException - if the DragSource for the trigger event is null . throws: IllegalArgumentException - if the drag action for thetrigger event is DnDConstants.ACTION_NONE . throws: IllegalArgumentException - if the source actions for theDragGestureRecognizer associated with the triggerevent are equal to DnDConstants.ACTION_NONE . |
Method Summary | |
public synchronized void | addDragSourceListener(DragSourceListener dsl) Add a DragSourceListener to this
DragSourceContext if one has not already been added. | public void | dragDropEnd(DragSourceDropEvent dsde) Calls dragDropEnd on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDropEvent . | public void | dragEnter(DragSourceDragEvent dsde) Calls dragEnter on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDragEvent . | public void | dragExit(DragSourceEvent dse) Calls dragExit on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceEvent . | public void | dragMouseMoved(DragSourceDragEvent dsde) Calls dragMouseMoved on the
DragSourceMotionListener s registered with the
DragSource associated with this
DragSourceContext , and them passes the specified
DragSourceDragEvent . | public void | dragOver(DragSourceDragEvent dsde) Calls dragOver on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDragEvent . | public void | dropActionChanged(DragSourceDragEvent dsde) Calls dropActionChanged on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDragEvent . | public Component | getComponent() Returns the Component associated with this
DragSourceContext . | public Cursor | getCursor() Returns the current drag Cursor . | public DragSource | getDragSource() Returns the DragSource
that instantiated this DragSourceContext . | public int | getSourceActions() Returns a bitwise mask of DnDConstants that
represent the set of drop actions supported by the drag source for the
drag operation associated with this DragSourceContext . | public Transferable | getTransferable() Returns the Transferable associated with
this DragSourceContext . | public DragGestureEvent | getTrigger() Returns the DragGestureEvent
that initially triggered the drag. | public synchronized void | removeDragSourceListener(DragSourceListener dsl) Removes the specified DragSourceListener
from this DragSourceContext . | public synchronized void | setCursor(Cursor c) Sets the cursor for this drag operation to the specified
Cursor . | public void | transferablesFlavorsChanged() Notifies the peer that the Transferable 's
DataFlavor s have changed. | 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. |
CHANGED | final protected static int CHANGED(Code) | | An int used by updateCurrentCursor()
indicating that the user operation has changed.
|
DEFAULT | final protected static int DEFAULT(Code) | | An int used by updateCurrentCursor()
indicating that the Cursor should change
to the default (no drop) Cursor .
|
ENTER | final protected static int ENTER(Code) | | An int used by updateCurrentCursor()
indicating that the Cursor
has entered a DropTarget .
|
OVER | final protected static int OVER(Code) | | An int used by updateCurrentCursor()
indicating that the Cursor is
over a DropTarget .
|
DragSourceContext | public DragSourceContext(DragSourceContextPeer dscp, DragGestureEvent trigger, Cursor dragCursor, Image dragImage, Point offset, Transferable t, DragSourceListener dsl)(Code) | | Called from 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.
If DragSourceContextPeer is null
NullPointerException is thrown.
If DragGestureEvent is null
NullPointerException is thrown.
If Cursor is null no exception is thrown and
the default drag cursor behavior is activated for this drag operation.
If Image is null no exception is thrown.
If Image is not null and the offset is
null NullPointerException is thrown.
If Transferable is null
NullPointerException is thrown.
If DragSourceListener is null no exception
is thrown.
Parameters: dscp - the DragSourceContextPeer for this drag Parameters: trigger - the triggering event Parameters: dragCursor - the initial Cursor for this drag operationor null for the default cursor handling;see class level documentationfor more details on the cursor handling mechanism during drag and drop Parameters: dragImage - the Image to drag (or null ) Parameters: offset - the offset of the image origin from the hotspot at theinstant of the triggering event Parameters: t - the Transferable Parameters: dsl - the DragSourceListener throws: IllegalArgumentException - if the Component associatedwith the trigger event is null . throws: IllegalArgumentException - if the DragSource for the trigger event is null . throws: IllegalArgumentException - if the drag action for thetrigger event is DnDConstants.ACTION_NONE . throws: IllegalArgumentException - if the source actions for theDragGestureRecognizer associated with the triggerevent are equal to DnDConstants.ACTION_NONE . throws: NullPointerException - if dscp, trigger, or t are null, orif dragImage is non-null and offset is null |
addDragSourceListener | public synchronized void addDragSourceListener(DragSourceListener dsl) throws TooManyListenersException(Code) | | Add a DragSourceListener to this
DragSourceContext if one has not already been added.
If a DragSourceListener already exists,
this method throws a TooManyListenersException .
Parameters: dsl - the DragSourceListener to add.Note that while null is not prohibited,it is not acceptable as a parameter. throws: TooManyListenersException - ifa DragSourceListener has already been added
|
dragDropEnd | public void dragDropEnd(DragSourceDropEvent dsde)(Code) | | Calls dragDropEnd on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDropEvent .
Parameters: dsde - the DragSourceDropEvent |
dragEnter | public void dragEnter(DragSourceDragEvent dsde)(Code) | | Calls dragEnter on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDragEvent .
Parameters: dsde - the DragSourceDragEvent |
dragExit | public void dragExit(DragSourceEvent dse)(Code) | | Calls dragExit on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceEvent .
Parameters: dse - the DragSourceEvent |
dragMouseMoved | public void dragMouseMoved(DragSourceDragEvent dsde)(Code) | | Calls dragMouseMoved on the
DragSourceMotionListener s registered with the
DragSource associated with this
DragSourceContext , and them passes the specified
DragSourceDragEvent .
Parameters: dsde - the DragSourceDragEvent since: 1.4 |
dragOver | public void dragOver(DragSourceDragEvent dsde)(Code) | | Calls dragOver on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDragEvent .
Parameters: dsde - the DragSourceDragEvent |
dropActionChanged | public void dropActionChanged(DragSourceDragEvent dsde)(Code) | | Calls dropActionChanged on the
DragSourceListener s registered with this
DragSourceContext and with the associated
DragSource , and passes them the specified
DragSourceDragEvent .
Parameters: dsde - the DragSourceDragEvent |
getComponent | public Component getComponent()(Code) | | Returns the Component associated with this
DragSourceContext .
the Component that started the drag |
getCursor | public Cursor getCursor()(Code) | | Returns the current drag Cursor .
the current drag Cursor |
getDragSource | public DragSource getDragSource()(Code) | | Returns the DragSource
that instantiated this DragSourceContext .
the DragSource that instantiated this DragSourceContext |
getSourceActions | public int getSourceActions()(Code) | | Returns a bitwise mask of DnDConstants that
represent the set of drop actions supported by the drag source for the
drag operation associated with this DragSourceContext .
the drop actions supported by the drag source |
getTransferable | public Transferable getTransferable()(Code) | | Returns the Transferable associated with
this DragSourceContext .
the Transferable |
getTrigger | public DragGestureEvent getTrigger()(Code) | | Returns the DragGestureEvent
that initially triggered the drag.
the Event that triggered the drag |
removeDragSourceListener | public synchronized void removeDragSourceListener(DragSourceListener dsl)(Code) | | Removes the specified DragSourceListener
from this DragSourceContext .
Parameters: dsl - the DragSourceListener to remove;note that while null is not prohibited,it is not acceptable as a parameter |
setCursor | public synchronized void setCursor(Cursor c)(Code) | | Sets the cursor for this drag operation to the specified
Cursor . If the specified Cursor
is null , the default drag cursor behavior is
activated for this drag operation, otherwise it is deactivated.
Parameters: c - the initial Cursor for this drag operation,or null for the default cursor handling;see for more detailson the cursor handling during drag and drop |
transferablesFlavorsChanged | public void transferablesFlavorsChanged()(Code) | | Notifies the peer that the Transferable 's
DataFlavor s have changed.
|
updateCurrentCursor | protected synchronized void updateCurrentCursor(int sourceAct, int targetAct, int status)(Code) | | 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.
Parameters: sourceAct - the actions supported by the drag source Parameters: targetAct - the drop target action Parameters: status - one of the fields DEFAULT ,ENTER , OVER , CHANGED |
|
|