feat(fx): open and activate dockables from Java and FXML
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
This runnable application demonstrates [NeitzelLib FX](../fx/README.md) and [injection](../injection/README.md) together. It edits one Person with a home Address, nested Note, visit list, selected visit and tags. Use it as a reference for wiring a real screen; the [minimal quick start](../fx/docs/quick-start.md) is the smaller starting point for a new project.
|
||||
|
||||
Separate Java/FXML launchers demonstrate [standalone bars](../fx/docs/bars.md)
|
||||
and [docking](../fx/docs/docking.md) without initializing MVVM or injection.
|
||||
Their guides describe the implemented behavior and launch options.
|
||||
|
||||
## Build and run
|
||||
|
||||
From the NeitzelLib root with JDK 25:
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package de.neitzel.fx.example.docking;
|
||||
|
||||
import de.neitzel.fx.docking.DockGroupDefinition;
|
||||
import de.neitzel.fx.docking.DockLayout;
|
||||
import de.neitzel.fx.docking.DockPane;
|
||||
import de.neitzel.fx.docking.DockTarget;
|
||||
import de.neitzel.fx.docking.Dockable;
|
||||
import de.neitzel.fx.docking.DockableId;
|
||||
import de.neitzel.fx.docking.DockingManager;
|
||||
import de.neitzel.fx.docking.DockingOptions;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.geometry.Side;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/** A small ordinary JavaFX application with editor and tool tabs, without MVVM. */
|
||||
public final class DockingApp extends Application {
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
DockPane pane = getParameters().getRaw().contains("--fxml")
|
||||
? FXMLLoader.load(DockingApp.class.getResource("Docking.fxml")) : initialPane();
|
||||
Button activate = new Button("Activate Notes");
|
||||
BorderPane shell = new BorderPane(pane);
|
||||
shell.setTop(activate);
|
||||
stage.setScene(new Scene(shell, 900, 600));
|
||||
DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions());
|
||||
DockableId notesId = new DockableId("notes");
|
||||
TextArea notes = new TextArea("Unsaved notes stay in this live editor.");
|
||||
Dockable editor = new Dockable(notesId, notes);
|
||||
editor.setTitle("Notes");
|
||||
manager.open(editor, DockTarget.area("editors"));
|
||||
Dockable other = new Dockable(new DockableId("readme"), new TextArea("Readme"));
|
||||
other.setTitle("Readme");
|
||||
manager.open(other, DockTarget.area("editors"));
|
||||
Dockable project = new Dockable(new DockableId("project"), new Label("Project files"));
|
||||
project.setTitle("Project");
|
||||
project.setIcon(new Label("▦"));
|
||||
manager.open(project, DockTarget.area("tools"));
|
||||
activate.setOnAction(event -> manager.activate(notesId));
|
||||
stage.setTitle("NeitzelLib docking — Java or ordinary FXML");
|
||||
stage.show();
|
||||
manager.activate(notesId);
|
||||
}
|
||||
|
||||
private static DockPane initialPane() {
|
||||
DockLayout layout = new DockLayout();
|
||||
layout.setCenter(new DockGroupDefinition("editors"));
|
||||
DockGroupDefinition tools = new DockGroupDefinition("tools");
|
||||
tools.setTabSide(Side.RIGHT);
|
||||
tools.setPreferredWidth(200);
|
||||
layout.setRight(tools);
|
||||
DockPane pane = new DockPane();
|
||||
pane.setInitialLayout(layout);
|
||||
return pane;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package de.neitzel.fx.example.docking;
|
||||
|
||||
import javafx.application.Application;
|
||||
|
||||
/** Plain launcher for the docking example; pass --fxml to load the equivalent FXML layout. */
|
||||
public final class DockingMain {
|
||||
private DockingMain() { }
|
||||
|
||||
public static void main(String[] args) {
|
||||
Application.launch(DockingApp.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?import de.neitzel.fx.docking.DockPane?>
|
||||
<?import de.neitzel.fx.docking.DockLayout?>
|
||||
<?import de.neitzel.fx.docking.DockGroupDefinition?>
|
||||
<DockPane xmlns:fx="http://javafx.com/fxml/1">
|
||||
<initialLayout>
|
||||
<DockLayout>
|
||||
<center><DockGroupDefinition destinationId="editors"/></center>
|
||||
<right><DockGroupDefinition destinationId="tools" tabSide="RIGHT" preferredWidth="200"/></right>
|
||||
</DockLayout>
|
||||
</initialLayout>
|
||||
</DockPane>
|
||||
Reference in New Issue
Block a user