Package com.sun.jna.platform.dnd
Class DragHandler
java.lang.Object
com.sun.jna.platform.dnd.DragHandler
- All Implemented Interfaces:
- 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 Iconwith transparency to represent the item being dragged (restricted to theWindowof 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().- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final intConvenience to referenceDnDConstants.ACTION_COPY.(package private) static final intModifier mask for a user-requested copy.static final floatDefault transparency for ghosting.(package private) static final intModifier mask for any user-requested action.protected static final intConvenience to referenceDnDConstants.ACTION_LINK.(package private) static final intModifier mask for a user-requested link.static final DimensionDefault maximum size for ghosted images.protected static final intConvenience to referenceDnDConstants.ACTION_MOVE.(package private) static final intModifier mask for a user-requested move.protected static final intConvenience to referenceDnDConstants.ACTION_NONE.(package private) static final booleanstatic final intgetModifiers()returns this value when the current modifiers state is unknown.static final TransferablegetTransferable(java.awt.dnd.DropTargetEvent)returns this value when the currentTransferableis unknown.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedDragHandler(Component dragSource, int actions) Enable drags from the given component, supporting the actions in the given action mask.
- 
Method SummaryModifier and TypeMethodDescription(package private) static StringactionString(int action) protected intPick a different drop action if the target doesn't support the current one and there are no modifiers.protected booleanOverride to control whether a drag is started.protected ImagecreateDragImage(GraphicsConfiguration gc, Icon icon) Create an image from the given icon.voidvoidvoidvoidCalled when a user drag gesture is recognized.voidvoidprotected voidOverride to perform any decoration of the target at the start of a drag, if desired.voidprotected intgetAcceptableDropAction(int targetActions) Returns the first available action supported by source and target.protected CursorgetCursorForAction(int actualAction) protected IcongetDragIcon(DragGestureEvent e, Point srcOffset) Override this to provide a custom image.protected intGet the currently requested drop action.(package private) static intUsed to communicate modifier state toDropHandler.protected abstract TransferableOverride to provide an appropriateTransferablerepresenting the data being dragged.static TransferableUsed to communicate the currentTransferableduring a drag, if available.protected IconscaleDragIcon(Icon icon, Point imageOffset) Change the size of the given drag icon, if appropriate.protected voidsetModifiers(int mods) Update the modifiers hint.protected voidHook to update the cursor on variousDragSourceEventupdates.
- 
Field Details- 
MAX_GHOST_SIZEDefault maximum size for ghosted images.
- 
DEFAULT_GHOST_ALPHApublic static final float DEFAULT_GHOST_ALPHADefault transparency for ghosting.- See Also:
 
- 
UNKNOWN_MODIFIERSpublic static final int UNKNOWN_MODIFIERSgetModifiers()returns this value when the current modifiers state is unknown.- See Also:
 
- 
UNKNOWN_TRANSFERABLEgetTransferable(java.awt.dnd.DropTargetEvent)returns this value when the currentTransferableis unknown.
- 
MOVEprotected static final int MOVEConvenience to referenceDnDConstants.ACTION_MOVE.- See Also:
 
- 
COPYprotected static final int COPYConvenience to referenceDnDConstants.ACTION_COPY.- See Also:
 
- 
LINKprotected static final int LINKConvenience to referenceDnDConstants.ACTION_LINK.- See Also:
 
- 
NONEprotected static final int NONEConvenience to referenceDnDConstants.ACTION_NONE.- See Also:
 
- 
MOVE_MASKstatic final int MOVE_MASKModifier mask for a user-requested move.- See Also:
 
- 
OSXstatic final boolean OSX
- 
COPY_MASKstatic final int COPY_MASKModifier mask for a user-requested copy.
- 
LINK_MASKstatic final int LINK_MASKModifier mask for a user-requested link.
- 
KEY_MASKstatic final int KEY_MASKModifier mask for any user-requested action.- See Also:
 
 
- 
- 
Constructor Details- 
DragHandlerEnable drags from the given component, supporting the actions in the given action mask.- Parameters:
- dragSource- source of the drag.
- actions- actions which should be supported.
 
 
- 
- 
Method Details- 
getModifiersstatic int getModifiers()Used to communicate modifier state toDropHandler. Note that this field will only be accurate when aDragHandlerin the same VM started the drag. Otherwise,UNKNOWN_MODIFIERSwill be returned.- Returns:
- Current drag modifiers.
 
- 
getTransferableUsed to communicate the currentTransferableduring a drag, if available. Work around absence of access to the data when dragging pre-1.5.- Parameters:
- e- event
- Returns:
- Transferablerepresentation of the item being dragged.
 
- 
canDragOverride 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.- Parameters:
- e- event
- Returns:
- Whether to allow a drag
 
- 
setModifiersprotected void setModifiers(int mods) Update the modifiers hint.- Parameters:
- mods- Current modifiers
 
- 
getTransferableOverride to provide an appropriateTransferablerepresenting the data being dragged.- Parameters:
- e- event
- Returns:
- Transferablerepresentation of item being dragged.
 
- 
getDragIconOverride this to provide a custom image. TheIconreturned by this method by default isnull, which results in no drag image.- Parameters:
- e- event
- 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. 
- Returns:
- drag icon (defaults to none)
 
- 
dragStartedOverride to perform any decoration of the target at the start of a drag, if desired.- Parameters:
- e- event
 
- 
dragGestureRecognizedCalled when a user drag gesture is recognized. This method is responsible for initiating the drag operation.- Specified by:
- dragGestureRecognizedin interface- DragGestureListener
- Parameters:
- e- event
 
- 
scaleDragIconChange 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.- Parameters:
- icon- Icon to be scaled.
- imageOffset- Modified to account for the new icon's size.
- Returns:
- Scaled Icon, or the original if there was no change.
 
- 
createDragImageCreate an image from the given icon. The image is provided to the native handler if drag images are supported natively.- Parameters:
- gc- current graphics configuration.
- icon- Icon on which to base the drag image.
- Returns:
- image based on the given icon.
 
- 
getCursorForAction
- 
getAcceptableDropActionprotected int getAcceptableDropAction(int targetActions) Returns the first available action supported by source and target.- Parameters:
- targetActions- current actions requested
- Returns:
- subset of actions supported based on the input
 
- 
getDropActionGet the currently requested drop action.- Parameters:
- ev- event
- Returns:
- effective drop action
 
- 
adjustDropActionPick a different drop action if the target doesn't support the current one and there are no modifiers.- Parameters:
- ev- event
- Returns:
- effective drop action
 
- 
updateCursorHook to update the cursor on variousDragSourceEventupdates.- Parameters:
- ev- event
 
- 
actionString
- 
dragDropEnd- Specified by:
- dragDropEndin interface- DragSourceListener
 
- 
dragEnter- Specified by:
- dragEnterin interface- DragSourceListener
 
- 
dragMouseMoved- Specified by:
- dragMouseMovedin interface- DragSourceMotionListener
 
- 
dragOver- Specified by:
- dragOverin interface- DragSourceListener
 
- 
dragExit- Specified by:
- dragExitin interface- DragSourceListener
 
- 
dropActionChanged- Specified by:
- dropActionChangedin interface- DragSourceListener
 
 
-