Skip to content

DropController

Drop target controller attachable to any widget via composition to filter payloads and handle drag enter, over, leave, and drop events.

Overview

DropController provides drop target validation and lifecycle management for container widgets.

Usage Pattern

DropController.attach(targetContainer)
        .accepts("items/weapon", "items/armor")
        .onDragEnter(event -> targetContainer.style().border(ColorView.GREEN, 2.0f))
        .onDragLeave(event -> targetContainer.style().clearBorder())
        .onDrop(event -> addItem(event.payload().data(Item.class)));

Features

  • Declarative Filtering: Set allowed types via accepts(String...) or custom logic via accepts(Predicate<DragPayload>).
  • Automatic Claiming: Automatically calls event.accept(zone) when payload matches.
  • Lifecycle Callbacks: Convenient chained handlers for onDragEnter, onDragOver, onDragLeave, and onDrop.

Attaching Drop Controller with Validation

DropController.attach(targetPanel)
        .accepts("card")
        .onDrop(event -> System.out.println("Dropped: " + event.payload().id()));
  • DragController: Drag gesture controller attachable to any widget via composition to initiate drag-and-drop operations with ghost previews, threshold handling, and autoscrolling.
  • DragSession: Live state and controller of an active drag gesture, managing pointer coordinates, active drop target, ghost positioning, insertion indicators, and autoscrolling.

API

DropController::accepts(DragPayload)

Tests whether the specified payload matches type and validator requirements.

Parameter Type Description
payload DragPayload Payload to validate.

Returns boolean: True if the payload is accepted by this drop zone..

DropController::accepts(Predicate)

Adds a custom predicate validation rule for candidate payloads.

Parameter Type Description
validator Predicate Predicate validator for payloads.

Returns DropController: This DropController for method chaining..

DropController::accepts(String)

Restricts accepted payload types by comma/pipe/whitespace delimited string (* accepts all).

Parameter Type Description
types String Accepted payload types.

Returns DropController: This DropController for method chaining..

DropController::attach(Widget)

Attaches a DropController to the specified widget zone.

Parameter Type Description
zone Widget Widget acting as the drop target zone.

Returns DropController: A newly attached DropController instance..

DropController::detach()

Detaches event listeners from the host drop zone widget.

DropController::enabled(boolean)

Enables or disables this drop controller.

Parameter Type Description
enabled boolean Whether the drop target is enabled.

Returns DropController: This DropController for method chaining..

DropController::hovering()

Returns true while an accepted drag payload is hovering over the zone.

Returns boolean: True if a drag gesture is hovering over this drop zone..

DropController::onDragEnter(Consumer)

Registers a listener called when an accepted payload enters the drop zone.

Parameter Type Description
listener Consumer Callback for drag enter event.

Returns DropController: This DropController for method chaining..

DropController::onDragLeave(Consumer)

Registers a listener called when the drag pointer leaves the drop zone or is cancelled.

Parameter Type Description
listener Consumer Callback for drag leave event.

Returns DropController: This DropController for method chaining..

DropController::onDragOver(Consumer)

Registers a listener called on each movement and frame tick over the drop zone.

Parameter Type Description
listener Consumer Callback for drag over event.

Returns DropController: This DropController for method chaining..

DropController::onDrop(Consumer)

Registers a listener called when an accepted payload is dropped over the zone.

Parameter Type Description
listener Consumer Callback for drop event.

Returns DropController: This DropController for method chaining..

DropController::zone()

Returns the host drop zone widget.

Returns Widget: The widget acting as the drop target zone..