feat(fx): add collapsible groups and managed floating windows

This commit is contained in:
2026-11-15 22:26:05 +01:00
parent 1a3aea6e09
commit f6539bdd29
34 changed files with 3062 additions and 48 deletions
+128
View File
@@ -0,0 +1,128 @@
# Floating editors
A tab's **Float** command moves its live content into a manager-owned window.
**Return to main** returns it to its last eligible main-window position, or the
configured fallback. Both commands also appear on floating tabs. The tab's
text, selection and content instance survive the transfer, and the destination
receives keyboard focus.
If neither destination is eligible, Return is rejected and the editor stays
in its floating window.
Application commands use the same path:
```java
manager.move(editorId, DockTarget.floating());
manager.move(editorId, DockTarget.floating(new Rectangle2D(100, 100, 640, 480)));
manager.move(editorId, DockTarget.returnToMain());
```
Use `checkMove` to enable a command and explain a rejected destination. The tab
menu does this whenever it opens; checking a destination does not create a
window. Set `dockable.setMainWindowOnly(true)` for content that must remain in
the main window. Its Float command is disabled with the rejection reason.
A floating window's groups remain destinations in the **Move to** menu, so
editors can share a window. Moving its final tab elsewhere removes the empty
window without closing that Dockable. Floating windows also support the
ordinary split commands.
`DockingOptions.setFloatingWindowCustomizer` supplies a configuration bean for
the title, icons and stylesheets before display. The manager continues to own
window placement and lifecycle.
Run `de.neitzel.fx.example.docking.FloatingDockingMain` from the `fx-example`
module for a desktop demonstration:
1. Edit Notes and select a word.
2. Float Notes, then Float Readme to create two windows.
3. Choose Join Readme to move Notes into the second window; the empty first
window disappears. Continue typing without clicking the editor again.
4. In that shared floating window, open Notes' tab menu and choose **Split →
Right** to place the editors beside each other. Resize their divider.
5. Return Notes and Readme to the main window.
6. Open Project's tab menu to inspect the disabled Float command.
The buttons and tab menus use the same manager operations. This example covers
command-based transfers. Native drag-and-drop between windows and the full
multi-tab window-close workflow are supplied by their subsequent tickets.
## Native keyboard qualification
`FloatingNativeFocusTest` sends actual AWT Robot key presses to the focused OS
window. It types into Notes in the main window, uses **Float**, moves Notes
through **Move to** into another floating window, then uses **Return to main**.
After those transfers it never clicks or explicitly repairs focus. It observes
the destination's native window and Scene focus, then verifies the exact text
sequence `1` → `12` → `123` → `1234`; the other editor remains unchanged.
This sequence passed on macOS 27.2 with Java 25 and JavaFX 27.0.1 on 2026-11-15
(one native test, zero failures, errors or skips). It qualifies command/menu
transfers on that environment; native cross-window pointer dragging and other
OS environments need their own qualification.
Run only with an exclusive desktop slot, since the test posts real keystrokes:
```sh
./mvnw -pl fx -am -Dtest=FloatingNativeFocusTest \
-Dneitzellib.nativeFocusTest=true \
-Dsurefire.failIfNoSpecifiedTests=false test
```
Without the opt-in property this test is explicitly skipped. Its fixture uses
digit keys on the active keyboard layout. It releases the keys and hides its
windows in `finally`; it does not move the pointer.
## Committed native window geometry
A floating `DockLayoutView.Window` exposes its last committed screen rectangle
as `bounds()`. Main-window bounds are `null`: the application owns its geometry.
Geometry property changes are collected while a native mouse button remains
down, including a pause in a titlebar drag or border resize. Publication resumes
when the native query observes release. A timeout alone cannot identify this
boundary because the user can pause with the button held.
The same boundary covers nested split ratios: a selection or other unrelated
publication during native resizing retains both the previous frame and its
committed split geometry. Native regression coverage shrinks a floating window
with unequal group minima, verifies that the live divider clamps while the
published ratio stays unchanged, then verifies the new frame and ratio after
release.
The implementation uses Java 25's Foreign Function and Memory API and existing
OS libraries, without an additional native-access dependency. Enable native
access for the module containing this library; for classpath applications use
`--enable-native-access=ALL-UNNAMED` (and `javafx.graphics` when JavaFX is on the
module path). A denied native call is treated as unknown state, never as release.
Backend boundaries are explicit:
- macOS uses combined-session CoreGraphics state for left, right and middle
buttons, covering either primary-button mapping. The native paused-gesture
behavior has been observed on macOS with Java 25 / JavaFX 27.
- Windows queries the five physical mouse buttons. An all-up result is accepted
only while this process owns the foreground window, because the API can also
return zero for inaccessible input. This backend requires native validation
on Windows before claiming equivalent coverage.
- X11 queries the pointer mask on a separate display connection. Its logical
state can lag frozen device processing; this backend requires X11 validation.
- Wayland sessions, unavailable libraries, denied native access and unrecognized
backends retain the last committed bounds and log the limitation. They do not
silently use a timer to claim a completed native gesture. XWayland sessions
are also conservatively excluded until independently verified.
This is mouse-state observation, not a general native window-manager gesture
API. Touch/keyboard-driven native geometry and delayed OS notifications need
separate validation. Global button state may defer publication when an
unrelated mouse button is held.
The opt-in native regression moves the real pointer and must run with an
exclusive desktop slot:
```sh
./mvnw -pl fx -am -Dtest=FloatingWindowGeometryTest \
-Dneitzellib.nativeGeometryTest=true \
-Dsurefire.failIfNoSpecifiedTests=false test
```
Without that property, the native pointer case is explicitly skipped. Ordinary
public initial-bounds verification still runs. The native case includes a
watchdog and restores the pointer in `finally`.
+52
View File
@@ -0,0 +1,52 @@
# Collapsible tab groups
A group shares its content size, tab side, minimum dimensions, splitting policy
and empty-space behavior across its tabs. Enable `collapsible` on an initial
`DockGroupDefinition` in Java or ordinary FXML. It defaults to `false`, so an
editor area keeps its content space and rejects collapse requests unless the
application explicitly enables them.
Clicking the selected visible tool tab collapses the group to its header rail.
The same headers and icons remain available. Clicking any collapsed tab opens
the group at its remembered size and selects that tab. Within a split, the
collapsed leaf keeps only its rail extent and its sibling receives the released
space. `Split.position()` retains the remembered expanded proportion during
that temporary allocation; reopening restores it. The split divider is hidden
while a branch is collapsed. Escape inside an open
collapsible group also collapses it. Keyboard focus returns to the selected
header; the active Dockable falls back to the most recently active visible
selected content, or becomes null. Other collapsed groups stay closed.
`setGroupCollapsed(groupId, boolean)` supplies the same state transition.
`activate(dockableId)` opens the Dockable's group before focusing its content.
A drag preview does not open a collapsed group: only the successful drop does;
Escape cancels the preview without changing the layout.
```java
manager.updateGroup(toolsId, DockGroupChanges.builder()
.preferredWidth(260)
.tabSide(Side.RIGHT)
.collapsible(false)
.build());
```
Only explicitly supplied settings change. In particular, `false` is a supplied
value, not an omitted setting. The manager validates the resulting definition
before applying anything, publishes one completed layout state, and returns a
rejection without partial changes for invalid dimensions. An empty or identical
patch returns `NoChange`. Disabling collapse opens a collapsed group as part of
the update. A missing group returns `TARGET_NOT_FOUND`; a pending close protects
its group from changes. Geometry changes also protect neighboring content that
would be resized while its close consent is pending; unrelated policy updates
remain possible. The initial definition supplied at attachment remains
independent of live updates.
`DockGroupChanges` covers tab side, preferred/minimum width and height,
persistence, empty visibility, empty-space release, collapsibility and split
directions. Each new split receives its own copy of its target's settings.
Overlay display is provided by the subsequent overlay slice.
Run `DockingMain` (or `--fxml`) and select Project. Click it again to collapse,
then click Changed files to reopen the same group. The toolbar also exposes
explicit collapse/open and shared-width updates. The `--splits` variants retain
these group actions in the nested editor demonstration.
+3 -2
View File
@@ -39,8 +39,9 @@ application actions. Moving keyboard focus to a global button preserves it.
The content instance remains owned by the application. A supplied
`setFocusTarget` chooses a Node within the content; otherwise the manager tries
the previously focused descendant. See [split groups](docking-splits.md) for
nested layouts and resizing and [close consent](docking-close.md) for asynchronous
close checks. Restoration is supplied by a later slice.
nested layouts and resizing, [group presentation](docking-groups.md) for
collapse and atomic configuration, and [close consent](docking-close.md) for
asynchronous close checks. Restoration is supplied by a later slice.
## Move and check placement