Module org.snapfx

Class DockLayoutSerializer

java.lang.Object
org.snapfx.persistence.DockLayoutSerializer

public class DockLayoutSerializer extends Object
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 Details

  • Constructor Details

    • DockLayoutSerializer

      public DockLayoutSerializer(DockGraph dockGraph)
      Creates a serializer bound to one dock graph.
      Parameters:
      dockGraph - dock graph to serialize/deserialize
  • Method Details

    • setNodeFactory

      public void setNodeFactory(DockNodeFactory factory)
      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

      public void registerNode(DockNode node)
      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

      public String serialize()
      Serializes the DockGraph to JSON.
      Returns:
      serialized layout JSON document
    • deserialize

      public void deserialize(String json) throws DockLayoutLoadException
      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