public abstract class DragHandler extends Object implements DragSourceListener, DragSourceMotionListener, 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 . |
static float |
DEFAULT_GHOST_ALPHA
Default transparency for ghosting.
|
protected static int |
LINK
Convenience to reference
DnDConstants.ACTION_LINK . |
static Dimension |
MAX_GHOST_SIZE
Default maximum size for ghosted images.
|
protected static int |
MOVE
Convenience to reference
DnDConstants.ACTION_MOVE . |
protected static int |
NONE
Convenience to reference
DnDConstants.ACTION_NONE . |
static int |
UNKNOWN_MODIFIERS
getModifiers() returns this value when the current
modifiers state is unknown. |
static Transferable |
UNKNOWN_TRANSFERABLE
#getTransferable(DropTargetDragEvent) returns this value when
the current Transferable is unknown. |
Modifier | Constructor and Description |
---|---|
protected |
DragHandler(Component dragSource,
int actions)
Enable drags from the given component, supporting the actions in
the given action mask.
|
Modifier and Type | Method and Description |
---|---|
protected int |
adjustDropAction(DragSourceEvent ev)
Pick a different drop action if the target doesn't support the current
one and there are no modifiers.
|
protected boolean |
canDrag(DragGestureEvent e)
Override to control whether a drag is started.
|
protected Image |
createDragImage(Icon icon)
Create an image from the given icon.
|
protected GhostedDragImage |
createGhostedDragImage(JComponent dragSource,
Point screen,
Icon dragIcon,
Point dragIconOffset)
Create a ghosted drag image.
|
void |
dragDropEnd(DragSourceDropEvent e) |
void |
dragEnter(DragSourceDragEvent e) |
void |
dragExit(DragSourceEvent e) |
void |
dragGestureRecognized(DragGestureEvent e)
Called when a user drag gesture is recognized.
|
void |
dragMouseMoved(DragSourceDragEvent e) |
void |
dragOver(DragSourceDragEvent e) |
protected void |
dragStarted(DragGestureEvent e)
Override to perform any decoration of the target at the start of a drag,
if desired.
|
void |
dropActionChanged(DragSourceDragEvent e) |
protected int |
getAcceptableDropAction(int targetActions)
Returns the first available action supported by source and target.
|
protected Cursor |
getCursorForAction(int actualAction) |
protected Icon |
getDragIcon(DragGestureEvent e,
Point srcOffset)
Override this to provide a custom image.
|
protected int |
getDropAction(DragSourceEvent ev)
Get the currently requested drop action.
|
protected abstract Transferable |
getTransferable(DragGestureEvent e)
Override to provide an appropriate
Transferable representing
the data being dragged. |
static Transferable |
getTransferable(DropTargetEvent e)
Used to communicate the current
Transferable during a drag,
if available. |
protected Icon |
scaleDragIcon(Icon dragIcon,
Point offset)
Reduce the size of the given drag icon, if appropriate.
|
protected void |
setModifiers(int mods)
Update the modifiers hint.
|
protected void |
updateCursor(DragSourceEvent ev) |
public static final 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 Transferable UNKNOWN_TRANSFERABLE
#getTransferable(DropTargetDragEvent)
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
.protected DragHandler(Component dragSource, int actions)
public static Transferable getTransferable(DropTargetEvent e)
Transferable
during a drag,
if available. Work around absence of access to the data when dragging
pre-1.5.protected boolean canDrag(DragGestureEvent e)
protected void setModifiers(int mods)
protected abstract Transferable getTransferable(DragGestureEvent e)
Transferable
representing
the data being dragged.protected Icon getDragIcon(DragGestureEvent e, Point srcOffset)
Icon
returned by this method by default is null
, which results
in no drag image.srcOffset
- 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(DragGestureEvent e)
public void dragGestureRecognized(DragGestureEvent e)
dragGestureRecognized
in interface DragGestureListener
protected Icon scaleDragIcon(Icon dragIcon, Point offset)
protected GhostedDragImage createGhostedDragImage(JComponent dragSource, Point screen, Icon dragIcon, Point dragIconOffset)
protected Image createDragImage(Icon icon)
protected Cursor getCursorForAction(int actualAction)
protected int getAcceptableDropAction(int targetActions)
protected int getDropAction(DragSourceEvent ev)
protected int adjustDropAction(DragSourceEvent ev)
protected void updateCursor(DragSourceEvent ev)
public void dragDropEnd(DragSourceDropEvent e)
dragDropEnd
in interface DragSourceListener
public void dragEnter(DragSourceDragEvent e)
dragEnter
in interface DragSourceListener
public void dragMouseMoved(DragSourceDragEvent e)
dragMouseMoved
in interface DragSourceMotionListener
public void dragOver(DragSourceDragEvent e)
dragOver
in interface DragSourceListener
public void dragExit(DragSourceEvent e)
dragExit
in interface DragSourceListener
public void dropActionChanged(DragSourceDragEvent e)
dropActionChanged
in interface DragSourceListener
Copyright © 2023. All rights reserved.