public abstract class DragHandler
extends java.lang.Object
implements java.awt.dnd.DragSourceListener, java.awt.dnd.DragSourceMotionListener, java.awt.dnd.DragGestureListener
int actions = DnDConstants.MOVE_OR_COPY;
Component component = ...;
DragHandler handler = new DragHandler(component, actions);
Icon
with transparency to
represent the item being dragged (restricted to the Window
of the drag source if the platform doesn't support drag images).
DropTargetDragEvent.acceptDrag(int)
, but often client code
simply relies on DropTargetDragEvent.getDropAction()
.Modifier and Type | Field and Description |
---|---|
protected static int |
COPY
Convenience to reference
DnDConstants.ACTION_COPY . |
(package private) static int |
COPY_MASK
Modifier mask for a user-requested copy.
|
static float |
DEFAULT_GHOST_ALPHA
Default transparency for ghosting.
|
(package private) static int |
KEY_MASK
Modifier mask for any user-requested action.
|
protected static int |
LINK
Convenience to reference
DnDConstants.ACTION_LINK . |
(package private) static int |
LINK_MASK
Modifier mask for a user-requested link.
|
static java.awt.Dimension |
MAX_GHOST_SIZE
Default maximum size for ghosted images.
|
protected static int |
MOVE
Convenience to reference
DnDConstants.ACTION_MOVE . |
(package private) static int |
MOVE_MASK
Modifier mask for a user-requested move.
|
protected static int |
NONE
Convenience to reference
DnDConstants.ACTION_NONE . |
(package private) static boolean |
OSX |
static int |
UNKNOWN_MODIFIERS
getModifiers() returns this value when the current
modifiers state is unknown. |
static java.awt.datatransfer.Transferable |
UNKNOWN_TRANSFERABLE
getTransferable(java.awt.dnd.DropTargetEvent) returns this value when
the current Transferable is unknown. |
Modifier | Constructor and Description |
---|---|
protected |
DragHandler(java.awt.Component dragSource,
int actions)
Enable drags from the given component, supporting the actions in
the given action mask.
|
Modifier and Type | Method and Description |
---|---|
(package private) static java.lang.String |
actionString(int action) |
protected int |
adjustDropAction(java.awt.dnd.DragSourceEvent ev)
Pick a different drop action if the target doesn't support the current
one and there are no modifiers.
|
protected boolean |
canDrag(java.awt.dnd.DragGestureEvent e)
Override to control whether a drag is started.
|
protected java.awt.Image |
createDragImage(java.awt.GraphicsConfiguration gc,
javax.swing.Icon icon)
Create an image from the given icon.
|
void |
dragDropEnd(java.awt.dnd.DragSourceDropEvent e) |
void |
dragEnter(java.awt.dnd.DragSourceDragEvent e) |
void |
dragExit(java.awt.dnd.DragSourceEvent e) |
void |
dragGestureRecognized(java.awt.dnd.DragGestureEvent e)
Called when a user drag gesture is recognized.
|
void |
dragMouseMoved(java.awt.dnd.DragSourceDragEvent e) |
void |
dragOver(java.awt.dnd.DragSourceDragEvent e) |
protected void |
dragStarted(java.awt.dnd.DragGestureEvent e)
Override to perform any decoration of the target at the start of a drag,
if desired.
|
void |
dropActionChanged(java.awt.dnd.DragSourceDragEvent e) |
protected int |
getAcceptableDropAction(int targetActions)
Returns the first available action supported by source and target.
|
protected java.awt.Cursor |
getCursorForAction(int actualAction) |
protected javax.swing.Icon |
getDragIcon(java.awt.dnd.DragGestureEvent e,
java.awt.Point srcOffset)
Override this to provide a custom image.
|
protected int |
getDropAction(java.awt.dnd.DragSourceEvent ev)
Get the currently requested drop action.
|
(package private) static int |
getModifiers()
Used to communicate modifier state to
DropHandler . |
protected abstract java.awt.datatransfer.Transferable |
getTransferable(java.awt.dnd.DragGestureEvent e)
Override to provide an appropriate
Transferable representing
the data being dragged. |
static java.awt.datatransfer.Transferable |
getTransferable(java.awt.dnd.DropTargetEvent e)
Used to communicate the current
Transferable during a drag,
if available. |
protected javax.swing.Icon |
scaleDragIcon(javax.swing.Icon icon,
java.awt.Point imageOffset)
Change the size of the given drag icon, if appropriate.
|
protected void |
setModifiers(int mods)
Update the modifiers hint.
|
protected void |
updateCursor(java.awt.dnd.DragSourceEvent ev)
Hook to update the cursor on various
DragSourceEvent updates. |
public static final java.awt.Dimension MAX_GHOST_SIZE
public static final float DEFAULT_GHOST_ALPHA
public static final int UNKNOWN_MODIFIERS
getModifiers()
returns this value when the current
modifiers state is unknown.public static final java.awt.datatransfer.Transferable UNKNOWN_TRANSFERABLE
getTransferable(java.awt.dnd.DropTargetEvent)
returns this value when
the current Transferable
is unknown.protected static final int MOVE
DnDConstants.ACTION_MOVE
.protected static final int COPY
DnDConstants.ACTION_COPY
.protected static final int LINK
DnDConstants.ACTION_LINK
.protected static final int NONE
DnDConstants.ACTION_NONE
.static final int MOVE_MASK
static final boolean OSX
static final int COPY_MASK
static final int LINK_MASK
static final int KEY_MASK
protected DragHandler(java.awt.Component dragSource, int actions)
dragSource
- source of the drag.actions
- actions which should be supported.static int getModifiers()
DropHandler
. Note that
this field will only be accurate when a DragHandler
in
the same VM started the drag. Otherwise, UNKNOWN_MODIFIERS
will be returned.public static java.awt.datatransfer.Transferable getTransferable(java.awt.dnd.DropTargetEvent e)
Transferable
during a drag,
if available. Work around absence of access to the data when dragging
pre-1.5.e
- eventTransferable
representation of the item being dragged.protected boolean canDrag(java.awt.dnd.DragGestureEvent e)
e
- eventprotected void setModifiers(int mods)
mods
- Current modifiersprotected abstract java.awt.datatransfer.Transferable getTransferable(java.awt.dnd.DragGestureEvent e)
Transferable
representing
the data being dragged.e
- eventTransferable
representation of item being dragged.protected javax.swing.Icon getDragIcon(java.awt.dnd.DragGestureEvent e, java.awt.Point srcOffset)
Icon
returned by this method by default is null
, which results
in no drag image.e
- eventsrcOffset
- set this to be the offset from the drag source
component's upper left corner to the image's upper left corner.
For example, when dragging a row from a list, the offset would be the
row's bounding rectangle's (x,y) coordinate.The default value is (0,0), so if unchanged, the image is will use the same origin as the drag source component.
protected void dragStarted(java.awt.dnd.DragGestureEvent e)
e
- eventpublic void dragGestureRecognized(java.awt.dnd.DragGestureEvent e)
dragGestureRecognized
in interface java.awt.dnd.DragGestureListener
e
- eventprotected javax.swing.Icon scaleDragIcon(javax.swing.Icon icon, java.awt.Point imageOffset)
icon
- Icon to be scaled.imageOffset
- Modified to account for the new icon's size.Icon
, or the original if there was no change.protected java.awt.Image createDragImage(java.awt.GraphicsConfiguration gc, javax.swing.Icon icon)
gc
- current graphics configuration.icon
- Icon on which to base the drag image.protected java.awt.Cursor getCursorForAction(int actualAction)
protected int getAcceptableDropAction(int targetActions)
targetActions
- current actions requestedprotected int getDropAction(java.awt.dnd.DragSourceEvent ev)
ev
- eventprotected int adjustDropAction(java.awt.dnd.DragSourceEvent ev)
ev
- eventprotected void updateCursor(java.awt.dnd.DragSourceEvent ev)
DragSourceEvent
updates.ev
- eventstatic java.lang.String actionString(int action)
public void dragDropEnd(java.awt.dnd.DragSourceDropEvent e)
dragDropEnd
in interface java.awt.dnd.DragSourceListener
public void dragEnter(java.awt.dnd.DragSourceDragEvent e)
dragEnter
in interface java.awt.dnd.DragSourceListener
public void dragMouseMoved(java.awt.dnd.DragSourceDragEvent e)
dragMouseMoved
in interface java.awt.dnd.DragSourceMotionListener
public void dragOver(java.awt.dnd.DragSourceDragEvent e)
dragOver
in interface java.awt.dnd.DragSourceListener
public void dragExit(java.awt.dnd.DragSourceEvent e)
dragExit
in interface java.awt.dnd.DragSourceListener
public void dropActionChanged(java.awt.dnd.DragSourceDragEvent e)
dropActionChanged
in interface java.awt.dnd.DragSourceListener