feat(fx): add resizable split groups and asynchronous tab close
This commit is contained in:
@@ -84,11 +84,18 @@ class ActivateDockingWindowTest {
|
||||
};
|
||||
AnimationTimer clickAfterDisplay = new AnimationTimer() {
|
||||
private int pulses;
|
||||
private long lastClick;
|
||||
|
||||
@Override
|
||||
public void handle(long now) {
|
||||
if (stage.isFocused()) {
|
||||
focused.countDown();
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
if (++pulses < 2) return;
|
||||
stop();
|
||||
if (now - lastClick < 250_000_000) return;
|
||||
lastClick = now;
|
||||
Bounds bounds = stage.getScene().getRoot().localToScreen(
|
||||
stage.getScene().getRoot().getBoundsInLocal());
|
||||
Robot robot = new Robot();
|
||||
@@ -109,8 +116,9 @@ class ActivateDockingWindowTest {
|
||||
try {
|
||||
// A native click activates the application even if the previous test or
|
||||
// another application owned desktop focus. RequestFocus alone cannot
|
||||
// establish that precondition reliably on macOS. Two pulses allow the
|
||||
// newly shown native window to display before the Robot sends input.
|
||||
// establish that precondition reliably on macOS. FX pulses do not
|
||||
// guarantee that the native compositor has displayed the window;
|
||||
// retry only this focus precondition within the bounded wait.
|
||||
assertTrue(focused.await(5, TimeUnit.SECONDS), "Desktop did not focus the requested window");
|
||||
} finally {
|
||||
FxThread.onFx(() -> {
|
||||
|
||||
@@ -0,0 +1,321 @@
|
||||
package de.neitzel.fx.view;
|
||||
|
||||
import de.neitzel.fx.docking.CloseConsent;
|
||||
import de.neitzel.fx.docking.CloseRequest;
|
||||
import de.neitzel.fx.docking.CloseResult;
|
||||
import de.neitzel.fx.docking.CloseScope;
|
||||
import de.neitzel.fx.docking.DockGroupDefinition;
|
||||
import de.neitzel.fx.docking.DockLayout;
|
||||
import de.neitzel.fx.docking.DockPane;
|
||||
import de.neitzel.fx.docking.DockTarget;
|
||||
import de.neitzel.fx.docking.Dockable;
|
||||
import de.neitzel.fx.docking.DockableId;
|
||||
import de.neitzel.fx.docking.DockingManager;
|
||||
import de.neitzel.fx.docking.DockingOptions;
|
||||
import de.neitzel.fx.docking.ActionResult;
|
||||
import de.neitzel.fx.docking.DockFailure;
|
||||
import de.neitzel.fx.docking.MoveCheck;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.event.Event;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/** Consent and resource lifecycle are tested through the public manager API. */
|
||||
class CloseDockableTest {
|
||||
@BeforeAll
|
||||
static void startJavaFx() throws InterruptedException {
|
||||
FxThread.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
void duplicateRequestsAwaitOneConsentAndReleaseOnlyAfterActualClose() throws Exception {
|
||||
CompletableFuture<CloseConsent> consent = new CompletableFuture<>();
|
||||
AtomicReference<Fixture> fixture = new AtomicReference<>();
|
||||
AtomicReference<CompletionStage<CloseResult>> first = new AtomicReference<>();
|
||||
AtomicReference<CompletionStage<CloseResult>> duplicate = new AtomicReference<>();
|
||||
AtomicReference<CloseRequest> request = new AtomicReference<>();
|
||||
AtomicInteger checks = new AtomicInteger();
|
||||
AtomicInteger released = new AtomicInteger();
|
||||
FxThread.onFx(() -> {
|
||||
Fixture window = window();
|
||||
fixture.set(window);
|
||||
window.editor().setCloseCheck(context -> {
|
||||
checks.incrementAndGet();
|
||||
request.set(context);
|
||||
assertTrue(Platform.isFxApplicationThread());
|
||||
return consent;
|
||||
});
|
||||
window.editor().setOnClosed(() -> {
|
||||
assertTrue(Platform.isFxApplicationThread());
|
||||
released.incrementAndGet();
|
||||
});
|
||||
first.set(window.manager().requestTabClose(window.editor().getId()));
|
||||
duplicate.set(window.manager().requestTabClose(window.editor().getId()));
|
||||
assertEquals(1, checks.get());
|
||||
assertEquals(0, released.get());
|
||||
assertFalse(first.get().toCompletableFuture().isDone());
|
||||
assertTrue(window.manager().findDockable(window.editor().getId()).isPresent());
|
||||
assertEquals(CloseScope.Kind.TAB, request.get().scope().kind());
|
||||
assertEquals(List.of(window.editor().getId()), request.get().scope().dockableIds());
|
||||
assertSame(window.stage(), request.get().owner());
|
||||
assertEquals(request.get().scope(), window.manager().closingScopeProperty().get());
|
||||
});
|
||||
consent.complete(CloseConsent.ALLOW);
|
||||
assertInstanceOf(CloseResult.Closed.class, first.get().toCompletableFuture().get(5, TimeUnit.SECONDS));
|
||||
assertEquals(first.get().toCompletableFuture().get(), duplicate.get().toCompletableFuture().get());
|
||||
FxThread.onFx(() -> {
|
||||
assertEquals(1, released.get());
|
||||
assertTrue(fixture.get().manager().findDockable(fixture.get().editor().getId()).isEmpty());
|
||||
assertNull(fixture.get().manager().closingScopeProperty().get());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void anotherTabWaitsForTheCurrentConsentEvenWhenItVetoes() throws Exception {
|
||||
CompletableFuture<CloseConsent> notesConsent = new CompletableFuture<>();
|
||||
CompletableFuture<CloseConsent> projectConsent = new CompletableFuture<>();
|
||||
CompletableFuture<Void> projectStarted = new CompletableFuture<>();
|
||||
AtomicReference<Fixture> fixture = new AtomicReference<>();
|
||||
AtomicReference<CompletionStage<CloseResult>> notesResult = new AtomicReference<>();
|
||||
AtomicReference<CompletionStage<CloseResult>> projectResult = new AtomicReference<>();
|
||||
AtomicReference<CompletionStage<CloseResult>> projectDuplicate = new AtomicReference<>();
|
||||
AtomicInteger projectChecks = new AtomicInteger();
|
||||
DockableId projectId = new DockableId("project");
|
||||
FxThread.onFx(() -> {
|
||||
Fixture window = window();
|
||||
fixture.set(window);
|
||||
window.editor().setCloseCheck(request -> notesConsent);
|
||||
Dockable project = new Dockable(projectId, new TextArea("Project"));
|
||||
project.setCloseCheck(request -> {
|
||||
projectChecks.incrementAndGet();
|
||||
projectStarted.complete(null);
|
||||
return projectConsent;
|
||||
});
|
||||
window.manager().open(project, DockTarget.area("tools"));
|
||||
notesResult.set(window.manager().requestTabClose(window.editor().getId()));
|
||||
projectResult.set(window.manager().requestTabClose(projectId));
|
||||
projectDuplicate.set(window.manager().requestTabClose(projectId));
|
||||
assertEquals(0, projectChecks.get());
|
||||
assertFalse(projectResult.get().toCompletableFuture().isDone());
|
||||
});
|
||||
notesConsent.complete(CloseConsent.VETO);
|
||||
assertInstanceOf(CloseResult.Vetoed.class, notesResult.get().toCompletableFuture().get(5, TimeUnit.SECONDS));
|
||||
projectStarted.get(5, TimeUnit.SECONDS);
|
||||
FxThread.onFx(() -> {
|
||||
assertEquals(1, projectChecks.get());
|
||||
assertEquals(List.of(projectId), fixture.get().manager().closingScopeProperty().get().dockableIds());
|
||||
assertTrue(fixture.get().manager().findDockable(fixture.get().editor().getId()).isPresent());
|
||||
});
|
||||
projectConsent.complete(CloseConsent.ALLOW);
|
||||
assertInstanceOf(CloseResult.Closed.class, projectResult.get().toCompletableFuture().get(5, TimeUnit.SECONDS));
|
||||
assertEquals(projectResult.get().toCompletableFuture().get(), projectDuplicate.get().toCompletableFuture().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void closingActiveContentFallsBackToTheMostRecentlyActiveVisibleDockable() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture window = window();
|
||||
Dockable project = new Dockable(new DockableId("project"), new TextArea("Project"));
|
||||
Dockable console = new Dockable(new DockableId("console"), new TextArea("Console"));
|
||||
window.manager().open(project, DockTarget.area("tools"));
|
||||
window.manager().open(console, DockTarget.area("console"));
|
||||
window.manager().activate(project.getId());
|
||||
window.manager().activate(window.editor().getId());
|
||||
assertInstanceOf(CloseResult.Closed.class,
|
||||
window.manager().requestTabClose(window.editor().getId()).toCompletableFuture().getNow(null));
|
||||
assertSame(project, window.manager().activeDockable());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void tabCloseControlAndContextMenuBothWaitForConsent() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture window = window();
|
||||
AtomicInteger checks = new AtomicInteger();
|
||||
AtomicReference<CompletableFuture<CloseConsent>> answer = new AtomicReference<>();
|
||||
window.editor().setCloseCheck(request -> {
|
||||
checks.incrementAndGet();
|
||||
CompletableFuture<CloseConsent> pending = new CompletableFuture<>();
|
||||
answer.set(pending);
|
||||
return pending;
|
||||
});
|
||||
window.pane().applyCss();
|
||||
Tab tab = window.pane().lookupAll(".tab-pane").stream().map(TabPane.class::cast)
|
||||
.flatMap(tabs -> tabs.getTabs().stream())
|
||||
.filter(item -> item.getContent() == window.editor().getContent()).findFirst().orElseThrow();
|
||||
assertTrue(tab.isClosable());
|
||||
Event.fireEvent(tab, new Event(Tab.TAB_CLOSE_REQUEST_EVENT));
|
||||
assertEquals(1, checks.get());
|
||||
assertTrue(window.manager().findDockable(window.editor().getId()).isPresent());
|
||||
answer.get().complete(CloseConsent.VETO);
|
||||
assertTrue(window.manager().findDockable(window.editor().getId()).isPresent());
|
||||
MenuItem close = tab.getContextMenu().getItems().stream()
|
||||
.filter(item -> "Close".equals(item.getText())).findFirst().orElse(null);
|
||||
assertNotNull(close);
|
||||
close.fire();
|
||||
assertEquals(2, checks.get());
|
||||
assertTrue(window.manager().findDockable(window.editor().getId()).isPresent());
|
||||
answer.get().complete(CloseConsent.ALLOW);
|
||||
assertTrue(window.manager().findDockable(window.editor().getId()).isEmpty());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedChecksVetoWithoutReleasingAndALaterRequestCanClose() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture window = window();
|
||||
AtomicInteger released = new AtomicInteger();
|
||||
AtomicInteger discarded = new AtomicInteger();
|
||||
window.editor().setOnClosed(released::incrementAndGet);
|
||||
window.editor().setOnDiscarded(discarded::incrementAndGet);
|
||||
IllegalStateException failure = new IllegalStateException("Save failed");
|
||||
window.editor().setCloseCheck(request -> CompletableFuture.failedFuture(failure));
|
||||
var result = window.manager().requestTabClose(window.editor().getId()).toCompletableFuture().getNow(null);
|
||||
CloseResult.Vetoed veto = assertInstanceOf(CloseResult.Vetoed.class, result);
|
||||
assertEquals(List.of(window.editor().getId()), veto.vetoingIds());
|
||||
assertSame(failure, veto.checkFailures().getFirst().cause());
|
||||
assertEquals(DockFailure.Code.CLOSE_CHECK_FAILED, veto.checkFailures().getFirst().code());
|
||||
assertTrue(window.manager().findDockable(window.editor().getId()).isPresent());
|
||||
assertNull(window.manager().closingScopeProperty().get());
|
||||
assertEquals(0, released.get());
|
||||
assertEquals(0, discarded.get());
|
||||
|
||||
window.editor().setCloseCheck(request -> { throw failure; });
|
||||
assertInstanceOf(CloseResult.Vetoed.class,
|
||||
window.manager().requestTabClose(window.editor().getId()).toCompletableFuture().getNow(null));
|
||||
window.editor().setCloseCheck(request -> CompletableFuture.completedFuture(CloseConsent.ALLOW));
|
||||
assertInstanceOf(CloseResult.Closed.class,
|
||||
window.manager().requestTabClose(window.editor().getId()).toCompletableFuture().getNow(null));
|
||||
assertEquals(1, released.get());
|
||||
assertEquals(0, discarded.get());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void cleanupFailureReportsAnActualCloseAndKeepsScopeThroughRelease() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture window = window();
|
||||
IllegalStateException cleanup = new IllegalStateException("Release failed");
|
||||
window.editor().setOnClosed(() -> {
|
||||
assertTrue(window.manager().findDockable(window.editor().getId()).isEmpty());
|
||||
assertEquals(List.of(window.editor().getId()), window.manager().closingScopeProperty().get().dockableIds());
|
||||
Dockable duringRelease = new Dockable(new DockableId("during-release"), new TextArea());
|
||||
ActionResult.Rejected rejected = assertInstanceOf(ActionResult.Rejected.class,
|
||||
window.manager().open(duringRelease, DockTarget.area("tools")));
|
||||
assertEquals(DockFailure.Code.CLOSE_IN_PROGRESS, rejected.failure().code());
|
||||
throw cleanup;
|
||||
});
|
||||
CloseResult.Closed result = assertInstanceOf(CloseResult.Closed.class,
|
||||
window.manager().requestTabClose(window.editor().getId()).toCompletableFuture().getNow(null));
|
||||
assertEquals(DockFailure.Code.CLEANUP_FAILED, result.cleanupFailures().getFirst().code());
|
||||
assertSame(cleanup, result.cleanupFailures().getFirst().cause());
|
||||
assertNull(window.manager().activeDockable());
|
||||
assertNull(window.manager().closingScopeProperty().get());
|
||||
assertInstanceOf(CloseResult.NoChange.class,
|
||||
window.manager().requestTabClose(window.editor().getId()).toCompletableFuture().getNow(null));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void pendingConsentProtectsItsGroupWhileUnrelatedGroupsRemainUsable() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture window = window();
|
||||
CompletableFuture<CloseConsent> consent = new CompletableFuture<>();
|
||||
window.editor().setCloseCheck(request -> consent);
|
||||
Dockable project = new Dockable(new DockableId("project"), new TextArea("Project"));
|
||||
window.manager().open(project, DockTarget.area("tools"));
|
||||
window.manager().requestTabClose(window.editor().getId());
|
||||
ActionResult.Rejected move = assertInstanceOf(ActionResult.Rejected.class,
|
||||
window.manager().move(window.editor().getId(), DockTarget.area("tools")));
|
||||
assertEquals(DockFailure.Code.CLOSE_IN_PROGRESS, move.failure().code());
|
||||
MoveCheck.Rejected inbound = assertInstanceOf(MoveCheck.Rejected.class,
|
||||
window.manager().checkMove(project.getId(), DockTarget.area("editors")));
|
||||
assertEquals(DockFailure.Code.CLOSE_IN_PROGRESS, inbound.failure().code());
|
||||
Dockable prepared = new Dockable(new DockableId("new-editor"), new TextArea());
|
||||
assertInstanceOf(ActionResult.Rejected.class, window.manager().open(prepared, DockTarget.area("editors")));
|
||||
assertInstanceOf(ActionResult.Applied.class, window.manager().move(project.getId(), DockTarget.area("console")));
|
||||
consent.complete(CloseConsent.VETO);
|
||||
assertInstanceOf(ActionResult.Applied.class, window.manager().move(window.editor().getId(), DockTarget.area("tools")));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void closingActiveTabPrefersItsGroupsNewSelection() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture window = window();
|
||||
Dockable second = new Dockable(new DockableId("second"), new TextArea("Second"));
|
||||
Dockable project = new Dockable(new DockableId("project"), new TextArea("Project"));
|
||||
window.manager().open(second, DockTarget.area("editors"));
|
||||
window.manager().open(project, DockTarget.area("tools"));
|
||||
window.manager().activate(window.editor().getId());
|
||||
assertInstanceOf(CloseResult.Closed.class,
|
||||
window.manager().requestTabClose(window.editor().getId()).toCompletableFuture().getNow(null));
|
||||
assertSame(second, window.manager().activeDockable());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFailingReplacementFocusTargetCannotStrandAnActualClose() throws Exception {
|
||||
AtomicReference<Fixture> fixture = new AtomicReference<>();
|
||||
AtomicReference<CompletionStage<CloseResult>> result = new AtomicReference<>();
|
||||
AtomicReference<Dockable> replacement = new AtomicReference<>();
|
||||
AtomicInteger released = new AtomicInteger();
|
||||
FxThread.onFx(() -> {
|
||||
Fixture window = window();
|
||||
fixture.set(window);
|
||||
Dockable second = new Dockable(new DockableId("second"), new TextArea("Second"));
|
||||
replacement.set(second);
|
||||
window.manager().open(second, DockTarget.area("editors"));
|
||||
window.manager().activate(window.editor().getId());
|
||||
second.setFocusTarget(() -> { throw new IllegalStateException("Focus target unavailable"); });
|
||||
window.editor().setOnClosed(released::incrementAndGet);
|
||||
result.set(window.manager().requestTabClose(window.editor().getId()));
|
||||
});
|
||||
assertInstanceOf(CloseResult.Closed.class, result.get().toCompletableFuture().get(5, TimeUnit.SECONDS));
|
||||
FxThread.onFx(() -> {
|
||||
assertEquals(1, released.get());
|
||||
assertSame(replacement.get(), fixture.get().manager().activeDockable());
|
||||
assertTrue(fixture.get().manager().findDockable(fixture.get().editor().getId()).isEmpty());
|
||||
assertNull(fixture.get().manager().closingScopeProperty().get());
|
||||
});
|
||||
}
|
||||
|
||||
private static Fixture window() {
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(new DockGroupDefinition("editors"));
|
||||
initial.setLeft(new DockGroupDefinition("console"));
|
||||
initial.setRight(new DockGroupDefinition("tools"));
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
Dockable editor = new Dockable(new DockableId("notes"), new TextArea("Unsaved notes"));
|
||||
editor.setTitle("Notes");
|
||||
manager.open(editor, DockTarget.area("editors"));
|
||||
return new Fixture(stage, pane, manager, editor);
|
||||
}
|
||||
|
||||
private record Fixture(Stage stage, DockPane pane, DockingManager manager, Dockable editor) { }
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package de.neitzel.fx.view;
|
||||
|
||||
import de.neitzel.fx.docking.DockGroupDefinition;
|
||||
import de.neitzel.fx.docking.DockLayout;
|
||||
import de.neitzel.fx.docking.DockPane;
|
||||
import de.neitzel.fx.docking.DockTarget;
|
||||
import de.neitzel.fx.docking.Dockable;
|
||||
import de.neitzel.fx.docking.DockableId;
|
||||
import de.neitzel.fx.docking.DockingManager;
|
||||
import de.neitzel.fx.docking.DockingOptions;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Side;
|
||||
import javafx.scene.Cursor;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.input.PickResult;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/** The public surface follows a boundary drag before publishing its finished layout. */
|
||||
class OuterDockResizeTest {
|
||||
@BeforeAll
|
||||
static void startJavaFx() throws Exception {
|
||||
FxThread.start();
|
||||
FxThread.onFx(() -> Platform.setImplicitExit(false));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(Side.class)
|
||||
void sideBoundaryResizesLiveAndPublishesOnceOnRelease(Side side) throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockLayout initial = new DockLayout();
|
||||
DockGroupDefinition editors = new DockGroupDefinition("editors");
|
||||
editors.setMinimumWidth(180);
|
||||
editors.setMinimumHeight(120);
|
||||
initial.setCenter(editors);
|
||||
DockGroupDefinition tools = new DockGroupDefinition("tools");
|
||||
tools.setMinimumWidth(140);
|
||||
tools.setMinimumHeight(100);
|
||||
switch (side) {
|
||||
case LEFT -> initial.setLeft(tools);
|
||||
case RIGHT -> initial.setRight(tools);
|
||||
case TOP -> initial.setTop(tools);
|
||||
case BOTTOM -> initial.setBottom(tools);
|
||||
}
|
||||
if (side.isHorizontal()) {
|
||||
DockGroupDefinition navigation = new DockGroupDefinition("navigation");
|
||||
navigation.setMinimumHeight(260);
|
||||
initial.setLeft(navigation);
|
||||
}
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 900, 650));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
TextArea project = new TextArea("Project");
|
||||
TextArea notes = new TextArea("Notes");
|
||||
Dockable dockable = new Dockable(new DockableId("project"), project);
|
||||
manager.open(new Dockable(new DockableId("notes"), notes), DockTarget.area("editors"));
|
||||
manager.open(dockable, DockTarget.area("tools"));
|
||||
stage.show();
|
||||
try {
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
Node divider = tabPane(pane, project).getParent().lookup(".dock-area-divider");
|
||||
assertNotNull(divider, "A predefined side area needs a draggable boundary");
|
||||
assertEquals(side.isVertical() ? Cursor.H_RESIZE : Cursor.V_RESIZE, divider.getCursor());
|
||||
var origin = divider.localToScreen(divider.getBoundsInLocal());
|
||||
double oldSize = side.isVertical() ? project.getWidth() : project.getHeight();
|
||||
var before = manager.layout();
|
||||
AtomicInteger publications = new AtomicInteger();
|
||||
manager.layoutProperty().addListener((observable, old, value) -> publications.incrementAndGet());
|
||||
double dx = side == Side.LEFT ? 40 : side == Side.RIGHT ? -40 : 0;
|
||||
double dy = side == Side.TOP ? 40 : side == Side.BOTTOM ? -40 : 0;
|
||||
mouse(divider, MouseEvent.MOUSE_PRESSED, origin.getCenterX(), origin.getCenterY(), true);
|
||||
mouse(divider, MouseEvent.MOUSE_DRAGGED, origin.getCenterX() + dx, origin.getCenterY() + dy, true);
|
||||
pane.layout();
|
||||
assertTrue((side.isVertical() ? project.getWidth() : project.getHeight()) > oldSize + 30);
|
||||
assertSame(before, manager.layout());
|
||||
assertEquals(0, publications.get());
|
||||
mouse(divider, MouseEvent.MOUSE_RELEASED, origin.getCenterX() + dx, origin.getCenterY() + dy, false);
|
||||
assertNotSame(before, manager.layout());
|
||||
assertEquals(1, publications.get());
|
||||
var beforeArea = before.windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().value().equals("tools")).findFirst().orElseThrow();
|
||||
var afterArea = manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().value().equals("tools")).findFirst().orElseThrow();
|
||||
assertEquals(40, side.isVertical()
|
||||
? afterArea.preferredWidth() - beforeArea.preferredWidth()
|
||||
: afterArea.preferredHeight() - beforeArea.preferredHeight(), .1);
|
||||
assertSame(project, manager.findDockable(dockable.getId()).orElseThrow().getContent());
|
||||
var consent = new java.util.concurrent.CompletableFuture<de.neitzel.fx.docking.CloseConsent>();
|
||||
dockable.setCloseCheck(request -> consent);
|
||||
var closing = manager.requestTabClose(dockable.getId());
|
||||
var protectedLayout = manager.layout();
|
||||
var protectedBoundary = divider.localToScreen(divider.getBoundsInLocal());
|
||||
double protectedSize = side.isVertical() ? project.getWidth() : project.getHeight();
|
||||
mouse(divider, MouseEvent.MOUSE_PRESSED, protectedBoundary.getCenterX(), protectedBoundary.getCenterY(), true);
|
||||
mouse(divider, MouseEvent.MOUSE_DRAGGED, protectedBoundary.getCenterX() + dx,
|
||||
protectedBoundary.getCenterY() + dy, true);
|
||||
pane.layout();
|
||||
mouse(divider, MouseEvent.MOUSE_RELEASED, protectedBoundary.getCenterX() + dx,
|
||||
protectedBoundary.getCenterY() + dy, false);
|
||||
assertEquals(protectedSize, side.isVertical() ? project.getWidth() : project.getHeight(), .1);
|
||||
assertSame(protectedLayout, manager.layout());
|
||||
consent.complete(de.neitzel.fx.docking.CloseConsent.VETO);
|
||||
assertTrue(closing.toCompletableFuture().isDone());
|
||||
for (int direction : new int[]{1, -1}) {
|
||||
var boundary = divider.localToScreen(divider.getBoundsInLocal());
|
||||
mouse(divider, MouseEvent.MOUSE_PRESSED, boundary.getCenterX(), boundary.getCenterY(), true);
|
||||
mouse(divider, MouseEvent.MOUSE_DRAGGED, boundary.getCenterX() + dx * direction * 100,
|
||||
boundary.getCenterY() + dy * direction * 100, true);
|
||||
pane.layout();
|
||||
var toolsPane = tabPane(pane, project);
|
||||
var editorPane = tabPane(pane, notes);
|
||||
assertTrue((side.isVertical() ? toolsPane.getWidth() : toolsPane.getHeight())
|
||||
>= (side.isVertical() ? tools.getMinimumWidth() : tools.getMinimumHeight()) - .1);
|
||||
assertTrue((side.isVertical() ? editorPane.getWidth() : editorPane.getHeight())
|
||||
>= (side.isVertical() ? editors.getMinimumWidth() : 260) - .1,
|
||||
"Resizing must retain the minimum of the entire middle row");
|
||||
var available = pane.localToScene(pane.getLayoutBounds());
|
||||
var editorBounds = editorPane.localToScene(editorPane.getLayoutBounds());
|
||||
var toolsBounds = toolsPane.localToScene(toolsPane.getLayoutBounds());
|
||||
assertTrue(editorBounds.getMaxX() <= available.getMaxX() + 1
|
||||
&& editorBounds.getMaxY() <= available.getMaxY() + 1
|
||||
&& toolsBounds.getMaxX() <= available.getMaxX() + 1
|
||||
&& toolsBounds.getMaxY() <= available.getMaxY() + 1,
|
||||
"The remaining area must stay inside the docking pane");
|
||||
mouse(divider, MouseEvent.MOUSE_RELEASED, boundary.getCenterX() + dx * direction * 100,
|
||||
boundary.getCenterY() + dy * direction * 100, false);
|
||||
var finished = manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().value().equals("tools")).findFirst().orElseThrow();
|
||||
assertEquals(side.isVertical() ? toolsPane.getWidth() : toolsPane.getHeight(),
|
||||
side.isVertical() ? finished.preferredWidth() : finished.preferredHeight(), 1,
|
||||
"Published geometry must match the clamped visible size");
|
||||
}
|
||||
} finally {
|
||||
stage.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static javafx.scene.control.TabPane tabPane(DockPane pane, Node content) {
|
||||
return pane.lookupAll(".tab-pane").stream().map(javafx.scene.control.TabPane.class::cast)
|
||||
.filter(tabs -> tabs.getTabs().stream().anyMatch(tab -> tab.getContent() == content))
|
||||
.findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
private static void mouse(Node source, javafx.event.EventType<MouseEvent> type,
|
||||
double screenX, double screenY, boolean down) {
|
||||
var local = source.screenToLocal(screenX, screenY);
|
||||
source.fireEvent(new MouseEvent(type, local.getX(), local.getY(), screenX, screenY,
|
||||
MouseButton.PRIMARY, 1, false, false, false, false,
|
||||
down, false, false, false, false, false,
|
||||
new PickResult(source, local.getX(), local.getY())));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
package de.neitzel.fx.view;
|
||||
|
||||
import de.neitzel.fx.docking.DockGroupDefinition;
|
||||
import de.neitzel.fx.docking.DockLayout;
|
||||
import de.neitzel.fx.docking.DockLayoutView;
|
||||
import de.neitzel.fx.docking.DockPane;
|
||||
import de.neitzel.fx.docking.DockTarget;
|
||||
import de.neitzel.fx.docking.Dockable;
|
||||
import de.neitzel.fx.docking.DockableId;
|
||||
import de.neitzel.fx.docking.DockingManager;
|
||||
import de.neitzel.fx.docking.DockingOptions;
|
||||
import de.neitzel.fx.docking.DockFailure;
|
||||
import de.neitzel.fx.docking.ResolvedDockTarget;
|
||||
import de.neitzel.fx.docking.SplitDirections;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Bounds;
|
||||
import javafx.geometry.Side;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.control.Menu;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.input.PickResult;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
/** Split gestures are observed through visible controls and the public layout. */
|
||||
class SplitDockGroupsByGestureTest {
|
||||
@BeforeAll
|
||||
static void startJavaFx() throws Exception {
|
||||
FxThread.start();
|
||||
FxThread.onFx(() -> Platform.setImplicitExit(false));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(Side.class)
|
||||
void anEdgeDropCreatesThePreviewedAdjacentGroup(Side edge) throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(new DockGroupDefinition("editors"));
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 900, 500));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
TextArea notes = new TextArea("Unsaved notes");
|
||||
Dockable editor = new Dockable(new DockableId("notes"), notes);
|
||||
editor.setTitle("Notes");
|
||||
TextArea project = new TextArea("Project");
|
||||
Dockable tools = new Dockable(new DockableId("project"), project);
|
||||
tools.setTitle("Project");
|
||||
manager.open(editor, DockTarget.area("editors"));
|
||||
manager.open(tools, DockTarget.area("editors"));
|
||||
stage.show();
|
||||
try {
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
Node header = header(pane, "Notes");
|
||||
Bounds from = header.localToScreen(header.getBoundsInLocal());
|
||||
Bounds into = project.localToScreen(project.getBoundsInLocal());
|
||||
double x = edge == Side.LEFT ? into.getMinX() + 8
|
||||
: edge == Side.RIGHT ? into.getMaxX() - 8 : into.getCenterX();
|
||||
double y = edge == Side.TOP ? into.getMinY() + 8
|
||||
: edge == Side.BOTTOM ? into.getMaxY() - 8 : into.getCenterY();
|
||||
mouse(header, MouseEvent.MOUSE_PRESSED, from.getCenterX(), from.getCenterY(), true);
|
||||
mouse(header, MouseEvent.MOUSE_DRAGGED, x, y, true);
|
||||
assertTrue(pane.lookup(".dock-drop-indicator").isVisible());
|
||||
assertEquals(1, manager.layout().windows().getFirst().areas().getFirst().groups().size());
|
||||
mouse(header, MouseEvent.MOUSE_RELEASED, x, y, false);
|
||||
|
||||
DockLayoutView.Area area = manager.layout().windows().getFirst().areas().getFirst();
|
||||
assertInstanceOf(DockLayoutView.Split.class, area.root());
|
||||
assertEquals(2, area.groups().size());
|
||||
boolean before = edge == Side.TOP || edge == Side.LEFT;
|
||||
assertEquals(List.of(editor.getId()), area.groups().get(before ? 0 : 1).dockableIds());
|
||||
assertSame(notes, manager.findDockable(editor.getId()).orElseThrow().getContent());
|
||||
assertEquals("Unsaved notes", notes.getText());
|
||||
} finally {
|
||||
stage.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void splitMenuExplainsRejectedDirectionsAndUsesTheSameMoveOperation() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(new DockGroupDefinition("editors"));
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 900, 500));
|
||||
AtomicBoolean allowed = new AtomicBoolean(false);
|
||||
DockingOptions options = new DockingOptions();
|
||||
options.setPlacementRule((dockable, target) -> target instanceof ResolvedDockTarget.Split && !allowed.get()
|
||||
? Optional.of(new DockFailure(DockFailure.Code.PLACEMENT_REJECTED, dockable.getId(), "No splits today", null))
|
||||
: Optional.empty());
|
||||
DockingManager manager = DockingManager.attach(stage, pane, options);
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Notes"));
|
||||
notes.setTitle("Notes");
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
manager.open(new Dockable(new DockableId("project"), new TextArea("Project")), DockTarget.area("editors"));
|
||||
stage.show();
|
||||
ContextMenu context = null;
|
||||
try {
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
context = ((TabPane) pane.lookup(".tab-pane")).getTabs().getFirst().getContextMenu();
|
||||
context.show(stage, stage.getX() + 80, stage.getY() + 80);
|
||||
Menu splits = context.getItems().stream().filter(item -> "Split".equals(item.getText()))
|
||||
.map(Menu.class::cast).findFirst().orElse(null);
|
||||
assertNotNull(splits);
|
||||
MenuItem right = splits.getItems().stream().filter(item -> item.getText().startsWith("Right"))
|
||||
.findFirst().orElseThrow();
|
||||
assertTrue(right.isDisable());
|
||||
assertTrue(right.getText().contains("No splits today"));
|
||||
context.hide();
|
||||
allowed.set(true);
|
||||
context.show(stage, stage.getX() + 80, stage.getY() + 80);
|
||||
right = splits.getItems().stream().filter(item -> item.getText().startsWith("Right"))
|
||||
.findFirst().orElseThrow();
|
||||
assertFalse(right.isDisable());
|
||||
right.fire();
|
||||
assertInstanceOf(DockLayoutView.Split.class, manager.layout().windows().getFirst().areas().getFirst().root());
|
||||
} finally {
|
||||
if (context != null) context.hide();
|
||||
stage.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"directions", "minimum", "placement"})
|
||||
void aRejectedEdgeSplitFallsBackToJoiningTheTargetGroup(String restriction) throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockLayout initial = new DockLayout();
|
||||
DockGroupDefinition editors = new DockGroupDefinition("editors");
|
||||
if (restriction.equals("directions")) editors.setSplitDirections(SplitDirections.VERTICAL);
|
||||
if (restriction.equals("minimum")) editors.setMinimumWidth(400);
|
||||
initial.setCenter(editors);
|
||||
initial.setLeft(new DockGroupDefinition("tools"));
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 900, 500));
|
||||
DockingOptions options = new DockingOptions();
|
||||
if (restriction.equals("placement")) options.setPlacementRule((dockable, target) ->
|
||||
target instanceof ResolvedDockTarget.Split ? Optional.of(new DockFailure(
|
||||
DockFailure.Code.PLACEMENT_REJECTED, dockable.getId(), "No split", null)) : Optional.empty());
|
||||
DockingManager manager = DockingManager.attach(stage, pane, options);
|
||||
TextArea content = new TextArea("Editor");
|
||||
Dockable editor = new Dockable(new DockableId("editor"), content);
|
||||
manager.open(editor, DockTarget.area("editors"));
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Notes"));
|
||||
notes.setTitle("Notes");
|
||||
manager.open(notes, DockTarget.area("tools"));
|
||||
stage.show();
|
||||
try {
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
Node header = header(pane, "Notes");
|
||||
Bounds from = header.localToScreen(header.getBoundsInLocal());
|
||||
Bounds target = content.localToScreen(content.getBoundsInLocal());
|
||||
double x = target.getMaxX() - 8;
|
||||
double y = target.getCenterY();
|
||||
mouse(header, MouseEvent.MOUSE_PRESSED, from.getCenterX(), from.getCenterY(), true);
|
||||
mouse(header, MouseEvent.MOUSE_DRAGGED, x, y, true);
|
||||
assertTrue(pane.lookup(".dock-drop-indicator").isVisible());
|
||||
mouse(header, MouseEvent.MOUSE_RELEASED, x, y, false);
|
||||
DockLayoutView.Area area = manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(candidate -> candidate.id().value().equals("editors")).findFirst().orElseThrow();
|
||||
assertInstanceOf(DockLayoutView.Group.class, area.root());
|
||||
assertEquals(List.of(editor.getId(), notes.getId()), area.groups().getFirst().dockableIds());
|
||||
} finally { stage.hide(); }
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSoleTabDroppedAtItsOwnEdgeIsAnExplicitNoChange() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(new DockGroupDefinition("editors"));
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 900, 500));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
TextArea content = new TextArea("Unsaved notes");
|
||||
Dockable notes = new Dockable(new DockableId("notes"), content);
|
||||
notes.setTitle("Notes");
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
stage.show();
|
||||
try {
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
DockLayoutView before = manager.layout();
|
||||
Node header = header(pane, "Notes");
|
||||
Bounds from = header.localToScreen(header.getBoundsInLocal());
|
||||
Bounds target = content.localToScreen(content.getBoundsInLocal());
|
||||
mouse(header, MouseEvent.MOUSE_PRESSED, from.getCenterX(), from.getCenterY(), true);
|
||||
mouse(header, MouseEvent.MOUSE_DRAGGED, target.getMaxX() - 8, target.getCenterY(), true);
|
||||
Node marker = pane.lookup(".dock-drop-indicator");
|
||||
assertTrue(marker.isVisible());
|
||||
assertTrue(marker.getPseudoClassStates().contains(javafx.css.PseudoClass.getPseudoClass("no-change")));
|
||||
mouse(header, MouseEvent.MOUSE_RELEASED, target.getMaxX() - 8, target.getCenterY(), false);
|
||||
assertEquals(before, manager.layout());
|
||||
assertSame(content, manager.findDockable(notes.getId()).orElseThrow().getContent());
|
||||
} finally { stage.hide(); }
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"LEFT,true", "RIGHT,true", "TOP,true", "BOTTOM,true",
|
||||
"LEFT,false", "RIGHT,false", "TOP,false", "BOTTOM,false"})
|
||||
void aPersistentGroupRemainsAnInvisibleDropTargetAndRestoresItsExtent(Side edge, boolean releaseSpace) throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
String property = edge.name().toLowerCase(java.util.Locale.ROOT);
|
||||
String fxml = """
|
||||
<?import de.neitzel.fx.docking.*?>
|
||||
<DockPane xmlns:fx="http://javafx.com/fxml/1">
|
||||
<initialLayout><DockLayout>
|
||||
<center><DockGroupDefinition destinationId="editors"/></center>
|
||||
<%s><DockGroupDefinition destinationId="tools" persistent="true"
|
||||
visibleWhenEmpty="false" releaseSpaceWhenEmpty="%s"/></%s>
|
||||
</DockLayout></initialLayout>
|
||||
</DockPane>
|
||||
""".formatted(property, releaseSpace, property);
|
||||
DockPane pane = new FXMLLoader().load(new ByteArrayInputStream(fxml.getBytes(StandardCharsets.UTF_8)));
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 900, 500));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
manager.open(new Dockable(new DockableId("project"), new TextArea("Project")), DockTarget.area("editors"));
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Notes"));
|
||||
notes.setTitle("Notes");
|
||||
manager.open(notes, DockTarget.area("tools"));
|
||||
stage.show();
|
||||
try {
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
TabPane empty = pane.lookupAll(".tab-pane").stream().map(TabPane.class::cast)
|
||||
.filter(tabs -> tabs.getTabs().stream().anyMatch(tab -> tab.getContent() == notes.getContent()))
|
||||
.findFirst().orElseThrow();
|
||||
double occupiedExtent = edge.isVertical() ? empty.getWidth() : empty.getHeight();
|
||||
manager.move(notes.getId(), DockTarget.area("editors"));
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
assertFalse(empty.isVisible());
|
||||
assertEquals(!releaseSpace, empty.isManaged());
|
||||
Node header = header(pane, "Notes");
|
||||
Bounds from = header.localToScreen(header.getBoundsInLocal());
|
||||
Bounds target = releaseSpace ? pane.localToScreen(pane.getBoundsInLocal())
|
||||
: empty.localToScreen(empty.getBoundsInLocal());
|
||||
double x = !releaseSpace ? target.getCenterX() : edge == Side.LEFT ? target.getMinX() + 8
|
||||
: edge == Side.RIGHT ? target.getMaxX() - 8 : target.getCenterX();
|
||||
double y = !releaseSpace ? target.getCenterY() : edge == Side.TOP ? target.getMinY() + 8
|
||||
: edge == Side.BOTTOM ? target.getMaxY() - 8 : target.getCenterY();
|
||||
mouse(header, MouseEvent.MOUSE_PRESSED, from.getCenterX(), from.getCenterY(), true);
|
||||
mouse(header, MouseEvent.MOUSE_DRAGGED, x, y, true);
|
||||
assertTrue(pane.lookup(".dock-drop-indicator").isVisible());
|
||||
assertFalse(empty.isVisible());
|
||||
assertEquals(!releaseSpace, empty.isManaged());
|
||||
mouse(header, MouseEvent.MOUSE_RELEASED, x, y, false);
|
||||
DockLayoutView.Area tools = manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().value().equals("tools")).findFirst().orElseThrow();
|
||||
assertEquals(List.of(notes.getId()), tools.groups().getFirst().dockableIds());
|
||||
assertTrue(empty.isVisible());
|
||||
assertTrue(empty.isManaged());
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
assertEquals(occupiedExtent, edge.isVertical() ? empty.getWidth() : empty.getHeight(), 1.0);
|
||||
} finally { stage.hide(); }
|
||||
});
|
||||
}
|
||||
|
||||
private static Node header(DockPane pane, String title) {
|
||||
return pane.lookupAll(".tab").stream().filter(node -> {
|
||||
Node label = node.lookup(".tab-label");
|
||||
return label instanceof Label text && title.equals(text.getText());
|
||||
}).findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
private static void mouse(Node source, javafx.event.EventType<MouseEvent> type,
|
||||
double screenX, double screenY, boolean down) {
|
||||
var local = source.screenToLocal(screenX, screenY);
|
||||
source.fireEvent(new MouseEvent(type, local.getX(), local.getY(), screenX, screenY,
|
||||
MouseButton.PRIMARY, 1, false, false, false, false,
|
||||
down, false, false, false, false, false,
|
||||
new PickResult(source, local.getX(), local.getY())));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
package de.neitzel.fx.view;
|
||||
|
||||
import de.neitzel.fx.docking.*;
|
||||
import javafx.geometry.Side;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** A split displays two groups while preserving the same live Dockables. */
|
||||
class SplitDockGroupsTest {
|
||||
@BeforeAll
|
||||
static void startJavaFx() throws InterruptedException { FxThread.start(); }
|
||||
|
||||
@Test
|
||||
void splittingAnEditorCreatesAnAdjacentGroupWithTheSameContent() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(new DockGroupDefinition("editors"));
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
TextArea notes = new TextArea("Unsaved notes");
|
||||
Dockable moved = new Dockable(new DockableId("notes"), notes);
|
||||
Dockable remaining = new Dockable(new DockableId("readme"), new TextArea("Readme"));
|
||||
manager.open(moved, DockTarget.area("editors"));
|
||||
manager.open(remaining, DockTarget.area("editors"));
|
||||
pane.resize(800, 500);
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
DockGroupId original = manager.layout().windows().getFirst().areas().getFirst().groups().getFirst().id();
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(moved.getId(), DockTarget.split(original, Side.RIGHT)));
|
||||
var groups = manager.layout().windows().getFirst().areas().getFirst().groups();
|
||||
assertEquals(2, groups.size());
|
||||
assertEquals(List.of(remaining.getId()), groups.getFirst().dockableIds());
|
||||
assertEquals(List.of(moved.getId()), groups.getLast().dockableIds());
|
||||
assertSame(notes, manager.findDockable(moved.getId()).orElseThrow().getContent());
|
||||
assertSame(moved, manager.activeDockable());
|
||||
});
|
||||
}
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(booleans = {false, true})
|
||||
void emptyingEitherBranchDissolvesTheSplitAndPreservesTheArea(boolean emptyOriginal) throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixture();
|
||||
DockingManager manager = fixture.manager();
|
||||
DockGroupId original = manager.layout().windows().getFirst().areas().getFirst().groups().getFirst().id();
|
||||
manager.move(fixture.notes(), DockTarget.split(original, Side.RIGHT));
|
||||
DockGroupId added = manager.layout().windows().getFirst().areas().getFirst().groups().getLast().id();
|
||||
DockGroupId survivor = emptyOriginal ? added : original;
|
||||
DockGroupId removed = emptyOriginal ? original : added;
|
||||
DockableId moved = emptyOriginal ? fixture.readme() : fixture.notes();
|
||||
var changes = new java.util.ArrayList<DockLayoutView>();
|
||||
manager.layoutProperty().addListener((observable, old, current) -> changes.add(current));
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(moved, DockTarget.group(survivor)));
|
||||
assertEquals(1, changes.size());
|
||||
var area = manager.layout().windows().getFirst().areas().getFirst();
|
||||
assertEquals(1, area.groups().size());
|
||||
assertEquals(survivor, area.groups().getFirst().id());
|
||||
assertInstanceOf(DockLayoutView.Group.class, area.root());
|
||||
assertInstanceOf(MoveCheck.Rejected.class, manager.checkMove(moved, DockTarget.group(removed)));
|
||||
Dockable next = new Dockable(new DockableId("next"), new TextArea());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.open(next, DockTarget.area("editors")));
|
||||
assertEquals(3, manager.layout().windows().getFirst().areas().getFirst().groups().getFirst().dockableIds().size());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void nestedFxmlSplitsSurviveWhenTheirSiblingBecomesEmpty() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockPane pane = javafx.fxml.FXMLLoader.load(getClass().getResource("docking-nested-splits.fxml"));
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 900, 600));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
for (String area : List.of("one", "two", "three")) {
|
||||
manager.open(new Dockable(new DockableId(area), new TextArea(area)), DockTarget.area(area));
|
||||
}
|
||||
manager.move(new DockableId("one"), DockTarget.area("two"));
|
||||
var editorArea = manager.layout().windows().getFirst().areas().getFirst();
|
||||
assertEquals(new DockAreaId("editors"), editorArea.id());
|
||||
assertEquals(2, editorArea.groups().size());
|
||||
DockLayoutView.Split remaining = assertInstanceOf(DockLayoutView.Split.class, editorArea.root());
|
||||
assertEquals(javafx.geometry.Orientation.VERTICAL, remaining.orientation());
|
||||
assertEquals(.3, remaining.position(), .001);
|
||||
assertInstanceOf(MoveCheck.Rejected.class, manager.checkMove(new DockableId("one"),
|
||||
DockTarget.group(new DockGroupId("one"))));
|
||||
assertFalse(manager.checkMove(new DockableId("three"), DockTarget.area("one")) instanceof MoveCheck.Rejected);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void areaTargetsPreferTheMostRecentlyActiveEligibleGroup() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
var rejectedGroup = new java.util.concurrent.atomic.AtomicReference<DockGroupId>();
|
||||
DockingOptions options = new DockingOptions();
|
||||
options.setPlacementRule((dockable, destination) -> destination instanceof ResolvedDockTarget.Insertion insertion
|
||||
&& insertion.groupId().equals(rejectedGroup.get())
|
||||
? java.util.Optional.of(new DockFailure(DockFailure.Code.PLACEMENT_REJECTED,
|
||||
dockable.getId(), "Use another group", null)) : java.util.Optional.empty());
|
||||
Fixture fixture = fixture(options);
|
||||
DockingManager manager = fixture.manager();
|
||||
DockGroupId original = manager.layout().windows().getFirst().areas().getFirst().groups().getFirst().id();
|
||||
manager.move(fixture.notes(), DockTarget.split(original, Side.RIGHT));
|
||||
DockGroupId right = manager.layout().windows().getFirst().areas().getFirst().groups().getLast().id();
|
||||
Dockable third = new Dockable(new DockableId("third"), new TextArea());
|
||||
manager.open(third, DockTarget.area("editors"));
|
||||
assertEquals(List.of(fixture.notes(), third.getId()), manager.layout().windows().getFirst()
|
||||
.areas().getFirst().groups().getLast().dockableIds());
|
||||
rejectedGroup.set(right);
|
||||
Dockable fourth = new Dockable(new DockableId("fourth"), new TextArea());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.open(fourth, DockTarget.area("editors")));
|
||||
assertEquals(List.of(fixture.readme(), fourth.getId()), manager.layout().windows().getFirst()
|
||||
.areas().getFirst().groups().getFirst().dockableIds());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void splitDirectionsAndBothMinimumSizesAreCheckedBeforeCreatingAGroup() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockPane pane = javafx.fxml.FXMLLoader.load(getClass().getResource("docking-split-policy.fxml"));
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
DockableId notes = new DockableId("notes");
|
||||
manager.open(new Dockable(notes, new TextArea()), DockTarget.area("editors"));
|
||||
manager.open(new Dockable(new DockableId("readme"), new TextArea()), DockTarget.area("editors"));
|
||||
pane.resize(800, 500);
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
DockGroupId original = manager.layout().windows().getFirst().areas().getFirst().groups().getFirst().id();
|
||||
var before = manager.layout();
|
||||
assertInstanceOf(MoveCheck.Rejected.class, manager.checkMove(notes, DockTarget.split(original, Side.RIGHT)));
|
||||
assertInstanceOf(ActionResult.Rejected.class, manager.move(notes, DockTarget.split(original, Side.BOTTOM)));
|
||||
assertEquals(before, manager.layout());
|
||||
pane.resize(800, 900);
|
||||
pane.layout();
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(notes, DockTarget.split(original, Side.TOP)));
|
||||
DockLayoutView.Split split = assertInstanceOf(DockLayoutView.Split.class,
|
||||
manager.layout().windows().getFirst().areas().getFirst().root());
|
||||
assertEquals(.5, split.position());
|
||||
});
|
||||
}
|
||||
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.EnumSource(value = Side.class, names = {"RIGHT", "BOTTOM"})
|
||||
void dividerGesturesPublishOnlyTheirCompletedGeometry(Side side) throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixture();
|
||||
DockingManager manager = fixture.manager();
|
||||
DockGroupId original = manager.layout().windows().getFirst().areas().getFirst().groups().getFirst().id();
|
||||
manager.move(fixture.notes(), DockTarget.split(original, side));
|
||||
fixture.pane().applyCss();
|
||||
fixture.pane().layout();
|
||||
javafx.scene.control.SplitPane split = (javafx.scene.control.SplitPane) fixture.pane().lookup(".split-pane");
|
||||
javafx.scene.Node divider = split.lookup(".split-pane-divider");
|
||||
assertNotNull(divider);
|
||||
var changes = new java.util.ArrayList<DockLayoutView>();
|
||||
manager.layoutProperty().addListener((observable, old, current) -> changes.add(current));
|
||||
divider.fireEvent(dividerMouse(javafx.scene.input.MouseEvent.MOUSE_PRESSED, divider));
|
||||
assertEquals(side == Side.RIGHT ? javafx.scene.Cursor.H_RESIZE : javafx.scene.Cursor.V_RESIZE, divider.getCursor());
|
||||
split.setDividerPositions(.7);
|
||||
fixture.pane().layout();
|
||||
assertEquals(.5, ((DockLayoutView.Split) manager.layout().windows().getFirst().areas().getFirst().root()).position());
|
||||
assertTrue(changes.isEmpty());
|
||||
divider.fireEvent(dividerMouse(javafx.scene.input.MouseEvent.MOUSE_RELEASED, divider));
|
||||
assertEquals(1, changes.size());
|
||||
assertEquals(.7, ((DockLayoutView.Split) changes.getFirst().windows().getFirst().areas().getFirst().root()).position(), .02);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void movingOneTabDoesNotDissolveAnUnrelatedInitiallyEmptySplit() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockPane pane = javafx.fxml.FXMLLoader.load(getClass().getResource("docking-nested-splits.fxml"));
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 900, 600));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
manager.open(new Dockable(new DockableId("one"), new TextArea()), DockTarget.area("one"));
|
||||
manager.open(new Dockable(new DockableId("moving"), new TextArea()), DockTarget.area("one"));
|
||||
manager.open(new Dockable(new DockableId("two"), new TextArea()), DockTarget.area("two"));
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(new DockableId("moving"), DockTarget.area("two")));
|
||||
DockLayoutView.Split root = assertInstanceOf(DockLayoutView.Split.class,
|
||||
manager.layout().windows().getFirst().areas().getFirst().root());
|
||||
assertInstanceOf(DockLayoutView.Split.class, root.second());
|
||||
assertInstanceOf(ActionResult.Applied.class,
|
||||
manager.open(new Dockable(new DockableId("three"), new TextArea()),
|
||||
DockTarget.group(new DockGroupId("three"))));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void aNonpersistentRootDisappearsOnlyAfterItsLastContentLeaves() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(new DockGroupDefinition("editors"));
|
||||
DockGroupDefinition temporary = new DockGroupDefinition("temporary");
|
||||
temporary.setPersistent(false);
|
||||
initial.setLeft(temporary);
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
DockableId id = new DockableId("notes");
|
||||
assertInstanceOf(ActionResult.Applied.class,
|
||||
manager.open(new Dockable(id, new TextArea()), DockTarget.area("temporary")));
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(id, DockTarget.area("editors")));
|
||||
assertEquals(List.of(new DockAreaId("editors")), manager.layout().windows().getFirst().areas().stream()
|
||||
.map(DockLayoutView.Area::id).toList());
|
||||
MoveCheck.Rejected missing = assertInstanceOf(MoveCheck.Rejected.class,
|
||||
manager.checkMove(id, DockTarget.area("temporary")));
|
||||
assertEquals(DockFailure.Code.TARGET_NOT_FOUND, missing.failure().code());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void releasingEmptySpaceHidesTheGroupEvenWithDefaultEmptyVisibility() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(new DockGroupDefinition("editors"));
|
||||
DockGroupDefinition tools = new DockGroupDefinition("tools");
|
||||
tools.setReleaseSpaceWhenEmpty(true);
|
||||
initial.setRight(tools);
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea());
|
||||
manager.open(notes, DockTarget.area("tools"));
|
||||
pane.resize(800, 500);
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
javafx.scene.control.TabPane tabs = pane.lookupAll(".tab-pane").stream()
|
||||
.map(javafx.scene.control.TabPane.class::cast)
|
||||
.filter(candidate -> !candidate.getTabs().isEmpty()).findFirst().orElseThrow();
|
||||
double width = tabs.getWidth();
|
||||
manager.move(notes.getId(), DockTarget.area("editors"));
|
||||
pane.layout();
|
||||
assertFalse(tabs.isManaged());
|
||||
assertFalse(tabs.isVisible(), "A released area must not remain painted over its replacement");
|
||||
manager.move(notes.getId(), DockTarget.area("tools"));
|
||||
pane.layout();
|
||||
assertTrue(tabs.isVisible());
|
||||
assertTrue(tabs.isManaged());
|
||||
assertEquals(width, tabs.getWidth(), 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void thePublishedInitialSplitHonorsItsMinimumAdjustedGeometry() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockGroupDefinition first = new DockGroupDefinition("first");
|
||||
first.setMinimumWidth(200);
|
||||
DockSplitDefinition split = new DockSplitDefinition();
|
||||
split.setDestinationId("editors");
|
||||
split.setFirst(first);
|
||||
split.setSecond(new DockGroupDefinition("second"));
|
||||
split.setPosition(.1);
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(split);
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 500, 400));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
DockLayoutView.Split view = assertInstanceOf(DockLayoutView.Split.class,
|
||||
manager.layout().windows().getFirst().areas().getFirst().root());
|
||||
assertTrue(view.position() >= .4 && view.position() < .5,
|
||||
"Published geometry must describe the minimum-adjusted layout");
|
||||
javafx.scene.control.SplitPane surface = (javafx.scene.control.SplitPane) pane.lookup(".split-pane");
|
||||
assertEquals(surface.getDividers().getFirst().getPosition(), view.position(), .001);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyingASiblingCannotResizeAGroupWhoseCloseConsentIsPending() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockSplitDefinition split = new DockSplitDefinition();
|
||||
split.setDestinationId("editors");
|
||||
split.setFirst(new DockGroupDefinition("pending"));
|
||||
split.setSecond(new DockGroupDefinition("sibling"));
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(split);
|
||||
initial.setRight(new DockGroupDefinition("tools"));
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 900, 600));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
var consent = new java.util.concurrent.CompletableFuture<CloseConsent>();
|
||||
Dockable pending = new Dockable(new DockableId("pending"), new TextArea());
|
||||
pending.setCloseCheck(request -> consent);
|
||||
manager.open(pending, DockTarget.area("pending"));
|
||||
DockableId last = new DockableId("last");
|
||||
DockableId extra = new DockableId("extra");
|
||||
manager.open(new Dockable(last, new TextArea()), DockTarget.area("sibling"));
|
||||
manager.open(new Dockable(extra, new TextArea()), DockTarget.area("sibling"));
|
||||
var close = manager.requestTabClose(pending.getId());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(extra, DockTarget.area("tools")),
|
||||
"Moving a non-last sibling tab does not affect the pending group");
|
||||
DockLayoutView before = manager.layout();
|
||||
MoveCheck.Rejected check = assertInstanceOf(MoveCheck.Rejected.class,
|
||||
manager.checkMove(last, DockTarget.area("tools")));
|
||||
assertEquals(DockFailure.Code.CLOSE_IN_PROGRESS, check.failure().code());
|
||||
ActionResult.Rejected rejected = assertInstanceOf(ActionResult.Rejected.class,
|
||||
manager.move(last, DockTarget.area("tools")));
|
||||
assertEquals(DockFailure.Code.CLOSE_IN_PROGRESS, rejected.failure().code());
|
||||
assertEquals(before, manager.layout());
|
||||
consent.complete(CloseConsent.VETO);
|
||||
assertInstanceOf(CloseResult.Vetoed.class, close.toCompletableFuture().join());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(last, DockTarget.area("tools")));
|
||||
assertInstanceOf(DockLayoutView.Group.class,
|
||||
manager.layout().windows().getFirst().areas().getFirst().root());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnrelatedPendingCloseDoesNotCaptureANestedDividerGesture() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockPane pane = javafx.fxml.FXMLLoader.load(getClass().getResource("docking-nested-splits.fxml"));
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 900, 600));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
var consent = new java.util.concurrent.CompletableFuture<CloseConsent>();
|
||||
for (String area : List.of("one", "two", "three")) {
|
||||
Dockable dockable = new Dockable(new DockableId(area), new TextArea(area));
|
||||
if (area.equals("one")) dockable.setCloseCheck(request -> consent);
|
||||
manager.open(dockable, DockTarget.area(area));
|
||||
}
|
||||
var close = manager.requestTabClose(new DockableId("one"));
|
||||
try {
|
||||
javafx.scene.control.SplitPane nested = pane.lookupAll(".split-pane").stream()
|
||||
.map(javafx.scene.control.SplitPane.class::cast)
|
||||
.filter(candidate -> candidate.getOrientation() == javafx.geometry.Orientation.VERTICAL)
|
||||
.findFirst().orElseThrow();
|
||||
javafx.scene.Node divider = nested.lookup(".split-pane-divider");
|
||||
var changes = new java.util.ArrayList<DockLayoutView>();
|
||||
manager.layoutProperty().addListener((observable, old, current) -> changes.add(current));
|
||||
divider.fireEvent(dividerMouse(javafx.scene.input.MouseEvent.MOUSE_PRESSED, divider));
|
||||
nested.setDividerPositions(.7);
|
||||
pane.layout();
|
||||
assertTrue(changes.isEmpty());
|
||||
divider.fireEvent(dividerMouse(javafx.scene.input.MouseEvent.MOUSE_RELEASED, divider));
|
||||
assertEquals(1, changes.size(), "Only the owning nested split handles its divider");
|
||||
assertEquals(javafx.scene.Cursor.V_RESIZE, divider.getCursor());
|
||||
DockLayoutView.Split root = (DockLayoutView.Split) manager.layout().windows().getFirst().areas().getFirst().root();
|
||||
assertEquals(.4, root.position(), .01);
|
||||
assertEquals(.7, ((DockLayoutView.Split) root.second()).position(), .02);
|
||||
assertFalse(close.toCompletableFuture().isDone());
|
||||
} finally {
|
||||
consent.complete(CloseConsent.VETO);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static javafx.scene.input.MouseEvent dividerMouse(javafx.event.EventType<javafx.scene.input.MouseEvent> type,
|
||||
javafx.scene.Node divider) {
|
||||
return new javafx.scene.input.MouseEvent(type, 0, 0, 0, 0, javafx.scene.input.MouseButton.PRIMARY, 1,
|
||||
false, false, false, false, type != javafx.scene.input.MouseEvent.MOUSE_RELEASED,
|
||||
false, false, false, false, false, new javafx.scene.input.PickResult(divider, 0, 0));
|
||||
}
|
||||
|
||||
private static Fixture fixture() { return fixture(new DockingOptions()); }
|
||||
|
||||
private static Fixture fixture(DockingOptions options) {
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(new DockGroupDefinition("editors"));
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(initial);
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, options);
|
||||
DockableId notes = new DockableId("notes");
|
||||
DockableId readme = new DockableId("readme");
|
||||
manager.open(new Dockable(notes, new TextArea("Unsaved notes")), DockTarget.area("editors"));
|
||||
manager.open(new Dockable(readme, new TextArea("Readme")), DockTarget.area("editors"));
|
||||
pane.resize(800, 500);
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
return new Fixture(manager, pane, notes, readme);
|
||||
}
|
||||
|
||||
private record Fixture(DockingManager manager, DockPane pane, DockableId notes, DockableId readme) { }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?import de.neitzel.fx.docking.*?>
|
||||
<DockPane xmlns:fx="http://javafx.com/fxml/1">
|
||||
<initialLayout>
|
||||
<DockLayout>
|
||||
<center>
|
||||
<DockSplitDefinition destinationId="editors" orientation="HORIZONTAL" position="0.4">
|
||||
<first><DockGroupDefinition destinationId="one"/></first>
|
||||
<second>
|
||||
<DockSplitDefinition destinationId="remaining" orientation="VERTICAL" position="0.3">
|
||||
<first><DockGroupDefinition destinationId="two"/></first>
|
||||
<second><DockGroupDefinition destinationId="three"/></second>
|
||||
</DockSplitDefinition>
|
||||
</second>
|
||||
</DockSplitDefinition>
|
||||
</center>
|
||||
</DockLayout>
|
||||
</initialLayout>
|
||||
</DockPane>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?import de.neitzel.fx.docking.*?>
|
||||
<DockPane xmlns:fx="http://javafx.com/fxml/1">
|
||||
<initialLayout>
|
||||
<DockLayout>
|
||||
<center><DockGroupDefinition destinationId="editors" splitDirections="VERTICAL"
|
||||
minimumWidth="100" minimumHeight="300"/></center>
|
||||
</DockLayout>
|
||||
</initialLayout>
|
||||
</DockPane>
|
||||
Reference in New Issue
Block a user