The mechanisms available for advanced users
are:
- Subgraph correction, to correct the subgraphs during layout
- Listener layout, to install layout event listeners efficiently
Subgraph correction
In Rogue Wave JViews, the position of a subgrapher (instance of IlvGrapher) is always calculated from the
positions of the contents of the subgrapher. The position of the
subgrapher is simply the position of the bounding box around its
contents. This mechanism has side effects when performing layout:
a subgraph will never appear fixed if its contents is laid out,
because when a layout is applied to the contents of the subgraph,
the bounding box, hence the position, of the subgraph changes.
Depending on the applications, this may be an unwanted effect.
Normally, after the subgraph is laid out,
its parent graph gets laid out, which eventually moves the entire
subgraph to its final position. Therefore, in most cases, the
unwanted position of the subgraph is only temporary and you can
ignore the entire problem. However, in a few situations, you need
to be aware of the effect, namely:
- if the subgraph is specified as fixed (for instance, by a call to the method
setFixed
) and hence should not move; - if the parent graph is never laid out;
- if the parent graph is laid out in a layout style with incremental mode on, which analyzes the positions of the nodes (for instance in Tree Layout and Hierarchical Layout).
In all these situations, it is important that the subgraph
remains at the old position even after its contents has been laid
out. The implementation of IlvGrapher does not behave like this.
The solution is simply to move the subgraph back to its old
position immediately after the subgraph has been laid out, just
before the layout of its parent graph is started. The Recursive
Layout allows you to install a subgraph correction interface that
contains a
correct
method which is called exactly at this point. You install a
subgraph correction interface in the following way:
layout.setSubgraphCorrectionInterface( new IlvSubgraphCorrectionBarycenterFixed());
Effect of subgraph correction illustrates
the effect of subgraph correction.
Two default implementations of IlvSubgraphCorrectionInterface are
available:
- IlvSubgraphCorrectionBarycenterFixed corrects the subgraph so that after its contents has been laid out, the center of the subgraph remains the same. However, the size of the subgraph bounding box may change due to the contents layout.
- IlvSubgraphCorrectionBoundsFixed corrects the subgraph so that after its contents has been laid out, the bounding box of the subgraph remains the same. However, to achieve this, the zoom level of the subgraph is changed.
These implementations of the subgraph correction interface do not
correct the top-level graph, but only the nested subgraphs The
instances can be shared between different instances of IlvRecursiveLayout.
![Effect
of subgraph correction](../../../GraphLayout/_media/layoutRecursivesubcorr_default.png)
Effect of subgraph correction
Listener layout
Event listener layout is an advanced feature documented in Using event listeners. You need to
understand that general description and the concept of layout
listeners before you read this section. This section describes
some specific details of the Recursive Layout related to layout
listeners.
The application can listen for layout
events sent by the Recursive Layout or by each sublayout
individually. For example, a progress bar that displays the
progress of the entire nested layout should listen for the layout
events fired by the Recursive Layout itself, while an application
that wants to detect when a specific sublayout of a subgraph is
started or stopped should listen for the layout events sent by
that particular sublayout.
To install a layout event listener at the
Recursive Layout, call usually:
recursiveLayout.addGraphLayoutEventListener(listener);
To install a layout listener that receives
the layout events of all sublayouts of the Recursive Layout, you
can call:
recursiveLayout.addSubLayoutEventListener(listener);
Note that in this case, the listener is
installed at the Recursive Layout instance (not at the sublayout
instances) but receives the events from the sublayouts (not from
the Recursive Layout). An internal mechanism makes sure that the
events are forwarded to the listener.
Alternatively, you could traverse the nesting structure and
install the same listener at all subgraph layouts. However, this
would have two disadvantages: it requires more memory and you
need to reinstall or update the listener whenever you change the
layout of a subgraph or the nesting structure by adding or
removing subgraphs. When you use
addSubLayoutEventListener
, updating the listener is not necessary in this case.