Package furbelow

Class DropHandler

java.lang.Object
furbelow.DropHandler
All Implemented Interfaces:
DropTargetListener, EventListener

public abstract class DropHandler extends Object implements DropTargetListener
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 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 DragHandler provides).
  • Drops may be refused based on data flavor, location, intended drop action, or any combination of those, by overriding canDrop(java.awt.dnd.DropTargetEvent, int, java.awt.Point).
  • Custom decoration of the drop area may be performed in paintDropTarget(DropTargetEvent, int, Point).
The method getDropAction(DropTargetEvent) follows these steps to determine the appropriate action (if any). Override drop(DropTargetDropEvent, int) to handle the drop. You should invoke DropTargetDropEvent.dropComplete(boolean) as soon as the Transferable data is obtained, to avoid making the DnD operation look suspended.
See Also:
  • Constructor Details

    • DropHandler

      public DropHandler(Component c, int acceptedActions)
      Create a handler that allows the given set of actions. If using this constructor, you will need to override isSupported(java.util.List) to indicate which data flavors are allowed.
    • DropHandler

      public DropHandler(Component c, int acceptedActions, DataFlavor[] acceptedFlavors)
      Enable handling of drops, indicating what actions and flavors are acceptable.
      Parameters:
      c - The component to receive drops
      acceptedActions - Allowed actions for drops
      acceptedFlavors - Allowed data flavors for drops
      See Also:
    • DropHandler

      public DropHandler(Component c, int acceptedActions, DataFlavor[] acceptedFlavors, DropTargetPainter painter)
      Enable handling of drops, indicating what actions and flavors are acceptable, and providing a painter for drop target feedback.
      Parameters:
      c - The component to receive drops
      acceptedActions - Allowed actions for drops
      acceptedFlavors - Allowed data flavors for drops
      painter - Painter to handle drop target feedback
      See Also:
  • Method Details