DragSourceContext (Java Platform SE 6) (original) (raw)



java.awt.dnd

Class DragSourceContext

java.lang.Object extended by java.awt.dnd.DragSourceContext

All Implemented Interfaces:

DragSourceListener, DragSourceMotionListener, Serializable, EventListener


public class DragSourceContext

extends Object

implements DragSourceListener, DragSourceMotionListener, Serializable

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 DragSourceListeners and DragSourceMotionListeners, and providing theTransferable representing the source data for the drag operation.

Note that the DragSourceContext itself implements the DragSourceListener andDragSourceMotionListener 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 theDragSourceContext to interpose itself between the platform and the listeners provided by the initiator of the drag operation.

Since:

1.2

See Also:

DragSourceListener, DragSourceMotionListener, Serialized Form


Field Summary
protected static int CHANGED An int used by updateCurrentCursor() indicating that the user operation has changed.
protected static int DEFAULT An int used by updateCurrentCursor() indicating that the Cursor should change to the default (no drop) Cursor.
protected static int ENTER An int used by updateCurrentCursor() indicating that the Cursor has entered a DropTarget.
protected static int OVER An int used by updateCurrentCursor() indicating that the Cursor is over a DropTarget.
Constructor Summary
[DragSourceContext](../../../java/awt/dnd/DragSourceContext.html#DragSourceContext%28java.awt.dnd.peer.DragSourceContextPeer, java.awt.dnd.DragGestureEvent, java.awt.Cursor, java.awt.Image, java.awt.Point, java.awt.datatransfer.Transferable, java.awt.dnd.DragSourceListener%29)(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 newDragSourceContext given theDragSourceContextPeer for this Drag, theDragGestureEvent that triggered the Drag, the initialCursor 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.
Method Summary
void addDragSourceListener(DragSourceListener dsl) Add a DragSourceListener to thisDragSourceContext if one has not already been added.
void dragDropEnd(DragSourceDropEvent dsde) Calls dragDropEnd on theDragSourceListeners registered with thisDragSourceContext and with the associatedDragSource, and passes them the specifiedDragSourceDropEvent.
void dragEnter(DragSourceDragEvent dsde) Calls dragEnter on theDragSourceListeners registered with thisDragSourceContext and with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.
void dragExit(DragSourceEvent dse) Calls dragExit on theDragSourceListeners registered with thisDragSourceContext and with the associatedDragSource, and passes them the specifiedDragSourceEvent.
void dragMouseMoved(DragSourceDragEvent dsde) Calls dragMouseMoved on theDragSourceMotionListeners registered with theDragSource associated with thisDragSourceContext, and them passes the specifiedDragSourceDragEvent.
void dragOver(DragSourceDragEvent dsde) Calls dragOver on theDragSourceListeners registered with thisDragSourceContext and with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.
void dropActionChanged(DragSourceDragEvent dsde) Calls dropActionChanged on theDragSourceListeners registered with thisDragSourceContext and with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.
Component getComponent() Returns the Component associated with this DragSourceContext.
Cursor getCursor() Returns the current drag Cursor.
DragSource getDragSource() Returns the DragSource that instantiated this DragSourceContext.
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.
Transferable getTransferable() Returns the Transferable associated with this DragSourceContext.
DragGestureEvent getTrigger() Returns the DragGestureEvent that initially triggered the drag.
void removeDragSourceListener(DragSourceListener dsl) Removes the specified DragSourceListener from this DragSourceContext.
void setCursor(Cursor c) Sets the cursor for this drag operation to the specifiedCursor.
void transferablesFlavorsChanged() Notifies the peer that the Transferable'sDataFlavors have changed.
protected void [updateCurrentCursor](../../../java/awt/dnd/DragSourceContext.html#updateCurrentCursor%28int, int, int%29)(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.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, [wait](../../../java/lang/Object.html#wait%28long, int%29)
Field Detail

DEFAULT

protected static final int DEFAULT

An int used by updateCurrentCursor() indicating that the Cursor should change to the default (no drop) Cursor.

See Also:

Constant Field Values


ENTER

protected static final int ENTER

An int used by updateCurrentCursor() indicating that the Cursor has entered a DropTarget.

See Also:

Constant Field Values


OVER

protected static final int OVER

An int used by updateCurrentCursor() indicating that the Cursor is over a DropTarget.

See Also:

Constant Field Values


CHANGED

protected static final int CHANGED

An int used by updateCurrentCursor() indicating that the user operation has changed.

See Also:

Constant Field Values

Constructor Detail

DragSourceContext

public 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 newDragSourceContext given theDragSourceContextPeer for this Drag, theDragGestureEvent that triggered the Drag, the initialCursor 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 isnull 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

trigger - the triggering event

dragCursor - the initial Cursor

dragImage - the Image to drag (or null)

offset - the offset of the image origin from the hotspot at the instant of the triggering event

t - the Transferable

dsl - the DragSourceListener

Throws:

[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang") - if the Component associated with the trigger event is null.

[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang") - if the DragSource for the trigger event is null.

[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang") - if the drag action for the trigger event is DnDConstants.ACTION_NONE.

[IllegalArgumentException](../../../java/lang/IllegalArgumentException.html "class in java.lang") - if the source actions for theDragGestureRecognizer associated with the trigger event are equal to DnDConstants.ACTION_NONE.

[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang") - if dscp, trigger, or t are null, or if dragImage is non-null and offset is null

Method Detail

getDragSource

public DragSource getDragSource()

Returns the DragSource that instantiated this DragSourceContext.

Returns:

the DragSource that instantiated this DragSourceContext


getComponent

public Component getComponent()

Returns the Component associated with this DragSourceContext.

Returns:

the Component that started the drag


getTrigger

public DragGestureEvent getTrigger()

Returns the DragGestureEvent that initially triggered the drag.

Returns:

the Event that triggered the drag


getSourceActions

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.

Returns:

the drop actions supported by the drag source


setCursor

public void setCursor(Cursor c)

Sets the cursor for this drag operation to the specifiedCursor. If the specified Cursor is null, the default drag cursor behavior is activated for this drag operation, otherwise it is deactivated.

Parameters:

c - the Cursor to display, or null to activate the default drag cursor behavior


getCursor

public Cursor getCursor()

Returns the current drag Cursor.

Returns:

the current drag Cursor


addDragSourceListener

public void addDragSourceListener(DragSourceListener dsl) throws TooManyListenersException

Add a DragSourceListener to thisDragSourceContext 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` - if a DragSourceListener has already been added

[TooManyListenersException](../../../java/util/TooManyListenersException.html "class in java.util")


removeDragSourceListener

public void removeDragSourceListener(DragSourceListener dsl)

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


transferablesFlavorsChanged

public void transferablesFlavorsChanged()

Notifies the peer that the Transferable'sDataFlavors have changed.


dragEnter

public void dragEnter(DragSourceDragEvent dsde)

Calls dragEnter on theDragSourceListeners registered with thisDragSourceContext and with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.

Specified by:

[dragEnter](../../../java/awt/dnd/DragSourceListener.html#dragEnter%28java.awt.dnd.DragSourceDragEvent%29) in interface [DragSourceListener](../../../java/awt/dnd/DragSourceListener.html "interface in java.awt.dnd")

Parameters:

dsde - the DragSourceDragEvent


dragOver

public void dragOver(DragSourceDragEvent dsde)

Calls dragOver on theDragSourceListeners registered with thisDragSourceContext and with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.

Specified by:

[dragOver](../../../java/awt/dnd/DragSourceListener.html#dragOver%28java.awt.dnd.DragSourceDragEvent%29) in interface [DragSourceListener](../../../java/awt/dnd/DragSourceListener.html "interface in java.awt.dnd")

Parameters:

dsde - the DragSourceDragEvent


dragExit

public void dragExit(DragSourceEvent dse)

Calls dragExit on theDragSourceListeners registered with thisDragSourceContext and with the associatedDragSource, and passes them the specifiedDragSourceEvent.

Specified by:

[dragExit](../../../java/awt/dnd/DragSourceListener.html#dragExit%28java.awt.dnd.DragSourceEvent%29) in interface [DragSourceListener](../../../java/awt/dnd/DragSourceListener.html "interface in java.awt.dnd")

Parameters:

dse - the DragSourceEvent


dropActionChanged

public void dropActionChanged(DragSourceDragEvent dsde)

Calls dropActionChanged on theDragSourceListeners registered with thisDragSourceContext and with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.

Specified by:

[dropActionChanged](../../../java/awt/dnd/DragSourceListener.html#dropActionChanged%28java.awt.dnd.DragSourceDragEvent%29) in interface [DragSourceListener](../../../java/awt/dnd/DragSourceListener.html "interface in java.awt.dnd")

Parameters:

dsde - the DragSourceDragEvent


dragDropEnd

public void dragDropEnd(DragSourceDropEvent dsde)

Calls dragDropEnd on theDragSourceListeners registered with thisDragSourceContext and with the associatedDragSource, and passes them the specifiedDragSourceDropEvent.

Specified by:

[dragDropEnd](../../../java/awt/dnd/DragSourceListener.html#dragDropEnd%28java.awt.dnd.DragSourceDropEvent%29) in interface [DragSourceListener](../../../java/awt/dnd/DragSourceListener.html "interface in java.awt.dnd")

Parameters:

dsde - the DragSourceDropEvent


dragMouseMoved

public void dragMouseMoved(DragSourceDragEvent dsde)

Calls dragMouseMoved on theDragSourceMotionListeners registered with theDragSource associated with thisDragSourceContext, and them passes the specifiedDragSourceDragEvent.

Specified by:

[dragMouseMoved](../../../java/awt/dnd/DragSourceMotionListener.html#dragMouseMoved%28java.awt.dnd.DragSourceDragEvent%29) in interface [DragSourceMotionListener](../../../java/awt/dnd/DragSourceMotionListener.html "interface in java.awt.dnd")

Parameters:

dsde - the DragSourceDragEvent

Since:

1.4


getTransferable

public Transferable getTransferable()

Returns the Transferable associated with this DragSourceContext.

Returns:

the Transferable


updateCurrentCursor

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.

Parameters:

sourceAct - the actions supported by the drag source

targetAct - the drop target action

status - one of the fields DEFAULT,ENTER, OVER, CHANGED



Submit a bug or feature
For further API reference and developer documentation, see Java SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 1993, 2015, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

Scripting on this page tracks web page traffic, but does not change the content in any way.