feat(fx): add collapsible groups and managed floating windows
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package de.neitzel.fx.example.docking;
|
||||
|
||||
import de.neitzel.fx.docking.DockGroupDefinition;
|
||||
import de.neitzel.fx.docking.DockGroupChanges;
|
||||
import de.neitzel.fx.docking.DockLayoutView;
|
||||
import de.neitzel.fx.docking.DockSplitDefinition;
|
||||
import de.neitzel.fx.docking.SplitDirections;
|
||||
import javafx.geometry.Orientation;
|
||||
@@ -35,9 +37,11 @@ public final class DockingApp extends Application {
|
||||
Button toTools = new Button("Move Notes to tools");
|
||||
Button toEditors = new Button("Move Notes to editors");
|
||||
Button splitNotes = new Button("Split Notes right");
|
||||
Button toggleTools = new Button("Toggle tools");
|
||||
Button widenTools = new Button("Tools width 260");
|
||||
Label status = new Label("Drag a tab to an edge to split; drag dividers to resize.");
|
||||
BorderPane shell = new BorderPane(pane);
|
||||
shell.setTop(new ToolBar(activate, toTools, toEditors, splitNotes));
|
||||
shell.setTop(new ToolBar(activate, toTools, toEditors, splitNotes, toggleTools, widenTools));
|
||||
shell.setBottom(status);
|
||||
stage.setScene(new Scene(shell, 900, 600));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
@@ -54,6 +58,10 @@ public final class DockingApp extends Application {
|
||||
output.setTitle("Output");
|
||||
manager.open(output, DockTarget.area("output"));
|
||||
}
|
||||
Dockable changes = new Dockable(new DockableId("changes"), new TextArea("Changed files"));
|
||||
changes.setTitle("Changed files");
|
||||
changes.setIcon(new Label("Δ"));
|
||||
manager.open(changes, DockTarget.area("tools"));
|
||||
Dockable project = new Dockable(new DockableId("project"), new Label("Project files"));
|
||||
project.setTitle("Project");
|
||||
project.setIcon(new Label("▦"));
|
||||
@@ -65,6 +73,10 @@ public final class DockingApp extends Application {
|
||||
.flatMap(window -> window.areas().stream()).flatMap(area -> area.groups().stream())
|
||||
.filter(group -> group.dockableIds().contains(notesId)).findFirst()
|
||||
.ifPresent(group -> report(status, manager.move(notesId, DockTarget.split(group.id(), Side.RIGHT)))));
|
||||
toggleTools.setOnAction(event -> toolsGroup(manager).ifPresent(group ->
|
||||
report(status, manager.setGroupCollapsed(group.id(), !group.collapsed()))));
|
||||
widenTools.setOnAction(event -> toolsGroup(manager).ifPresent(group ->
|
||||
report(status, manager.updateGroup(group.id(), DockGroupChanges.builder().preferredWidth(260).build()))));
|
||||
stage.setTitle("NeitzelLib docking — Java or ordinary FXML");
|
||||
stage.show();
|
||||
manager.activate(notesId);
|
||||
@@ -72,12 +84,18 @@ public final class DockingApp extends Application {
|
||||
|
||||
private static void report(Label status, ActionResult result) {
|
||||
status.setText(switch (result) {
|
||||
case ActionResult.Applied ignored -> "Notes moved.";
|
||||
case ActionResult.NoChange ignored -> "Notes is already at that position.";
|
||||
case ActionResult.Applied ignored -> "Layout updated.";
|
||||
case ActionResult.NoChange ignored -> "The layout already has that state.";
|
||||
case ActionResult.Rejected rejected -> rejected.failure().message();
|
||||
});
|
||||
}
|
||||
|
||||
private static java.util.Optional<DockLayoutView.Group> toolsGroup(DockingManager manager) {
|
||||
return manager.layout().windows().stream().flatMap(window -> window.areas().stream())
|
||||
.filter(area -> area.id().value().equals("tools"))
|
||||
.flatMap(area -> area.groups().stream()).findFirst();
|
||||
}
|
||||
|
||||
private static DockPane initialPane(boolean splits) {
|
||||
DockLayout layout = new DockLayout();
|
||||
if (splits) {
|
||||
@@ -96,6 +114,7 @@ public final class DockingApp extends Application {
|
||||
}
|
||||
DockGroupDefinition tools = new DockGroupDefinition("tools");
|
||||
tools.setTabSide(Side.RIGHT);
|
||||
tools.setCollapsible(true);
|
||||
tools.setPreferredWidth(200);
|
||||
tools.setSplitDirections(SplitDirections.VERTICAL);
|
||||
tools.setVisibleWhenEmpty(false);
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package de.neitzel.fx.example.docking;
|
||||
|
||||
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.Application;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.ToolBar;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/** Demonstrates live editor transfers between the main window and floating windows. */
|
||||
public final class FloatingDockingApp extends Application {
|
||||
@Override
|
||||
public void start(Stage stage) {
|
||||
DockPane pane = new DockPane();
|
||||
pane.getInitialLayout().setCenter(new DockGroupDefinition("editors"));
|
||||
pane.getInitialLayout().setLeft(new DockGroupDefinition("project"));
|
||||
Label notice = new Label("Edit Notes and select a word before moving it. Project stays in the main window.");
|
||||
BorderPane shell = new BorderPane(pane);
|
||||
shell.setBottom(notice);
|
||||
stage.setScene(new Scene(shell, 1040, 560));
|
||||
DockingOptions options = new DockingOptions();
|
||||
options.setFloatingWindowCustomizer(configuration -> configuration.setTitle("NeitzelLib — floating editor"));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, options);
|
||||
Dockable notes = editor("notes", "Notes", "Unsaved notes travel with this editor.\nSelect a word, float the tab, and continue typing.");
|
||||
Dockable readme = editor("readme", "Readme", "A second editor can share a floating window with Notes.");
|
||||
Dockable project = editor("project", "Project", "This panel is restricted to the main window.\nIts Float menu command is disabled.");
|
||||
project.setMainWindowOnly(true);
|
||||
manager.open(project, DockTarget.area("project"));
|
||||
manager.open(readme, DockTarget.area("editors"));
|
||||
manager.open(notes, DockTarget.area("editors"));
|
||||
|
||||
Button floatNotes = new Button("Float Notes");
|
||||
Button floatReadme = new Button("Float Readme");
|
||||
Button join = new Button("Join Readme");
|
||||
Button returnNotes = new Button("Return Notes");
|
||||
Button returnReadme = new Button("Return Readme");
|
||||
shell.setTop(new ToolBar(floatNotes, floatReadme, join, returnNotes, returnReadme));
|
||||
floatNotes.setOnAction(event -> move(manager, notes, DockTarget.floating(), notice));
|
||||
floatReadme.setOnAction(event -> move(manager, readme, DockTarget.floating(), notice));
|
||||
join.setOnAction(event -> {
|
||||
DockTarget target = floatingGroup(manager, readme.getId());
|
||||
if (target != null) move(manager, notes, target, notice);
|
||||
});
|
||||
returnNotes.setOnAction(event -> move(manager, notes, DockTarget.returnToMain(), notice));
|
||||
returnReadme.setOnAction(event -> move(manager, readme, DockTarget.returnToMain(), notice));
|
||||
Runnable refresh = () -> {
|
||||
floatNotes.setDisable(!(manager.checkMove(notes.getId(), DockTarget.floating()) instanceof MoveCheck.Allowed));
|
||||
floatReadme.setDisable(!(manager.checkMove(readme.getId(), DockTarget.floating()) instanceof MoveCheck.Allowed));
|
||||
returnNotes.setDisable(!(manager.checkMove(notes.getId(), DockTarget.returnToMain()) instanceof MoveCheck.Allowed));
|
||||
returnReadme.setDisable(!(manager.checkMove(readme.getId(), DockTarget.returnToMain()) instanceof MoveCheck.Allowed));
|
||||
DockTarget target = floatingGroup(manager, readme.getId());
|
||||
join.setDisable(target == null || !(manager.checkMove(notes.getId(), target) instanceof MoveCheck.Allowed));
|
||||
};
|
||||
manager.layoutProperty().addListener((observable, old, current) -> refresh.run());
|
||||
refresh.run();
|
||||
stage.setTitle("NeitzelLib — floating windows");
|
||||
stage.show();
|
||||
}
|
||||
|
||||
private static Dockable editor(String id, String title, String text) {
|
||||
Dockable editor = new Dockable(new DockableId(id), new TextArea(text));
|
||||
editor.setTitle(title);
|
||||
return editor;
|
||||
}
|
||||
|
||||
private static DockTarget floatingGroup(DockingManager manager, DockableId id) {
|
||||
return manager.layout().windows().stream().filter(window -> !window.main())
|
||||
.flatMap(window -> window.areas().stream()).flatMap(area -> area.groups().stream())
|
||||
.filter(group -> group.dockableIds().contains(id)).findFirst()
|
||||
.map(group -> DockTarget.group(group.id())).orElse(null);
|
||||
}
|
||||
|
||||
private static void move(DockingManager manager, Dockable editor, DockTarget target, Label notice) {
|
||||
ActionResult result = manager.move(editor.getId(), target);
|
||||
notice.setText(result instanceof ActionResult.Rejected rejected ? rejected.failure().message()
|
||||
: editor.getTitle() + " moved. Continue editing in its destination window.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package de.neitzel.fx.example.docking;
|
||||
|
||||
import javafx.application.Application;
|
||||
|
||||
/** Plain Java launcher for the floating editor example. */
|
||||
public final class FloatingDockingMain {
|
||||
private FloatingDockingMain() { }
|
||||
|
||||
public static void main(String[] args) {
|
||||
Application.launch(FloatingDockingApp.class, args);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<initialLayout>
|
||||
<DockLayout>
|
||||
<center><DockGroupDefinition destinationId="editors"/></center>
|
||||
<right><DockGroupDefinition destinationId="tools" tabSide="RIGHT" preferredWidth="200" splitDirections="VERTICAL"
|
||||
<right><DockGroupDefinition destinationId="tools" tabSide="RIGHT" collapsible="true" preferredWidth="200" splitDirections="VERTICAL"
|
||||
visibleWhenEmpty="false" releaseSpaceWhenEmpty="true"/></right>
|
||||
</DockLayout>
|
||||
</initialLayout>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</second>
|
||||
</DockSplitDefinition>
|
||||
</center>
|
||||
<right><DockGroupDefinition destinationId="tools" tabSide="RIGHT" preferredWidth="200" splitDirections="VERTICAL"
|
||||
<right><DockGroupDefinition destinationId="tools" tabSide="RIGHT" collapsible="true" preferredWidth="200" splitDirections="VERTICAL"
|
||||
visibleWhenEmpty="false" releaseSpaceWhenEmpty="true"/></right>
|
||||
</DockLayout>
|
||||
</initialLayout>
|
||||
|
||||
Reference in New Issue
Block a user