skip to main content
Defense > Programmer's documentation > Essential Features > Graphers > Managing nodes and links
 
Managing nodes and links
Introduces nodes and links and explains how to manage the nodes and links in a grapher.
*Nodes
*Describes what nodes are.
*Links
*Describes what links are.
*Predefined link classes
*Describes the predefined link classes.
*Managing link visibility
*Describes how to manage the visibility of links.
*Showing and hiding grapher branches
*Describes how to manage the visibility of grapher branches.
Nodes
Nodes are simply graphic objects, presented in a grapher. Any graphic object can be used as a node in a grapher.
To add a node to a grapher, use one of the following methods:
 
void addNode(IlvGraphic obj, boolean redraw)
 
void addNode(IlvGraphic obj, int layer, boolean redraw)
These methods add the object to the specified layer of a grapher and add additional information to the object so that it becomes a node. Graphic objects that have already been added to the grapher using the addObject method can be made into nodes of the grapher using the method:
 
void makeNode(IlvGraphic obj)
Links
Links are graphic objects used to interconnect nodes in a grapher.
All links are instances of the class IlvLinkImage (or subclasses). The constructor of the class IlvLinkImage has two graphic objects as parameters, so, when creating a link, you always have to give the origin and destination of the link. Here is the constructor of IlvLinkImage :
 
IlvLinkImage(IlvGraphic from, IlvGraphic to, boolean oriented)
The oriented parameter specifies whether or not an arrowhead is to be drawn at one end of the link. Once a link is created, you can add it to the grapher using one of the following methods:
 
void addLink(IlvLinkImage obj, boolean redraw)
 
void addLink(IlvLinkImage obj, int layer, boolean redraw)
The following code creates a grapher with two nodes and a link.
 
IlvGrapher grapher = new IlvGrapher();
IlvGraphic node1 = new IlvLabel(new IlvPoint(0,0), "node 1");
grapher.addNode(node1, false);
IlvGraphic node2 = new IlvLabel(new IlvPoint(100, 0), "node 2");
grapher.addNode(node2, false);
IlvLinkImage link = new IlvLinkImage(node1, node2, true);
grapher.addLink(link, false);
Predefined link classes
The library provides a set of predefined links:
*IlvLinkImage - a direct link between two nodes.
*IlvPolylineLinkImage - a link defined by a polyline.
*IlvOneLinkImage - a link defined by two lines forming a right angle.
*IlvOneSplineLinkImage - a link that shows a spline.
*IlvDoubleLinkImage - a link defined by three lines forming two right angles.
*IlvDoubleSplineLinkImage - a link defined by two spline angles.
*IlvSplineLinkImage - a free-form spline capable of creating mono- or multicurve links.
*IlvEnhancedPolylineLinkImage - a link defined by a polyline that supports link shape policies to keep the link in orthogonal shape or to display link crossings or to organize the multi links and self links in bundles. See Shape policies for details.
*IlvLinkBundle - a link that displays a set of individual links between two nodes in a fixed order and with a specified distance between them.
Managing link visibility
The visibility of links can be controlled independently of the visibility of nodes. This allows you to set a link visible even though its origin and destination nodes are invisible.
It is possible to couple the visibility of a link to the visibility of its end nodes. In this case, the visibility of the link can no longer be controlled independently. A link becomes automatically invisible if its origin node or its destination node becomes invisible. To enable this behavior, you must install the IlvLinkVisibilityHandler as manager listener on the grapher.
 
IlvGrapher grapher = new IlvGrapher();
grapher.addManagerContentChangedListener(new IlvLinkVisibilityHandler());
When the link visibility handler is installed, it is possible to select which links are managed by the handler and which links are not managed.
The visibility of a managed link is derived from the visibility of its end nodes. The visibility of an unmanaged link is independent of the visibility of its end nodes and can be controlled by setVisible. By default, all links are managed. Setting a Link as Unmanaged to Control Its Visibility shows how to set a link as unmanaged to control its visibility.
Setting a Link as Unmanaged to Control Its Visibility
 
// install a link visibility handler. All links are managed.
grapher.addManagerContentChangedListener(new IlvLinkVisibilityHandler());
// mark one link as unmanaged
IlvLinkImage link = ...
IlvLinkVisibilityHandler.setManaged(link, false);
// the visibility of the unmanaged link can be controlled independently
grapher.setVisible(link, false, redraw);
NOTE In nested graphers, it is sufficient to install the link visibility handler on the top-level grapher only as tree content-changed listener to manage the visibility of all links in all subgraphers. See Content-change events in nested managers.
Showing and hiding grapher branches
You can turn on or off the visibility of the nodes and links that compose a branch of a grapher. Use the method:
 
IlvGrapher.setVisibleBranch(IlvGraphic node, boolean visible,
                            boolean origin)
If the argument origin is true, the method will show or hide the branch that has the node as its origin; that is, all nodes and links reachable by a traversal from the origins to the destinations. The visibility of the node from which the traversal starts is never changed.
If the argument origin is false, the method will show or hide the branch that has the node as its destination; that is, all nodes and links reachable by a traversal from the destinations to the origins. The visibility of the node from which the traversal starts is never changed.
In addition, the following method allows you to specify how many levels away from the start node that nodes and links should start to be shown or hidden:
 
IlvGrapher.setVisibleBranch(IlvGraphic node, int level,
                            boolean visible, boolean origin)
If the level is 0, this method is equivalent to the first method without the level argument.
If the level is 1, the visibility is kept unchanged for the links incident to the starting node and for the nodes adjacent to these links.
If the level is 2, the visibility is kept unchanged for the links incident to the starting node, the nodes adjacent to these links, the links incident to these later nodes, the nodes adjacent to these later links, and so on.
The change of visibility is performed using the method setVisible.
For an example, see <installdir> /jviews-framework/codefragments/show-hide-branch/index.html.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.