When loading a saved layout, the framework needs to recreate the DockNodes that were part of the original layout. Since only the node IDs are stored in the JSON (not the actual JavaFX content), the application must provide a way to recreate nodes from their IDs.
Usage Example:
DockNodeFactory factory = nodeId -> {
return switch (nodeId) {
case "projectExplorer" -> createProjectExplorer();
case "mainEditor" -> createMainEditor();
case "console" -> createConsole();
default -> null;
};
};
snapFX.setNodeFactory(factory);
try {
snapFX.loadLayout(json);
} catch (DockLayoutLoadException e) {
// Handle invalid/corrupt layout JSON.
}
Important: The factory must create DockNodes with the same ID that
was used when the layout was saved. Use the DockNode(String, Node, String)
constructor with the provided nodeId.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordContext passed tocreateUnknownNode(UnknownElementContext). -
Method Summary
Modifier and TypeMethodDescriptioncreateNode(String nodeId) Creates a DockNode for the given ID.default DockNodeOptional hook for unsupported serialized element types.
-
Method Details
-
createNode
Creates a DockNode for the given ID.This method is called during layout deserialization for each node ID found in the saved layout. The implementation must create and return a DockNode with the given ID and appropriate content.
- Parameters:
nodeId- The unique identifier of the node to create (same ID as used when saving)- Returns:
- A DockNode with the specified ID and recreated content, or null if the ID is unknown
-
createUnknownNode
Optional hook for unsupported serialized element types.The serializer invokes this callback when it encounters an unknown element type in the saved layout (for example "DockNode!!!"). Returning
nullkeeps the framework default behavior and inserts the built-in placeholder node.- Parameters:
context- Details about the unsupported element and its JSON location- Returns:
- Custom replacement node, or
nullto use the framework placeholder
-