public abstract class IlvGraphModel extends Object
IlvGraphModel
defines a suitable generic API for graphs
that have to be laid out with JViews graph layout algorithms.
The concept of the graph model is in many ways similar to Swing's TreeModel and TableModel. Instead of asking programmers to extend their data objects from a predefined base class, it allows the use of any application object as a graph, a node, or a link. This makes it much easier to add graph layout features to existing applications.
All the layout algorithms provided in JViews are designed to lay out a
graph model. This allows any application to benefit from the JViews
graph layout algorithms, whether or not it uses the JViews grapher
(IlvGrapher
). However, to make things
simple for the common case of applications that use an
IlvGrapher
, it is not mandatory to work directly with the
graph model, except when using some of the advanced features, such as
filtering (see the methods IlvGrapherAdapter.setFilter
and IlvGrapherAdapter.addLayer
), or when using some features that are
needed only when laying out an IlvGrapher
, such as the
reference transformer (IlvGrapherAdapter.setReferenceTransformer
) and the reference view
(IlvGrapherAdapter.setReferenceView
).
Learning to use these classes is a bit difficult because they are very
general and use class java.lang.Object
for the arguments
of many methods (representing nodes, links, and subgraphs). But if you
are spending the time learning Swing, especially the packages
javax.swing.tree
and javax.swing.table
, you
will be learning the same concepts. For laying out
IlvGrapher
graphs, most often it is sufficient to use the
API of the layout algorithms.
This class is abstract. Since its purpose is not to provide a concrete
implementation of a graph data structure, a complete implementation
must be provided by "adapter" classes. Thus, to create a concrete
Graph Model, you need to provide an implementation for the abstract
methods in an "adapter" class. The adapters extend the graph model and
must use an underlying graph data structure. A special adapter class,
IlvGrapherAdapter
, is provided in order to use an IlvGrapher
as the underlying graph data
structure.
Note that if an application uses the class IlvGrapher
, the grapher can be attached
directly to the layout instance without explicitly using a graph model
(see the method IlvGraphLayout.attach
). In this case the appropriate adapter (IlvGrapherAdapter
) is created internally. If necessary, this adapter
can be retrieved using the method IlvGraphLayout.getGraphModel()
, which in this circumstance returns an
instance of IlvGrapherAdapter
.
The methods defined in this class can be divided into the following categories:
getNodes()
, getLinks()
, getNeighbors(Object)
, and so on.
boundingBox(Object)
and getLinkPoints(Object)
.
moveNode
and reshapeLink
.
IlvGrapherAdapter
provides
implementation for all the methods.)
Other methods are useful for managing nested graphs, that is, if a node of a graph can be a graph:
getSubgraphs()
, getSubgraphsCount()
getParentModel()
getInterGraphLinks()
, getInterGraphLinksCount()
createGraphModel(java.lang.Object)
, getGraphModel(java.lang.Object)
Finally, the method performLayout(ilog.views.graphlayout.IlvLayoutProvider, boolean, boolean, boolean)
allows you to perform
layout algorithms on a nested graph. To customize the layout to be
applied to each subgraph, you can implement the interface IlvLayoutProvider
or use its default implementation IlvDefaultLayoutProvider
(in most cases the latter is the easiest
choice).
Note that the efficiency of the layout algorithms directly depends on the efficiency of the implementation of the adapter class as well as the efficiency of the implementation of the underlying graph data structure.
If the graph model is subclassed in order to use a graph data
structure other than IlvGrapher
, the performance can be
improved by replacing, in the adapter class, the default
implementation of the nonabstract methods with an overridden version
that is optimized for the particular graph data structure. The IlvGrapherAdapter
provides the optimized methods for the JViews
grapher (IlvGrapher
).
The default implementations of the following methods, although functional, are particularly inefficient. Any time the underlying graph allows a more efficient implementation, these methods should be overridden:
getNodesCount()
getLinksCount()
getLinksCount(Object)
getLinksFromCount(Object)
getLinksToCount(Object)
getSubgraphsCount()
getInterGraphLinksCount()
IlvGraphModel
) that
uses an IlvGrapher
as an underlying graph must be
implemented as a subclass of IlvGrapherAdapter
.
Note that you must call the method dispose()
after detaching
the layouts when you no longer need the graph model instance;
otherwise, some objects may not be garbage collected. This is
necessary only if the graph model instance is directly created by your
code. Calling dispose()
is not necessary if the graph model
instance is created internally by the JViews Graph Layout library for
instance, when directly attaching an IlvGrapher
to a
layout instance using IlvGraphLayout.attach(IlvGrapher)
or
when using an IlvDefaultLayoutProvider
for recursive layout.
IlvGraphLayout.attach(ilog.views.graphlayout.IlvGraphModel)
,
IlvGraphLayout.attach(ilog.views.IlvGrapher)
,
IlvGrapherAdapter
Constructor and Description |
---|
IlvGraphModel()
Creates a new
IlvGraphModel . |
Modifier and Type | Method and Description |
---|---|
void |
addGraphModelListener(GraphModelListener listener)
Adds a listener to listen for modifications of the graph models.
|
void |
adjustmentEnd()
Notifies the graph model that it is the end of a series of events.
|
void |
afterAnimationStep()
Notifies the graph model that a layout animation step has finished.
|
protected void |
afterAttach(IlvGraphLayout layout)
Notifies the graph model that it has been attached to a layout.
|
protected void |
afterDetach(IlvGraphLayout layout)
Notifies the graph model that it has been detached from a layout.
|
void |
afterLayout(IlvGraphLayout layout,
IlvGraphLayoutReport layoutReport,
boolean redraw)
Notifies the graph model that a layout session has finished.
|
void |
beforeAnimationStep()
Notifies the graph model that a layout animation step has been
started.
|
void |
beforeLayout(IlvGraphLayout layout,
boolean redraw)
Notifies the graph model that a layout session has been started.
|
IlvRect |
boundingBox()
Returns the bounding rectangle of the graph.
|
abstract IlvRect |
boundingBox(Object nodeOrLink)
Returns the bounding rectangle of a node or a link.
|
protected abstract IlvGraphModel |
createGraphModel(Object subgraph)
Creates a new graph model for a subgraph.
|
void |
dispose()
Disposes of this
IlvGraphModel and releases any resources
that it is using. |
protected void |
fireGraphModelEvent(GraphModelEvent event)
This method must be called by the adapter classes when the contents of
the graph have changed.
|
void |
fireGraphModelEvent(Object nodeOrLink,
int eventType,
boolean adjusting)
Notifies the graph-model-event listeners that nodes or links have been
added or removed, or that their geometry has changed (nodes or links
were moved or reshaped).
|
void |
geometryChanged(boolean adjusting)
Deprecated.
Beginning with JViews 5.5, use the method
fireGraphModelEvent(java.lang.Object, int, boolean) instead. |
abstract Object |
getFrom(Object link)
Returns the origin node of a link.
|
IlvGrapher |
getGrapher()
Returns the
IlvGrapher that stores the nodes and links of the
graph. |
IlvGraphModel |
getGraphModel(Object subgraph)
Returns a graph model instance for a subgraph of a nested graph.
|
int |
getInstanceId()
A utility method that returns a unique integer value for each graph
model instance inside the same Java program.
|
abstract Enumeration |
getInterGraphLinks()
Returns the intergraph links contained in this graph.
|
int |
getInterGraphLinksCount()
Returns the number of intergraph links contained in this graph.
|
IlvGraphLayout |
getLayout(IlvLayoutProvider layoutProvider,
Object subgraph)
Returns the layout instance for a subgraph of the nested graph
encapsulated by this graph model.
|
Enumeration |
getLayouts(IlvLayoutProvider layoutProvider,
boolean preOrder)
Returns the instances of
IlvGraphLayout for the nested
graph encapsulated by this graph model. |
IlvPoint |
getLinkPointAt(Object link,
int index)
Returns the point of a link at a specified index.
|
abstract IlvPoint[] |
getLinkPoints(Object link)
Returns the points that define a link.
|
abstract int |
getLinkPointsCount(Object link)
Returns the number of points that define a link, including the
connection points of the link on the origin and destination nodes.
|
abstract Enumeration |
getLinks()
Returns an enumeration of the links.
|
Enumeration |
getLinks(Object node)
Returns an enumeration of all the links that have
node as
their origin or destination. |
int |
getLinksCount()
Returns the number of links.
|
int |
getLinksCount(Object node)
Returns the number of links adjacent to a node.
|
abstract Enumeration |
getLinksFrom(Object node)
Returns an enumeration of all the links that have
node as
their origin. |
int |
getLinksFromCount(Object node)
Returns the number of links that have
node as their
origin. |
abstract Enumeration |
getLinksTo(Object node)
Returns an enumeration of all the links that have
node as
their destination. |
int |
getLinksToCount(Object node)
Returns the number of links that have
node as their
destination. |
double |
getLinkWidth(Object link)
Returns the width of a link.
|
Enumeration |
getNeighbors(Object node)
Returns an enumeration of all the nodes that are the "neighbors" of
node , that is, the nodes that have a common normal link
with node . |
int |
getNodeDegree(Object node)
Returns the degree of a node, that is, the number of its neighbors.
|
abstract Enumeration |
getNodes()
Returns an enumeration of the nodes.
|
Enumeration |
getNodesAndLinks()
Returns an enumeration of the nodes and links.
|
int |
getNodesCount()
Returns the number of nodes.
|
Object |
getOpposite(Object link,
Object node)
Returns the opposite node on a link.
|
IlvGraphLayout |
getOriginatingLayout()
Returns the layout that created this model internally because an
IlvGrapher got directly attached. |
abstract IlvGraphModel |
getParentModel()
Returns the graph model that encapsulates the parent graph of the
graph encapsulated by this graph model, or
null . |
Object |
getProperty(Object nodeOrLink,
String key)
Returns the value of a property.
|
Object |
getProperty(String key)
Returns the value of a property of the graph model.
|
IlvGraphModel |
getRootModel()
Returns the root graph model of this graph model, if any, or
null otherwise. |
abstract Enumeration |
getSubgraphs()
Returns an enumeration of the subgraphs of the graph encapsulated by
this graph model.
|
int |
getSubgraphsCount()
Returns the number of subgraphs.
|
abstract Object |
getTo(Object link)
Returns the destination node of a link.
|
IlvTransformer |
getTransformer(IlvGraphModel subgraphModel)
Returns the transformer that allows you to convert the coordinate
system of the graph model of a subgraph to the coordinate system of
this graph model.
|
boolean |
hasMoveableConnectionPoint(Object link,
boolean origin)
Returns
true if the connection point of link
on the origin or destination node can be moved by a call to the
method reshapeLink(java.lang.Object, ilog.views.IlvPoint, ilog.views.IlvPoint[], int, int, ilog.views.IlvPoint, boolean) . |
boolean |
hasPinnedConnectionPoint(Object link,
boolean origin)
Returns
true if the connection point of link
on the origin or destination node is "pinned," and false
otherwise. |
boolean |
isConnectionPointCheckEnabled()
Returns
true if the checks for the connection points of
the links are enabled, and false otherwise. |
abstract boolean |
isInterGraphLink(Object obj)
Returns
true if the object is a valid intergraph link,
and false otherwise. |
boolean |
isInternalGraphModelChecking()
Returns
true if the extended checking of internally
created graph models is enabled. |
boolean |
isLayoutNeeded(IlvGraphLayout layout)
Returns
true if a given layout that has been already
applied to this graph is still valid. |
abstract boolean |
isLink(Object obj)
Returns
true if the object is a valid normal link, and
false otherwise. |
boolean |
isLinkBetween(Object node1,
Object node2)
Tests whether a normal link exists between two nodes.
|
boolean |
isLinkCheckEnabled()
Returns
true if the checks for the links are enabled, and
false otherwise. |
abstract boolean |
isNode(Object obj)
Returns
true if an object is a valid node, and
false otherwise. |
boolean |
isReshapeableLink(Object link,
boolean toStraightLine)
Returns
true if link can be reshaped, and
false otherwise. |
abstract boolean |
isSubgraph(Object obj)
Returns
true if the object is a valid subgraph, and
false otherwise. |
void |
move(double x,
double y,
boolean redraw)
Moves the entire graph.
|
abstract void |
moveNode(Object node,
double x,
double y,
boolean redraw)
Changes the position of the specified node.
|
int |
performLayout(IlvLayoutProvider layoutProvider,
boolean force,
boolean redraw,
boolean traverse)
Applies layout instances recursively to this graph model.
|
int |
performLayout(IlvLayoutProvider layoutProvider,
IlvGraphLayout recursiveLayout,
boolean force,
boolean redraw,
boolean traverse)
Applies layout instances recursively to this graph model.
|
void |
removeGraphModelListener(GraphModelListener listener)
Removes a listener added with
addGraphModelListener . |
abstract void |
reshapeLink(Object link,
IlvPoint fromPoint,
IlvPoint[] points,
int startIndex,
int length,
IlvPoint toPoint,
boolean redraw)
Reshapes all the points of a link, given an array of intermediate
points, the start position in the array of points, the number of
intermediate points, and the connection points.
|
void |
setConnectionPointCheckEnabled(boolean enable)
Enables or disables the checks of the connection points of the links
on the origin or destination node.
|
void |
setInternalGraphModelChecking(boolean flag)
Enables or disables the extended checking of internally created graph
models, that is, the grapher adapter that is internally created
inside
IlvGraphLayout.attach(IlvGrapher) . |
void |
setLinkCheckEnabled(boolean enable)
Enables or disables the checks of the links.
|
void |
setProperty(Object nodeOrLink,
String key,
Object value)
Sets the value of a property for a node or a link.
|
void |
setProperty(String key,
Object value)
Sets the value of a property for the graph model.
|
void |
structureChanged(boolean adjusting)
Deprecated.
Beginning with JViews 5.5, use the method
fireGraphModelEvent(java.lang.Object, int, boolean) instead. |
public void dispose()
IlvGraphModel
and releases any resources
that it is using. An IlvGraphModel
object cannot be used
after the dispose
method has been called. If there are
any layouts still attached, they get automatically detached from the
graph model. The method recursively disposes of this graph model and
all its graph model children (if any).IlvGraphLayout.detach()
public final IlvGraphLayout getOriginatingLayout()
IlvGrapher
got directly attached. It returns
null
if the model was not internally created but
explicitly allocated by the user.IlvGraphLayout.attach(IlvGrapher)
public final void setInternalGraphModelChecking(boolean flag)
IlvGraphLayout.attach(IlvGrapher)
. Internally created
graph models are automatically disposed of when no longer needed. If
the checking is enabled, exceptions are thrown in certain situations
that are a potential misuse of the internally created graph model,
since it may be disposed of too early. The option is enabled by
default. Normally, you should not disable this option.flag
- Set to true
to enable extended checking.isInternalGraphModelChecking()
,
IlvGraphLayout.attach(IlvGrapher)
public final boolean isInternalGraphModelChecking()
true
if the extended checking of internally
created graph models is enabled.setInternalGraphModelChecking(boolean)
public final int getInstanceId()
public IlvGrapher getGrapher()
IlvGrapher
that stores the nodes and links of the
graph. It returns null
if the nodes and links are not
stored by the JViews grapher class (IlvGrapher
).
The default implementation always returns null
. The
method is overridden in the class IlvGrapherAdapter
.
public abstract IlvGraphModel getParentModel()
null
.null
.getGraphModel(java.lang.Object)
,
getRootModel()
public IlvGraphModel getRootModel()
null
otherwise.
If this method is called for a graph model encapsulating one of the
subgraphs of a nested graph, it returns the graph model that
encapsulates the topmost graph. It returns null
when
called on the graph model that encapsulates the topmost graph.
The returned root graph model is the one that created this graph
model by createGraphModel(java.lang.Object)
.
null
.getGraphModel(java.lang.Object)
,
getParentModel()
public IlvGraphModel getGraphModel(Object subgraph)
The typical way to deal with nested graphs is the following:
getGraphModel(subgraph)
on the root graph model. If a
graph model has already been created for a subgraph, the graph model
is returned. Otherwise, a new instance of a graph model is created by
calling createGraphModel(java.lang.Object)
on the root graph model.
subgraph
- The subgraph object. This is an object for which the
method isSubgraph(java.lang.Object)
, called on the parent graph model of the
returned graph model, returns true
. This must not be
the root graph.subgraph
.getRootModel()
protected abstract IlvGraphModel createGraphModel(Object subgraph)
Subclasses must override this method in order to return a new
instance of the appropriate subclass of IlvGraphModel
,
encapsulating subgraph
.
subgraph
- The subgraph object.public IlvTransformer getTransformer(IlvGraphModel subgraphModel)
null
to indicate that both
graph models use the same coordinate system.
The default implementation always returns null
.
public Enumeration getLayouts(IlvLayoutProvider layoutProvider, boolean preOrder)
IlvGraphLayout
for the nested
graph encapsulated by this graph model. It returns the layout
instance for this graph, and recursively for all subgraphs. The order
of the enumeration can be pre-order (that is, the layout of parent
graph comes before the layout of the subgraphs) or post-order (that
is, the layout of the subgraphs comes before the layout of the parent
graph).
layoutProvider
- The object that provides a layout instance to be
used for laying out each subgraph.preOrder
- If true
, the layout instances are returned
in pre-order, otherwise in post-order.IlvGraphLayout
for the nested
graph.performLayout(ilog.views.graphlayout.IlvLayoutProvider, boolean, boolean, boolean)
,
IlvGraphLayout.getLayouts(boolean)
public IlvGraphLayout getLayout(IlvLayoutProvider layoutProvider, Object subgraph)
layoutProvider
- The object that provides a layout instance to be
used for laying out subgraph
.subgraph
- The subgraph object. This must not be the root graph.IlvLayoutProvider.getGraphLayout(ilog.views.graphlayout.IlvGraphModel)
,
performLayout(ilog.views.graphlayout.IlvLayoutProvider, boolean, boolean, boolean)
,
getLayouts(ilog.views.graphlayout.IlvLayoutProvider, boolean)
,
IlvGraphLayout.getLayout(java.lang.Object)
public int performLayout(IlvLayoutProvider layoutProvider, boolean force, boolean redraw, boolean traverse) throws IlvGraphLayoutException
The layout instance to be applied to each subgraph is obtained using
the method IlvLayoutProvider.getGraphLayout(ilog.views.graphlayout.IlvGraphModel)
. If this method
returns null
for a given graph, no layout is applied to
this graph.
If the argument traverse
is false
and the
graph is nested, layout is applied only to the topmost graph. In this
case, the return value is the result code stored in the layout report
(see IlvGraphLayoutReport.getCode()
). If the argument
traverse
is true
, layout is applied
recursively to the top-level graph and all subgraphs. In this case,
the return value is the combined result code of all layout calls:
IlvGraphLayoutReport.EMPTY_GRAPHER
- The graph is empty.
IlvGraphLayoutReport.NOT_NEEDED
- The layout was
up-to-date in the graph and in all subgraphs.
IlvGraphLayoutReport.LAYOUT_DONE
- The layout was
successfully done in the graph and in all subgraphs, as needed.
IlvGraphLayoutReport.STOPPED_AND_VALID
- The layout was
successfully done in the graph and in all subgraphs, as needed, but
some layouts of subgraphs ran out of time before completion and
stored the result code STOPPED_AND_VALID
in their layout
reports.
IlvGraphLayoutReport.STOPPED_AND_INVALID
- The layout
was not completed. The method IlvGraphLayout.stopImmediately()
was called, or the layout of one of the subgraphs ran out of time
before completion and stored the result code
STOPPED_AND_INVALID
in its layout report. In this case,
the entire recursion stopped immediately and the layouts of the
remaining subgraphs were not done.
IlvRecursiveLayout
and IlvRecursiveMultipleLayout
.
When you lay out an IlvGrapher
object using this method, you
are recommended to use links of type IlvPolylineLinkImage
and link connectors of type
IlvFreeLinkConnector
. Unlike IlvRecursiveLayout
or IlvRecursiveMultipleLayout
, this method does not throw a chain of
IlvInappropriateLinkException
exceptions when the links or
link connectors are not appropriate. Therefore, if it is not possible
to ensure in advance that the link and link connector types are
appropriate, you are recommended to lay out the nested graphs using
IlvRecursiveLayout
or IlvRecursiveMultipleLayout
, because using these facilities it is
possible to use IlvGraphLayoutUtil.EnsureAppropriateLinks(IlvInappropriateLinkException)
to replace inappropriate links or link connectors automatically for
the entire nested graph.
layoutProvider
- The object that provides a layout instance to be
used for laying out each subgraph.force
- This parameter is passed to the method IlvGraphLayout.performLayout(boolean, boolean)
.redraw
- This parameter is passed to the method IlvGraphLayout.performLayout(boolean, boolean)
.traverse
- If false
, the layout instance provided by
layoutProvider
is applied to this graph model. If
true
, the layout instances provided by the
layoutProvider
layout are applied to this graph model
and recursively to all subgraph models of this graph model.IlvGraphLayoutReport.getCode()
).IlvGraphLayoutException
IlvGraphLayout.performLayout(boolean, boolean, boolean)
,
IlvGraphLayout.PerformLayout(IlvGraphModel, IlvLayoutProvider, boolean, boolean, boolean)
public int performLayout(IlvLayoutProvider layoutProvider, IlvGraphLayout recursiveLayout, boolean force, boolean redraw, boolean traverse) throws IlvGraphLayoutException
performLayout(IlvLayoutProvider, boolean, boolean,
boolean)
. This entry point for the layout of a nested graph is used
by the IlvRecursiveLayout
. You should not call this method directly.
IlvGraphLayoutException
public boolean isLayoutNeeded(IlvGraphLayout layout)
true
if a given layout that has been already
applied to this graph is still valid. The method returns
true
if at least one of the following holds:
IlvGraphLayout.isParametersUpToDate()
called on
layout
returns false
.
IlvGraphLayout.isGeometryUpToDate()
called on
layout
returns false
.
IlvGraphLayout.isStructureUpToDate()
called on
layout
returns false
.
false
public void beforeLayout(IlvGraphLayout layout, boolean redraw)
IlvGraphLayout.performLayout()
before the call to the method IlvGraphLayout.layout(boolean)
.
If necessary, you can override this method in order to perform
preliminary operations before the layout. In this case, you must
always call super.beforeLayout
.
layout
- The layout instance that is the origin of the
notification.redraw
- If true
, the layout algorithm will ask the
graph model to redraw the graph when the method
afterLayout
is called (that is, it will pass
true
for its redraw
argument).afterLayout(ilog.views.graphlayout.IlvGraphLayout, ilog.views.graphlayout.IlvGraphLayoutReport, boolean)
public void afterLayout(IlvGraphLayout layout, IlvGraphLayoutReport layoutReport, boolean redraw)
IlvGraphLayout.performLayout()
after
the method IlvGraphLayout.layout(boolean)
has finished, even if an
exception is thrown during the layout process.
Note that you can detect whether the layout was performed
successfully using the test layoutReport.getCode() ==
IlvGraphLayoutReport.LAYOUT_DONE
.
If necessary, you can override this method in order to perform some
operations after the layout. In this case, you must always call
super.afterLayout
. Note also that any overridden
implementation of this method should redraw the graph if the argument
redraw
is true
.
layout
- The layout instance that is the origin of the
notification.layoutReport
- The layout report, or null
.redraw
- If true
, the layout algorithm asks the graph
model to redraw the graph.beforeLayout(ilog.views.graphlayout.IlvGraphLayout, boolean)
protected void afterAttach(IlvGraphLayout layout)
IlvGraphLayout.attach(IlvGraphModel)
.
The default implementation does nothing. If necessary, you can override this method in order to perform some operations.
layout
- The layout instance to which the model has been attached.afterDetach(ilog.views.graphlayout.IlvGraphLayout)
,
IlvGraphLayout.attach(IlvGraphModel)
protected void afterDetach(IlvGraphLayout layout)
IlvGraphLayout.detach()
.
The default implementation does nothing. If necessary, you can override this method in order to perform some operations.
layout
- The layout instance from which the model has been
detached.afterAttach(ilog.views.graphlayout.IlvGraphLayout)
,
IlvGraphLayout.detach()
public void beforeAnimationStep()
The default implementation does nothing. If necessary, you can override this method in order to perform preliminary operations before the animation step.
afterAnimationStep()
public void afterAnimationStep()
The default implementation does nothing. To support the animation mechanism, this method can be overridden by an adapter to redraw the graph after each step of the layout.
beforeAnimationStep()
public Enumeration getNodesAndLinks()
getNodes()
and
getLinks()
.getNodes()
,
getLinks()
,
getNodesCount()
,
getLinksCount()
public abstract Enumeration getNodes()
public int getNodesCount()
getNodes()
.getNodes()
public abstract Enumeration getLinks()
public int getLinksCount()
getLinks()
.public abstract Enumeration getSubgraphs()
isNode(java.lang.Object)
returns
true
.isSubgraph(java.lang.Object)
,
getSubgraphsCount()
,
getNodes()
,
getLinks()
public int getSubgraphsCount()
getSubgraphs()
.getSubgraphs()
public abstract Enumeration getInterGraphLinks()
isInterGraphLink(java.lang.Object)
,
getInterGraphLinksCount()
public int getInterGraphLinksCount()
The default implementation simply counts the number of objects as
returned by the method getInterGraphLinks()
.
getInterGraphLinks()
public abstract Enumeration getLinksFrom(Object node)
node
as
their origin. This enumeration must not contain intergraph links,
that is, links whose origin or destination node is not stored in this
graph.node
- The origin node.isLink(java.lang.Object)
,
isInterGraphLink(java.lang.Object)
,
getLinksTo(java.lang.Object)
,
getLinks(java.lang.Object)
public int getLinksFromCount(Object node)
node
as their
origin. The default implementation simply counts the number of links
returned by the method getLinksFrom
.node
- The node.getLinksFrom(java.lang.Object)
public abstract Enumeration getLinksTo(Object node)
node
as
their destination. This enumeration must not contain intergraph
links, that is, links whose origin or destination node is not stored
in this graph.node
- The destination node.isLink(java.lang.Object)
,
isInterGraphLink(java.lang.Object)
,
getLinksFrom(java.lang.Object)
,
getLinks(java.lang.Object)
public int getLinksToCount(Object node)
node
as their
destination. The default implementation simply counts the number of
links returned by the method getLinksTo
.node
- The node.getLinksTo(java.lang.Object)
public Enumeration getLinks(Object node)
node
as
their origin or destination. This enumeration must not contain
intergraph links, that is, links whose origin or destination node is
not stored in this graph.
The default implementation uses the enumerations returned by the
methods getLinksFrom(Object)
and getLinksTo
to build the enumeration of all the links.
node
- The node.isLink(java.lang.Object)
,
isInterGraphLink(java.lang.Object)
,
getLinksCount()
,
getLinksFrom(java.lang.Object)
,
getLinksTo(java.lang.Object)
public int getLinksCount(Object node)
getLinks(Object)
.node
- The node.public Enumeration getNeighbors(Object node)
node
, that is, the nodes that have a common normal link
with node
. This method does not consider intergraph
links.
The default implementation browses the links connected to
node
(the method getLinks(Object)
is called)
and returns an enumeration that gives you access to each of their
opposite nodes (the method getOpposite(java.lang.Object, java.lang.Object)
is called). An
IllegalArgumentException
is thrown if the argument is
not a node of the graph.
In the case where a link that is incident to node
is a
self-link (that is, a link whose origin and destination are the same
node), the enumeration does not contain node
.
In the case of multiple links between node
and one of
its neighbors, the neighbor is contained in the enumeration the
number of times equal to the number of links.
node
- The node.isLink(java.lang.Object)
,
isInterGraphLink(java.lang.Object)
public int getNodeDegree(Object node)
The default implementation counts the number of elements in the
enumeration returned by the method getNeighbors(java.lang.Object)
. However, if
a node is contained in the enumeration returned by the method
getNeighbors
several times (for example, because
node
has more than one common link with a neighbor),
this neighbor is counted just once.
Note that any overridden implementation must take care not to count the same neighbor several times.
public Object getOpposite(Object link, Object node)
getFrom
and getTo
.
This method must work for intergraph links as well. Notice that for
intergraph links, the input node and the returned node may not be
nodes of this graph model (that is, isNode(java.lang.Object)
may return
false
).
public abstract Object getFrom(Object link)
This method must work for normal links and for intergraph links.
Notice that for intergraph links, the returned node may not be a node
of this graph model (that is, isNode(java.lang.Object)
may return
false
).
public abstract Object getTo(Object link)
This method must work for normal links and for intergraph links.
Notice that for intergraph links, the returned node may not be a node
of this graph model (that is, isNode(java.lang.Object)
may return
false
).
public abstract boolean isNode(Object obj)
true
if an object is a valid node, and
false
otherwise.
Note that an object can be both a node and a graph; therefore, both
this method and isSubgraph(java.lang.Object)
can return true
for
the same object.
obj
- The object to test.public abstract boolean isLink(Object obj)
true
if the object is a valid normal link, and
false
otherwise.
The method must return false
for intergraph links.
obj
- The object to test.isInterGraphLink(java.lang.Object)
public abstract boolean isInterGraphLink(Object obj)
true
if the object is a valid intergraph link,
and false
otherwise. An intergraph link is a link stored
in a given graph that has an origin or destination not stored in this
graph.obj
- The object to test.isLink(java.lang.Object)
,
IlvGrapherAdapter.isInterGraphLink(java.lang.Object)
public abstract boolean isSubgraph(Object obj)
true
if the object is a valid subgraph, and
false
otherwise. A subgraph is a node of this graph
model (that is isNode(java.lang.Object)
must return true
) that
represents a graph nested inside this graph. The method getGraphModel(java.lang.Object)
is applied to subgraphs when performing a nested
layout.
obj
- The object to test.public boolean isLinkBetween(Object node1, Object node2)
node1
and
node2
as their origin (the method
getLinksFrom
is called) and checks the other extremity
for each link (the method getTo
is called). The method
does not check for intergraph links.
public void setProperty(Object nodeOrLink, String key, Object value)
value
is null
, the property is removed.
Otherwise, the property value is set to value
. The
method must work for normal links and intergraph links.
The default implementation uses an internal data structure to store the binding between the node or link, the value of the property, and its key.
nodeOrLink
- The node or link for which the property is to be set.key
- The key string for the property.value
- The new value of the property.getProperty(java.lang.Object, java.lang.String)
public Object getProperty(Object nodeOrLink, String key)
null
if the property does not exist. The method must work for normal links
and intergraph links.
nodeOrLink
- The node or link for which the property is to be
retrieved.key
- The key string for the property.setProperty(java.lang.Object, java.lang.String, java.lang.Object)
public void setProperty(String key, Object value)
value
is null
, the property is removed.
Otherwise, the property value is set to value
. The
default implementation uses an internal data structure to store the
binding between the node or link, the value of the property, and its
key.key
- The key string for the property.value
- The new value of the property.getProperty(java.lang.Object, java.lang.String)
public Object getProperty(String key)
null
if the property does not exist.key
- The key string for the property.setProperty(java.lang.Object, java.lang.String, java.lang.Object)
public void addGraphModelListener(GraphModelListener listener)
listener
- The listener to add.removeGraphModelListener(ilog.views.graphlayout.GraphModelListener)
public void removeGraphModelListener(GraphModelListener listener)
addGraphModelListener
.listener
- The listener to remove.addGraphModelListener(ilog.views.graphlayout.GraphModelListener)
public final void structureChanged(boolean adjusting)
fireGraphModelEvent(java.lang.Object, int, boolean)
instead.GraphModelListener
listeners that the topology of
the graph has changed (nodes or links were added or removed).
It is the responsibility of the adapter classes to call this method any time the structure of the graph is changed (for example, when changes are due to user interaction).
public final void geometryChanged(boolean adjusting)
fireGraphModelEvent(java.lang.Object, int, boolean)
instead.public final void fireGraphModelEvent(Object nodeOrLink, int eventType, boolean adjusting)
It is the responsibility of the graph model subclasses to call this
method any time the contents of the model have changed (for example,
when changes are due to user interaction). The method constructs the
event and then calls fireGraphModelEvent(GraphModelEvent)
to
pass the event to the listeners.
This notification is needed to allow the graph layout algorithms to
detect changes and avoid performing the layout when it is not needed.
If a graph model subclass does not call this method but a change has
occurred in the graph, you need to force a re-layout by passing a
force
flag of true
and calling the method
IlvGraphLayout.performLayout()
.
Furthermore, the notification is used by the default graph model
(IlvGrapherAdapter
) to ensure that IlvGraphLayout.cleanNode(ilog.views.graphlayout.IlvGraphModel, java.lang.Object)
and IlvGraphLayout.cleanLink(ilog.views.graphlayout.IlvGraphModel, java.lang.Object)
are
called automatically at the right time. The
IlvGrapherAdapter
calls this method with event type
GraphModelEvent.NODE_REMOVED
or GraphModelEvent.LINK_REMOVED
whenever a node or link is removed. If
you do not use the IlvGrapherAdapter
or if your model
does not fire these events, the cleanup is not automatically
performed, so you need to call these cleaning methods yourself.
nodeOrLink
- The object that was added, removed, moved or reshaped,
or null
if the event concerns unknown nodes or links.eventType
- The type of the event (a combination of the bit masks,
see GraphModelEvent.getType()
).adjusting
- Indicates whether this event is in a series of similar
events.addGraphModelListener(ilog.views.graphlayout.GraphModelListener)
,
adjustmentEnd()
,
fireGraphModelEvent(GraphModelEvent)
public final void adjustmentEnd()
This method allows you to notify the graph model that you are doing a major modification of its contents, for example by adding, removing, moving, or reshaping many nodes or links.
It is the responsibility of the graph model subclasses to call this method after a series of adjusting events.
This notification is needed to allow the graph layout algorithms to
detect changes and avoid performing the layout when it is not needed.
If a graph model subclass does not call this method but a change has
occurred in the graph, you need to force a re-layout by passing a
force
flag of true
and calling the method
IlvGraphLayout.performLayout()
.
addGraphModelListener(ilog.views.graphlayout.GraphModelListener)
,
fireGraphModelEvent(java.lang.Object, int, boolean)
protected void fireGraphModelEvent(GraphModelEvent event)
event
- The graph model event.removeGraphModelListener(ilog.views.graphlayout.GraphModelListener)
,
addGraphModelListener(ilog.views.graphlayout.GraphModelListener)
,
fireGraphModelEvent(java.lang.Object, int, boolean)
,
adjustmentEnd()
public abstract void moveNode(Object node, double x, double y, boolean redraw)
x
and
y
coordinates correspond to the top-left corner of the
rectangle that defines the node (see also the method boundingBox(Object)
).node
- The node.x
- The new x
position of the node.y
- The new y
position of the node.redraw
- If true
, the node is redrawn.public abstract IlvRect boundingBox(Object nodeOrLink)
Note that the IlvRect
object that is returned by this
method may be modified by internal methods of JViews.
public void move(double x, double y, boolean redraw)
boundingBox()
has the top-left corner at the
coordinates (x, y)
.
During this operation, the link checks are temporarily disabled (see
setLinkCheckEnabled(boolean)
and setConnectionPointCheckEnabled(boolean)
).
x
- The new x
position of the graph.y
- The new y
position of the graph.redraw
- If true
, the graph is redrawn.public IlvRect boundingBox()
Note that the IlvRect
object that is returned by this
method can be modified by internal methods of JViews.
public abstract int getLinkPointsCount(Object link)
public abstract IlvPoint[] getLinkPoints(Object link)
getLinkPointsCount(link) - 1
must
correspond to the connection point of the link on the destination
node.
A link must always have at least two points, corresponding to the connection points. Therefore, the length of the array returned by this method must be at least 2. The method must work for normal links and intergraph links.
public IlvPoint getLinkPointAt(Object link, int index)
The default implementation returns the point at the specified index
in the array returned by the method getLinkPoints
.
link
- The link.index
- The index of the point on the polyline link.isLink(java.lang.Object)
,
isInterGraphLink(java.lang.Object)
public void setLinkCheckEnabled(boolean enable)
If enabled, when the method reshapeLink(java.lang.Object, ilog.views.IlvPoint, ilog.views.IlvPoint[], int, int, ilog.views.IlvPoint, boolean)
receives a
non-null
argument for the array of intermediate points
(or its length is 0
), it checks whether the link can be
reshaped using the method isReshapeableLink(java.lang.Object, boolean)
.
The default value is true
. The checks can be disabled to
avoid the extra overhead cost when it is known that appropriate link
types are used.
public boolean isLinkCheckEnabled()
true
if the checks for the links are enabled, and
false
otherwise.
The default value is true
. The checks can be disabled to
avoid the extra overhead cost when it is known that appropriate link
types are used.
public void setConnectionPointCheckEnabled(boolean enable)
If enabled, when the method reshapeLink(java.lang.Object, ilog.views.IlvPoint, ilog.views.IlvPoint[], int, int, ilog.views.IlvPoint, boolean)
receives a
non-null
argument for the connection point on the origin
and/or destination node, it checks whether the corresponding
connection point can be moved using the method hasMoveableConnectionPoint(java.lang.Object, boolean)
.
The default value is true
. The checks can be disabled to
avoid the extra overhead cost when it is known that the connection
points can be freely moved.
public boolean isConnectionPointCheckEnabled()
true
if the checks for the connection points of
the links are enabled, and false
otherwise.
The default value is true
. The checks can be disabled to
avoid the extra overhead cost when it is known that the connection
points can be freely moved.
public abstract void reshapeLink(Object link, IlvPoint fromPoint, IlvPoint[] points, int startIndex, int length, IlvPoint toPoint, boolean redraw) throws IlvInappropriateLinkException
If the new shape of the link must be a straight-line link without any
intermediate points, call the method with null
for the
points
argument. The values of the arguments
startIndex
and length
are ignored.
If the connection point on the origin and/or destination node should
not be moved, call the method with null
for the
fromPoint
and/or toPoint
arguments.
The implementation of this method must use the methods isReshapeableLink(java.lang.Object, boolean)
and hasMoveableConnectionPoint(java.lang.Object, boolean)
to verify
whether it is able to perform the requested operation. See the
methods setLinkCheckEnabled(boolean)
and setConnectionPointCheckEnabled(boolean)
. (The overridden version of this
method in IlvGrapherAdapter
optionally performs these checks.
For details, see IlvGrapherAdapter.reshapeLink(java.lang.Object, ilog.views.IlvPoint, ilog.views.IlvPoint[], int, int, ilog.views.IlvPoint, boolean)
.)
link
- The link to be reshaped.fromPoint
- The connection point of the link on the origin node.points
- The array of intermediate points, or null
for
straight links.startIndex
- The starting position in the array of points.length
- The number of intermediate points.toPoint
- The connection point of the link on the destination node.redraw
- If true
, the link is redrawn.IlvInappropriateLinkException
- if the type of link is not
appropriate for this reshape operation (see setLinkCheckEnabled(boolean)
and setConnectionPointCheckEnabled(boolean)
).isLink(java.lang.Object)
,
isInterGraphLink(java.lang.Object)
public boolean isReshapeableLink(Object link, boolean toStraightLine)
true
if link
can be reshaped, and
false
otherwise. The method must work for normal links
and intergraph links.
If the argument toStraightLine
is true
, the
method returns true
for any link that can be reshaped to
a straight line. Otherwise it returns false
.
If the argument toStraightLine
is false
,
the method returns true
for any link that can be
reshaped to a polyline (or a spline) with intermediate points.
Otherwise it returns false
.
The default implementation always returns true
. The
method is overridden in the class IlvGrapherAdapter
.
public boolean hasMoveableConnectionPoint(Object link, boolean origin)
true
if the connection point of link
on the origin or destination node can be moved by a call to the
method reshapeLink(java.lang.Object, ilog.views.IlvPoint, ilog.views.IlvPoint[], int, int, ilog.views.IlvPoint, boolean)
. It returns false
if such a
call may fail to set the connection point to the argument passed to
reshapeLink
. The method must work for normal links and
intergraph links.
The default implementation always returns true
. The
method is overridden in the class IlvGrapherAdapter
.
link
- The link.origin
- Set to true
if the connection point is on the
origin and false
otherwise.reshapeLink(java.lang.Object, ilog.views.IlvPoint, ilog.views.IlvPoint[], int, int, ilog.views.IlvPoint, boolean)
,
hasPinnedConnectionPoint(java.lang.Object, boolean)
public boolean hasPinnedConnectionPoint(Object link, boolean origin)
true
if the connection point of link
on the origin or destination node is "pinned," and false
otherwise. The connection point is said to be "pinned" if its
location is fixed with respect to the bounding box of the
corresponding origin or destination node of the link.
The method must work for normal links and intergraph links.
The default implementation always returns false
. The
method is overridden in the class IlvGrapherAdapter
.
link
- The link.origin
- Set to true
if the connection point is on the
origin and false
otherwise.reshapeLink(java.lang.Object, ilog.views.IlvPoint, ilog.views.IlvPoint[], int, int, ilog.views.IlvPoint, boolean)
,
hasMoveableConnectionPoint(java.lang.Object, boolean)
public double getLinkWidth(Object link)
1
. The method must work for normal links and intergraph
links.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.