java.lang.Object
org.snapfx.persistence.DockLayoutSerializer
Serializes and deserializes
DockGraph structures to/from JSON.
The serializer persists the full dock tree (split orientation, tab state, divider
positions, lock flag, sidebar state, and layout IDs). During load, applications can
provide a DockNodeFactory to recreate JavaFX content from saved node IDs.
Typical usage:
DockLayoutSerializer serializer = new DockLayoutSerializer(graph);
serializer.setNodeFactory(nodeId -> createDockNodeFor(nodeId));
String json = serializer.serialize();
serializer.deserialize(json);
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSerialized type token forDockNode.static final StringSerialized type token forDockSplitPane.static final StringSerialized type token forDockTabPane.static final StringJSON suffix used for element ID validation errors.static final StringJSON suffix used for title validation errors.static final StringJSON suffix used for type validation errors. -
Constructor Summary
ConstructorsConstructorDescriptionDockLayoutSerializer(DockGraph dockGraph) Creates a serializer bound to one dock graph. -
Method Summary
Modifier and TypeMethodDescriptionvoiddeserialize(String json) Deserializes JSON into a DockGraph.voidregisterNode(DockNode node) Registers a DockNode for serialization.Serializes the DockGraph to JSON.voidsetNodeFactory(DockNodeFactory factory) Sets the factory used to create DockNodes during deserialization.
-
Field Details
-
DOCK_NODE
Serialized type token forDockNode.- See Also:
-
DOCK_SPLIT_PANE
Serialized type token forDockSplitPane.- See Also:
-
DOCK_TAB_PANE
Serialized type token forDockTabPane.- See Also:
-
TYPE_JSON_SUFFIX
JSON suffix used for type validation errors.- See Also:
-
ID_JSON_SUFFIX
JSON suffix used for element ID validation errors.- See Also:
-
TITLE_JSON_SUFFIX
JSON suffix used for title validation errors.- See Also:
-
-
Constructor Details
-
DockLayoutSerializer
Creates a serializer bound to one dock graph.- Parameters:
dockGraph- dock graph to serialize/deserialize
-
-
Method Details
-
setNodeFactory
Sets the factory used to create DockNodes during deserialization. This is the recommended way to restore nodes across sessions.- Parameters:
factory- Factory that creates nodes from their IDs
-
registerNode
Registers a DockNode for serialization. Note: With a DockNodeFactory set, registration is not strictly required, as the factory will recreate nodes during deserialization.- Parameters:
node- node instance to register
-
serialize
Serializes the DockGraph to JSON.- Returns:
- serialized layout JSON document
-
deserialize
Deserializes JSON into a DockGraph.- Parameters:
json- serialized layout JSON- Throws:
DockLayoutLoadException- if the JSON is invalid or cannot be mapped to a valid layout
-