The following example shows how to load and recover the parameters
of the three layout instances when the layout settings are stored
in an
.ivl
file:
// Read the IVL file. This reads all named properties as well. grapher.read("abcd.ivl"); IlvGrapherAdapter adapter1 = (IlvGrapherAdapter)layout1.getGraphModel(); IlvGrapherAdapter adapter2 = (IlvGrapherAdapter)layout2.getGraphModel(); IlvGrapherAdapter adapter3 = (IlvGrapherAdapter)layout3.getGraphModel(); // Transfer the parameter settings from the named properties to the layouts. adapter3.loadParametersFromNamedProperties(layout3); adapter2.loadParametersFromNamedProperties(layout2); adapter1.loadParametersFromNamedProperties(layout1); // just to be sure that no named layout properties remain in the memory adapter1.removeParametersFromNamedProperties(); adapter2.removeParametersFromNamedProperties(); adapter3.removeParametersFromNamedProperties();
When reading an
.ivl
file, you usually do not know how many named layout properties are
stored in the file. In the previous example, if there are less than
three sets of named layout properties stored in the
.ivl
file, any unsuccessful call of the method loadParametersFromNamedProperties has simply
no effect, that is, it does not change the parameters of the
corresponding layout. If there are more than three sets, the final
calls of the method removeParametersFromNamedProperties guarantee
that no memory is wasted by the remaining unused layout properties.
As mentioned in Saving layout parameters to .ivl files, only
one call to the method
removeParametersFromNamedProperties
is necessary if only one grapher adapter is attached to all three
layout instances.
Note
Parameters are loaded in the reverse order with respect to the
order in which they are stored. This is not important if all three
layout instances are of different classes because a layout
automatically loads only parameters that fit the layout class.
However, if, for example, all three layouts are instances of IlvTreeLayout, the last saved set of named
properties for any Tree Layout is the first set of named
properties that is loaded for a Tree Layout.
To load layout parameters, use one of the
following methods:
-
This method transfers a set of layout parameters from the named layout properties to the input layout. It automatically determines which layout properties fit the input layout. If several sets fit, it transfers the set that was stored last, removes this set of named layout properties from the grapher, and returns
true
. If no set fits and loading cannot be done, it returnsfalse
. -
This method transfers a set of layout parameters from the layout properties having the input property name to the input layout. It returns
true
if successful, andfalse
otherwise. -
This method transfers a set of layout parameters from the layout properties having the input property name to a newly created instance of
IlvGraphLayout
. It returns the new instance. It returnsnull
if no set of layout properties with the input name is found.