Perforce JViews Diagrammer Code Example: Link Layout (Java SDK Version)
Description
This sample shows how to use the Link Layout algorithm
in a Java application.
It shows how to perform a Link 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 or CSS.
A version of the Link Layout sample that uses CSS can be found here
How to Use the Code Example
- The Link Layout algorithm reshapes the links of a graph without moving the nodes. By default, the algorithm computes orthogonal links. That is, links composed of alternating horizontal and vertical segments. Optionally, direct links can be computed.
-
This application shows a manager view that displays a grapher read from an
IVL
file. You may change the grapher sample using the list at the top of the application.- Sample1, Sample2, and Sample3 are typical graphs of different sizes for the short link layout mode. Sample1 shows the advantage of the short link mode to connect links in the center of the node border. This is in contrast to the long link mode, which in order to find a straight route on the grid. It sometimes uses connection points closer to a node corner.
- Sample4 and Sample5 are typical graphs for the long link layout mode with orthogonal links.
- Sample5 shows the capability of the long link layout mode to find a route in a labyrinth without node overlaps.
- The application also has interactor buttons on the top of the application window. They are: pan, select, zoom box, zoom in, zoom out, and show all (fit to contents).
- You may use the select interactor to select a root node for the Link Layout.
- On the bottom of the application window, there is the Layout button. It is used to perform a layout by using the Link Layout algorithm. Two checkboxes allow you to choose the layout mode (short links with a limited number of bends placed freely in the plane or long links placed overlap-free on a grid), and the desired link style (orthogonal or direct). Furthermore, a checkbox allows you to enable or disable the automatic layout feature. If it is selected, a layout is automatically performed whenever a node is moved or a link is changed.
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,
linklayout.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
- Link Layout in Java Code
- Link Layout Parameters
Installation Directory
The Link Layout (Java SDK Version) code example is installed here.