The IlvGraphModel class is an abstract Java™ class. Because it does not provide
a concrete implementation of a graph data structure, a complete
implementation must be provided by “adapter” classes. The adapters
extend the
IlvGraphModel
class and must use an underlying graph data structure. A special
adapter class called IlvGrapherAdapter is provided so that an IlvGrapher can be used as the underlying
graph data structure.
Note
If an application uses the
IlvGrapher
class, the grapher can be attached directly to the layout instance
without explicitly using a graph model, see the attach method. In this case, the appropriate
adapter (
IlvGrapherAdapter
) will be created internally. This adapter can be retrieved using
the getGraphModel method, which will return an
instance of
IlvGrapherAdapter
.
Most of the methods defined in the
IlvGraphModel
class have a name and definition very similar to the corresponding
methods of the
IlvGrapher
class. The main difference is that the arguments of the
IlvGraphModel
methods are
java.lang.Object
instead of
IlvGraphic
or
IlvLinkImage
. The methods can be divided into several categories that provide
information on the structure of the graph, the geometry of the
graph, modification of the graph geometry, and notification of
changes in the graph.
This section is divided as follows:
Information on the structure of the graph
The following methods of the IlvGraphModel class allow the layout
algorithms to retrieve information on the structure of the graph:
Enumeration getNodesAndLinks()
Enumeration getNodes()
int getNodesCount()
Enumeration getLinks()
int getLinksCount()
boolean isNode(Object obj)
boolean isLink(Object obj)
Enumeration getLinks(Object node)
int getLinksCount(Object node)
Enumeration getLinksFrom(Object node)
int getLinksFromCount(Object node)
Enumeration getLinksTo(Object node)
int getLinksToCount(Object node)
Enumeration getNeighbors(Object node)
int getNodeDegree(Object node)
Object getFrom(Object link)
Object getTo(Object link)
Object getOpposite(Object link, Object node)
boolean isLinkBetween(Object node1, Object node2)
The following methods are provided for use with nested graphs
(see also Nested layouts):
IlvGraphModel getParentModel()
IlvGraphModel getRootModel()
IlvGraphModel getGraphModel(Object subgraph)
IlvGraphModel createGraphModel(Object subgraph)
Enumeration getSubgraphs()
int getSubgraphsCount()
boolean isSubgraph(Object obj)
Enumeration getInterGraphLinks()
int getInterGraphLinksCount()
boolean isInterGraphLink(Object obj)
Information on the geometry of the graph
The following methods of the
IlvGraphModel
class allow the layout algorithms to retrieve information on the
geometry of the graph:
IlvRect boundingBox(Object nodeOrLink)
IlvRect boundingBox()
IlvPoint[] getLinkPoints(Object link)
IlvPoint getLinkPointAt(Object link, int index)
int getLinkPointsCount(Object link)
float getLinkWidth(Object link)
The
boundingBox
method is called by a layout algorithm whenever it needs to get
the position and the dimensions of a node or a link. The other
methods are used mainly by link layout algorithms.
Modification of the geometry of the graph
The following methods of the
IlvGraphModel
class allow a layout algorithm to modify the geometry of the
graph:
void moveNode(Object node, float x, float y, boolean redraw)
void reshapeLink(Object link, IlvPoint fromPoint, IlvPoint[] points, int startIndex, int length, IlvPoint toPoint, boolean redraw)
void move(float x, float y, boolean redraw)
Layout algorithms that compute new coordinates for the nodes use
the
moveNode
method. Link layout algorithms that compute new shapes for the
links call one of the
reshapeLink
methods.
Notification of changes
The following methods of the
IlvGraphModel
class allow a layout algorithm to be notified of changes in the
graph:
void addGraphModelListener(GraphModelListener listener)
void removeGraphModelListener(GraphModelListener listener)
void fireGraphModelEvent(GraphModelEvent event)
void fireGraphModelEvent(Object nodeOrLink, int type, boolean adjusting)
void adjustmentEnd()
A “change” in the graph can be a structure
change (that is, a node or a link was added or removed) or a
geometry change (that is, a node or a link was moved or
reshaped). The graph model event listener mechanism provides a
means to keep the layout algorithms informed of these changes.
When the layout algorithm is restarted on the same graph, it is
able to detect whether the graph has changed since the last time
the layout was successfully performed. If necessary, the layout
can be performed again. If there is no change in the graph, the
layout algorithm can avoid unnecessary work by not performing the
layout. To know whether the previous layout is still valid or it
must be redone, the layout algorithms call the following method
of the model:
boolean isLayoutNeeded()
The graph model event listener is defined by the GraphModelListener interface. To receive
the graph model events (that is, instances of the GraphModelEventclass), a class must
implement the
GraphModelListener
interface and must register itself using the addGraphModelListener method of the
IlvGraphModel
class.
Note
The creation of the graph model event listener is handled
transparently by the IlvGraphModel class. Therefore, there is
usually no need to manipulate this listener directly.
Storing and retrieving data objects (“properties”)
The following methods of the
IlvGraphModel
class allow a layout algorithm to store data objects for each
node, link, or graph:
void setProperty(Object nodeOrLink, String key, Object value)
Object getProperty(Object nodeOrLink, String key)
void setProperty(String key, Object value)
Object getProperty(String key)
The layout algorithm may need to associate a set of properties
with the nodes and links of the graph or with the graph itself.
Properties are a set of
key-value
pairs, where the
key
is a
String
object and the
value
can be any kind of information value.
Note
Creating a property and associating it with a node, a link, or a
graph is handled transparently by the layout algorithm whenever
it is necessary. Therefore, there is usually no need to
manipulate the properties directly. However, if needed, you can
do this in your own subclass of IlvGraphLayout.