Perforce JViews Diagrammer Code Example: Tree Layout (Java SDK Version)
Description
This sample shows how to use the Tree Layout algorithm
in a Java application.
It shows how to perform a tree layout and how to control its
layout parameters in Java code.
This sample uses the graphic framework but it does not use
the IlvDiagrammer
component nor CSS.
A version of the Tree Layout sample that uses CSS can be found here
How to Use the Code Example
- The Tree Layout algorithm is primarily designed for pure trees but it can also be used for other graphs. The Tree Layout arranges the nodes of a tree horizontally, vertically, or radially, starting from the root of the tree.
-
This application shows a manager view that displays a grapher that is read from an
IVL
file. You can change the grapher sample by using the list at the top of the application. - The application also has interactor buttons at the top of the graph window: pan, select, zoom box, zoom in, zoom out, and show all (fit to contents).
- You can use the select interactor to select a root node for the Tree Layout.
-
Two buttons are located under the graph window:
- Random performs a Random Layout.
- Layout uses the Tree Layout algorithm.
- A layout is performed when you press these buttons. If the Auto layout check box is selected, the layout is also performed when you change any layout parameter. You can see the effect of layout parameters immediately.
- If the Auto fit to view check box is selected, the view fits the zoom automatically when a layout is performed.
- Under the buttons, a series of list boxes allow you to select the layout mode, the flow direction, the global link style, and the global alignment option. You can also change the offsets between siblings, between branches, or between a parent and its child objects. For details, see the relevant section of the User's documentation.
- Neighboring nodes are specified for the end nodes of the green links. Compare the layout mode without neighboring to the layout mode with neighboring.
- Note the difference between tip-over alignment and tip-over layout mode. Tip-over alignment affects all nodes. Tip-over layout mode tries to fit the layout to the aspect ratio and therefore affects only some nodes. For example, the effect of the tip-over layout mode might not be visible for the medium graph with default offsets and a bottom or top flow direction. The reason is because this graph fits best to the aspect ratio without any tip-over alignment. It depends on which node is chosen as the root node.
- The difference between the radial and the alternating radial mode is most visible with the large sample graph. The tip-over alignment option has no effect in the level and radial layout modes.
- The balloon mode works best with the samples named "balloonXXX". The balloon mode has additional modes for radius and angles that occur in the layout. These options are only displayed when the balloon mode is selected. For details, see the relevant section of the User's documentation.
- The status bar at the bottom of the window displays a message indicating which action was performed. While the layout is being performed, the status bar shows the percentage that is already completed.
How to Run the Code Example as an Application
This code example can
be run as an application.
The installation directory contains
an executable JAR file,
treelayout.jar
,
that allows you to execute the code example with a double click from a
file browser. Note that if you are using Internet Explorer, you can
open the installation directory
and execute the JAR file from the browser. This
technique may not work in other Web browsers.
Alternatively, you
can run the code example application from the command line.
First check that the Ant utility is properly configured. If not, see the
instructions on how to configure Ant for Perforce JViews.
Then, go to the installation directory
of the code example and type:
ant run
Topics Covered
- Grapher
- Graph Layout
- Tree Layout in Java Code
- Tree Layout Parameters
Installation Directory
The Tree Layout (Java SDK Version) code example is installed here.
Classes Involved
- ilog.views.graphlayout.tree.IlvTreeLayout
- ilog.views.graphlayout.random.IlvRandomLayout
- ilog.views.IlvGrapher
- ilog.views.IlvManagerView