Provides simplified drop handling for a component. Usage:
int actions = DnDConstants.MOVE_OR_COPY; Component component = ...; DropHandler handler = new DropHandler(component, actions);
- Accept drops where the action is the default (i.e. no modifiers) but the intersection of source and target actions is not the default. Doing so allows the source to adjust the cursor appropriately.
- Refuse drops where the user modifiers request an action that is not supported (this works for all cases except when the drag source is not a {@link DragHandler} and the user explicitly requests a MOVE operation;this is indistinguishable from a drag with no modifiers unless we have access to the key modifiers, which {@link DragHandler} provides).
- Drops may be refused based on data flavor, location, intended drop action, or any combination of those, by overriding {@link #canDrop}.
- Custom decoration of the drop area may be performed in {@link #paintDropTarget(DropTargetEvent,int,Point)} or by providinga {@link DropTargetPainter}.
The method {@link #getDropAction(DropTargetEvent)} follows these steps todetermine the appropriate action (if any).
- {@link #isSupported(DataFlavor[])} determines if there are any supported flavors
- {@link #getDropActionsForFlavors(DataFlavor[])} reduces the supported actions based on available flavors. For instance, a text field for file paths might support {@link DnDConstants#ACTION_COPY_OR_MOVE} on a plain string, but {@link DnDConstants#ACTION_LINK} might be the only action supported on a file.
- {@link #getDropAction(DropTargetEvent,int,int,int)} relax the actionif it's the default, or restrict it for user requested actions.
- {@link #canDrop(DropTargetEvent,int,Point)} change the action based on the location in the drop target component, or any other criteria.
Override {@link #drop(DropTargetDropEvent,int)} to handle the drop. You should invoke {@link DropTargetDropEvent#dropComplete} as soonas the {@link Transferable} data is obtained, to avoid making the DnDoperation look suspended.
@see DragHandler
@author twall