DragSourceContext (Java SE 10 & JDK 10 )
-
-
Field Summary
Fields Modifier and Type Field Description protected static intCHANGEDAn
intused by updateCurrentCursor() indicating that the user operation has changed.protected static intDEFAULTAn
intused by updateCurrentCursor() indicating that theCursorshould change to the default (no drop)Cursor.protected static intENTERAn
intused by updateCurrentCursor() indicating that theCursorhas entered aDropTarget.protected static intOVERAn
intused by updateCurrentCursor() indicating that theCursoris over aDropTarget.
-
Constructor Summary
Constructors Constructor Description DragSourceContext(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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDragSourceListener(DragSourceListener dsl)Add a
DragSourceListenerto thisDragSourceContextif one has not already been added.voiddragDropEnd(DragSourceDropEvent dsde)Calls
dragDropEndon theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDropEvent.voiddragEnter(DragSourceDragEvent dsde)Calls
dragEnteron theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.voiddragExit(DragSourceEvent dse)Calls
dragExiton theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceEvent.voiddragMouseMoved(DragSourceDragEvent dsde)Calls
dragMouseMovedon theDragSourceMotionListeners registered with theDragSourceassociated with thisDragSourceContext, and them passes the specifiedDragSourceDragEvent.voiddragOver(DragSourceDragEvent dsde)Calls
dragOveron theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.voiddropActionChanged(DragSourceDragEvent dsde)Calls
dropActionChangedon theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.ComponentgetComponent()Returns the
Componentassociated with thisDragSourceContext.CursorgetCursor()Returns the current custom drag
Cursor.DragSourcegetDragSource()Returns the
DragSourcethat instantiated thisDragSourceContext.intgetSourceActions()Returns a bitwise mask of
DnDConstantsthat represent the set of drop actions supported by the drag source for the drag operation associated with thisDragSourceContext.TransferablegetTransferable()Returns the
Transferableassociated with thisDragSourceContext.DragGestureEventgetTrigger()Returns the
DragGestureEventthat initially triggered the drag.voidremoveDragSourceListener(DragSourceListener dsl)Removes the specified
DragSourceListenerfrom thisDragSourceContext.voidsetCursor(Cursor c)Sets the custom cursor for this drag operation to the specified
Cursor.voidtransferablesFlavorsChanged()Notifies the peer that the
Transferable'sDataFlavors have changed.protected voidupdateCurrentCursor(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.
-
-
-
Field Detail
-
DEFAULT
protected static final int DEFAULT
An
intused by updateCurrentCursor() indicating that theCursorshould change to the default (no drop)Cursor.- See Also:
- Constant Field Values
-
ENTER
protected static final int ENTER
An
intused by updateCurrentCursor() indicating that theCursorhas entered aDropTarget.- See Also:
- Constant Field Values
-
OVER
protected static final int OVER
An
intused by updateCurrentCursor() indicating that theCursoris over aDropTarget.- See Also:
- Constant Field Values
-
CHANGED
protected static final int CHANGED
An
intused by updateCurrentCursor() indicating that the user operation has changed.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DragSourceContext
public DragSourceContext(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.
IfDragSourceContextPeerisnullNullPointerExceptionis thrown.
IfDragGestureEventisnullNullPointerExceptionis thrown.
IfCursorisnullno exception is thrown and the default drag cursor behavior is activated for this drag operation.
IfImageisnullno exception is thrown.
IfImageis notnulland the offset isnull NullPointerExceptionis thrown.
IfTransferableisnullNullPointerExceptionis thrown.
IfDragSourceListenerisnullno exception is thrown.- Parameters:
trigger- the triggering eventdragCursor- the initialCursorfor this drag operation ornullfor the default cursor handling; see class level documentation for more details on the cursor handling mechanism during drag and dropdragImage- theImageto drag (ornull)offset- the offset of the image origin from the hotspot at the instant of the triggering eventt- theTransferabledsl- theDragSourceListener- Throws:
IllegalArgumentException- if theComponentassociated with the trigger event isnull.IllegalArgumentException- if theDragSourcefor the trigger event isnull.IllegalArgumentException- if the drag action for the trigger event isDnDConstants.ACTION_NONE.IllegalArgumentException- if the source actions for theDragGestureRecognizerassociated with the trigger event are equal toDnDConstants.ACTION_NONE.NullPointerException- 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
DragSourcethat instantiated thisDragSourceContext.- Returns:
- the
DragSourcethat instantiated thisDragSourceContext
-
getComponent
public Component getComponent()
Returns the
Componentassociated with thisDragSourceContext.- Returns:
- the
Componentthat started the drag
-
getTrigger
public DragGestureEvent getTrigger()
Returns the
DragGestureEventthat initially triggered the drag.- Returns:
- the Event that triggered the drag
-
getSourceActions
public 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.- Returns:
- the drop actions supported by the drag source
-
setCursor
public void setCursor(Cursor c)
Sets the custom cursor for this drag operation to the specified
Cursor. If the specifiedCursorisnull, the default drag cursor behavior is activated for this drag operation, otherwise it is deactivated.- Parameters:
c- the initialCursorfor this drag operation, ornullfor the default cursor handling; see class level documentation for more details on the cursor handling during drag and drop
-
getCursor
public Cursor getCursor()
Returns the current custom drag
Cursor.- Returns:
- the current custom drag
Cursor, if it was set otherwise returnsnull. - See Also:
setCursor(java.awt.Cursor)
-
addDragSourceListener
public void addDragSourceListener(DragSourceListener dsl) throws TooManyListenersException
Add a
DragSourceListenerto thisDragSourceContextif one has not already been added. If aDragSourceListeneralready exists, this method throws aTooManyListenersException.- Parameters:
dsl- theDragSourceListenerto add. Note that whilenullis not prohibited, it is not acceptable as a parameter.- Throws:
TooManyListenersException- if aDragSourceListenerhas already been added
-
removeDragSourceListener
public void removeDragSourceListener(DragSourceListener dsl)
Removes the specified
DragSourceListenerfrom thisDragSourceContext.- Parameters:
dsl- theDragSourceListenerto remove; note that whilenullis 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
dragEnteron theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.- Specified by:
dragEnterin interfaceDragSourceListener- Parameters:
dsde- theDragSourceDragEvent
-
dragOver
public void dragOver(DragSourceDragEvent dsde)
Calls
dragOveron theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.- Specified by:
dragOverin interfaceDragSourceListener- Parameters:
dsde- theDragSourceDragEvent
-
dragExit
public void dragExit(DragSourceEvent dse)
Calls
dragExiton theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceEvent.- Specified by:
dragExitin interfaceDragSourceListener- Parameters:
dse- theDragSourceEvent
-
dropActionChanged
public void dropActionChanged(DragSourceDragEvent dsde)
Calls
dropActionChangedon theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDragEvent.- Specified by:
dropActionChangedin interfaceDragSourceListener- Parameters:
dsde- theDragSourceDragEvent
-
dragDropEnd
public void dragDropEnd(DragSourceDropEvent dsde)
Calls
dragDropEndon theDragSourceListeners registered with thisDragSourceContextand with the associatedDragSource, and passes them the specifiedDragSourceDropEvent.- Specified by:
dragDropEndin interfaceDragSourceListener- Parameters:
dsde- theDragSourceDropEvent
-
dragMouseMoved
public void dragMouseMoved(DragSourceDragEvent dsde)
Calls
dragMouseMovedon theDragSourceMotionListeners registered with theDragSourceassociated with thisDragSourceContext, and them passes the specifiedDragSourceDragEvent.- Specified by:
dragMouseMovedin interfaceDragSourceMotionListener- Parameters:
dsde- theDragSourceDragEvent- Since:
- 1.4
-
getTransferable
public Transferable getTransferable()
Returns the
Transferableassociated with thisDragSourceContext.- 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 sourcetargetAct- the drop target actionstatus- one of the fieldsDEFAULT,ENTER,OVER,CHANGED
-
-