Class DropPanel

All Implemented Interfaces:
ClientEventListener, DragDropListener, EventListener

public abstract class DropPanel extends Div<DropPanel> implements DragDropListener
An abstract panel that serves as a drop target for drag-and-drop operations.

DropPanel provides a container that accepts draggable elements. When elements are added to the panel, they automatically become draggable. The panel handles all drag-and-drop events and maintains the correct parent-child relationships when elements are moved.

Subclasses must implement three abstract methods to respond to drag-and-drop events:

Usage Example:


 public class TaskBoard extends DropPanel {
     protected void onDragStart(Element element) {
         element.setOpacity(50);
     }

     protected void onDragEnd(Element element) {
         element.setOpacity(100);
     }

     protected void onDrop(Element dropped) {
         // Handle the dropped element
         System.out.println("Dropped: " + dropped.getId());
     }
 }
 
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • DropPanel

      public DropPanel()
      Creates a new DropPanel configured as a drop target.
  • Method Details

    • onElementAdded

      public final void onElementAdded(Element element)
      Description copied from class: Element
      Hook method called when a child element has been added.
      Overrides:
      onElementAdded in class Element<DropPanel>
      Parameters:
      element - The child element that was added.
    • onEvent

      public final void onEvent(DragStartEvent event)
      Description copied from interface: DragDropListener
      Called when a drag operation starts on the element.
      Specified by:
      onEvent in interface DragDropListener
      Parameters:
      event - the DragStartEvent containing drag data and source element information
    • onEvent

      public final void onEvent(DragEndEvent event)
      Description copied from interface: DragDropListener
      Called when a drag operation ends, whether by dropping or canceling.
      Specified by:
      onEvent in interface DragDropListener
      Parameters:
      event - the DragEndEvent indicating how the drag operation concluded
    • onEvent

      public final void onEvent(DragExitEvent event)
      Description copied from interface: DragDropListener
      Called when the dragged element exits the browser window or valid drop area.
      Specified by:
      onEvent in interface DragDropListener
      Parameters:
      event - the DragExitEvent with exit information
    • onEvent

      public final void onEvent(DragEnterEvent event)
      Description copied from interface: DragDropListener
      Called when a dragged element enters this element's bounds.
      Specified by:
      onEvent in interface DragDropListener
      Parameters:
      event - the DragEnterEvent containing information about the entering drag
    • onEvent

      public final void onEvent(DragOverEvent event)
      Description copied from interface: DragDropListener
      Called continuously while a dragged element is over this element.
      Specified by:
      onEvent in interface DragDropListener
      Parameters:
      event - the DragOverEvent with current position and drag data
    • onEvent

      public final void onEvent(DragLeaveEvent event)
      Description copied from interface: DragDropListener
      Called when a dragged element leaves this element's bounds.
      Specified by:
      onEvent in interface DragDropListener
      Parameters:
      event - the DragLeaveEvent indicating the drag has left this target
    • onEvent

      public final void onEvent(DropEvent event)
      Description copied from interface: DragDropListener
      Called when an element is dropped on this drop target.
      Specified by:
      onEvent in interface DragDropListener
      Parameters:
      event - the DropEvent containing the dropped data and position
    • setMaxScrollSpeed

      public DropPanel setMaxScrollSpeed(int speed)
      Sets the maximum auto-scroll speed when dragging near the top or bottom edge of the viewport.

      During a drag operation, if the cursor is near the top or bottom edge of the viewport, the page will automatically scroll. This value controls the maximum scroll speed in pixels per animation frame. Higher values produce faster scrolling.

      Parameters:
      speed - The maximum scroll speed in pixels per frame. Default is 20.
      Returns:
      This DropPanel for method chaining.
    • setEdgeThreshold

      public DropPanel setEdgeThreshold(int pixels)
      Sets the edge threshold distance for triggering auto-scroll during drag operations.

      When the cursor is within this many pixels of the top or bottom edge of the viewport during a drag operation, auto-scrolling begins. Larger values make it easier to trigger scrolling but reduce the usable drag area.

      Parameters:
      pixels - The distance from the viewport edge in pixels. Default is 80.
      Returns:
      This DropPanel for method chaining.
    • onDragStart

      protected abstract void onDragStart(Element element)
      Called when an element within this panel starts being dragged.
      Parameters:
      element - The element that is being dragged.
    • onDragEnd

      protected abstract void onDragEnd(Element element)
      Called when dragging of an element ends, whether by dropping or canceling.
      Parameters:
      element - The element that was being dragged.
    • onDrop

      protected abstract void onDrop(Element dropped)
      Called when an element is dropped onto this panel.
      Parameters:
      dropped - The element that was dropped.