Saving preferred layouts to .ivl files

The class IlvDefaultLayoutProvider allows you to specify the layout instances to be used for each graph. The layout provider can then be used for the recursive layout of a nested graph. (For details, see Nested layouts.)
You can set your preferred layouts using one of the methods setPreferredLayout of the class IlvDefaultLayoutProvider and save these preferred layouts to .ivl files using the method:
boolean savePreferredLayoutsToNamedProperties(IlvDefaultLayoutProvider 
provider, boolean withParameters, boolean withDefaults, boolean traverse);   
The method takes the Layout Provider as an argument and several flags:
  • withParameters : if the flag is true , the parameters of the preferred layout instances are saved. In this case it is not necessary to use the method saveParametersToNamedProperties . Otherwise, only the name of the class of the preferred layout is saved, without its parameters. Therefore, after loading the .ivl file, the preferred layout will have, in this case, the default values for all its parameters.
  • withDefaults : the flag has the same meaning as for the method saveParametersToNamedProperties .
  • traverse : if the flag is true , the method applies recursively to the subgraphs. Otherwise, the method saves only the preferred layout of the grapher adapter on which the method is called.
The following code example shows how to save the preferred layouts to .ivl files.
IlvGrapher grapherA = new IlvGrapher();
IlvGrapher grapherB = new IlvGrapher();

// fill the graphers with nodes and links;
// grapherB is added as a subgraph of grapherA
grapherA.addNode(grapherB, false);

// Create the grapher adapter for the topmost graph
IlvGrapherAdapter adapterA = new IlvGrapherAdapter(grapherA);

// Get a grapher adapter for the subgraph
IlvGraphModel adapterB = adapterA.getGraphModel(grapherB);

// create the layout provider
IlvDefaultLayoutProvider provider = new IlvDefaultLayoutProvider();

// specify the preferred layouts for each grapher
// (this automatically attaches the layouts)
provider.setPreferredLayout(adapterA, new IlvTreeLayout());
provider.setPreferredLayout(adapterB, new IlvGridLayout());
...

// Save the settings to named properties
adapterA.savePreferredLayouts(provider, true, false, true);

// Save the nested grapher to an .ivl file
grapherA.write("abcd.ivl")