Package com.sun.jna.platform.dnd
Klasse DragHandler
java.lang.Object
com.sun.jna.platform.dnd.DragHandler
- Alle implementierten Schnittstellen:
DragGestureListener
,DragSourceListener
,DragSourceMotionListener
,EventListener
public abstract class DragHandler
extends Object
implements DragSourceListener, DragSourceMotionListener, DragGestureListener
Provides simplified drag handling for a component.
Usage:
int actions = DnDConstants.MOVE_OR_COPY;
Component component = ...;
DragHandler handler = new DragHandler(component, actions);
- Supports painting an arbitrary
Icon
with transparency to represent the item being dragged (restricted to theWindow
of the drag source if the platform doesn't support drag images). - Disallow starting a drag if the user requests an unsupported action.
- Adjusts the cursor on drags with no modifier for which the default action is disallowed but where one or more non-default actions are allowed, e.g. a drag (with no modifiers) to a target which supports "link" should change the cursor to "link" (prior to 1.6, the JRE behavior is to display a "not allowed" cursor, even though the action actually depends on how the drop target responds). The bug is fixed in java 1.6.
- Disallow drops to targets if the non-default (user-requested) action is not supported by the target, e.g. the user requests a "copy" when the target only supports "move". This is generally the responsibility of the drop handler, which decides whether or not to accept a drag. The DragHandler provides static modifier state information since the drop handler doesn't have access to it.
DropTargetDragEvent.acceptDrag(int)
, but often client code
simply relies on DropTargetDragEvent.getDropAction()
.-
Feldübersicht
FelderModifizierer und TypFeldBeschreibungprotected static final int
Convenience to referenceDnDConstants.ACTION_COPY
.(Package privat) static final int
Modifier mask for a user-requested copy.static final float
Default transparency for ghosting.(Package privat) static final int
Modifier mask for any user-requested action.protected static final int
Convenience to referenceDnDConstants.ACTION_LINK
.(Package privat) static final int
Modifier mask for a user-requested link.static final Dimension
Default maximum size for ghosted images.protected static final int
Convenience to referenceDnDConstants.ACTION_MOVE
.(Package privat) static final int
Modifier mask for a user-requested move.protected static final int
Convenience to referenceDnDConstants.ACTION_NONE
.(Package privat) static final boolean
static final int
getModifiers()
returns this value when the current modifiers state is unknown.static final Transferable
getTransferable(java.awt.dnd.DropTargetEvent)
returns this value when the currentTransferable
is unknown. -
Konstruktorübersicht
KonstruktorenModifiziererKonstruktorBeschreibungprotected
DragHandler
(Component dragSource, int actions) Enable drags from the given component, supporting the actions in the given action mask. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibung(Package privat) static String
actionString
(int action) protected int
Pick a different drop action if the target doesn't support the current one and there are no modifiers.protected boolean
Override to control whether a drag is started.protected Image
createDragImage
(GraphicsConfiguration gc, Icon icon) Create an image from the given icon.void
void
void
void
Called when a user drag gesture is recognized.void
void
protected void
Override to perform any decoration of the target at the start of a drag, if desired.void
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
Get the currently requested drop action.(Package privat) static int
Used to communicate modifier state toDropHandler
.protected abstract Transferable
Override to provide an appropriateTransferable
representing the data being dragged.static Transferable
Used to communicate the currentTransferable
during a drag, if available.protected Icon
scaleDragIcon
(Icon icon, Point imageOffset) Change the size of the given drag icon, if appropriate.protected void
setModifiers
(int mods) Update the modifiers hint.protected void
Hook to update the cursor on variousDragSourceEvent
updates.
-
Felddetails
-
MAX_GHOST_SIZE
Default maximum size for ghosted images. -
DEFAULT_GHOST_ALPHA
public static final float DEFAULT_GHOST_ALPHADefault transparency for ghosting.- Siehe auch:
-
UNKNOWN_MODIFIERS
public static final int UNKNOWN_MODIFIERSgetModifiers()
returns this value when the current modifiers state is unknown.- Siehe auch:
-
UNKNOWN_TRANSFERABLE
getTransferable(java.awt.dnd.DropTargetEvent)
returns this value when the currentTransferable
is unknown. -
MOVE
protected static final int MOVEConvenience to referenceDnDConstants.ACTION_MOVE
.- Siehe auch:
-
COPY
protected static final int COPYConvenience to referenceDnDConstants.ACTION_COPY
.- Siehe auch:
-
LINK
protected static final int LINKConvenience to referenceDnDConstants.ACTION_LINK
.- Siehe auch:
-
NONE
protected static final int NONEConvenience to referenceDnDConstants.ACTION_NONE
.- Siehe auch:
-
MOVE_MASK
static final int MOVE_MASKModifier mask for a user-requested move.- Siehe auch:
-
OSX
static final boolean OSX -
COPY_MASK
static final int COPY_MASKModifier mask for a user-requested copy. -
LINK_MASK
static final int LINK_MASKModifier mask for a user-requested link. -
KEY_MASK
static final int KEY_MASKModifier mask for any user-requested action.- Siehe auch:
-
-
Konstruktordetails
-
DragHandler
Enable drags from the given component, supporting the actions in the given action mask.- Parameter:
dragSource
- source of the drag.actions
- actions which should be supported.
-
-
Methodendetails
-
getModifiers
static int getModifiers()Used to communicate modifier state toDropHandler
. Note that this field will only be accurate when aDragHandler
in the same VM started the drag. Otherwise,UNKNOWN_MODIFIERS
will be returned.- Gibt zurück:
- Current drag modifiers.
-
getTransferable
Used to communicate the currentTransferable
during a drag, if available. Work around absence of access to the data when dragging pre-1.5.- Parameter:
e
- event- Gibt zurück:
Transferable
representation of the item being dragged.
-
canDrag
Override to control whether a drag is started. The default implementation disallows the drag if the user is applying modifiers and the user-requested action is not supported.- Parameter:
e
- event- Gibt zurück:
- Whether to allow a drag
-
setModifiers
protected void setModifiers(int mods) Update the modifiers hint.- Parameter:
mods
- Current modifiers
-
getTransferable
Override to provide an appropriateTransferable
representing the data being dragged.- Parameter:
e
- event- Gibt zurück:
Transferable
representation of item being dragged.
-
getDragIcon
Override this to provide a custom image. TheIcon
returned by this method by default isnull
, which results in no drag image.- Parameter:
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.
- Gibt zurück:
- drag icon (defaults to none)
-
dragStarted
Override to perform any decoration of the target at the start of a drag, if desired.- Parameter:
e
- event
-
dragGestureRecognized
Called when a user drag gesture is recognized. This method is responsible for initiating the drag operation.- Angegeben von:
dragGestureRecognized
in SchnittstelleDragGestureListener
- Parameter:
e
- event
-
scaleDragIcon
Change the size of the given drag icon, if appropriate. When using a differently-sized drag icon, we also need to adjust the cursor offset within the icon.- Parameter:
icon
- Icon to be scaled.imageOffset
- Modified to account for the new icon's size.- Gibt zurück:
- Scaled
Icon
, or the original if there was no change.
-
createDragImage
Create an image from the given icon. The image is provided to the native handler if drag images are supported natively.- Parameter:
gc
- current graphics configuration.icon
- Icon on which to base the drag image.- Gibt zurück:
- image based on the given icon.
-
getCursorForAction
-
getAcceptableDropAction
protected int getAcceptableDropAction(int targetActions) Returns the first available action supported by source and target.- Parameter:
targetActions
- current actions requested- Gibt zurück:
- subset of actions supported based on the input
-
getDropAction
Get the currently requested drop action.- Parameter:
ev
- event- Gibt zurück:
- effective drop action
-
adjustDropAction
Pick a different drop action if the target doesn't support the current one and there are no modifiers.- Parameter:
ev
- event- Gibt zurück:
- effective drop action
-
updateCursor
Hook to update the cursor on variousDragSourceEvent
updates.- Parameter:
ev
- event
-
actionString
-
dragDropEnd
- Angegeben von:
dragDropEnd
in SchnittstelleDragSourceListener
-
dragEnter
- Angegeben von:
dragEnter
in SchnittstelleDragSourceListener
-
dragMouseMoved
- Angegeben von:
dragMouseMoved
in SchnittstelleDragSourceMotionListener
-
dragOver
- Angegeben von:
dragOver
in SchnittstelleDragSourceListener
-
dragExit
- Angegeben von:
dragExit
in SchnittstelleDragSourceListener
-
dropActionChanged
- Angegeben von:
dropActionChanged
in SchnittstelleDragSourceListener
-