org.jhotdraw8.fxcontrols.dock.DockRoot Maven / Gradle / Ivy
/*
* @(#)DockRoot.java
* Copyright © 2023 The authors and contributors of JHotDraw. MIT License.
*/
package org.jhotdraw8.fxcontrols.dock;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.Parent;
import javafx.scene.input.DataFormat;
import org.jhotdraw8.application.Activity;
import org.jspecify.annotations.Nullable;
import java.util.function.Predicate;
/**
* The root node of a docking hierarchy.
*
* The root node manages drag and drop of {@link Dockable} nodes, and
* creates or destroys {@link Track} nodes that hold the {@link Dockable}s.
*/
public interface DockRoot extends DockParent {
/**
* Data format used for dragging a DockItem with the drag board.
* The value of this data format is the {@link System#identityHashCode(Object)}
* of the dragged leaf.
*/
DataFormat DOCKABLE_DATA_FORMAT = new DataFormat("application/x-jhotdraw8-dragged-dock-leaf");
/**
* We store the dragged item here, because we move the reference
* of a DockItem with the drag board rather than a value of the DockItem.
*/
ObjectProperty draggedDockable = new SimpleObjectProperty<>();
static ObjectProperty draggedDockableProperty() {
return draggedDockable;
}
static @Nullable Dockable getDraggedDockable() {
return draggedDockable.get();
}
static void setDraggedDockable(@Nullable Dockable value) {
draggedDockable.set(value);
}
/**
* Only {@link Dockable}s accepted by this filter can be docked.
*
* This can be used to restrict docking to dockables that belong
* to the same {@link Activity}.
*
* @return filter for accepting {@link Dockable}s
*/
ObjectProperty> dockablePredicateProperty();
default Predicate getDockablePredicate() {
return dockablePredicateProperty().get();
}
default void setDockablePredicate(Predicate value) {
dockablePredicateProperty().set(value);
}
@Override
Parent getNode();
}