When a layout algorithm is executed, it
moves the nodes and/or reshapes the links of the graph. If the
graph is displayed on a screen, its display must be updated to
reflect the changes made by the layout.
- If you use a diagram component (a subclass of IlvDiagrammer)), the updating is done automatically.
- If you call layout by using the method
performLayout
, you have more detailed control on the redraw mechanism, as explained in the following sections:Rogue Wave® JViews provides complete flexibility, concerning the redraw of an IlvGrapher instance that has undergone layout. Your choice will depend on your particular application. The following scenarios are possible:
Automatic and selective redraw
If you just want the grapher to be automatically redrawn after
the layout, simply call the following method with the value
true
for the
redraw
argument:
IlvGraphLayoutReport performLayout(boolean force, boolean redraw)
When you do this, an initReDraws/ reDrawViews session is initiated
automatically. When the nodes and the links are moved or
reshaped, the value
true
is passed for the
redraw
argument of the appropriate methods of IlvGrapher. At the end of the layout, the
initReDraws/reDrawViews
session is ended. This produces a selective redraw of the invalid
regions of the views where the graph is displayed.
Nonautomatic and complete redraw
If all the nodes are moved by the layout, it may be more
efficient to redraw the entire graph at the end of the layout
instead of using the mechanism of the invalid regions provided by
IlvGrapher
. In this case, you can use the following code:
try { layout.performLayout(false, false); // argument redraw at false } catch (IlvGraphLayoutException e) { e.printStackTrace(); } finally { // redraw in the final clause to ensure that the redraw // is performed even if an exception occurs grapher.reDraw(); }
This completely redraws the grapher in all its visible views.
Alternatively, you can call the method
repaint
on some of its views.
Delayed redraw
After the layout, you may want to perform other changes in the
grapher before redrawing. You can start the initReDraws/ reDrawViews session on your own to control
the point in time when the redraw is performed. You can use the
following code:
grapher.initReDraws(); try { layout.performLayout(false, true); } catch (IlvGraphLayoutException e) { e.printStackTrace(); } finally { grapher.moveObject(..., false); // some other changes in the grapher grapher.reDrawViews(); }
No redraw at all
Sometimes, the layout may need to be performed without any
display of the grapher. For instance, this can be done to
automatically produce
.ivl
files containing the result of the layout for future use. To
avoid any redraw during the layout, just call the method performLayout with the value
false
for the
redraw
argument.
Note
During animated layout (for layouts supporting this option), the
grapher needs to be redrawn after each step to produce the
animation effect. Therefore, you need to pass the value
true
for the
redraw
argument of the method performLayout. In this case, the initReDraws/ reDrawViews session is automatically used
for each animation step. Users should not add their own
initReDraw/reDrawViews
session because this would prevent the graph from being redrawn
during the animation.