feat(fx): add collapsible groups and managed floating windows
This commit is contained in:
@@ -0,0 +1,434 @@
|
||||
package de.neitzel.fx.view;
|
||||
|
||||
import de.neitzel.fx.docking.*;
|
||||
import javafx.geometry.Side;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Group presentation is exercised through public operations and the rendered JavaFX surface. */
|
||||
class CollapseDockGroupsTest {
|
||||
@BeforeAll
|
||||
static void startJavaFx() throws InterruptedException { FxThread.start(); }
|
||||
|
||||
@Test
|
||||
void collapsingAnEdgeGroupKeepsItsHeadersAndReleasesItsContentSpace() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(new DockGroupDefinition("editors"));
|
||||
DockGroupDefinition tools = new DockGroupDefinition("tools");
|
||||
tools.setTabSide(Side.RIGHT);
|
||||
tools.setCollapsible(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());
|
||||
manager.open(new Dockable(new DockableId("editor"), new TextArea()), DockTarget.area("editors"));
|
||||
Dockable project = new Dockable(new DockableId("project"), new TextArea("Project"));
|
||||
project.setTitle("Project");
|
||||
project.setIcon(new Label("P"));
|
||||
manager.open(project, DockTarget.area("tools"));
|
||||
TabPane tabs = pane.lookupAll(".tab-pane").stream().map(TabPane.class::cast)
|
||||
.filter(candidate -> candidate.getTabs().stream().anyMatch(tab -> tab.getContent() == project.getContent()))
|
||||
.findFirst().orElseThrow();
|
||||
double expandedWidth = tabs.getWidth();
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.setGroupCollapsed(new DockGroupId("tools"), true));
|
||||
DockLayoutView.Group group = manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().equals(new DockAreaId("tools"))).findFirst().orElseThrow().groups().getFirst();
|
||||
assertTrue(group.collapsed());
|
||||
assertTrue(tabs.lookup(".tab-header-area").isVisible());
|
||||
assertFalse(tabs.lookup(".tab-content-area").isVisible());
|
||||
assertTrue(tabs.getWidth() < expandedWidth / 2, "The whole group releases its content width");
|
||||
assertEquals(new DockableId("editor"), manager.activeDockable().getId());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.setGroupCollapsed(new DockGroupId("tools"), false));
|
||||
assertSame(project.getContent(), pane.getScene().getFocusOwner(),
|
||||
"Reopening the same selected tab restores keyboard focus into its content");
|
||||
assertTrue(visibleThroughParents(project.getContent()));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void clickingProjectThenChangedFilesCollapsesAndReopensTheSharedGroup() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixture();
|
||||
TabPane tabs = fixture.tabs();
|
||||
double width = tabs.getWidth();
|
||||
javafx.scene.Node projectHeader = header(tabs, fixture.project().getId());
|
||||
click(projectHeader);
|
||||
assertTrue(group(fixture.manager()).collapsed());
|
||||
assertFalse(visibleThroughParents(fixture.project().getContent()), "The selected tab content is hidden, not just the first tab");
|
||||
assertSame(projectHeader, fixture.pane().getScene().getFocusOwner());
|
||||
assertEquals(new DockableId("editor"), fixture.manager().activeDockable().getId());
|
||||
click(header(tabs, fixture.changes().getId()));
|
||||
assertFalse(group(fixture.manager()).collapsed());
|
||||
assertSame(fixture.changes(), fixture.manager().activeDockable());
|
||||
assertTrue(visibleThroughParents(fixture.changes().getContent()));
|
||||
assertSame(fixture.changes().getContent(), tabs.getSelectionModel().getSelectedItem().getContent());
|
||||
assertEquals(width, tabs.getWidth(), 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void aGroupUpdateAppliesOnlyExplicitSettingsTogetherIncludingFalse() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixture();
|
||||
DockingManager manager = fixture.manager();
|
||||
DockGroupId tools = new DockGroupId("tools");
|
||||
assertInstanceOf(ActionResult.Rejected.class,
|
||||
manager.setGroupCollapsed(new DockGroupId("editors"), true));
|
||||
manager.setGroupCollapsed(tools, true);
|
||||
var changes = new java.util.ArrayList<DockLayoutView>();
|
||||
manager.layoutProperty().addListener((observable, old, current) -> changes.add(current));
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.updateGroup(tools, DockGroupChanges.builder()
|
||||
.preferredWidth(260.0).tabSide(Side.LEFT).collapsible(false).build()));
|
||||
assertEquals(1, changes.size());
|
||||
assertFalse(group(manager).collapsed());
|
||||
assertEquals(Side.LEFT, group(manager).tabSide());
|
||||
assertEquals(260, fixture.tabs().getWidth(), 1);
|
||||
assertEquals(150, fixture.tabs().prefHeight(-1), "Unspecified dimensions are retained");
|
||||
ActionResult.Rejected disabled = assertInstanceOf(ActionResult.Rejected.class,
|
||||
manager.setGroupCollapsed(tools, true));
|
||||
assertEquals(DockFailure.Code.COLLAPSE_DISABLED, disabled.failure().code());
|
||||
DockLayoutView beforeInvalid = manager.layout();
|
||||
assertInstanceOf(ActionResult.Rejected.class, manager.updateGroup(tools, DockGroupChanges.builder()
|
||||
.tabSide(Side.BOTTOM).preferredWidth(-1.0).build()));
|
||||
assertEquals(beforeInvalid, manager.layout());
|
||||
assertEquals(Side.LEFT, fixture.tabs().getSide());
|
||||
assertEquals(1, changes.size());
|
||||
assertInstanceOf(ActionResult.NoChange.class, manager.updateGroup(tools, DockGroupChanges.builder().build()));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void escapeReturnsFocusToTheSymbolAndActivationReopensTheRequestedTab() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixture();
|
||||
var changes = new java.util.ArrayList<DockLayoutView>();
|
||||
fixture.manager().layoutProperty().addListener((observable, old, current) -> changes.add(current));
|
||||
fixture.project().getContent().fireEvent(new javafx.scene.input.KeyEvent(
|
||||
javafx.scene.input.KeyEvent.KEY_PRESSED, "", "", javafx.scene.input.KeyCode.ESCAPE,
|
||||
false, false, false, false));
|
||||
assertTrue(group(fixture.manager()).collapsed());
|
||||
assertEquals(1, changes.size());
|
||||
assertSame(header(fixture.tabs(), fixture.project().getId()), fixture.pane().getScene().getFocusOwner());
|
||||
assertEquals(new DockableId("editor"), fixture.manager().activeDockable().getId());
|
||||
assertInstanceOf(ActionResult.Applied.class, fixture.manager().activate(fixture.changes().getId()));
|
||||
assertFalse(group(fixture.manager()).collapsed());
|
||||
assertSame(fixture.changes(), fixture.manager().activeDockable());
|
||||
assertTrue(visibleThroughParents(fixture.changes().getContent()));
|
||||
assertEquals(2, changes.size());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void closingTheLastVisibleContentDoesNotActivateACollapsedGroup() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixture();
|
||||
fixture.manager().setGroupCollapsed(new DockGroupId("tools"), true);
|
||||
assertEquals(new DockableId("editor"), fixture.manager().activeDockable().getId());
|
||||
var closed = fixture.manager().requestTabClose(new DockableId("editor"));
|
||||
assertInstanceOf(CloseResult.Closed.class, closed.toCompletableFuture().join());
|
||||
assertNull(fixture.manager().activeDockable());
|
||||
assertTrue(group(fixture.manager()).collapsed());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPendingCenterCloseProtectsItsGeometryFromToolGroupChanges() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixture();
|
||||
DockingManager manager = fixture.manager();
|
||||
var consent = new java.util.concurrent.CompletableFuture<CloseConsent>();
|
||||
Dockable editor = manager.findDockable(new DockableId("editor")).orElseThrow();
|
||||
editor.setCloseCheck(request -> consent);
|
||||
manager.requestTabClose(editor.getId());
|
||||
DockGroupId tools = new DockGroupId("tools");
|
||||
try {
|
||||
DockLayoutView before = manager.layout();
|
||||
ActionResult.Rejected collapse = assertInstanceOf(ActionResult.Rejected.class,
|
||||
manager.setGroupCollapsed(tools, true));
|
||||
assertEquals(DockFailure.Code.CLOSE_IN_PROGRESS, collapse.failure().code());
|
||||
ActionResult.Rejected resize = assertInstanceOf(ActionResult.Rejected.class,
|
||||
manager.updateGroup(tools, DockGroupChanges.builder().preferredWidth(300).build()));
|
||||
assertEquals(DockFailure.Code.CLOSE_IN_PROGRESS, resize.failure().code());
|
||||
assertEquals(before, manager.layout());
|
||||
assertInstanceOf(ActionResult.Applied.class,
|
||||
manager.updateGroup(tools, DockGroupChanges.builder().splitDirections(SplitDirections.NONE).build()),
|
||||
"Non-geometric settings remain independent of a neighboring close");
|
||||
} finally {
|
||||
consent.complete(CloseConsent.VETO);
|
||||
}
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.setGroupCollapsed(tools, true));
|
||||
assertInstanceOf(ActionResult.Applied.class,
|
||||
manager.updateGroup(tools, DockGroupChanges.builder().preferredWidth(300).build()));
|
||||
var secondConsent = new java.util.concurrent.CompletableFuture<CloseConsent>();
|
||||
editor.setCloseCheck(request -> secondConsent);
|
||||
manager.requestTabClose(editor.getId());
|
||||
try {
|
||||
assertInstanceOf(ActionResult.NoChange.class,
|
||||
manager.move(fixture.project().getId(), DockTarget.group(tools)),
|
||||
"A move that leaves a collapsed group unchanged remains allowed");
|
||||
ActionResult.Rejected activation = assertInstanceOf(ActionResult.Rejected.class,
|
||||
manager.activate(fixture.project().getId()));
|
||||
assertEquals(DockFailure.Code.CLOSE_IN_PROGRESS, activation.failure().code());
|
||||
assertTrue(group(manager).collapsed());
|
||||
} finally {
|
||||
secondConsent.complete(CloseConsent.VETO);
|
||||
}
|
||||
manager.setGroupCollapsed(tools, false);
|
||||
assertEquals(300, fixture.tabs().getWidth(), 1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void splitGroupsInheritSettingsAndSubsequentUpdatesRemainIndependent() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixture();
|
||||
DockingManager manager = fixture.manager();
|
||||
DockGroupId original = new DockGroupId("tools");
|
||||
manager.updateGroup(original, DockGroupChanges.builder().preferredWidth(260)
|
||||
.minimumHeight(180).splitDirections(SplitDirections.VERTICAL).build());
|
||||
assertInstanceOf(ActionResult.Applied.class,
|
||||
manager.move(fixture.project().getId(), DockTarget.split(original, Side.BOTTOM)));
|
||||
var area = manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(candidate -> candidate.id().equals(new DockAreaId("tools"))).findFirst().orElseThrow();
|
||||
DockGroupId added = area.groups().getLast().id();
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.setGroupCollapsed(added, true));
|
||||
manager.updateGroup(original, DockGroupChanges.builder().collapsible(false)
|
||||
.minimumHeight(20).splitDirections(SplitDirections.ALL).build());
|
||||
MoveCheck.Rejected direction = assertInstanceOf(MoveCheck.Rejected.class,
|
||||
manager.checkMove(new DockableId("editor"), DockTarget.split(added, Side.RIGHT)));
|
||||
assertEquals(DockFailure.Code.SPLIT_DISABLED, direction.failure().code());
|
||||
MoveCheck.Rejected minimum = assertInstanceOf(MoveCheck.Rejected.class,
|
||||
manager.checkMove(new DockableId("editor"), DockTarget.split(added, Side.TOP)));
|
||||
assertEquals(DockFailure.Code.SPLIT_TOO_SMALL, minimum.failure().code());
|
||||
assertInstanceOf(MoveCheck.Allowed.class,
|
||||
manager.checkMove(new DockableId("editor"), DockTarget.split(original, Side.TOP)));
|
||||
assertInstanceOf(ActionResult.Applied.class,
|
||||
manager.move(fixture.changes().getId(), DockTarget.group(added)));
|
||||
ActionResult.Rejected stale = assertInstanceOf(ActionResult.Rejected.class,
|
||||
manager.updateGroup(original, DockGroupChanges.builder().collapsible(true).build()));
|
||||
assertEquals(DockFailure.Code.TARGET_NOT_FOUND, stale.failure().code());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void collapsingASplitLeafGivesItsContentSpaceToItsSiblingAndRestoresTheDivider() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixture();
|
||||
DockingManager manager = fixture.manager();
|
||||
DockGroupId first = new DockGroupId("tools");
|
||||
manager.move(fixture.project().getId(), DockTarget.split(first, Side.BOTTOM));
|
||||
TabPane second = fixture.pane().lookupAll(".tab-pane").stream().map(TabPane.class::cast)
|
||||
.filter(candidate -> candidate.getTabs().stream()
|
||||
.anyMatch(tab -> tab.getContent() == fixture.project().getContent())).findFirst().orElseThrow();
|
||||
double firstHeight = fixture.tabs().getHeight();
|
||||
double secondHeight = second.getHeight();
|
||||
DockLayoutView.Split before = (DockLayoutView.Split) manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().equals(new DockAreaId("tools"))).findFirst().orElseThrow().root();
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.setGroupCollapsed(first, true));
|
||||
assertTrue(fixture.tabs().getHeight() < firstHeight - 60,
|
||||
"The collapsed leaf retains only its header rail along the split axis");
|
||||
assertTrue(second.getHeight() > secondHeight + 60, "The sibling receives the released content space");
|
||||
DockLayoutView.Split collapsed = (DockLayoutView.Split) manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().equals(new DockAreaId("tools"))).findFirst().orElseThrow().root();
|
||||
assertEquals(before.position(), collapsed.position(), .001, "Published state remembers the expanded proportion");
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.setGroupCollapsed(first, false));
|
||||
assertEquals(firstHeight, fixture.tabs().getHeight(), 2);
|
||||
assertEquals(secondHeight, second.getHeight(), 2);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void anExplicitWidthIsComparedWithTheLiveDividerExtentAndProtectedAsGeometry() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixture();
|
||||
DockingManager manager = fixture.manager();
|
||||
DockGroupId tools = new DockGroupId("tools");
|
||||
dragRightBoundary(fixture, 100);
|
||||
assertEquals(300, fixture.tabs().getWidth(), 1);
|
||||
assertInstanceOf(ActionResult.Applied.class,
|
||||
manager.updateGroup(tools, DockGroupChanges.builder().preferredWidth(200).build()),
|
||||
"An explicit initial width still changes the user's resized live width");
|
||||
assertEquals(200, fixture.tabs().getWidth(), 1);
|
||||
dragRightBoundary(fixture, 100);
|
||||
var consent = new java.util.concurrent.CompletableFuture<CloseConsent>();
|
||||
Dockable editor = manager.findDockable(new DockableId("editor")).orElseThrow();
|
||||
editor.setCloseCheck(request -> consent);
|
||||
manager.requestTabClose(editor.getId());
|
||||
try {
|
||||
DockLayoutView before = manager.layout();
|
||||
ActionResult.Rejected rejected = assertInstanceOf(ActionResult.Rejected.class,
|
||||
manager.updateGroup(tools, DockGroupChanges.builder()
|
||||
.preferredWidth(200).splitDirections(SplitDirections.NONE).build()));
|
||||
assertEquals(DockFailure.Code.CLOSE_IN_PROGRESS, rejected.failure().code());
|
||||
assertEquals(before, manager.layout());
|
||||
assertEquals(300, fixture.tabs().getWidth(), 1);
|
||||
} finally {
|
||||
consent.complete(CloseConsent.VETO);
|
||||
}
|
||||
assertInstanceOf(ActionResult.Applied.class,
|
||||
manager.updateGroup(tools, DockGroupChanges.builder().preferredWidth(200).build()));
|
||||
assertEquals(200, fixture.tabs().getWidth(), 1);
|
||||
assertInstanceOf(ActionResult.NoChange.class,
|
||||
manager.updateGroup(tools, DockGroupChanges.builder().preferredWidth(200).build()));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void anOrdinaryWindowResizeKeepsACollapsedRailFixedAndGivesSpaceToItsSibling() throws Exception {
|
||||
var fixtureRef = new java.util.concurrent.atomic.AtomicReference<Fixture>();
|
||||
var siblingRef = new java.util.concurrent.atomic.AtomicReference<TabPane>();
|
||||
var resized = new java.util.concurrent.CountDownLatch(1);
|
||||
double[] before = new double[3];
|
||||
try {
|
||||
FxThread.onFx(() -> {
|
||||
javafx.application.Platform.setImplicitExit(false);
|
||||
Fixture fixture = fixture();
|
||||
fixtureRef.set(fixture);
|
||||
Stage stage = (Stage) fixture.pane().getScene().getWindow();
|
||||
stage.show();
|
||||
fixture.manager().move(fixture.project().getId(),
|
||||
DockTarget.split(new DockGroupId("tools"), Side.BOTTOM));
|
||||
TabPane sibling = fixture.pane().lookupAll(".tab-pane").stream().map(TabPane.class::cast)
|
||||
.filter(candidate -> candidate.getTabs().stream()
|
||||
.anyMatch(tab -> tab.getContent() == fixture.project().getContent())).findFirst().orElseThrow();
|
||||
siblingRef.set(sibling);
|
||||
fixture.manager().setGroupCollapsed(new DockGroupId("tools"), true);
|
||||
before[0] = fixture.tabs().getHeight();
|
||||
before[1] = sibling.getHeight();
|
||||
before[2] = stage.getScene().getHeight();
|
||||
stage.getScene().heightProperty().addListener((observable, old, current) -> {
|
||||
if (current.doubleValue() > before[2] + 60) resized.countDown();
|
||||
});
|
||||
stage.setHeight(stage.getHeight() + 120);
|
||||
});
|
||||
assertTrue(resized.await(5, java.util.concurrent.TimeUnit.SECONDS), "The native window resize reaches the Scene");
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixtureRef.get();
|
||||
fixture.pane().layout();
|
||||
assertEquals(before[0], fixture.tabs().getHeight(), 2,
|
||||
"Resizing a window does not expand the collapsed header rail");
|
||||
double addedHeight = fixture.pane().getScene().getHeight() - before[2];
|
||||
assertEquals(before[1] + addedHeight, siblingRef.get().getHeight(), 2);
|
||||
assertTrue(group(fixture.manager()).collapsed());
|
||||
});
|
||||
} finally {
|
||||
if (fixtureRef.get() != null) FxThread.onFx(() -> ((Stage) fixtureRef.get().pane().getScene().getWindow()).hide());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyTheSelectedOwnedContentIsVisibleAndNestedApplicationTabsRemainUntouched() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
Fixture fixture = fixture();
|
||||
DockingManager manager = fixture.manager();
|
||||
manager.activate(fixture.changes().getId());
|
||||
assertTrue(visibleThroughParents(fixture.changes().getContent()));
|
||||
assertFalse(visibleThroughParents(fixture.project().getContent()),
|
||||
"Selecting an earlier tab must not also show the newest tab");
|
||||
|
||||
TabPane applicationTabs = new TabPane(
|
||||
new javafx.scene.control.Tab("Application first", new TextArea("First")),
|
||||
new javafx.scene.control.Tab("Application second", new TextArea("Second")));
|
||||
applicationTabs.setStyle("-fx-font-size: 40px;");
|
||||
Dockable application = new Dockable(new DockableId("application"), applicationTabs);
|
||||
application.setTitle("Application");
|
||||
manager.open(application, DockTarget.area("tools"));
|
||||
var nestedVisibility = applicationTabs.getChildrenUnmodifiable().stream()
|
||||
.filter(node -> node.getStyleClass().contains("tab-content-area"))
|
||||
.collect(java.util.stream.Collectors.toMap(node -> node, javafx.scene.Node::isVisible));
|
||||
assertEquals(2, nestedVisibility.size());
|
||||
manager.activate(fixture.changes().getId());
|
||||
assertFalse(visibleThroughParents(applicationTabs));
|
||||
manager.setGroupCollapsed(new DockGroupId("tools"), true);
|
||||
assertFalse(visibleThroughParents(fixture.changes().getContent()));
|
||||
assertFalse(visibleThroughParents(fixture.project().getContent()));
|
||||
assertFalse(visibleThroughParents(applicationTabs));
|
||||
assertTrue(fixture.tabs().getWidth() < 50, "The rail uses its own header, not the application's large-font header");
|
||||
nestedVisibility.forEach((node, visible) -> assertEquals(visible, node.isVisible()));
|
||||
manager.setGroupCollapsed(new DockGroupId("tools"), false);
|
||||
assertTrue(visibleThroughParents(fixture.changes().getContent()));
|
||||
assertFalse(visibleThroughParents(fixture.project().getContent()));
|
||||
assertFalse(visibleThroughParents(applicationTabs));
|
||||
nestedVisibility.forEach((node, visible) -> assertEquals(visible, node.isVisible()));
|
||||
});
|
||||
}
|
||||
|
||||
private static void dragRightBoundary(Fixture fixture, double pixels) {
|
||||
javafx.scene.Node divider = fixture.pane().lookup(".dock-area-divider");
|
||||
for (var type : java.util.List.of(javafx.scene.input.MouseEvent.MOUSE_PRESSED,
|
||||
javafx.scene.input.MouseEvent.MOUSE_DRAGGED, javafx.scene.input.MouseEvent.MOUSE_RELEASED)) {
|
||||
double screenX = type == javafx.scene.input.MouseEvent.MOUSE_PRESSED ? 0 : -pixels;
|
||||
divider.fireEvent(new javafx.scene.input.MouseEvent(type, 0, 0, screenX, 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)));
|
||||
fixture.pane().layout();
|
||||
}
|
||||
}
|
||||
|
||||
private static DockLayoutView.Group group(DockingManager manager) {
|
||||
return manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().equals(new DockAreaId("tools"))).findFirst().orElseThrow().groups().getFirst();
|
||||
}
|
||||
|
||||
private static javafx.scene.Node header(TabPane tabs, DockableId id) {
|
||||
var tab = tabs.getTabs().stream().filter(candidate -> id.equals(candidate.getUserData())).findFirst().orElseThrow();
|
||||
return tabs.lookup("#" + tab.getId());
|
||||
}
|
||||
|
||||
private static boolean visibleThroughParents(javafx.scene.Node node) {
|
||||
for (javafx.scene.Node current = node; current != null; current = current.getParent()) {
|
||||
if (!current.isVisible()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void click(javafx.scene.Node header) {
|
||||
for (var type : java.util.List.of(javafx.scene.input.MouseEvent.MOUSE_PRESSED,
|
||||
javafx.scene.input.MouseEvent.MOUSE_RELEASED, javafx.scene.input.MouseEvent.MOUSE_CLICKED)) {
|
||||
header.fireEvent(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_PRESSED, false, false, false, false, true,
|
||||
new javafx.scene.input.PickResult(header, 0, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
private static Fixture fixture() {
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(new DockGroupDefinition("editors"));
|
||||
DockGroupDefinition tools = new DockGroupDefinition("tools");
|
||||
tools.setTabSide(Side.RIGHT);
|
||||
tools.setCollapsible(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());
|
||||
manager.open(new Dockable(new DockableId("editor"), new TextArea()), DockTarget.area("editors"));
|
||||
Dockable changes = new Dockable(new DockableId("changes"), new TextArea("Changed files"));
|
||||
changes.setTitle("Changed files");
|
||||
changes.setIcon(new Label("C"));
|
||||
manager.open(changes, DockTarget.area("tools"));
|
||||
Dockable project = new Dockable(new DockableId("project"), new TextArea("Project"));
|
||||
project.setTitle("Project");
|
||||
project.setIcon(new Label("P"));
|
||||
manager.open(project, DockTarget.area("tools"));
|
||||
TabPane tabs = pane.lookupAll(".tab-pane").stream().map(TabPane.class::cast)
|
||||
.filter(candidate -> candidate.getTabs().stream().anyMatch(tab -> tab.getContent() == project.getContent()))
|
||||
.findFirst().orElseThrow();
|
||||
return new Fixture(manager, pane, tabs, project, changes);
|
||||
}
|
||||
|
||||
private record Fixture(DockingManager manager, DockPane pane, TabPane tabs, Dockable project, Dockable changes) { }
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package de.neitzel.fx.view;
|
||||
|
||||
import de.neitzel.fx.docking.DockGroupDefinition;
|
||||
import de.neitzel.fx.docking.DockGroupId;
|
||||
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 javafx.application.Platform;
|
||||
import javafx.geometry.Bounds;
|
||||
import javafx.geometry.Side;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.input.KeyCode;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
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 static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/** A collapsed tool rail is a destination without opening merely for a preview. */
|
||||
class CollapsedDockDropTest {
|
||||
@BeforeAll
|
||||
static void startJavaFx() throws Exception {
|
||||
FxThread.start();
|
||||
FxThread.onFx(() -> Platform.setImplicitExit(false));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Side.class, names = {"LEFT", "RIGHT"})
|
||||
void aPreviewAndEscapeKeepTheRailCollapsedButDroppingOpensItsRememberedWidth(Side side) throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockLayout initial = new DockLayout();
|
||||
initial.setCenter(new DockGroupDefinition("editors"));
|
||||
DockGroupDefinition tools = new DockGroupDefinition("tools");
|
||||
tools.setCollapsible(true);
|
||||
tools.setTabSide(side);
|
||||
tools.setPreferredWidth(240);
|
||||
if (side == Side.LEFT) initial.setLeft(tools);
|
||||
else initial.setRight(tools);
|
||||
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());
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Unsaved notes"));
|
||||
notes.setTitle("Notes");
|
||||
Dockable project = new Dockable(new DockableId("project"), new TextArea("Project"));
|
||||
project.setTitle("Project");
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
manager.open(project, DockTarget.area("tools"));
|
||||
stage.show();
|
||||
try {
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
TabPane target = tabs(pane, project.getId());
|
||||
double expandedWidth = target.getWidth();
|
||||
manager.setGroupCollapsed(new DockGroupId("tools"), true);
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
DockLayoutView collapsed = manager.layout();
|
||||
assertTrue(group(manager).collapsed());
|
||||
assertTrue(target.getWidth() < expandedWidth / 2);
|
||||
Node sourceHeader = header(tabs(pane, notes.getId()), notes.getId());
|
||||
Node targetHeader = header(target, project.getId());
|
||||
Bounds from = sourceHeader.localToScreen(sourceHeader.getBoundsInLocal());
|
||||
Bounds into = targetHeader.localToScreen(targetHeader.getBoundsInLocal());
|
||||
mouse(sourceHeader, MouseEvent.MOUSE_PRESSED, from.getCenterX(), from.getCenterY(), true);
|
||||
mouse(sourceHeader, MouseEvent.MOUSE_DRAGGED, into.getCenterX(), into.getCenterY(), true);
|
||||
assertTrue(pane.lookup(".dock-drop-indicator").isVisible());
|
||||
assertEquals(collapsed, manager.layout());
|
||||
assertTrue(group(manager).collapsed());
|
||||
assertFalse(target.lookup(".tab-content-area").isVisible());
|
||||
stage.getScene().getRoot().fireEvent(new KeyEvent(KeyEvent.KEY_PRESSED, "", "", KeyCode.ESCAPE,
|
||||
false, false, false, false));
|
||||
assertFalse(pane.lookup(".dock-drop-indicator").isVisible());
|
||||
mouse(sourceHeader, MouseEvent.MOUSE_RELEASED, into.getCenterX(), into.getCenterY(), false);
|
||||
assertEquals(collapsed, manager.layout());
|
||||
assertTrue(group(manager).collapsed());
|
||||
|
||||
mouse(sourceHeader, MouseEvent.MOUSE_PRESSED, from.getCenterX(), from.getCenterY(), true);
|
||||
mouse(sourceHeader, MouseEvent.MOUSE_DRAGGED, into.getCenterX(), into.getCenterY(), true);
|
||||
mouse(sourceHeader, MouseEvent.MOUSE_RELEASED, into.getCenterX(), into.getCenterY(), false);
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
assertFalse(group(manager).collapsed());
|
||||
assertEquals(notes.getId(), group(manager).selectedDockableId());
|
||||
assertSame(notes, manager.activeDockable());
|
||||
assertSame(notes.getContent(), target.getSelectionModel().getSelectedItem().getContent());
|
||||
assertEquals(expandedWidth, target.getWidth(), 1);
|
||||
assertTrue(target.lookup(".tab-content-area").isVisible());
|
||||
assertTrue(notes.getContent().isVisible());
|
||||
} finally { stage.hide(); }
|
||||
});
|
||||
}
|
||||
|
||||
private static DockLayoutView.Group group(DockingManager manager) {
|
||||
return manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().value().equals("tools")).findFirst().orElseThrow().groups().getFirst();
|
||||
}
|
||||
|
||||
private static TabPane tabs(DockPane pane, DockableId id) {
|
||||
return pane.lookupAll(".tab-pane").stream().map(TabPane.class::cast)
|
||||
.filter(tabs -> tabs.getTabs().stream().anyMatch(tab -> id.equals(tab.getUserData())))
|
||||
.findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
private static Node header(TabPane tabs, DockableId id) {
|
||||
return tabs.lookup("#" + tabs.getTabs().stream().filter(tab -> id.equals(tab.getUserData()))
|
||||
.findFirst().orElseThrow().getId());
|
||||
}
|
||||
|
||||
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,425 @@
|
||||
package de.neitzel.fx.view;
|
||||
|
||||
import de.neitzel.fx.docking.ActionResult;
|
||||
import de.neitzel.fx.docking.DockGroupDefinition;
|
||||
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.MoveCheck;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Rectangle2D;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.IndexRange;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/** Window moves retain application content and can be inspected without creating a window. */
|
||||
class FloatDockablesTest {
|
||||
@BeforeAll
|
||||
static void startJavaFx() throws Exception {
|
||||
FxThread.start();
|
||||
FxThread.onFx(() -> Platform.setImplicitExit(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedWindowCustomizationLeavesLiveContentUntouchedAndDiscardsOnlyFactoryContent() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 800, 500));
|
||||
RuntimeException cause = new IllegalStateException("Window customization failed");
|
||||
DockingOptions options = new DockingOptions();
|
||||
options.setFloatingWindowCustomizer(configuration -> { throw cause; });
|
||||
DockingManager manager = DockingManager.attach(main, pane, options);
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Unsaved"));
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
var layout = manager.layout();
|
||||
var windows = List.copyOf(Window.getWindows());
|
||||
assertInstanceOf(MoveCheck.Allowed.class, manager.checkMove(notes.getId(), DockTarget.floating()));
|
||||
var moved = assertInstanceOf(ActionResult.Rejected.class, manager.move(notes.getId(), DockTarget.floating()));
|
||||
assertSame(cause, moved.failure().cause());
|
||||
assertSame(layout, manager.layout());
|
||||
assertSame(main, notes.getContent().getScene().getWindow());
|
||||
var discarded = new java.util.concurrent.atomic.AtomicInteger();
|
||||
var id = new DockableId("prepared");
|
||||
var opened = manager.open(id, () -> {
|
||||
Dockable prepared = new Dockable(id, new TextArea("Prepared"));
|
||||
prepared.setOnDiscarded(discarded::incrementAndGet);
|
||||
return prepared;
|
||||
}, DockTarget.floating());
|
||||
assertInstanceOf(ActionResult.Rejected.class, opened);
|
||||
assertEquals(1, discarded.get());
|
||||
assertTrue(manager.findDockable(id).isEmpty());
|
||||
assertSame(layout, manager.layout());
|
||||
assertEquals(windows, List.copyOf(Window.getWindows()));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void floatingGroupsCanSplitAndRejoinWithoutReplacingOrClosingTheirContents() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
Dockable first = new Dockable(new DockableId("first"), new TextArea("First unsaved"));
|
||||
Dockable second = new Dockable(new DockableId("second"), new TextArea("Second unsaved"));
|
||||
var closed = new java.util.concurrent.atomic.AtomicInteger();
|
||||
first.setOnClosed(closed::incrementAndGet);
|
||||
second.setOnClosed(closed::incrementAndGet);
|
||||
main.show();
|
||||
try {
|
||||
manager.open(first, DockTarget.floating());
|
||||
var group = manager.layout().windows().getLast().areas().getFirst().groups().getFirst().id();
|
||||
manager.open(second, DockTarget.group(group));
|
||||
Window owner = first.getContent().getScene().getWindow();
|
||||
assertInstanceOf(ActionResult.Applied.class,
|
||||
manager.move(second.getId(), DockTarget.split(group, javafx.geometry.Side.RIGHT)));
|
||||
var area = manager.layout().windows().getLast().areas().getFirst();
|
||||
assertInstanceOf(de.neitzel.fx.docking.DockLayoutView.Split.class, area.root());
|
||||
assertEquals(2, area.groups().size());
|
||||
assertSame(owner, second.getContent().getScene().getWindow());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(second.getId(), DockTarget.group(group)));
|
||||
var joined = manager.layout().windows().getLast().areas().getFirst();
|
||||
assertEquals(1, joined.groups().size());
|
||||
assertEquals(List.of(first.getId(), second.getId()), joined.groups().getFirst().dockableIds());
|
||||
assertSame(first.getContent(), manager.findDockable(first.getId()).orElseThrow().getContent());
|
||||
assertEquals("Second unsaved", ((TextArea) second.getContent()).getText());
|
||||
assertEquals(0, closed.get());
|
||||
} finally {
|
||||
for (Window window : List.copyOf(Window.getWindows())) if (!existing.contains(window)) window.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidFloatingGeometryIsRejectedWithoutAllocatingAWindow() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Unsaved"));
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
var before = manager.layout();
|
||||
for (Rectangle2D bounds : List.of(new Rectangle2D(0, 0, 0, 100),
|
||||
new Rectangle2D(Double.NaN, 0, 100, 100),
|
||||
new Rectangle2D(0, 0, Double.POSITIVE_INFINITY, 100))) {
|
||||
var rejected = assertInstanceOf(MoveCheck.Rejected.class,
|
||||
manager.checkMove(notes.getId(), DockTarget.floating(bounds)));
|
||||
assertEquals(de.neitzel.fx.docking.DockFailure.Code.INVALID_WINDOW_BOUNDS, rejected.failure().code());
|
||||
assertInstanceOf(ActionResult.Rejected.class, manager.move(notes.getId(), DockTarget.floating(bounds)));
|
||||
assertSame(before, manager.layout());
|
||||
assertSame(main, notes.getContent().getScene().getWindow());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkedDetachmentAndReturnKeepTheLiveEditorAndSelection() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
TextArea notes = new TextArea("Edited without saving");
|
||||
Dockable editor = new Dockable(new DockableId("notes"), notes);
|
||||
editor.setTitle("Notes");
|
||||
manager.open(editor, DockTarget.area("editors"));
|
||||
main.show();
|
||||
try {
|
||||
notes.selectRange(2, 8);
|
||||
var before = manager.layout();
|
||||
int windows = Window.getWindows().size();
|
||||
DockTarget floating = DockTarget.floating(new Rectangle2D(150, 150, 520, 360));
|
||||
assertInstanceOf(MoveCheck.Allowed.class, manager.checkMove(editor.getId(), floating));
|
||||
assertSame(before, manager.layout());
|
||||
assertEquals(windows, Window.getWindows().size());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(editor.getId(), floating));
|
||||
Window detached = notes.getScene().getWindow();
|
||||
assertNotSame(main, detached);
|
||||
assertTrue(detached.isShowing());
|
||||
assertEquals(2, manager.layout().windows().size());
|
||||
assertEquals("Edited without saving", notes.getText());
|
||||
assertEquals(new IndexRange(2, 8), notes.getSelection());
|
||||
assertSame(editor, manager.activeDockable());
|
||||
assertSame(notes, manager.findDockable(editor.getId()).orElseThrow().getContent());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(editor.getId(), DockTarget.returnToMain()));
|
||||
assertSame(main, notes.getScene().getWindow());
|
||||
assertFalse(detached.isShowing());
|
||||
assertEquals(1, manager.layout().windows().size());
|
||||
assertEquals(new IndexRange(2, 8), notes.getSelection());
|
||||
assertEquals("Edited without saving", notes.getText());
|
||||
} finally {
|
||||
for (Window window : List.copyOf(Window.getWindows())) {
|
||||
if (!existing.contains(window)) window.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void mainWindowOnlyContentCannotCreateOrEnterAFloatingWindow() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Notes"));
|
||||
Dockable project = new Dockable(new DockableId("project"), new TextArea("Project"));
|
||||
project.setMainWindowOnly(true);
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
manager.open(project, DockTarget.area("editors"));
|
||||
main.show();
|
||||
try {
|
||||
var before = manager.layout();
|
||||
assertInstanceOf(MoveCheck.Rejected.class, manager.checkMove(project.getId(), DockTarget.floating()));
|
||||
assertInstanceOf(ActionResult.Rejected.class, manager.move(project.getId(), DockTarget.floating()));
|
||||
assertSame(before, manager.layout());
|
||||
assertEquals(1, manager.layout().windows().size());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(notes.getId(), DockTarget.floating()));
|
||||
var floatingGroup = manager.layout().windows().stream().filter(window -> !window.main())
|
||||
.findFirst().orElseThrow().areas().getFirst().groups().getFirst();
|
||||
var target = DockTarget.group(floatingGroup.id());
|
||||
assertInstanceOf(MoveCheck.Rejected.class, manager.checkMove(project.getId(), target));
|
||||
assertInstanceOf(ActionResult.Rejected.class, manager.move(project.getId(), target));
|
||||
assertSame(main, project.getContent().getScene().getWindow());
|
||||
Dockable another = new Dockable(new DockableId("another-project"), new TextArea("Another project"));
|
||||
another.setMainWindowOnly(true);
|
||||
assertInstanceOf(ActionResult.Rejected.class, manager.open(another, DockTarget.floating()));
|
||||
assertTrue(manager.findDockable(another.getId()).isEmpty());
|
||||
} finally {
|
||||
for (Window window : List.copyOf(Window.getWindows())) {
|
||||
if (!existing.contains(window)) window.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void floatingCustomizationAndLiveContentAreReadyBeforeTheWindowAppears() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 800, 500));
|
||||
var icon = new javafx.scene.image.WritableImage(1, 1);
|
||||
String stylesheet = getClass().getResource("floating-window.css").toExternalForm();
|
||||
var customized = new java.util.concurrent.atomic.AtomicInteger();
|
||||
DockingOptions options = new DockingOptions();
|
||||
options.setFloatingWindowCustomizer(configuration -> {
|
||||
customized.incrementAndGet();
|
||||
assertTrue(Window.getWindows().stream().allMatch(window -> existing.contains(window) || window == main));
|
||||
configuration.setTitle("Floating editor");
|
||||
configuration.getIcons().add(icon);
|
||||
configuration.getStylesheets().add(stylesheet);
|
||||
});
|
||||
DockingManager manager = DockingManager.attach(main, pane, options);
|
||||
TextArea notes = new TextArea("Edited without saving");
|
||||
Dockable editor = new Dockable(new DockableId("notes"), notes);
|
||||
manager.open(editor, DockTarget.area("editors"));
|
||||
main.show();
|
||||
var appearedWithContent = new java.util.concurrent.atomic.AtomicBoolean();
|
||||
javafx.collections.ListChangeListener<Window> shown = change -> {
|
||||
while (change.next()) {
|
||||
for (Window window : change.getAddedSubList()) {
|
||||
if (window != main && !existing.contains(window)) {
|
||||
appearedWithContent.set(notes.getScene() == window.getScene());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Window.getWindows().addListener(shown);
|
||||
try {
|
||||
assertInstanceOf(MoveCheck.Allowed.class, manager.checkMove(editor.getId(), DockTarget.floating()));
|
||||
assertEquals(0, customized.get());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(editor.getId(), DockTarget.floating()));
|
||||
Stage floating = (Stage) notes.getScene().getWindow();
|
||||
assertEquals(1, customized.get());
|
||||
assertEquals("Floating editor", floating.getTitle());
|
||||
assertEquals(List.of(icon), floating.getIcons());
|
||||
assertEquals(List.of(stylesheet), floating.getScene().getStylesheets());
|
||||
assertTrue(appearedWithContent.get(), "A floating window must appear with its prepared content");
|
||||
} finally {
|
||||
Window.getWindows().removeListener(shown);
|
||||
for (Window window : List.copyOf(Window.getWindows())) {
|
||||
if (!existing.contains(window)) window.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void returningUsesThePreviousRelativeTabPosition() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Notes"));
|
||||
Dockable readme = new Dockable(new DockableId("readme"), new TextArea("Readme"));
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
manager.open(readme, DockTarget.area("editors"));
|
||||
main.show();
|
||||
try {
|
||||
manager.move(notes.getId(), DockTarget.floating());
|
||||
manager.move(notes.getId(), DockTarget.returnToMain());
|
||||
assertEquals(List.of(notes.getId(), readme.getId()), manager.layout().windows().getFirst()
|
||||
.areas().getFirst().groups().getFirst().dockableIds());
|
||||
} finally {
|
||||
for (Window window : List.copyOf(Window.getWindows())) {
|
||||
if (!existing.contains(window)) window.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void returningFindsTheOriginalAreaAfterItsConcreteSplitGroupDisappears() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
DockGroupDefinition tools = new DockGroupDefinition("tools");
|
||||
tools.setPreferredWidth(400);
|
||||
pane.getInitialLayout().setRight(tools);
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 1000, 600));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Notes"));
|
||||
Dockable anchor = new Dockable(new DockableId("anchor"), new TextArea("Anchor"));
|
||||
manager.open(anchor, DockTarget.area("tools"));
|
||||
manager.open(notes, DockTarget.area("tools"));
|
||||
main.show();
|
||||
try {
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(notes.getId(),
|
||||
DockTarget.split(new de.neitzel.fx.docking.DockGroupId("tools"), javafx.geometry.Side.BOTTOM)));
|
||||
manager.move(notes.getId(), DockTarget.floating());
|
||||
assertEquals(1, manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().value().equals("tools")).findFirst().orElseThrow().groups().size());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(notes.getId(), DockTarget.returnToMain()));
|
||||
var returned = manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().value().equals("tools")).findFirst().orElseThrow();
|
||||
assertEquals(List.of(anchor.getId(), notes.getId()), returned.groups().getFirst().dockableIds());
|
||||
} finally {
|
||||
for (Window window : List.copyOf(Window.getWindows())) {
|
||||
if (!existing.contains(window)) window.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnUsesTheCapturedFallbackAndKeepsFloatingWhenNeitherTargetAcceptsIt() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
pane.getInitialLayout().setLeft(new DockGroupDefinition("return-place"));
|
||||
pane.getInitialLayout().setRight(new DockGroupDefinition("tools"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 1000, 600));
|
||||
var allowTools = new java.util.concurrent.atomic.AtomicBoolean(true);
|
||||
var allowFallback = new java.util.concurrent.atomic.AtomicBoolean(true);
|
||||
DockingOptions options = new DockingOptions();
|
||||
options.setFallbackTarget(DockTarget.area("return-place"));
|
||||
options.setPlacementRule((dockable, destination) -> {
|
||||
if (destination instanceof de.neitzel.fx.docking.ResolvedDockTarget.Insertion insertion
|
||||
&& ((!allowTools.get() && insertion.groupId().value().equals("tools"))
|
||||
|| (!allowFallback.get() && insertion.groupId().value().equals("return-place")))) {
|
||||
return java.util.Optional.of(new de.neitzel.fx.docking.DockFailure(
|
||||
de.neitzel.fx.docking.DockFailure.Code.PLACEMENT_REJECTED, dockable.getId(), "Destination disabled", null));
|
||||
}
|
||||
return java.util.Optional.empty();
|
||||
});
|
||||
DockingManager manager = DockingManager.attach(main, pane, options);
|
||||
options.setFallbackTarget(DockTarget.area("editors"));
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Notes"));
|
||||
manager.open(notes, DockTarget.area("tools"));
|
||||
main.show();
|
||||
try {
|
||||
manager.move(notes.getId(), DockTarget.floating());
|
||||
allowTools.set(false);
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(notes.getId(), DockTarget.returnToMain()));
|
||||
var fallback = manager.layout().windows().getFirst().areas().stream()
|
||||
.filter(area -> area.id().value().equals("return-place")).findFirst().orElseThrow();
|
||||
assertEquals(List.of(notes.getId()), fallback.groups().getFirst().dockableIds());
|
||||
manager.move(notes.getId(), DockTarget.floating());
|
||||
allowFallback.set(false);
|
||||
var before = manager.layout();
|
||||
Window floating = notes.getContent().getScene().getWindow();
|
||||
assertInstanceOf(MoveCheck.Rejected.class, manager.checkMove(notes.getId(), DockTarget.returnToMain()));
|
||||
assertInstanceOf(ActionResult.Rejected.class, manager.move(notes.getId(), DockTarget.returnToMain()));
|
||||
assertSame(before, manager.layout());
|
||||
assertSame(floating, notes.getContent().getScene().getWindow());
|
||||
assertTrue(floating.isShowing());
|
||||
} finally {
|
||||
for (Window window : List.copyOf(Window.getWindows())) {
|
||||
if (!existing.contains(window)) window.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(booleans = {false, true})
|
||||
void aMoveCheckFitsRequestedFloatingBoundsToAnAvailableScreen(boolean tinyFrame) throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Notes"));
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
main.show();
|
||||
try {
|
||||
Rectangle2D available = javafx.stage.Screen.getPrimary().getVisualBounds();
|
||||
Rectangle2D requested = tinyFrame ? new Rectangle2D(available.getMaxX() - 1, available.getMaxY() - 1, 1, 1)
|
||||
: new Rectangle2D(available.getMinX() - 10000, available.getMinY() - 10000,
|
||||
available.getWidth() + 100, available.getHeight() + 100);
|
||||
MoveCheck.Allowed allowed = assertInstanceOf(MoveCheck.Allowed.class,
|
||||
manager.checkMove(notes.getId(), DockTarget.floating(requested)));
|
||||
var target = assertInstanceOf(de.neitzel.fx.docking.ResolvedDockTarget.Detachment.class, allowed.destination());
|
||||
assertEquals(tinyFrame ? requested : available, target.bounds());
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.move(notes.getId(), DockTarget.floating(requested)));
|
||||
Window floating = notes.getContent().getScene().getWindow();
|
||||
assertTrue(floating.getX() >= available.getMinX() - 1);
|
||||
assertTrue(floating.getY() >= available.getMinY() - 1);
|
||||
assertTrue(floating.getX() + floating.getWidth() <= available.getMaxX() + 1);
|
||||
assertTrue(floating.getY() + floating.getHeight() <= available.getMaxY() + 1);
|
||||
} finally {
|
||||
for (Window window : List.copyOf(Window.getWindows())) {
|
||||
if (!existing.contains(window)) window.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package de.neitzel.fx.view;
|
||||
|
||||
import de.neitzel.fx.docking.DockGroupDefinition;
|
||||
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.scene.Scene;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.Menu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
|
||||
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/** Real keyboard input after tab-menu transfers; run only with an exclusive desktop slot. */
|
||||
@EnabledIfSystemProperty(named = "neitzellib.nativeFocusTest", matches = "true")
|
||||
class FloatingNativeFocusTest {
|
||||
private static final int[] DIGITS = {KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_3, KeyEvent.VK_4};
|
||||
|
||||
@BeforeAll
|
||||
static void startJavaFx() throws Exception {
|
||||
FxThread.start();
|
||||
FxThread.onFx(() -> Platform.setImplicitExit(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(20)
|
||||
void nativeTypingContinuesWithoutClicksAfterFloatCrossWindowMoveAndReturn() throws Exception {
|
||||
Robot robot = new Robot();
|
||||
robot.setAutoDelay(20);
|
||||
Fixture fixture = fixture();
|
||||
AtomicReference<Stage> firstFloating = new AtomicReference<>();
|
||||
try {
|
||||
typeIntoFocusedNotes(robot, fixture, KeyEvent.VK_1, "1");
|
||||
FxThread.onFx(() -> {
|
||||
command(fixture.notes, "Float", null);
|
||||
firstFloating.set((Stage) fixture.notes.getScene().getWindow());
|
||||
assertNotSame(fixture.main, firstFloating.get());
|
||||
assertNotSame(fixture.other, firstFloating.get());
|
||||
});
|
||||
typeIntoFocusedNotes(robot, fixture, KeyEvent.VK_2, "12");
|
||||
|
||||
FxThread.onFx(() -> {
|
||||
command(fixture.notes, "Move to", "Readme");
|
||||
assertSame(fixture.other, fixture.notes.getScene().getWindow());
|
||||
assertFalse(firstFloating.get().isShowing(), "The emptied source window is removed");
|
||||
});
|
||||
typeIntoFocusedNotes(robot, fixture, KeyEvent.VK_3, "123");
|
||||
|
||||
FxThread.onFx(() -> {
|
||||
command(fixture.notes, "Return to main", null);
|
||||
assertSame(fixture.main, fixture.notes.getScene().getWindow());
|
||||
});
|
||||
typeIntoFocusedNotes(robot, fixture, KeyEvent.VK_4, "1234");
|
||||
FxThread.onFx(() -> {
|
||||
assertEquals("untouched", fixture.readme.getText());
|
||||
assertSame(fixture.notes, fixture.manager.findDockable(new DockableId("notes")).orElseThrow().getContent());
|
||||
assertEquals(new DockableId("notes"), fixture.manager.activeDockable().getId());
|
||||
});
|
||||
} finally {
|
||||
for (int key : DIGITS) robot.keyRelease(key);
|
||||
FxThread.onFx(() -> {
|
||||
if (firstFloating.get() != null) firstFloating.get().hide();
|
||||
fixture.other.hide();
|
||||
fixture.main.hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void typeIntoFocusedNotes(Robot robot, Fixture fixture, int key, String expected) throws Exception {
|
||||
// Observe focus only. Do not repair it with a click, activate(), or requestFocus().
|
||||
await(() -> fixture.notes.getScene().getWindow().isFocused()
|
||||
&& fixture.notes.getScene().getFocusOwner() == fixture.notes, "Transferred editor did not receive native window focus");
|
||||
try { robot.keyPress(key); }
|
||||
finally { robot.keyRelease(key); }
|
||||
await(() -> expected.equals(fixture.notes.getText()), "Native input did not reach the transferred editor: " + expected);
|
||||
FxThread.onFx(() -> {
|
||||
assertEquals(expected, fixture.notes.getText());
|
||||
assertEquals("untouched", fixture.readme.getText());
|
||||
assertSame(fixture.notes, fixture.notes.getScene().getFocusOwner());
|
||||
});
|
||||
}
|
||||
|
||||
private static void await(BooleanSupplier condition, String failure) throws Exception {
|
||||
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(3);
|
||||
AtomicReference<Boolean> ready = new AtomicReference<>(false);
|
||||
do {
|
||||
Thread.sleep(25);
|
||||
FxThread.onFx(() -> ready.set(condition.getAsBoolean()));
|
||||
} while (!ready.get() && System.nanoTime() < deadline);
|
||||
assertTrue(ready.get(), failure);
|
||||
}
|
||||
|
||||
private static void command(TextArea content, String label, String childTitle) {
|
||||
ContextMenu menu = content.getScene().getRoot().lookupAll(".tab-pane").stream().map(TabPane.class::cast)
|
||||
.flatMap(tabs -> tabs.getTabs().stream()).filter(tab -> tab.getContent() == content)
|
||||
.findFirst().orElseThrow().getContextMenu();
|
||||
Stage owner = (Stage) content.getScene().getWindow();
|
||||
menu.show(owner, owner.getX() + 60, owner.getY() + 60);
|
||||
try {
|
||||
MenuItem action = menu.getItems().stream().filter(item -> item.getText().equals(label)).findFirst().orElseThrow();
|
||||
if (childTitle != null) action = ((Menu) action).getItems().stream()
|
||||
.filter(item -> item.getText().contains(childTitle)).findFirst().orElseThrow();
|
||||
assertFalse(action.isDisable());
|
||||
menu.hide();
|
||||
action.fire();
|
||||
} finally { menu.hide(); }
|
||||
}
|
||||
|
||||
private static Fixture fixture() throws Exception {
|
||||
AtomicReference<Fixture> result = new AtomicReference<>();
|
||||
FxThread.onFx(() -> {
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
TextArea notes = new TextArea();
|
||||
TextArea readme = new TextArea("untouched");
|
||||
Dockable editor = new Dockable(new DockableId("notes"), notes);
|
||||
editor.setTitle("Notes");
|
||||
Dockable other = new Dockable(new DockableId("readme"), readme);
|
||||
other.setTitle("Readme");
|
||||
manager.open(editor, DockTarget.area("editors"));
|
||||
manager.open(other, DockTarget.area("editors"));
|
||||
main.show();
|
||||
manager.move(other.getId(), DockTarget.floating());
|
||||
Stage floating = (Stage) readme.getScene().getWindow();
|
||||
manager.activate(editor.getId()); // Initial setup only; all later focus must follow the transfer itself.
|
||||
result.set(new Fixture(main, floating, manager, notes, readme));
|
||||
});
|
||||
return result.get();
|
||||
}
|
||||
|
||||
private record Fixture(Stage main, Stage other, DockingManager manager, TextArea notes, TextArea readme) { }
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package de.neitzel.fx.view;
|
||||
|
||||
import de.neitzel.fx.docking.ActionResult;
|
||||
import de.neitzel.fx.docking.DockAreaId;
|
||||
import de.neitzel.fx.docking.DockFailure;
|
||||
import de.neitzel.fx.docking.DockGroupDefinition;
|
||||
import de.neitzel.fx.docking.DockGroupId;
|
||||
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.MoveCheck;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Side;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/** Manager ownership and destination identity remain stable when windows and groups change. */
|
||||
class FloatingOwnershipTest {
|
||||
@BeforeAll
|
||||
static void startJavaFx() throws Exception {
|
||||
FxThread.start();
|
||||
FxThread.onFx(() -> Platform.setImplicitExit(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFloatingWindowCannotBeAttachedToASecondManager() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
try (Fixture fixture = fixture("editors", null)) {
|
||||
Dockable notes = fixture.open("notes", "editors");
|
||||
assertInstanceOf(ActionResult.Applied.class, fixture.manager.move(notes.getId(), DockTarget.floating()));
|
||||
Stage floating = (Stage) notes.getContent().getScene().getWindow();
|
||||
DockPane floatingPane = assertInstanceOf(DockPane.class, floating.getScene().getRoot());
|
||||
DockLayoutView before = fixture.manager.layout();
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> DockingManager.attach(floating, floatingPane, new DockingOptions()));
|
||||
assertSame(before, fixture.manager.layout());
|
||||
assertSame(floating, notes.getContent().getScene().getWindow());
|
||||
assertSame(notes, fixture.manager.findDockable(notes.getId()).orElseThrow());
|
||||
assertInstanceOf(ActionResult.Applied.class,
|
||||
fixture.manager.move(notes.getId(), DockTarget.returnToMain()));
|
||||
assertSame(fixture.main, notes.getContent().getScene().getWindow());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void aRetiredConcreteGroupIdNeverTargetsANewFloatingOrSplitGroup(boolean floating) throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
DockGroupDefinition temporary = new DockGroupDefinition("group-1");
|
||||
temporary.setPersistent(false);
|
||||
try (Fixture fixture = fixture("editors", temporary)) {
|
||||
Dockable anchor = fixture.open("anchor", "editors");
|
||||
Dockable notes = fixture.open("notes", "group-1");
|
||||
DockGroupId retired = new DockGroupId("group-1");
|
||||
assertInstanceOf(ActionResult.Applied.class,
|
||||
fixture.manager.move(notes.getId(), DockTarget.area("editors")));
|
||||
assertMissingGroup(fixture.manager, anchor.getId(), retired);
|
||||
|
||||
DockTarget destination = floating ? DockTarget.floating()
|
||||
: DockTarget.split(new DockGroupId("editors"), Side.RIGHT);
|
||||
assertInstanceOf(ActionResult.Applied.class, fixture.manager.move(notes.getId(), destination));
|
||||
DockGroupId allocated = fixture.manager.layout().windows().stream()
|
||||
.flatMap(window -> window.areas().stream()).flatMap(area -> area.groups().stream())
|
||||
.filter(group -> group.dockableIds().contains(notes.getId())).findFirst().orElseThrow().id();
|
||||
assertNotEquals(retired, allocated, "A stale concrete destination must not acquire a new meaning");
|
||||
assertMissingGroup(fixture.manager, anchor.getId(), retired);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void aGeneratedFloatingAreaDoesNotShadowAnInitialAreaWithTheSameName() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
try (Fixture fixture = fixture("floating-1", null)) {
|
||||
Dockable notes = fixture.open("notes", "floating-1");
|
||||
assertInstanceOf(ActionResult.Applied.class, fixture.manager.move(notes.getId(), DockTarget.floating()));
|
||||
DockLayoutView.Window floating = fixture.manager.layout().windows().stream()
|
||||
.filter(window -> !window.main()).findFirst().orElseThrow();
|
||||
assertNotEquals(new DockAreaId("floating-1"), floating.areas().getFirst().id());
|
||||
Dockable readme = fixture.open("readme", "floating-1");
|
||||
assertSame(fixture.main, readme.getContent().getScene().getWindow(),
|
||||
"The application's original area target must still select the main window");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void assertMissingGroup(DockingManager manager, DockableId id, DockGroupId group) {
|
||||
MoveCheck.Rejected rejected = assertInstanceOf(MoveCheck.Rejected.class,
|
||||
manager.checkMove(id, DockTarget.group(group)));
|
||||
assertEquals(DockFailure.Code.TARGET_NOT_FOUND, rejected.failure().code());
|
||||
}
|
||||
|
||||
private static Fixture fixture(String centerId, DockGroupDefinition right) {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition(centerId));
|
||||
pane.getInitialLayout().setRight(right);
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 900, 600));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
main.show();
|
||||
return new Fixture(main, manager, existing);
|
||||
}
|
||||
|
||||
private record Fixture(Stage main, DockingManager manager, List<Window> existing) implements AutoCloseable {
|
||||
Dockable open(String id, String area) {
|
||||
Dockable dockable = new Dockable(new DockableId(id), new TextArea(id));
|
||||
assertInstanceOf(ActionResult.Applied.class, manager.open(dockable, DockTarget.area(area)));
|
||||
return dockable;
|
||||
}
|
||||
|
||||
@Override public void close() {
|
||||
for (Window window : List.copyOf(Window.getWindows())) {
|
||||
if (!existing.contains(window)) window.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
package de.neitzel.fx.view;
|
||||
|
||||
import de.neitzel.fx.docking.DockGroupDefinition;
|
||||
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.scene.Scene;
|
||||
import javafx.scene.control.ContextMenu;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.Menu;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
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;
|
||||
|
||||
/** Floating commands are exercised through visible tab menus and public layout state. */
|
||||
class FloatingTabsByMenuTest {
|
||||
@BeforeAll
|
||||
static void startJavaFx() throws Exception {
|
||||
FxThread.start();
|
||||
FxThread.onFx(() -> Platform.setImplicitExit(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tabMenusFloatAndReturnTheSameEditorWithoutLosingItsSelection() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 760, 420));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
TextArea content = new TextArea("Unsaved notes survive a transfer");
|
||||
Dockable notes = new Dockable(new DockableId("notes"), content);
|
||||
notes.setTitle("Notes");
|
||||
AtomicInteger closed = new AtomicInteger();
|
||||
notes.setOnClosed(closed::incrementAndGet);
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
main.show();
|
||||
ContextMenu menu = null;
|
||||
try {
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
content.selectRange(8, 13);
|
||||
menu = tab(content).getContextMenu();
|
||||
menu.show(main, main.getX() + 80, main.getY() + 80);
|
||||
MenuItem floatItem = item(menu, "Float");
|
||||
assertFalse(floatItem.isDisable());
|
||||
assertEquals(1, manager.layout().windows().size(), "Opening a menu must not create a window");
|
||||
menu.hide();
|
||||
floatItem.fire();
|
||||
|
||||
assertEquals(2, manager.layout().windows().size());
|
||||
Window floating = content.getScene().getWindow();
|
||||
assertNotSame(main, floating);
|
||||
assertTrue(floating.isShowing());
|
||||
assertSame(content, manager.findDockable(notes.getId()).orElseThrow().getContent());
|
||||
assertEquals("Unsaved notes survive a transfer", content.getText());
|
||||
assertEquals("notes", content.getSelectedText());
|
||||
assertSame(content, content.getScene().getFocusOwner());
|
||||
|
||||
menu = tab(content).getContextMenu();
|
||||
menu.show(floating, floating.getX() + 80, floating.getY() + 80);
|
||||
MenuItem returnItem = item(menu, "Return to main");
|
||||
assertFalse(returnItem.isDisable());
|
||||
menu.hide();
|
||||
returnItem.fire();
|
||||
|
||||
assertEquals(1, manager.layout().windows().size());
|
||||
assertFalse(floating.isShowing());
|
||||
assertSame(main, content.getScene().getWindow());
|
||||
assertEquals("notes", content.getSelectedText());
|
||||
assertSame(content, main.getScene().getFocusOwner());
|
||||
assertSame(notes, manager.activeDockable());
|
||||
assertEquals(0, closed.get(), "Moving an editor must not close its resources");
|
||||
} finally {
|
||||
if (menu != null) menu.hide();
|
||||
List.copyOf(Window.getWindows()).stream().filter(window -> !existing.contains(window)).forEach(Window::hide);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void theMoveMenuOffersAnotherFloatingWindowsGroup() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 760, 420));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
TextArea notesContent = new TextArea("Unsaved notes");
|
||||
TextArea readmeContent = new TextArea("Readme");
|
||||
Dockable notes = new Dockable(new DockableId("notes"), notesContent);
|
||||
notes.setTitle("Notes");
|
||||
Dockable readme = new Dockable(new DockableId("readme"), readmeContent);
|
||||
readme.setTitle("Readme");
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
manager.open(readme, DockTarget.area("editors"));
|
||||
main.show();
|
||||
ContextMenu menu = null;
|
||||
try {
|
||||
manager.move(notes.getId(), DockTarget.floating());
|
||||
manager.move(readme.getId(), DockTarget.floating());
|
||||
Window source = notesContent.getScene().getWindow();
|
||||
Window destination = readmeContent.getScene().getWindow();
|
||||
notesContent.selectRange(8, 13);
|
||||
menu = tab(notesContent).getContextMenu();
|
||||
menu.show(source, source.getX() + 80, source.getY() + 80);
|
||||
Menu destinations = (Menu) item(menu, "Move to");
|
||||
MenuItem readmeTarget = destinations.getItems().stream()
|
||||
.filter(candidate -> candidate.getText().contains("Readme")).findFirst().orElseThrow();
|
||||
assertFalse(readmeTarget.isDisable());
|
||||
menu.hide();
|
||||
readmeTarget.fire();
|
||||
assertFalse(source.isShowing());
|
||||
assertEquals(2, manager.layout().windows().size());
|
||||
assertSame(destination, notesContent.getScene().getWindow());
|
||||
assertEquals("notes", notesContent.getSelectedText());
|
||||
assertSame(notesContent, destination.getScene().getFocusOwner());
|
||||
assertSame(notes, manager.activeDockable());
|
||||
} finally {
|
||||
if (menu != null) menu.hide();
|
||||
List.copyOf(Window.getWindows()).stream().filter(window -> !existing.contains(window)).forEach(Window::hide);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMainWindowOnlyTabExplainsItsDisabledFloatingCommands() throws Exception {
|
||||
FxThread.onFx(() -> {
|
||||
List<Window> existing = List.copyOf(Window.getWindows());
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 760, 420));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
TextArea projectContent = new TextArea("Project");
|
||||
Dockable project = new Dockable(new DockableId("project"), projectContent);
|
||||
project.setTitle("Project");
|
||||
project.setMainWindowOnly(true);
|
||||
Dockable readme = new Dockable(new DockableId("readme"), new TextArea("Readme"));
|
||||
readme.setTitle("Readme");
|
||||
manager.open(project, DockTarget.area("editors"));
|
||||
manager.open(readme, DockTarget.area("editors"));
|
||||
main.show();
|
||||
ContextMenu menu = null;
|
||||
try {
|
||||
manager.move(readme.getId(), DockTarget.floating());
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
var before = manager.layout();
|
||||
menu = tab(projectContent).getContextMenu();
|
||||
menu.show(main, main.getX() + 80, main.getY() + 80);
|
||||
MenuItem floatItem = item(menu, "Float");
|
||||
assertTrue(floatItem.isDisable());
|
||||
assertTrue(floatItem.getText().contains("main window"));
|
||||
Menu destinations = (Menu) item(menu, "Move to");
|
||||
MenuItem floatingTarget = destinations.getItems().stream()
|
||||
.filter(candidate -> candidate.getText().contains("Readme")).findFirst().orElseThrow();
|
||||
assertTrue(floatingTarget.isDisable());
|
||||
assertTrue(floatingTarget.getText().contains("main window"));
|
||||
assertEquals(before, manager.layout(), "Opening the menu only checks destinations");
|
||||
assertSame(main, projectContent.getScene().getWindow());
|
||||
} finally {
|
||||
if (menu != null) menu.hide();
|
||||
List.copyOf(Window.getWindows()).stream().filter(window -> !existing.contains(window)).forEach(Window::hide);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static Tab tab(TextArea content) {
|
||||
return content.getScene().getRoot().lookupAll(".tab-pane").stream().map(TabPane.class::cast)
|
||||
.flatMap(tabs -> tabs.getTabs().stream()).filter(tab -> tab.getContent() == content)
|
||||
.findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
private static MenuItem item(ContextMenu menu, String label) {
|
||||
MenuItem item = menu.getItems().stream().filter(candidate -> candidate.getText().startsWith(label))
|
||||
.findFirst().orElse(null);
|
||||
assertNotNull(item, "Expected tab command: " + label);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
package de.neitzel.fx.view;
|
||||
|
||||
import de.neitzel.fx.docking.DockGroupDefinition;
|
||||
import de.neitzel.fx.docking.DockGroupChanges;
|
||||
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 javafx.application.Platform;
|
||||
import javafx.geometry.Rectangle2D;
|
||||
import javafx.geometry.Side;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.SplitPane;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
|
||||
|
||||
import java.awt.MouseInfo;
|
||||
import java.awt.Point;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
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.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/** Public geometry observations; native pointer movement requires an exclusive desktop opt-in. */
|
||||
class FloatingWindowGeometryTest {
|
||||
@BeforeAll
|
||||
static void startJavaFx() throws Exception {
|
||||
FxThread.start();
|
||||
FxThread.onFx(() -> Platform.setImplicitExit(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theLayoutExposesFloatingBoundsAndLeavesMainWindowGeometryToTheApplication() throws Exception {
|
||||
Fixture fixture = fixture();
|
||||
try {
|
||||
FxThread.onFx(() -> {
|
||||
assertNull(fixture.manager.layout().windows().stream().filter(DockLayoutView.Window::main)
|
||||
.findFirst().orElseThrow().bounds());
|
||||
assertEquals(actual(fixture.floating), published(fixture.manager));
|
||||
});
|
||||
} finally { FxThread.onFx(fixture::close); }
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledIfSystemProperty(named = "neitzellib.nativeGeometryTest", matches = "true")
|
||||
void nativeTitlebarAndBorderGesturesPublishOnlyAfterReleaseEvenWithAHeldPause() throws Exception {
|
||||
Fixture fixture = fixture();
|
||||
Robot robot = new Robot();
|
||||
robot.setAutoDelay(15);
|
||||
Point original = MouseInfo.getPointerInfo().getLocation();
|
||||
var watchdog = Executors.newSingleThreadScheduledExecutor();
|
||||
watchdog.schedule(() -> {
|
||||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.mouseMove(original.x, original.y);
|
||||
}, 15, TimeUnit.SECONDS);
|
||||
try {
|
||||
Thread.sleep(400);
|
||||
FxThread.onFx(fixture.committed::clear);
|
||||
for (boolean border : List.of(false, true)) {
|
||||
AtomicReference<Rectangle2D> before = new AtomicReference<>();
|
||||
AtomicReference<Point> start = new AtomicReference<>();
|
||||
FxThread.onFx(() -> {
|
||||
before.set(published(fixture.manager));
|
||||
Rectangle2D frame = actual(fixture.floating);
|
||||
double titleHeight = fixture.floating.getScene().getRoot().localToScreen(0, 0).getY() - frame.getMinY();
|
||||
start.set(border ? new Point((int) frame.getMaxX() - 1, (int) frame.getMaxY() - 1)
|
||||
: new Point((int) (frame.getMinX() + frame.getWidth() / 2),
|
||||
(int) (frame.getMinY() + titleHeight / 2)));
|
||||
});
|
||||
robot.mouseMove(start.get().x, start.get().y);
|
||||
Thread.sleep(100);
|
||||
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||
try {
|
||||
for (int step = 1; step <= 8; step++) {
|
||||
robot.mouseMove(start.get().x + step * 8, start.get().y + step * 5);
|
||||
Thread.sleep(35);
|
||||
}
|
||||
Thread.sleep(600);
|
||||
FxThread.onFx(() -> {
|
||||
assertFalse(before.get().equals(actual(fixture.floating)), "Native gesture must change the real frame");
|
||||
assertEquals(before.get(), published(fixture.manager), "A held pause is not gesture completion");
|
||||
});
|
||||
robot.mouseMove(start.get().x + 88, start.get().y + 55);
|
||||
Thread.sleep(100);
|
||||
} finally {
|
||||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
}
|
||||
awaitPublishedFrame(fixture, before.get());
|
||||
}
|
||||
FxThread.onFx(() -> assertEquals(2, fixture.committed.size(), "One completed publication per native gesture"));
|
||||
} finally {
|
||||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.mouseMove(original.x, original.y);
|
||||
watchdog.shutdownNow();
|
||||
FxThread.onFx(fixture::close);
|
||||
}
|
||||
}
|
||||
|
||||
private static void awaitPublishedFrame(Fixture fixture, Rectangle2D previous) throws Exception {
|
||||
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(3);
|
||||
AtomicReference<Boolean> complete = new AtomicReference<>(false);
|
||||
do {
|
||||
Thread.sleep(25);
|
||||
FxThread.onFx(() -> complete.set(!published(fixture.manager).equals(previous)
|
||||
&& published(fixture.manager).equals(actual(fixture.floating))));
|
||||
} while (!complete.get() && System.nanoTime() < deadline);
|
||||
assertTrue(complete.get(), "Released native geometry must reach the public layout");
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledIfSystemProperty(named = "neitzellib.nativeGeometryTest", matches = "true")
|
||||
void anotherPublicationKeepsSplitGeometryCommittedDuringNativeResize() throws Exception {
|
||||
Fixture fixture = fixture();
|
||||
Robot robot = new Robot();
|
||||
robot.setAutoDelay(15);
|
||||
Point original = MouseInfo.getPointerInfo().getLocation();
|
||||
var watchdog = Executors.newSingleThreadScheduledExecutor();
|
||||
watchdog.schedule(() -> {
|
||||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.mouseMove(original.x, original.y);
|
||||
}, 15, TimeUnit.SECONDS);
|
||||
AtomicReference<Rectangle2D> before = new AtomicReference<>();
|
||||
AtomicReference<Double> ratio = new AtomicReference<>();
|
||||
AtomicReference<Point> start = new AtomicReference<>();
|
||||
try {
|
||||
FxThread.onFx(() -> {
|
||||
fixture.floating.setWidth(760);
|
||||
var window = fixture.manager.layout().windows().stream().filter(candidate -> !candidate.main()).findFirst().orElseThrow();
|
||||
var group = window.areas().getFirst().groups().getFirst().id();
|
||||
Dockable anchor = new Dockable(new DockableId("anchor"), new TextArea("Anchor"));
|
||||
fixture.manager.open(anchor, DockTarget.group(group));
|
||||
fixture.manager.move(anchor.getId(), DockTarget.split(group, Side.RIGHT));
|
||||
fixture.manager.updateGroup(group, DockGroupChanges.builder().minimumWidth(320).build());
|
||||
});
|
||||
Thread.sleep(400);
|
||||
FxThread.onFx(() -> {
|
||||
before.set(published(fixture.manager));
|
||||
ratio.set(publishedSplit(fixture.manager).position());
|
||||
Rectangle2D frame = actual(fixture.floating);
|
||||
start.set(new Point((int) frame.getMaxX() - 1, (int) frame.getMaxY() - 1));
|
||||
});
|
||||
robot.mouseMove(start.get().x, start.get().y);
|
||||
Thread.sleep(100);
|
||||
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||
try {
|
||||
for (int step = 1; step <= 10; step++) {
|
||||
robot.mouseMove(start.get().x - step * 34, start.get().y);
|
||||
Thread.sleep(35);
|
||||
}
|
||||
Thread.sleep(600);
|
||||
FxThread.onFx(() -> {
|
||||
SplitPane split = (SplitPane) fixture.floating.getScene().getRoot().lookup(".dock-split");
|
||||
double live = split.getDividers().getFirst().getPosition();
|
||||
assertTrue(Math.abs(live - ratio.get()) > .03,
|
||||
"Unequal minima must change the live split ratio: prior=" + ratio.get() + ", live=" + live
|
||||
+ ", prior frame=" + before.get() + ", actual=" + actual(fixture.floating)
|
||||
+ ", split width=" + split.getWidth() + ", first minimum=" + split.getItems().getFirst().minWidth(-1));
|
||||
assertEquals(before.get(), published(fixture.manager));
|
||||
fixture.manager.activate(new DockableId("notes"));
|
||||
assertEquals(before.get(), published(fixture.manager), "Selection publication must retain committed bounds");
|
||||
assertEquals(ratio.get(), publishedSplit(fixture.manager).position(), 1e-9,
|
||||
"Selection publication must retain committed split geometry during the same native gesture");
|
||||
});
|
||||
} finally { robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); }
|
||||
awaitPublishedFrame(fixture, before.get());
|
||||
FxThread.onFx(() -> {
|
||||
SplitPane split = (SplitPane) fixture.floating.getScene().getRoot().lookup(".dock-split");
|
||||
assertTrue(Math.abs(publishedSplit(fixture.manager).position() - ratio.get()) > .03);
|
||||
assertEquals(split.getDividers().getFirst().getPosition(), publishedSplit(fixture.manager).position(), 1e-9);
|
||||
});
|
||||
} finally {
|
||||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.mouseMove(original.x, original.y);
|
||||
watchdog.shutdownNow();
|
||||
FxThread.onFx(fixture::close);
|
||||
}
|
||||
}
|
||||
|
||||
private static DockLayoutView.Split publishedSplit(DockingManager manager) {
|
||||
var area = manager.layout().windows().stream().filter(window -> !window.main()).findFirst().orElseThrow().areas().getFirst();
|
||||
return assertInstanceOf(DockLayoutView.Split.class, area.root());
|
||||
}
|
||||
|
||||
private static Fixture fixture() throws Exception {
|
||||
AtomicReference<Fixture> result = new AtomicReference<>();
|
||||
FxThread.onFx(() -> {
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
Stage main = new Stage();
|
||||
main.setScene(new Scene(pane, 800, 500));
|
||||
DockingManager manager = DockingManager.attach(main, pane, new DockingOptions());
|
||||
Dockable notes = new Dockable(new DockableId("notes"), new TextArea("Unsaved notes"));
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
main.show();
|
||||
manager.move(notes.getId(), DockTarget.floating(new Rectangle2D(200, 180, 540, 360)));
|
||||
Stage floating = (Stage) notes.getContent().getScene().getWindow();
|
||||
List<Rectangle2D> committed = new ArrayList<>();
|
||||
manager.layoutProperty().addListener((observable, old, current) -> {
|
||||
Rectangle2D prior = old.windows().stream().filter(window -> !window.main()).findFirst().orElseThrow().bounds();
|
||||
Rectangle2D next = current.windows().stream().filter(window -> !window.main()).findFirst().orElseThrow().bounds();
|
||||
if (!java.util.Objects.equals(prior, next)) committed.add(next);
|
||||
});
|
||||
result.set(new Fixture(main, floating, manager, committed));
|
||||
});
|
||||
return result.get();
|
||||
}
|
||||
|
||||
private static Rectangle2D published(DockingManager manager) {
|
||||
return manager.layout().windows().stream().filter(window -> !window.main()).findFirst().orElseThrow().bounds();
|
||||
}
|
||||
|
||||
private static Rectangle2D actual(Stage stage) {
|
||||
return new Rectangle2D(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight());
|
||||
}
|
||||
|
||||
private record Fixture(Stage main, Stage floating, DockingManager manager, List<Rectangle2D> committed) {
|
||||
void close() { floating.hide(); main.hide(); }
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,19 @@ class OuterDockResizeTest {
|
||||
assertSame(protectedLayout, manager.layout());
|
||||
consent.complete(de.neitzel.fx.docking.CloseConsent.VETO);
|
||||
assertTrue(closing.toCompletableFuture().isDone());
|
||||
var centerConsent = new java.util.concurrent.CompletableFuture<de.neitzel.fx.docking.CloseConsent>();
|
||||
var centerDockable = manager.findDockable(new DockableId("notes")).orElseThrow();
|
||||
centerDockable.setCloseCheck(request -> centerConsent);
|
||||
manager.requestTabClose(centerDockable.getId());
|
||||
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,
|
||||
"A side resize must protect the dependent center area too");
|
||||
centerConsent.complete(de.neitzel.fx.docking.CloseConsent.VETO);
|
||||
for (int direction : new int[]{1, -1}) {
|
||||
var boundary = divider.localToScreen(divider.getBoundsInLocal());
|
||||
mouse(divider, MouseEvent.MOUSE_PRESSED, boundary.getCenterX(), boundary.getCenterY(), true);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
.dock-pane { -fx-background-color: #f4f4f4; }
|
||||
Reference in New Issue
Block a user