feat(fx): add overlay groups and atomic floating window close
This commit is contained in:
@@ -11,5 +11,5 @@ public record CloseScope(Kind kind, List<DockableId> dockableIds) {
|
||||
}
|
||||
|
||||
/** The entry point that requested consent. */
|
||||
public enum Kind { TAB }
|
||||
public enum Kind { TAB, FLOATING_WINDOW }
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import javafx.beans.property.ReadOnlyObjectProperty;
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.stage.Window;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
@@ -12,113 +13,136 @@ import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
||||
/** Keeps consent, live-layout removal and application resource release in order. */
|
||||
/** Collects every consent before removing content, then releases application resources. */
|
||||
final class DockCloseCoordinator {
|
||||
interface Host {
|
||||
Optional<Dockable> find(DockableId id);
|
||||
Optional<List<DockableId>> floatingDockables(DockWindowId id);
|
||||
Window owner(DockableId id);
|
||||
void remove(DockableId id);
|
||||
void remove(List<DockableId> ids);
|
||||
}
|
||||
|
||||
private final Host host;
|
||||
private final ReadOnlyObjectWrapper<CloseScope> scope = new ReadOnlyObjectWrapper<>(this, "closingScope");
|
||||
private CompletableFuture<CloseResult> completion;
|
||||
private CompletionStage<CloseResult> outcome;
|
||||
private final LinkedHashMap<DockableId, CompletableFuture<CloseResult>> queued = new LinkedHashMap<>();
|
||||
private final LinkedHashMap<RequestKey, Pending> queued = new LinkedHashMap<>();
|
||||
private Running running;
|
||||
|
||||
DockCloseCoordinator(Host host) {
|
||||
this.host = host;
|
||||
}
|
||||
DockCloseCoordinator(Host host) { this.host = host; }
|
||||
|
||||
ReadOnlyObjectProperty<CloseScope> closingScopeProperty() {
|
||||
return scope.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
CloseScope scope() {
|
||||
return scope.get();
|
||||
ReadOnlyObjectProperty<CloseScope> closingScopeProperty() { return scope.getReadOnlyProperty(); }
|
||||
CloseScope scope() { return scope.get(); }
|
||||
boolean coversWindow(DockWindowId id) {
|
||||
return id != null && running != null && id.equals(running.pending.key.windowId);
|
||||
}
|
||||
|
||||
CompletionStage<CloseResult> requestTabClose(DockableId id) {
|
||||
return request(new RequestKey(Objects.requireNonNull(id, "id"), null));
|
||||
}
|
||||
|
||||
CompletionStage<CloseResult> requestFloatingWindowClose(DockWindowId id) {
|
||||
return request(new RequestKey(null, Objects.requireNonNull(id, "id")));
|
||||
}
|
||||
|
||||
private CompletionStage<CloseResult> request(RequestKey key) {
|
||||
if (!Platform.isFxApplicationThread()) {
|
||||
throw new IllegalStateException("Docking operations require the JavaFX Application Thread");
|
||||
}
|
||||
Objects.requireNonNull(id, "id");
|
||||
if (completion != null) {
|
||||
if (scope.get().dockableIds().contains(id)) return outcome;
|
||||
return enqueue(id);
|
||||
if (running != null && (running.pending.key.equals(key)
|
||||
|| key.tabId != null && scope.get().dockableIds().contains(key.tabId))) {
|
||||
return running.pending.outcome;
|
||||
}
|
||||
if (!queued.isEmpty()) {
|
||||
CompletionStage<CloseResult> result = enqueue(id);
|
||||
Platform.runLater(this::nextQueued);
|
||||
return result;
|
||||
if (running != null || !queued.isEmpty()) {
|
||||
Pending pending = queued.computeIfAbsent(key, Pending::new);
|
||||
if (running == null) Platform.runLater(this::nextQueued);
|
||||
return pending.outcome;
|
||||
}
|
||||
return begin(id);
|
||||
}
|
||||
|
||||
private CompletionStage<CloseResult> enqueue(DockableId id) {
|
||||
return queued.computeIfAbsent(id, ignored -> new CompletableFuture<>()).minimalCompletionStage();
|
||||
Pending pending = new Pending(key);
|
||||
begin(pending);
|
||||
return pending.outcome;
|
||||
}
|
||||
|
||||
private void nextQueued() {
|
||||
if (completion != null || queued.isEmpty()) return;
|
||||
var next = queued.pollFirstEntry();
|
||||
begin(next.getKey()).whenComplete((result, failure) -> {
|
||||
if (failure != null) next.getValue().completeExceptionally(failure);
|
||||
else next.getValue().complete(result);
|
||||
});
|
||||
if (completion == null && !queued.isEmpty()) Platform.runLater(this::nextQueued);
|
||||
if (running != null || queued.isEmpty()) return;
|
||||
begin(queued.pollFirstEntry().getValue());
|
||||
}
|
||||
|
||||
private CompletionStage<CloseResult> begin(DockableId id) {
|
||||
Dockable dockable = host.find(id).orElse(null);
|
||||
if (dockable == null) return CompletableFuture.completedFuture(new CloseResult.NoChange());
|
||||
CompletableFuture<CloseResult> request = new CompletableFuture<>();
|
||||
CompletionStage<CloseResult> result = request.minimalCompletionStage();
|
||||
completion = request;
|
||||
outcome = result;
|
||||
scope.set(new CloseScope(CloseScope.Kind.TAB, List.of(id)));
|
||||
try {
|
||||
CompletionStage<CloseConsent> answer = dockable.getCloseCheck() == null
|
||||
? CompletableFuture.completedFuture(CloseConsent.ALLOW)
|
||||
: Objects.requireNonNull(dockable.getCloseCheck().check(new CloseRequest(scope.get(), host.owner(id))),
|
||||
"Close check returned no stage");
|
||||
answer.whenComplete((consent, failure) -> onFx(() -> answered(request, dockable, consent, failure)));
|
||||
} catch (RuntimeException failure) {
|
||||
answered(request, dockable, null, failure);
|
||||
private void begin(Pending pending) {
|
||||
RequestKey key = pending.key;
|
||||
List<DockableId> ids = key.windowId == null
|
||||
? host.find(key.tabId).map(ignored -> List.of(key.tabId)).orElse(List.of())
|
||||
: host.floatingDockables(key.windowId).orElse(List.of());
|
||||
if (ids.isEmpty()) {
|
||||
pending.completion.complete(new CloseResult.NoChange());
|
||||
if (!queued.isEmpty()) Platform.runLater(this::nextQueued);
|
||||
return;
|
||||
}
|
||||
return result;
|
||||
Running request = new Running(pending, ids.stream().map(id -> host.find(id).orElseThrow()).toList());
|
||||
running = request;
|
||||
scope.set(new CloseScope(key.windowId == null ? CloseScope.Kind.TAB : CloseScope.Kind.FLOATING_WINDOW, ids));
|
||||
askNext(request);
|
||||
}
|
||||
|
||||
private void answered(CompletableFuture<CloseResult> request, Dockable dockable,
|
||||
CloseConsent consent, Throwable failure) {
|
||||
if (completion != request) return;
|
||||
if (failure != null || consent == null) {
|
||||
Throwable cause = failure == null ? new IllegalStateException("Close check returned no consent") : failure;
|
||||
DockFailure checkFailure = new DockFailure(DockFailure.Code.CLOSE_CHECK_FAILED,
|
||||
dockable.getId(), "Close consent check failed", cause);
|
||||
finish(request, new CloseResult.Vetoed(List.of(dockable.getId()), List.of(checkFailure)));
|
||||
} else if (consent == CloseConsent.VETO) {
|
||||
finish(request, new CloseResult.Vetoed(List.of(dockable.getId()), List.of()));
|
||||
} else {
|
||||
host.remove(dockable.getId());
|
||||
List<DockFailure> cleanupFailures = List.of();
|
||||
if (dockable.getOnClosed() != null) {
|
||||
/** Synchronous answers drain iteratively; asynchronous answers resume on the FX thread. */
|
||||
private void askNext(Running request) {
|
||||
request.checking = true;
|
||||
try {
|
||||
while (!request.awaiting && request.index < request.dockables.size()) {
|
||||
Dockable dockable = request.dockables.get(request.index);
|
||||
request.awaiting = true;
|
||||
try {
|
||||
dockable.getOnClosed().run();
|
||||
} catch (RuntimeException cleanup) {
|
||||
cleanupFailures = List.of(new DockFailure(DockFailure.Code.CLEANUP_FAILED,
|
||||
dockable.getId(), "Closed Dockable resource release failed", cleanup));
|
||||
CompletionStage<CloseConsent> answer = dockable.getCloseCheck() == null
|
||||
? CompletableFuture.completedFuture(CloseConsent.ALLOW)
|
||||
: Objects.requireNonNull(dockable.getCloseCheck().check(
|
||||
new CloseRequest(scope.get(), host.owner(dockable.getId()))), "Close check returned no stage");
|
||||
answer.whenComplete((consent, failure) -> onFx(() -> answered(request, dockable, consent, failure)));
|
||||
} catch (RuntimeException failure) {
|
||||
answered(request, dockable, null, failure);
|
||||
}
|
||||
}
|
||||
finish(request, new CloseResult.Closed(cleanupFailures));
|
||||
} finally {
|
||||
request.checking = false;
|
||||
}
|
||||
if (!request.awaiting && request.index == request.dockables.size()) commit(request);
|
||||
}
|
||||
|
||||
private void finish(CompletableFuture<CloseResult> request, CloseResult result) {
|
||||
completion = null;
|
||||
outcome = null;
|
||||
private void answered(Running request, Dockable dockable, CloseConsent consent, Throwable failure) {
|
||||
if (running != request || !request.awaiting) return;
|
||||
if (failure != null || consent == null) {
|
||||
Throwable cause = failure == null ? new IllegalStateException("Close check returned no consent") : failure;
|
||||
request.failures.add(new DockFailure(DockFailure.Code.CLOSE_CHECK_FAILED,
|
||||
dockable.getId(), "Close consent check failed", cause));
|
||||
request.vetoes.add(dockable.getId());
|
||||
} else if (consent == CloseConsent.VETO) {
|
||||
request.vetoes.add(dockable.getId());
|
||||
}
|
||||
request.index++;
|
||||
request.awaiting = false;
|
||||
if (!request.checking) askNext(request);
|
||||
}
|
||||
|
||||
private void commit(Running request) {
|
||||
if (!request.vetoes.isEmpty()) {
|
||||
finish(request, new CloseResult.Vetoed(request.vetoes, request.failures));
|
||||
return;
|
||||
}
|
||||
host.remove(request.dockables.stream().map(Dockable::getId).toList());
|
||||
List<DockFailure> cleanupFailures = new ArrayList<>();
|
||||
for (Dockable dockable : request.dockables) {
|
||||
if (dockable.getOnClosed() == null) continue;
|
||||
try {
|
||||
dockable.getOnClosed().run();
|
||||
} catch (RuntimeException cleanup) {
|
||||
cleanupFailures.add(new DockFailure(DockFailure.Code.CLEANUP_FAILED,
|
||||
dockable.getId(), "Closed Dockable resource release failed", cleanup));
|
||||
}
|
||||
}
|
||||
finish(request, new CloseResult.Closed(cleanupFailures));
|
||||
}
|
||||
|
||||
private void finish(Running request, CloseResult result) {
|
||||
running = null;
|
||||
scope.set(null);
|
||||
request.complete(result);
|
||||
request.pending.completion.complete(result);
|
||||
if (!queued.isEmpty()) Platform.runLater(this::nextQueued);
|
||||
}
|
||||
|
||||
@@ -126,4 +150,25 @@ final class DockCloseCoordinator {
|
||||
if (Platform.isFxApplicationThread()) action.run();
|
||||
else Platform.runLater(action);
|
||||
}
|
||||
|
||||
private record RequestKey(DockableId tabId, DockWindowId windowId) { }
|
||||
private static final class Pending {
|
||||
final RequestKey key;
|
||||
final CompletableFuture<CloseResult> completion = new CompletableFuture<>();
|
||||
final CompletionStage<CloseResult> outcome = completion.minimalCompletionStage();
|
||||
Pending(RequestKey key) { this.key = key; }
|
||||
}
|
||||
private static final class Running {
|
||||
final Pending pending;
|
||||
final List<Dockable> dockables;
|
||||
final List<DockableId> vetoes = new ArrayList<>();
|
||||
final List<DockFailure> failures = new ArrayList<>();
|
||||
int index;
|
||||
boolean awaiting;
|
||||
boolean checking;
|
||||
Running(Pending pending, List<Dockable> dockables) {
|
||||
this.pending = pending;
|
||||
this.dockables = dockables;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +60,17 @@ final class DockDragController {
|
||||
Menu splits = new Menu("Split");
|
||||
MenuItem close = new MenuItem("Close");
|
||||
close.setOnAction(event -> manager.requestTabClose(id));
|
||||
javafx.scene.control.CheckMenuItem pin = new javafx.scene.control.CheckMenuItem("Pin group");
|
||||
pin.setOnAction(event -> currentGroup(id).ifPresent(group -> manager.updateGroup(group.id(),
|
||||
DockGroupChanges.builder().mode(group.mode() == DockGroupMode.DOCKED
|
||||
? DockGroupMode.OVERLAY : DockGroupMode.DOCKED).build())));
|
||||
ContextMenu menu = new ContextMenu(destinations, splits, close,
|
||||
new MenuItem("Float"), new MenuItem("Return to main"));
|
||||
new MenuItem("Float"), new MenuItem("Return to main"), pin);
|
||||
menu.setOnShowing(event -> {
|
||||
currentGroup(id).ifPresent(group -> {
|
||||
pin.setSelected(group.mode() == DockGroupMode.DOCKED);
|
||||
pin.setDisable(!manager.canToggleGroupMode(group.id()));
|
||||
});
|
||||
populateDestinations(destinations, id);
|
||||
populateSplits(splits, id);
|
||||
menu.getItems().set(3, moveItem("Float", id, DockTarget.floating()));
|
||||
@@ -71,6 +79,11 @@ final class DockDragController {
|
||||
tab.setContextMenu(menu);
|
||||
}
|
||||
|
||||
private java.util.Optional<DockLayoutView.Group> currentGroup(DockableId id) {
|
||||
return manager.layout().windows().stream().flatMap(window -> window.areas().stream())
|
||||
.flatMap(area -> area.groups().stream()).filter(group -> group.dockableIds().contains(id)).findFirst();
|
||||
}
|
||||
|
||||
void uninstallTab(Tab tab) {
|
||||
DockableId removed = headers.remove(tab.getId());
|
||||
if (removed != null && removed.equals(pressed)) cancel();
|
||||
|
||||
@@ -90,10 +90,6 @@ final class DockEdgeRegion extends Region {
|
||||
setVisible(false);
|
||||
return;
|
||||
}
|
||||
if (extent < 0) {
|
||||
extent = side.isVertical() ? content.prefWidth(-1) : content.prefHeight(-1);
|
||||
committedExtent = extent;
|
||||
}
|
||||
getChildren().addAll(content, divider);
|
||||
managedProperty().bind(content.managedProperty());
|
||||
visibleProperty().bind(content.visibleProperty());
|
||||
@@ -113,7 +109,30 @@ final class DockEdgeRegion extends Region {
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
double committedExtent() { return committedExtent; }
|
||||
double committedExtent() { initializeExtent(); return committedExtent; }
|
||||
|
||||
private void initializeExtent() {
|
||||
if (extent >= 0 || content == null) return;
|
||||
extent = expandedPreference(content, side.isVertical());
|
||||
committedExtent = extent;
|
||||
}
|
||||
|
||||
private static double expandedPreference(Node node, boolean width) {
|
||||
if (node instanceof DockGroupSurface anchor) return width ? anchor.expandedWidth() : anchor.expandedHeight();
|
||||
if (!(node instanceof javafx.scene.control.SplitPane split)) return width ? node.prefWidth(-1) : node.prefHeight(-1);
|
||||
boolean parallel = (split.getOrientation() == javafx.geometry.Orientation.HORIZONTAL) == width;
|
||||
var extents = split.getItems().stream().mapToDouble(child -> expandedPreference(child, width));
|
||||
double extent = parallel ? extents.sum() : extents.max().orElse(0);
|
||||
if (parallel) {
|
||||
for (Node divider : split.lookupAll(".split-pane-divider")) {
|
||||
Node owner = divider.getParent();
|
||||
while (owner != null && !(owner instanceof javafx.scene.control.SplitPane)) owner = owner.getParent();
|
||||
if (owner == split) extent += width ? divider.prefWidth(-1) : divider.prefHeight(-1);
|
||||
}
|
||||
}
|
||||
return extent + (width ? split.getInsets().getLeft() + split.getInsets().getRight()
|
||||
: split.getInsets().getTop() + split.getInsets().getBottom());
|
||||
}
|
||||
Side side() { return side; }
|
||||
|
||||
@Override protected double computePrefWidth(double height) {
|
||||
@@ -135,6 +154,7 @@ final class DockEdgeRegion extends Region {
|
||||
private double dividerSize() { return DockGroupPane.allCollapsed(content) ? 0 : DIVIDER_SIZE; }
|
||||
|
||||
private double displayedExtent() {
|
||||
initializeExtent();
|
||||
return DockGroupPane.allCollapsed(content)
|
||||
? side.isVertical() ? content.prefWidth(-1) : content.prefHeight(-1) : extent;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.Objects;
|
||||
@Value @Builder
|
||||
public class DockGroupChanges {
|
||||
Side tabSide;
|
||||
DockGroupMode mode;
|
||||
Double preferredWidth;
|
||||
Double preferredHeight;
|
||||
Double minimumWidth;
|
||||
@@ -22,6 +23,7 @@ public class DockGroupChanges {
|
||||
|
||||
/** Builder accepts primitive dimensions/flags and requires non-null enum settings. */
|
||||
public static class DockGroupChangesBuilder {
|
||||
public DockGroupChangesBuilder mode(DockGroupMode value) { mode = Objects.requireNonNull(value); return this; }
|
||||
public DockGroupChangesBuilder tabSide(Side value) { tabSide = Objects.requireNonNull(value); return this; }
|
||||
public DockGroupChangesBuilder preferredWidth(double value) { preferredWidth = value; return this; }
|
||||
public DockGroupChangesBuilder preferredHeight(double value) { preferredHeight = value; return this; }
|
||||
@@ -36,6 +38,7 @@ public class DockGroupChanges {
|
||||
|
||||
DockGroupChanges resolved(DockGroupDefinition current) {
|
||||
return builder()
|
||||
.mode(mode == null ? current.getMode() : mode)
|
||||
.tabSide(tabSide == null ? current.getTabSide() : tabSide)
|
||||
.preferredWidth(preferredWidth == null ? current.getPreferredWidth() : preferredWidth)
|
||||
.preferredHeight(preferredHeight == null ? current.getPreferredHeight() : preferredHeight)
|
||||
@@ -50,6 +53,7 @@ public class DockGroupChanges {
|
||||
}
|
||||
|
||||
void applyTo(DockGroupDefinition target) {
|
||||
if (mode != null) target.setMode(mode);
|
||||
if (tabSide != null) target.setTabSide(tabSide);
|
||||
if (preferredWidth != null) target.setPreferredWidth(preferredWidth);
|
||||
if (preferredHeight != null) target.setPreferredHeight(preferredHeight);
|
||||
|
||||
@@ -9,6 +9,7 @@ import lombok.Setter;
|
||||
public final class DockGroupDefinition implements DockLayoutNode {
|
||||
private String destinationId;
|
||||
private Side tabSide = Side.TOP;
|
||||
private DockGroupMode mode = DockGroupMode.DOCKED;
|
||||
private double preferredWidth = 200;
|
||||
private double preferredHeight = 150;
|
||||
private double minimumWidth = 80;
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package de.neitzel.fx.docking;
|
||||
|
||||
/** Whether an open group reserves layout space or temporarily covers nearby content. */
|
||||
public enum DockGroupMode { DOCKED, OVERLAY }
|
||||
@@ -14,13 +14,20 @@ import javafx.scene.layout.Region;
|
||||
final class DockGroupPane extends TabPane {
|
||||
private final DockGroupDefinition definition;
|
||||
private boolean collapsed;
|
||||
private final DockGroupSurface surface;
|
||||
|
||||
DockGroupPane(DockGroupDefinition definition) {
|
||||
this.definition = definition;
|
||||
surface = new DockGroupSurface(this, definition);
|
||||
getStyleClass().add("dock-group");
|
||||
}
|
||||
|
||||
DockGroupSurface surface() { return surface; }
|
||||
double railWidth() { return getSide().isVertical() ? headerExtent() : headerLength(); }
|
||||
double railHeight() { return getSide().isHorizontal() ? headerExtent() : headerLength(); }
|
||||
boolean isOverlay() { return definition.getMode() == DockGroupMode.OVERLAY; }
|
||||
boolean isCollapsed() { return collapsed; }
|
||||
boolean isHeader(Node node) { return headerTab(node) != null; }
|
||||
|
||||
void setCollapsed(boolean collapsed) {
|
||||
this.collapsed = collapsed;
|
||||
@@ -76,7 +83,8 @@ final class DockGroupPane extends TabPane {
|
||||
}
|
||||
|
||||
static boolean allCollapsed(Node node) {
|
||||
if (node instanceof DockGroupPane group) return group.isCollapsed();
|
||||
if (node instanceof DockGroupSurface surface) return surface.unreserved();
|
||||
if (node instanceof DockGroupPane group) return group.isCollapsed() || group.isOverlay();
|
||||
return node instanceof SplitPane split && !split.getItems().isEmpty()
|
||||
&& split.getItems().stream().allMatch(DockGroupPane::allCollapsed);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package de.neitzel.fx.docking;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.Region;
|
||||
|
||||
/** Stable layout anchor; an overlay's live TabPane is hosted above the docked surface. */
|
||||
final class DockGroupSurface extends Region {
|
||||
final DockGroupPane tabs;
|
||||
private final DockGroupDefinition definition;
|
||||
private DockPane host;
|
||||
private double expandedWidth;
|
||||
private double expandedHeight;
|
||||
|
||||
DockGroupSurface(DockGroupPane tabs, DockGroupDefinition definition) {
|
||||
this.tabs = tabs;
|
||||
this.definition = definition;
|
||||
getStyleClass().add("dock-group-surface");
|
||||
getChildren().add(tabs);
|
||||
visibleProperty().bind(tabs.visibleProperty());
|
||||
managedProperty().bind(tabs.managedProperty());
|
||||
parentProperty().addListener((observable, old, current) -> { if (current == null) detach(); });
|
||||
}
|
||||
|
||||
boolean unreserved() { return tabs.isCollapsed() || tabs.isOverlay(); }
|
||||
double expandedWidth() { return expandedWidth > 0 ? expandedWidth : definition.getPreferredWidth(); }
|
||||
double expandedHeight() { return expandedHeight > 0 ? expandedHeight : definition.getPreferredHeight(); }
|
||||
|
||||
boolean spansEdgeExtent(javafx.geometry.Side side) {
|
||||
for (Node current = getParent(); current != null && !(current instanceof DockEdgeRegion); current = current.getParent()) {
|
||||
if (current instanceof javafx.scene.control.SplitPane split
|
||||
&& (split.getOrientation() == javafx.geometry.Orientation.HORIZONTAL) == side.isVertical()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
double edgeContentExtent(double extent, javafx.geometry.Side side) {
|
||||
for (Node current = getParent(); current != null && !(current instanceof DockEdgeRegion); current = current.getParent()) {
|
||||
if (current instanceof javafx.scene.control.SplitPane split) {
|
||||
extent -= side.isVertical() ? split.getInsets().getLeft() + split.getInsets().getRight()
|
||||
: split.getInsets().getTop() + split.getInsets().getBottom();
|
||||
}
|
||||
}
|
||||
return Math.max(0, extent);
|
||||
}
|
||||
|
||||
boolean changesPreferredSize(Double width, Double height) {
|
||||
return tabs.isOverlay() && ((width != null && Double.compare(width, expandedWidth()) != 0)
|
||||
|| (height != null && Double.compare(height, expandedHeight()) != 0));
|
||||
}
|
||||
|
||||
void updatePreferredSize(Double width, Double height) {
|
||||
if (width != null) expandedWidth = width;
|
||||
if (height != null) expandedHeight = height;
|
||||
}
|
||||
|
||||
void synchronize() {
|
||||
DockPane target = null;
|
||||
for (Node current = getParent(); current != null; current = current.getParent()) {
|
||||
if (current instanceof DockPane pane) { target = pane; break; }
|
||||
}
|
||||
if (host != null && (host != target || !tabs.isOverlay())) detach();
|
||||
if (tabs.isOverlay() && target != null && host == null) {
|
||||
getChildren().remove(tabs);
|
||||
host = target;
|
||||
host.overlays.attach(this);
|
||||
}
|
||||
requestLayout();
|
||||
if (target != null) target.requestLayout();
|
||||
}
|
||||
|
||||
private void detach() {
|
||||
if (host == null) return;
|
||||
host.overlays.detach(this);
|
||||
host = null;
|
||||
getChildren().add(tabs);
|
||||
}
|
||||
|
||||
@Override protected double computePrefWidth(double height) {
|
||||
return tabs.isOverlay() ? tabs.railWidth() : tabs.prefWidth(height);
|
||||
}
|
||||
@Override protected double computePrefHeight(double width) {
|
||||
return tabs.isOverlay() ? tabs.railHeight() : tabs.prefHeight(width);
|
||||
}
|
||||
@Override protected double computeMinWidth(double height) {
|
||||
return tabs.isOverlay() ? tabs.railWidth() : tabs.minWidth(height);
|
||||
}
|
||||
@Override protected double computeMinHeight(double width) {
|
||||
return tabs.isOverlay() ? tabs.railHeight() : tabs.minHeight(width);
|
||||
}
|
||||
@Override protected void layoutChildren() {
|
||||
if (host == null) {
|
||||
tabs.resizeRelocate(0, 0, getWidth(), getHeight());
|
||||
if (!tabs.isCollapsed() && !tabs.isOverlay()) {
|
||||
expandedWidth = getWidth();
|
||||
expandedHeight = getHeight();
|
||||
}
|
||||
} else host.overlays.requestLayout();
|
||||
}
|
||||
}
|
||||
@@ -24,14 +24,14 @@ final class DockLayoutTree {
|
||||
}
|
||||
|
||||
private record Leaf(DockingManager.Group group) implements Branch {
|
||||
@Override public Node node() { return group.tabs(); }
|
||||
@Override public Node node() { return ((DockGroupPane) group.tabs()).surface(); }
|
||||
@Override public List<DockingManager.Group> groups() { return List.of(group); }
|
||||
@Override public DockLayoutView.LayoutNode view() {
|
||||
Tab selected = group.tabs().getSelectionModel().getSelectedItem();
|
||||
return new DockLayoutView.Group(group.id(), group.tabs().getSide(),
|
||||
group.tabs().getTabs().stream().map(tab -> (DockableId) tab.getUserData()).toList(),
|
||||
selected == null ? null : (DockableId) selected.getUserData(),
|
||||
group.tabs() instanceof DockGroupPane pane && pane.isCollapsed());
|
||||
group.tabs() instanceof DockGroupPane pane && pane.isCollapsed(), group.definition().getMode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +244,41 @@ final class DockLayoutTree {
|
||||
return branch.groups().stream().allMatch(group -> group.tabs().getTabs().isEmpty());
|
||||
}
|
||||
|
||||
/** Reuses the live overlay dimensions when its group starts reserving space again. */
|
||||
void restoreGroupSize(DockGroupId id, double width, double height) {
|
||||
for (Root root : roots) {
|
||||
restoreGroupSize(nearestSplit(root.branch, id, Orientation.HORIZONTAL), id, width);
|
||||
restoreGroupSize(nearestSplit(root.branch, id, Orientation.VERTICAL), id, height);
|
||||
}
|
||||
}
|
||||
|
||||
private static Split nearestSplit(Branch branch, DockGroupId id, Orientation orientation) {
|
||||
if (!(branch instanceof Split split) || find(branch, id) == null) return null;
|
||||
Branch child = find(split.first, id) != null ? split.first : split.second;
|
||||
Split nested = nearestSplit(child, id, orientation);
|
||||
return nested != null ? nested : split.pane.getOrientation() == orientation ? split : null;
|
||||
}
|
||||
|
||||
private static void restoreGroupSize(Split split, DockGroupId id, double extent) {
|
||||
if (split == null || extent <= 0) return;
|
||||
boolean horizontal = split.pane.getOrientation() == Orientation.HORIZONTAL;
|
||||
double span = horizontal ? split.pane.getWidth() : split.pane.getHeight();
|
||||
if (span <= 0) return;
|
||||
Node divider = split.pane.lookupAll(".split-pane-divider").stream()
|
||||
.filter(node -> divider(node, split.pane) == node).findFirst().orElse(null);
|
||||
double dividerExtent = divider == null ? 6 : horizontal
|
||||
? divider.getLayoutBounds().getWidth() : divider.getLayoutBounds().getHeight();
|
||||
boolean first = find(split.first, id) != null;
|
||||
double inset = horizontal ? first ? split.pane.getInsets().getLeft() : split.pane.getInsets().getRight()
|
||||
: first ? split.pane.getInsets().getTop() : split.pane.getInsets().getBottom();
|
||||
double position = (extent + inset + dividerExtent / 2) / span;
|
||||
if (!first) position = 1 - position;
|
||||
position = Math.max(0, Math.min(1, position));
|
||||
if (Math.abs(position - split.position) * span < 1) return;
|
||||
split.position = position;
|
||||
if (!split.collapsedAllocation) split.pane.setDividerPositions(position);
|
||||
}
|
||||
|
||||
void captureGeometry() {
|
||||
for (Root root : roots) allocateCollapsed(root.branch);
|
||||
for (Root root : roots) captureGeometry(root.branch);
|
||||
|
||||
@@ -27,8 +27,12 @@ public record DockLayoutView(List<Window> windows) {
|
||||
public record Split(javafx.geometry.Orientation orientation, double position,
|
||||
LayoutNode first, LayoutNode second) implements LayoutNode { }
|
||||
public record Group(DockGroupId id, Side tabSide, List<DockableId> dockableIds,
|
||||
DockableId selectedDockableId, boolean collapsed) implements LayoutNode {
|
||||
DockableId selectedDockableId, boolean collapsed, DockGroupMode mode) implements LayoutNode {
|
||||
public Group { dockableIds = List.copyOf(dockableIds); }
|
||||
public Group(DockGroupId id, Side tabSide, List<DockableId> dockableIds,
|
||||
DockableId selectedDockableId, boolean collapsed) {
|
||||
this(id, tabSide, dockableIds, selectedDockableId, collapsed, DockGroupMode.DOCKED);
|
||||
}
|
||||
public Group(DockGroupId id, Side tabSide, List<DockableId> dockableIds, DockableId selectedDockableId) {
|
||||
this(id, tabSide, dockableIds, selectedDockableId, false);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package de.neitzel.fx.docking;
|
||||
|
||||
import javafx.geometry.Bounds;
|
||||
import javafx.geometry.Side;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Places live overlay groups above docked content without reserving their expanded size. */
|
||||
final class DockOverlayLayer extends Region {
|
||||
private final DockPane host;
|
||||
private final List<DockGroupSurface> anchors = new ArrayList<>();
|
||||
private final EventHandler<MouseEvent> outsidePress = this::outsidePress;
|
||||
private Scene registeredScene;
|
||||
private boolean disposed;
|
||||
|
||||
DockOverlayLayer(DockPane host) {
|
||||
this.host = host;
|
||||
setManaged(false);
|
||||
setPickOnBounds(false);
|
||||
getStyleClass().add("dock-overlay-layer");
|
||||
sceneProperty().addListener((observable, old, current) -> {
|
||||
if (registeredScene != null) registeredScene.removeEventFilter(MouseEvent.MOUSE_PRESSED, outsidePress);
|
||||
registeredScene = disposed ? null : current;
|
||||
if (registeredScene != null) registeredScene.addEventFilter(MouseEvent.MOUSE_PRESSED, outsidePress);
|
||||
});
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
disposed = true;
|
||||
if (registeredScene != null) registeredScene.removeEventFilter(MouseEvent.MOUSE_PRESSED, outsidePress);
|
||||
registeredScene = null;
|
||||
}
|
||||
|
||||
private void outsidePress(MouseEvent event) {
|
||||
Node target = event.getPickResult().getIntersectedNode();
|
||||
if (target == null && event.getTarget() instanceof Node node) target = node;
|
||||
if (host.manager != null) host.manager.dismissOutsideOverlays(target);
|
||||
}
|
||||
|
||||
void attach(DockGroupSurface anchor) {
|
||||
anchors.add(anchor);
|
||||
getChildren().add(anchor.tabs);
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
void detach(DockGroupSurface anchor) {
|
||||
anchors.remove(anchor);
|
||||
getChildren().remove(anchor.tabs);
|
||||
}
|
||||
|
||||
@Override protected void layoutChildren() {
|
||||
for (DockGroupSurface anchor : anchors) {
|
||||
DockGroupPane tabs = anchor.tabs;
|
||||
Bounds rail = sceneToLocal(anchor.localToScene(anchor.getLayoutBounds()));
|
||||
Side edge = host.edgeOf(anchor);
|
||||
Side side = edge == null ? tabs.getSide() : edge;
|
||||
double width = rail.getWidth();
|
||||
double height = rail.getHeight();
|
||||
if (!tabs.isCollapsed()) {
|
||||
width = Math.max(width, anchor.expandedWidth());
|
||||
height = Math.max(height, anchor.expandedHeight());
|
||||
double extent = edge == null ? -1 : host.committedExtent(edge);
|
||||
if (extent > 0 && anchor.spansEdgeExtent(edge)) {
|
||||
extent = anchor.edgeContentExtent(extent, edge);
|
||||
if (edge.isVertical()) width = extent;
|
||||
else height = extent;
|
||||
}
|
||||
}
|
||||
width = Math.min(getWidth(), width);
|
||||
height = Math.min(getHeight(), height);
|
||||
double x = side == Side.RIGHT ? rail.getMaxX() - width : rail.getMinX();
|
||||
double y = side == Side.BOTTOM ? rail.getMaxY() - height : rail.getMinY();
|
||||
tabs.resizeRelocate(Math.max(0, Math.min(getWidth() - width, x)),
|
||||
Math.max(0, Math.min(getHeight() - height, y)), width, height);
|
||||
tabs.layout();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,14 @@ import lombok.Setter;
|
||||
public final class DockPane extends Region {
|
||||
@Getter @Setter private DockLayout initialLayout = new DockLayout();
|
||||
final BorderPane surface = new BorderPane();
|
||||
final DockOverlayLayer overlays = new DockOverlayLayer(this);
|
||||
private final Rectangle dropIndicator = new Rectangle();
|
||||
private final java.util.Map<Side, DockEdgeRegion> edgeAreas = new java.util.EnumMap<>(Side.class);
|
||||
DockingManager manager;
|
||||
|
||||
public DockPane() {
|
||||
getStyleClass().add("dock-pane");
|
||||
getChildren().add(surface);
|
||||
getChildren().addAll(surface, overlays);
|
||||
dropIndicator.getStyleClass().add("dock-drop-indicator");
|
||||
dropIndicator.setManaged(false);
|
||||
dropIndicator.setMouseTransparent(true);
|
||||
@@ -63,7 +64,7 @@ public final class DockPane extends Region {
|
||||
}
|
||||
|
||||
Side edgeOf(Node node) {
|
||||
for (Node current = node; current != null; current = current.getParent()) {
|
||||
for (Node current = node instanceof DockGroupPane group ? group.surface() : node; current != null; current = current.getParent()) {
|
||||
if (current instanceof DockEdgeRegion edge) return edge.side();
|
||||
}
|
||||
return null;
|
||||
@@ -89,7 +90,13 @@ public final class DockPane extends Region {
|
||||
return available - remainingMinimum;
|
||||
}
|
||||
|
||||
@Override protected void layoutChildren() { surface.resizeRelocate(0, 0, getWidth(), getHeight()); }
|
||||
@Override protected void layoutChildren() {
|
||||
surface.resizeRelocate(0, 0, getWidth(), getHeight());
|
||||
surface.layout();
|
||||
overlays.resizeRelocate(0, 0, getWidth(), getHeight());
|
||||
overlays.requestLayout();
|
||||
overlays.layout();
|
||||
}
|
||||
@Override protected double computePrefWidth(double height) { return surface.prefWidth(height); }
|
||||
@Override protected double computePrefHeight(double width) { return surface.prefHeight(width); }
|
||||
@Override protected double computeMinWidth(double height) { return surface.minWidth(height); }
|
||||
|
||||
@@ -52,7 +52,15 @@ public final class DockingManager {
|
||||
closing = new DockCloseCoordinator(new DockCloseCoordinator.Host() {
|
||||
@Override public Optional<Dockable> find(DockableId id) { return findDockable(id); }
|
||||
@Override public javafx.stage.Window owner(DockableId id) { return DockingManager.this.owner(containing(id)); }
|
||||
@Override public void remove(DockableId id) { removeDockable(id); }
|
||||
@Override public Optional<List<DockableId>> floatingDockables(DockWindowId id) {
|
||||
FloatingWindow window = floatingWindows.get(id);
|
||||
if (window == null) return Optional.empty();
|
||||
return Optional.of(window.tree.view().stream().flatMap(area -> area.groups().stream())
|
||||
.map(DockLayoutView.Group::id).distinct().map(DockingManager.this::group)
|
||||
.flatMap(group -> group.tabs.getTabs().stream())
|
||||
.map(tab -> (DockableId) tab.getUserData()).toList());
|
||||
}
|
||||
@Override public void remove(List<DockableId> ids) { removeDockables(ids); }
|
||||
});
|
||||
this.placementRule = Objects.requireNonNull(options.getPlacementRule(), "placementRule");
|
||||
this.fallbackTarget = options.getFallbackTarget();
|
||||
@@ -206,34 +214,48 @@ public final class DockingManager {
|
||||
return closing.requestTabClose(id);
|
||||
}
|
||||
|
||||
/** Requests every contained Dockable's consent before closing a floating window. */
|
||||
public java.util.concurrent.CompletionStage<CloseResult> requestFloatingWindowClose(DockWindowId id) {
|
||||
requireFxThread();
|
||||
Objects.requireNonNull(id, "id");
|
||||
if (layout.get().windows().getFirst().id().equals(id)) {
|
||||
return java.util.concurrent.CompletableFuture.completedFuture(new CloseResult.Rejected(
|
||||
new DockFailure(DockFailure.Code.TARGET_NOT_FOUND, null, "The requested window is not floating", null)));
|
||||
}
|
||||
return closing.requestFloatingWindowClose(id);
|
||||
}
|
||||
|
||||
/** Scope remains available until checks and resource release have finished. */
|
||||
public ReadOnlyObjectProperty<CloseScope> closingScopeProperty() {
|
||||
return closing.closingScopeProperty();
|
||||
}
|
||||
|
||||
private void removeDockable(DockableId id) {
|
||||
Group group = containing(id);
|
||||
if (group == null) return;
|
||||
Tab tab = group.tabs.getTabs().get(tabIndex(group, id));
|
||||
boolean wasActive = active.get() == dockables.get(id);
|
||||
private void removeDockables(List<DockableId> ids) {
|
||||
Dockable previousActive = active.get();
|
||||
Group previousGroup = previousActive == null ? null : containing(previousActive.getId());
|
||||
updating = true;
|
||||
try {
|
||||
dragFor(group).uninstallTab(tab);
|
||||
tab.textProperty().unbind();
|
||||
tab.graphicProperty().unbind();
|
||||
tab.setGraphic(null);
|
||||
tab.setContent(null);
|
||||
group.tabs.getTabs().remove(tab);
|
||||
dockables.remove(id);
|
||||
previousFocus.remove(id);
|
||||
activationOrder.remove(id);
|
||||
returnTargets.remove(id);
|
||||
normalizeLayout(group.id);
|
||||
for (DockableId id : ids) {
|
||||
Group group = containing(id);
|
||||
if (group == null) continue;
|
||||
Tab tab = group.tabs.getTabs().get(tabIndex(group, id));
|
||||
dragFor(group).uninstallTab(tab);
|
||||
tab.textProperty().unbind();
|
||||
tab.graphicProperty().unbind();
|
||||
tab.setGraphic(null);
|
||||
tab.setContent(null);
|
||||
group.tabs.getTabs().remove(tab);
|
||||
dockables.remove(id);
|
||||
previousFocus.remove(id);
|
||||
activationOrder.remove(id);
|
||||
returnTargets.remove(id);
|
||||
normalizeLayout(group.id);
|
||||
}
|
||||
} finally {
|
||||
updating = false;
|
||||
}
|
||||
if (wasActive) {
|
||||
Tab selected = group.tabs.getSelectionModel().getSelectedItem();
|
||||
if (previousActive != null && ids.contains(previousActive.getId())) {
|
||||
Tab selected = previousGroup == null ? null : previousGroup.tabs.getSelectionModel().getSelectedItem();
|
||||
if (selected == null) {
|
||||
selected = groups.values().stream().filter(this::isGroupVisible)
|
||||
.map(candidate -> candidate.tabs.getSelectionModel().getSelectedItem())
|
||||
@@ -251,6 +273,9 @@ public final class DockingManager {
|
||||
private boolean groupClosing(Group group) {
|
||||
CloseScope scope = closing.scope();
|
||||
if (scope == null) return false;
|
||||
if (scope.kind() == CloseScope.Kind.FLOATING_WINDOW) {
|
||||
return group != null && closing.coversWindow(groupWindows.get(group.id));
|
||||
}
|
||||
for (DockableId id : scope.dockableIds()) {
|
||||
if (!dockables.containsKey(id) || (group != null && tabIndex(group, id) >= 0)) return true;
|
||||
}
|
||||
@@ -364,7 +389,8 @@ public final class DockingManager {
|
||||
if (receiver == null) return moveRejected(DockFailure.Code.TARGET_NOT_FOUND, id, "Destination does not exist");
|
||||
if (groupClosing(receiver)) return moveRejected(DockFailure.Code.CLOSE_IN_PROGRESS, id, "A close request covers this group");
|
||||
if (containing(id) == receiver && receiver.tabs.getTabs().size() == 1) return new MoveCheck.NoChange();
|
||||
if (((DockGroupPane) receiver.tabs).isCollapsed() && !canChangeGroupGeometry(receiver)) {
|
||||
if ((((DockGroupPane) receiver.tabs).isCollapsed() || ((DockGroupPane) receiver.tabs).isOverlay())
|
||||
&& !canChangeGroupGeometry(receiver)) {
|
||||
return moveRejected(DockFailure.Code.CLOSE_IN_PROGRESS, id,
|
||||
"Opening this group would resize a group awaiting close consent");
|
||||
}
|
||||
@@ -416,7 +442,8 @@ public final class DockingManager {
|
||||
if (index > oldIndex) index--;
|
||||
if (index == oldIndex) return new MoveCheck.NoChange();
|
||||
}
|
||||
if (((DockGroupPane) receiver.tabs).isCollapsed() && !canChangeGroupGeometry(receiver)) {
|
||||
if ((((DockGroupPane) receiver.tabs).isCollapsed() || ((DockGroupPane) receiver.tabs).isOverlay())
|
||||
&& !canChangeGroupGeometry(receiver)) {
|
||||
return moveRejected(DockFailure.Code.CLOSE_IN_PROGRESS, id,
|
||||
"Opening this group would resize a group awaiting close consent");
|
||||
}
|
||||
@@ -468,17 +495,23 @@ public final class DockingManager {
|
||||
if (ownerId != null && groups.values().stream().filter(group -> ownerId.equals(groupWindows.get(group.id)))
|
||||
.allMatch(group -> group.tabs.getTabs().isEmpty())) {
|
||||
FloatingWindow empty = floatingWindows.remove(ownerId);
|
||||
empty.drag.dispose();
|
||||
empty.geometry.dispose();
|
||||
empty.stage.getScene().focusOwnerProperty().removeListener(focusListener);
|
||||
empty.stage.hide();
|
||||
empty.pane.manager = null;
|
||||
empty.stage.getProperties().remove(ATTACHMENT_KEY);
|
||||
disposeFloatingWindow(empty);
|
||||
var remaining = groups.keySet().stream().filter(id -> ownerId.equals(groupWindows.get(id))).toList();
|
||||
remaining.forEach(id -> { groups.remove(id); groupWindows.remove(id); groupActivationOrder.remove(id); });
|
||||
}
|
||||
}
|
||||
|
||||
private void disposeFloatingWindow(FloatingWindow window) {
|
||||
window.stage.removeEventFilter(javafx.stage.WindowEvent.WINDOW_CLOSE_REQUEST, window.closeHandler);
|
||||
window.drag.dispose();
|
||||
window.pane.overlays.dispose();
|
||||
window.geometry.dispose();
|
||||
window.stage.getScene().focusOwnerProperty().removeListener(focusListener);
|
||||
window.stage.hide();
|
||||
window.pane.manager = null;
|
||||
window.stage.getProperties().remove(ATTACHMENT_KEY);
|
||||
}
|
||||
|
||||
/** Applies explicitly supplied settings as one validated group change. */
|
||||
public ActionResult updateGroup(DockGroupId id, DockGroupChanges changes) {
|
||||
requireFxThread();
|
||||
@@ -495,19 +528,23 @@ public final class DockingManager {
|
||||
return rejected(DockFailure.Code.INVALID_GROUP_CONFIGURATION, null, failure.getMessage());
|
||||
}
|
||||
DockEdgeRegion extentOwner = null;
|
||||
for (Node ancestor = group.tabs.getParent(); ancestor != null; ancestor = ancestor.getParent()) {
|
||||
for (Node ancestor = ((DockGroupPane) group.tabs).surface().getParent(); ancestor != null; ancestor = ancestor.getParent()) {
|
||||
if (ancestor instanceof DockEdgeRegion edge) {
|
||||
extentOwner = edge;
|
||||
break;
|
||||
}
|
||||
}
|
||||
boolean changesExtent = extentOwner != null
|
||||
&& extentOwner.changesPreferredExtent(changes.getPreferredWidth(), changes.getPreferredHeight());
|
||||
DockGroupSurface groupSurface = ((DockGroupPane) group.tabs).surface();
|
||||
if (extentOwner != null && !groupSurface.spansEdgeExtent(extentOwner.side())) extentOwner = null;
|
||||
boolean changesExtent = (extentOwner != null
|
||||
&& extentOwner.changesPreferredExtent(changes.getPreferredWidth(), changes.getPreferredHeight()))
|
||||
|| groupSurface.changesPreferredSize(changes.getPreferredWidth(), changes.getPreferredHeight());
|
||||
if (!changesExtent && resolved.equals(DockGroupChanges.builder().build().resolved(group.definition))) {
|
||||
return new ActionResult.NoChange();
|
||||
}
|
||||
DockGroupDefinition existing = group.definition;
|
||||
boolean changesGeometry = changesExtent || existing.getTabSide() != candidate.getTabSide()
|
||||
boolean changesGeometry = changesExtent || existing.getMode() != candidate.getMode()
|
||||
|| existing.getTabSide() != candidate.getTabSide()
|
||||
|| existing.getPreferredWidth() != candidate.getPreferredWidth()
|
||||
|| existing.getPreferredHeight() != candidate.getPreferredHeight()
|
||||
|| existing.getMinimumWidth() != candidate.getMinimumWidth()
|
||||
@@ -515,13 +552,19 @@ public final class DockingManager {
|
||||
|| (group.tabs.getTabs().isEmpty() && (existing.isVisibleWhenEmpty() != candidate.isVisibleWhenEmpty()
|
||||
|| existing.isReleaseSpaceWhenEmpty() != candidate.isReleaseSpaceWhenEmpty()))
|
||||
|| (((DockGroupPane) group.tabs).isCollapsed() && !candidate.isCollapsible());
|
||||
if (candidate.getMode() == DockGroupMode.OVERLAY && !((DockGroupPane) group.tabs).isCollapsed()
|
||||
&& openOverlays(group).stream().anyMatch(this::groupClosing)) {
|
||||
return rejected(DockFailure.Code.CLOSE_IN_PROGRESS, null, "Another overlay is covered by a close request");
|
||||
}
|
||||
if (changesGeometry && !canChangeGroupGeometry(group, true)) {
|
||||
return rejected(DockFailure.Code.CLOSE_IN_PROGRESS, null, "The group change would resize content covered by a close request");
|
||||
}
|
||||
boolean pinning = existing.getMode() == DockGroupMode.OVERLAY && candidate.getMode() == DockGroupMode.DOCKED;
|
||||
boolean wasUpdating = updating;
|
||||
updating = true;
|
||||
try {
|
||||
resolved.applyTo(group.definition);
|
||||
groupSurface.updatePreferredSize(changes.getPreferredWidth(), changes.getPreferredHeight());
|
||||
group.tabs.setSide(candidate.getTabSide());
|
||||
group.tabs.requestLayout();
|
||||
if (extentOwner != null) {
|
||||
@@ -534,7 +577,15 @@ public final class DockingManager {
|
||||
focus(active.get());
|
||||
}
|
||||
}
|
||||
if (candidate.getMode() == DockGroupMode.OVERLAY && !((DockGroupPane) group.tabs).isCollapsed()) revealGroup(group);
|
||||
refreshEmptyGroups();
|
||||
if (pinning) treeFor(group).restoreGroupSize(group.id, groupSurface.expandedWidth(), groupSurface.expandedHeight());
|
||||
if (active.get() != null && !isGroupVisible(containing(active.get().getId()))) {
|
||||
Tab selected = group.tabs.getSelectionModel().getSelectedItem();
|
||||
setActive(isGroupVisible(group) && selected != null
|
||||
? dockables.get((DockableId) selected.getUserData()) : selectedVisibleFallback());
|
||||
focus(active.get());
|
||||
}
|
||||
} finally {
|
||||
updating = wasUpdating;
|
||||
}
|
||||
@@ -542,7 +593,18 @@ public final class DockingManager {
|
||||
return new ActionResult.Applied();
|
||||
}
|
||||
|
||||
boolean canToggleGroupMode(DockGroupId id) {
|
||||
Group group = group(id);
|
||||
return group != null && group.definition.isCollapsible() && !groupClosing(group)
|
||||
&& canChangeGroupGeometry(group, true)
|
||||
&& openOverlays(group).stream().noneMatch(this::groupClosing);
|
||||
}
|
||||
|
||||
public ActionResult setGroupCollapsed(DockGroupId id, boolean collapsed) {
|
||||
return setGroupCollapsed(id, collapsed, true);
|
||||
}
|
||||
|
||||
private ActionResult setGroupCollapsed(DockGroupId id, boolean collapsed, boolean focusHeader) {
|
||||
requireFxThread();
|
||||
Group group = group(Objects.requireNonNull(id, "id"));
|
||||
if (group == null) return rejected(DockFailure.Code.TARGET_NOT_FOUND, null, "Group does not exist");
|
||||
@@ -555,10 +617,11 @@ public final class DockingManager {
|
||||
if (!canChangeGroupGeometry(group)) {
|
||||
return rejected(DockFailure.Code.CLOSE_IN_PROGRESS, null, "The group change would resize content covered by a close request");
|
||||
}
|
||||
tabs.setCollapsed(collapsed);
|
||||
if (collapsed) tabs.setCollapsed(true);
|
||||
else revealGroup(group);
|
||||
if (collapsed) {
|
||||
if (active.get() != null && containing(active.get().getId()) == group) setActive(selectedVisibleFallback());
|
||||
tabs.focusSelectedHeader();
|
||||
if (focusHeader) tabs.focusSelectedHeader();
|
||||
} else {
|
||||
Tab selected = tabs.getSelectionModel().getSelectedItem();
|
||||
if (selected != null) {
|
||||
@@ -572,9 +635,33 @@ public final class DockingManager {
|
||||
|
||||
private boolean revealGroup(Group group) {
|
||||
DockGroupPane tabs = (DockGroupPane) group.tabs;
|
||||
if (!tabs.isCollapsed()) return false;
|
||||
boolean changed = tabs.isCollapsed();
|
||||
if (tabs.isOverlay()) {
|
||||
for (Group other : openOverlays(group)) {
|
||||
((DockGroupPane) other.tabs).setCollapsed(true);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
tabs.setCollapsed(false);
|
||||
return true;
|
||||
return changed;
|
||||
}
|
||||
|
||||
private List<Group> openOverlays(Group group) {
|
||||
return groups.values().stream().filter(other -> other != group && owner(other) == owner(group))
|
||||
.filter(other -> ((DockGroupPane) other.tabs).isOverlay() && isGroupVisible(other)).toList();
|
||||
}
|
||||
|
||||
void dismissOutsideOverlays(Node target) {
|
||||
Group headerGroup = groups.values().stream()
|
||||
.filter(group -> ((DockGroupPane) group.tabs).isOverlay()
|
||||
&& ((DockGroupPane) group.tabs).isHeader(target)).findFirst().orElse(null);
|
||||
for (Group group : List.copyOf(groups.values())) {
|
||||
DockGroupPane tabs = (DockGroupPane) group.tabs;
|
||||
if (!tabs.isOverlay() || tabs.isCollapsed() || !tabs.isVisible() || contains(tabs, target)) continue;
|
||||
// The header action will preflight and publish same-window arbitration as one transition.
|
||||
if (headerGroup != null && owner(headerGroup) == owner(group)) continue;
|
||||
setGroupCollapsed(group.id, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isGroupVisible(Group group) {
|
||||
@@ -594,6 +681,7 @@ public final class DockingManager {
|
||||
group.tabs.setVisible(occupied || (group.definition.isVisibleWhenEmpty()
|
||||
&& !group.definition.isReleaseSpaceWhenEmpty()));
|
||||
group.tabs.setManaged(occupied || !group.definition.isReleaseSpaceWhenEmpty());
|
||||
((DockGroupPane) group.tabs).surface().synchronize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -632,7 +720,7 @@ public final class DockingManager {
|
||||
if (tree.groups(areaId).stream().anyMatch(this::groupClosing)) return false;
|
||||
for (Group candidate : groups.values()) {
|
||||
if (groupWindows.containsKey(candidate.id) || !groupClosing(candidate)) continue;
|
||||
if (contains(pane.surface.getCenter(), candidate.tabs)) return false;
|
||||
if (contains(pane.surface.getCenter(), ((DockGroupPane) candidate.tabs).surface())) return false;
|
||||
javafx.geometry.Side otherSide = pane.edgeOf(candidate.tabs);
|
||||
if (side.isHorizontal() && otherSide != null && otherSide.isVertical()) return false;
|
||||
}
|
||||
@@ -644,6 +732,10 @@ public final class DockingManager {
|
||||
}
|
||||
|
||||
private boolean canChangeGroupGeometry(Group group, boolean changingOuterExtent) {
|
||||
if (((DockGroupPane) group.tabs).isOverlay()) {
|
||||
if (openOverlays(group).stream().anyMatch(this::groupClosing)) return false;
|
||||
if (!changingOuterExtent) return !groupClosing(group);
|
||||
}
|
||||
if (treeFor(group).geometryAffects(group.id, this::groupClosing)) return false;
|
||||
if (groupWindows.containsKey(group.id)) return true;
|
||||
for (var entry : edgeAreas.entrySet()) {
|
||||
@@ -665,6 +757,7 @@ public final class DockingManager {
|
||||
private Group createGroup(DockGroupId id, DockGroupDefinition definition) {
|
||||
DockGroupDefinition captured = new DockGroupDefinition(definition.getDestinationId());
|
||||
captured.setTabSide(definition.getTabSide());
|
||||
captured.setMode(definition.getMode());
|
||||
captured.setPreferredWidth(definition.getPreferredWidth());
|
||||
captured.setPreferredHeight(definition.getPreferredHeight());
|
||||
captured.setMinimumWidth(definition.getMinimumWidth());
|
||||
@@ -676,6 +769,7 @@ public final class DockingManager {
|
||||
captured.setReleaseSpaceWhenEmpty(definition.isReleaseSpaceWhenEmpty());
|
||||
TabPane tabs = new DockGroupPane(captured);
|
||||
tabs.setSide(captured.getTabSide());
|
||||
((DockGroupPane) tabs).setCollapsed(captured.getMode() == DockGroupMode.OVERLAY);
|
||||
Group group = new Group(id, tabs, captured);
|
||||
allocatedGroupIds.add(id);
|
||||
groups.put(id, group);
|
||||
@@ -781,6 +875,9 @@ public final class DockingManager {
|
||||
validate(split.getSecond(), destinations);
|
||||
} else {
|
||||
DockGroupDefinition group = (DockGroupDefinition) definition;
|
||||
if (group.getMode() == null || (group.getMode() == DockGroupMode.OVERLAY && !group.isCollapsible())) {
|
||||
throw new IllegalArgumentException("Overlay mode requires a collapsible group");
|
||||
}
|
||||
if (group.getSplitDirections() == null || !Double.isFinite(group.getMinimumWidth())
|
||||
|| group.getMinimumWidth() < 0 || !Double.isFinite(group.getMinimumHeight()) || group.getMinimumHeight() < 0) {
|
||||
throw new IllegalArgumentException("Group minimum dimensions must be nonnegative and finite, with split directions");
|
||||
@@ -854,6 +951,11 @@ public final class DockingManager {
|
||||
DockPane floatingPane = new DockPane();
|
||||
Stage floatingStage = new Stage();
|
||||
floatingStage.setScene(new javafx.scene.Scene(floatingPane));
|
||||
javafx.event.EventHandler<javafx.stage.WindowEvent> closeHandler = event -> {
|
||||
event.consume();
|
||||
requestFloatingWindowClose(windowId);
|
||||
};
|
||||
floatingStage.addEventFilter(javafx.stage.WindowEvent.WINDOW_CLOSE_REQUEST, closeHandler);
|
||||
floatingStage.setTitle(configuration.getTitle());
|
||||
floatingStage.getIcons().setAll(configuration.getIcons());
|
||||
floatingStage.getScene().getStylesheets().setAll(configuration.getStylesheets());
|
||||
@@ -873,7 +975,7 @@ public final class DockingManager {
|
||||
.filter(candidate -> windowId.equals(groupWindows.get(candidate.id)))
|
||||
.map(candidate -> new DockDragController.GroupSurface(candidate.id, candidate.tabs)).toList());
|
||||
DockWindowGeometry geometry = new DockWindowGeometry(floatingStage, this::publish);
|
||||
floatingWindows.put(windowId, new FloatingWindow(windowId, floatingStage, floatingPane, floatingTree, floatingDrag, geometry));
|
||||
floatingWindows.put(windowId, new FloatingWindow(windowId, floatingStage, floatingPane, floatingTree, floatingDrag, geometry, closeHandler));
|
||||
floatingPane.manager = this;
|
||||
floatingStage.getProperties().put(ATTACHMENT_KEY, this);
|
||||
floatingStage.getScene().focusOwnerProperty().addListener(focusListener);
|
||||
@@ -885,7 +987,8 @@ public final class DockingManager {
|
||||
}
|
||||
|
||||
private record FloatingWindow(DockWindowId id, Stage stage, DockPane pane, DockLayoutTree tree,
|
||||
DockDragController drag, DockWindowGeometry geometry) { }
|
||||
DockDragController drag, DockWindowGeometry geometry,
|
||||
javafx.event.EventHandler<javafx.stage.WindowEvent> closeHandler) { }
|
||||
private record ReturnLocation(DockTarget target, DockAreaId areaId) { }
|
||||
|
||||
private static ActionResult rejected(DockFailure.Code code, DockableId id, String message) {
|
||||
|
||||
Reference in New Issue
Block a user