In this section, you will learn what a LayoutController
is and how to create and apply one to a VisualGraphView.
The layout of a VisualGraphView is delegated to a
LayoutController component. This is not the same kind of
“controller” that is described in the MVC tutorial in this manual. Rather it is an engine
that manages the state of a layout activity, both during and after the completion
of a visual graph. Moreover, the controller internally delegates certain
responsibilities to a specialized Layout component that
callers may specify using predefined string constants (also known as types).
Classes which implement the VisualGraphView interface provide a
drawing area for visual graphs and as such utilize a LayoutController
to automatically position visual graph elements relative to each another. Once you have
retrieved this LayoutController from a view, you may set the layout
“type” and/or directly call its apply() method to
trigger the layout task. Remember to follow through with a call to the
updateView() method, as shown in this example:
Example 7.1. Apply a Circular Layout to a VisualGraphView
// get a reference to the layout controller
GraphLayoutController layoutController =
(GraphLayoutController) graphView.getLayoutController();
// actually apply the layout
layoutController.apply(GraphLayoutController.Circular);
// center the graph in the middle of the view
VisualOperations.translateViewportAccordingToGraph(graphView);
In the example above, the layout type “Circular” is passed in a separate
call and specifies a specific layout from the Tensegrity Graph API. This type constant is used to
internally instantiate a specific Layout component which does
the actual layouting. These layout types can also be contextualized with specific
parameters called a “layout context”. Please see the following sections
and our javadocs for more complete information about these topics.
Example 7.2. Method that creates a GraphLayoutController
// create a layout controller
GraphLayoutController layoutController =
new GraphLayoutController();
// disable animation
layoutController.enableAnimation(false);
As the above example shows, a LayoutController instance is
created by instantiating a class derived from the abstract base class
LayoutController. The GraphLayoutController
instance is one of four out-of-the-box concrete LayoutController
classes which provide a specific kind of runtime layout control. Please read our javadocs
for more detailed information about the LayoutController base and
derived classes.
When working with a VisualGraphView, it is necessary to
assign a specific LayoutController to it. Below you can
see just how to do that.
© 2004, 2005 Tensegrity Software GmbH