Skip to content

DragPayload

Immutable transfer payload conveying identifier, type, preview text, and optional user object between drag source and drop target.

Overview

DragPayload encapsulates data transferred between the drag initiator and candidate drop zones.

Core Architecture

  • id: Unique identifier for tracking the dragged instance or item.
  • type: String MIME or semantic type (e.g. item/inventory, dock/tab). Supports wildcard prefix matching such as item/*.
  • preview: Brief text representation displayed in default ghosts and tooltips.
  • data: Optional attached in-memory Java object (Object), accessible via data(Class<T>).
DragPayload payload = DragPayload.of("item-42", "inventory/slot", "Diamond Sword", swordItem);
if (payload.matchesType("inventory/*")) {
    Sword item = payload.data(Sword.class);
}

Creating and Checking Payloads

DragPayload payload = DragPayload.of("item-42", "item.stack", "Iron Ingot", stackItem);
  • DragController: Drag gesture controller attachable to any widget via composition to initiate drag-and-drop operations with ghost previews, threshold handling, and autoscrolling.
  • DropController: Drop target controller attachable to any widget via composition to filter payloads and handle drag enter, over, leave, and drop events.

API

DragPayload(String, String, String)

Constructs a drag payload without extra object data.

Parameter Type Description
id String Unique identifier for the payload.
type String MIME or semantic type string.
preview String Short preview text.

DragPayload::data(Class)

Returns the attached data cast to the specified class, or null if absent or type mismatch.

Parameter Type Description
type Class Expected class of the data object.

Returns Object: The payload data cast to the target type, or null..

DragPayload::hasData()

Checks whether this payload carries attached data.

Returns boolean: True if a non-null payload data object is attached..

DragPayload::matchesType(String)

Checks whether the payload type matches the expected filter.

Parameter Type Description
expectedType String Expected type string to match against.

Returns boolean: True if the type matches the expected type string..

DragPayload::of(String, String, String)

Factory method to create a payload without extra data.

Parameter Type Description
id String Unique identifier for the payload.
type String MIME or semantic type string.
preview String Short preview text.

Returns DragPayload: A newly created immutable DragPayload instance..

DragPayload::of(String, String, String, Object)

Factory method to create a payload with arbitrary in-process data.

Parameter Type Description
id String Unique identifier for the payload.
type String MIME or semantic type string.
preview String Short preview text.
data Object User data payload object.

Returns DragPayload: A newly created immutable DragPayload instance..