Creating and accessing an intergraph link

To be able to create intergraph links, you must have a hierarchy of nested graphers (IlvGrapher). The hierarchy should not contain a manager ( IlvManager); otherwise the library will not let you create an intergraph link.

Creating an intergraph link

Given that an intergraph link has an origin and a destination in different graphers, the question that arises is in which grapher the link is stored. The intergraph link between a node stored in grapher A and a node stored in grapher B must be stored in the first common ancestor of A and B, as shown in the following figure.
commongrapher.gif
Intergraph link in a hierarchy of graphers
In this figure, the red intergraph link that connects an object of A and an object of B must be stored in grapher C, the first common ancestor of A and B.
The IlvGrapher class provides a static utility method that allows you to determine the first common grapher:
static IlvGrapher getLowestCommonGrapher(IlvGraphic obja, IlvGraphic objb)  
To create an intergraph link, the code will look like this (assuming that the origin and destination variables have been created and added in different graphers):

IlvGraphic origin, destination;
IlvLinkImage link;

...

link = new IlvLinkImage(origin, destination, false);

IlvGrapher common = IlvGrapher.getLowestCommonGrapher(origin, destination);

common.addLink(link, false);
The IlvGrapher .addInterGraphLink static utility method allows you to add the link directly to the common parent grapher:
static void addInterGraphLink(IlvLinkImage link, boolean redraw)  
The code shown in the previous example is equivalent to:
IlvGraphic origin, destination;
IlvLinkImage link;

...

link = new IlvLinkImage(origin, destination, false);

IlvGrapher.addInterGraphLink(link, false);

Accessing an intergraph link

The IlvGrapher class also provides methods that let you access intergraph links stored in a grapher in an efficient way:
IlvGraphicEnumeration getInterGraphLinks()  
int getInterGraphLinksCount()  
Since an intergraph link is stored in the same way as other links in the grapher, it is also part of the list of all objects contained in this grapher returned by the getObjects method of the class IlvManager :
IlvGraphicEnumeration getObjects()  
Nevertheless, calling the getInterGraphLinks method is much more efficient than traversing all objects of the grapher.
To distinguish an intergraph link from other objects in the grapher, you can use the following method of the IlvGrapher class:
boolean isInterGraphLink(IlvGraphic obj)  
This method returns true if the specified graphic object is a link stored in the grapher instance with the origin or the destination stored somewhere else. That is, if the graphic object is an intergraph link.
The IlvGrapher class also gives you access to intergraph links that are leaving or entering a grapher. You can access such links using the methods:
IlvGraphicEnumeration getExternalInterGraphLinks()  
int getExternalInterGraphLinksCount()  
The difference between the methods getInterGraphLinks and getExternalInterGraphLinks is:
  • The first method, getInterGraphLinks, returns the intergraph links stored in a grapher with an origin or destination in another grapher
  • The second method, getExternalInterGraphLinks, returns the intergraph links stored in another grapher but with the origin or destination in this grapher
If the grapher has no subgraphers, the external intergraph links obtained by getExternalInterGraphLinks() are all links that are leaving or entering the grapher.
If the grapher has subgraphers, the intergraph links that leave the grapher have one of the following characteristics:
  • An end node in this grapher
  • An end node in a subgrapher of this grapher
Calling getExternalInterGraphLinks() on the grapher gives only the links with an end node in the grapher, not the links with an end node in a subgrapher of the grapher.
In this case, links that are leaving or entering the nesting hierarchy of the grapher can be obtained by examining all external intergraph links of the subgraphers recursively. To help in this task the following convenience methods are supplied: getTreeExternalInterGraphLinks and getTreeExternalInterGraphLinksCount.
When a grapher is moved, it is possible that the grapher and all its nested subgraphers appear at a new location on the screen. The grapher displacement causes the shape of the following links to change:
  • All links that are directly connected to the grapher. That is, have the grapher as origin or destination.
  • All links that are obtained by grapher.getTreeExternalInterGraphLinks().
The following figure illustrates interlinked nested graphers:
externalintergraphlink.gif
External intergraph link
Grapher A contains two graphers, B and D. Grapher B contains another grapher, C. The intergraph link from an object of C to an object of D is then stored in A.
This link is an intergraph link of A (returned in getInterGraphLinks called on A) and is also an external intergraph link of C and D (returned by getExternalInterGraphLinks called on C or D).
Neither the origin nor destination of the intergraph link ends in grapher B, and thus this link is not returned by calling getExternalInterGraphLinks on B. However, the link is returned by calling getTreeExternalInterGraphLinks on B, since its origin node is nested inside B.