Download JGraph and JGraph Layout Pro User Manual
Transcript
JGraph User Manual edges have a direction in the model traveling from the source end to the target end. Again, the types involved in these methods are all Objects to provide complete flexibility. In combination with the GraphModel interface it is possible to obtain the cell(s) connecting to edges, determine their type and navigate consistently, without referring to implementation specifics. The Port interface defines the necessary methods to add, remove and obtain the edges connected to it. Remember that ports are conceptually a entity associated with a vertex to which any number of edges may connect. Edges may connect either their source or target end to a port, making that port the source or target port, respectively. An edge may also connect both its source and target ends to the same port, making the edge a self-loop. Note that self-loops are created when an edge has the same vertex as its source and target, not just if the source and targets port is the same. When testing for self-loops you should ensure that you obtain the source and target vertices, generally the parents of the source and target port, and see if they are the same vertex. The Edge interface also defines the static Routing interface. This interface defines the route method which deal with drawing the edge given a number of points through which the edge passes. This will be expanded upon later in this Chapter on the section on using edges. Port defines the methods edges(), addEdge() and removeEdge(). The add and remove methods take an Object as per-standard in the JGraph design. Edges() returns an Iterator to the Collection of Edges connected to this Port, as set up by the add and remove methods. Note that Port does not store any information about whether or not it is the source or target port of edges that connect to it. This information is only in Edges to avoid redundancy and the danger of the information getting out of synchronization. The two lesser known methods in Port are getAnchor() and setAnchor(). The idea of anchoring also requires an explanation of how ports are positioned, be they relative or absolute and where the origin of their offset is or if they have no offset at all. This is described in the later section in this chapter on Using Ports. 3.2.3 THE DEFAULTGRAPHCELL DefaultGraphCell is the standard implementation of a graph cell provided in JGraph and as with most of the default implementations is suitable either as-is, or as the superclass of your cells for the majority of applications. Like the corresponding interface, vertices use the DefaultGraphCell class and edges and ports use default classes subclassed from DefaultGraphCell: Page 44