Package org.jgraph.graph
Interface GraphModel
- All Known Implementing Classes:
DefaultGraphModel
public interface GraphModel
The interface that defines a suitable data model for a JGraph.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
acceptsSource
(Object edge, Object port) Returnstrue
ifport
is a valid source foredge
.boolean
acceptsTarget
(Object edge, Object port) Returnstrue
ifport
is a valid target foredge
.void
Adds a listener for the GraphModelEvent posted after the model changes.void
addUndoableEditListener
(UndoableEditListener listener) Adds an undo listener for notification of any changes.void
Indicates the start of one level of an executable changecloneCells
(Object[] cells) Returns a map of (cell, clone)-pairs for allcells
and their children.boolean
Returnstrue
ifnode
or one of its ancestors is in the model.Returns an iterator of the edges connected toport
.void
edit
(Map attributes, ConnectionSet cs, ParentMap pm, UndoableEdit[] e) Applies thepropertyMap
and the connection changes to the model.void
Indicates the end of the current level of an executable changevoid
execute
(ExecutableChange change) Executes the specified executable change on this graph modelgetAttributes
(Object node) Returns aAttributeMap
that represents the properties for the specified cell.Returns the child of parent at index index in the parent's child array.int
getChildCount
(Object parent) Returns the number of children of parent .int
getIndexOfChild
(Object parent, Object child) Returns the index of child in parent.int
getIndexOfRoot
(Object root) Returns the index ofroot
in the model.Returns the parent of child in the model.getRootAt
(int index) Returns the root at index index in the model.int
Returns the number of roots in the model.Returns the source ofedge
.Returns the target ofedge
.Returns the user object for the specified cell.void
insert
(Object[] roots, Map attributes, ConnectionSet cs, ParentMap pm, UndoableEdit[] e) Inserts thecells
and connections into the model, and passesattributes
to the views.boolean
Returnstrue
ifedge
is a valid edge.boolean
Returns whether the specified node is a leaf node.boolean
Returnstrue
ifport
is a valid port, possibly supporting edge connection.void
Removescells
from the model.void
Removes a listener previously added with addGraphModelListener() .void
Removes an undo listener.void
Sendscells
to back.void
Bringscells
to front.valueForCellChanged
(Object cell, Object newValue) Messaged when the value of the cell has changed, eg from within the edit method.
-
Method Details
-
getRootCount
int getRootCount()Returns the number of roots in the model. Returns 0 if the model is empty.- Returns:
- the number of roots in the model
-
getRootAt
Returns the root at index index in the model. This should not return null if index is a valid index for the model (that is index >= 0 && index < getRootCount()).- Returns:
- the root of at index index
-
getIndexOfRoot
Returns the index ofroot
in the model. If root isnull
, returns -1.- Parameters:
root
- a root in the model, obtained from this data source- Returns:
- the index of the root in the model, or -1 if the parent is
null
-
contains
Returnstrue
ifnode
or one of its ancestors is in the model.- Returns:
true
ifnode
is in the model
-
getAttributes
Returns aAttributeMap
that represents the properties for the specified cell.- Returns:
- properties of
node
as aMap
-
getValue
Returns the user object for the specified cell.- Returns:
- userobject of
node
-
getSource
Returns the source ofedge
. edge must be an object previously obtained from this data source.- Returns:
Object
that represents the source of edge
-
getTarget
Returns the target ofedge
. edge must be an object previously obtained from this data source.- Returns:
Object
that represents the target of edge
-
acceptsSource
Returnstrue
ifport
is a valid source foredge
. edge and port must be objects previously obtained from this data source.- Returns:
true
ifport
is a valid source foredge
.
-
acceptsTarget
Returnstrue
ifport
is a valid target foredge
. edge and port must be objects previously obtained from this data source.- Returns:
true
ifport
is a valid target foredge
.
-
edges
Returns an iterator of the edges connected toport
. port must be a object previously obtained from this data source. This method never returns null.- Parameters:
port
- a port in the graph, obtained from this data source- Returns:
Iterator
that represents the connected edges
-
isEdge
Returnstrue
ifedge
is a valid edge.- Returns:
true
ifedge
is a valid edge.
-
isPort
Returnstrue
ifport
is a valid port, possibly supporting edge connection.- Returns:
true
ifport
is a valid port.
-
getParent
Returns the parent of child in the model. child must be a node previously obtained from this data source. This returns null if child is a root in the model.- Parameters:
child
- a node in the graph, obtained from this data source- Returns:
- the parent of child
-
getIndexOfChild
Returns the index of child in parent. If either the parent or child isnull
, returns -1.- Parameters:
parent
- a note in the tree, obtained from this data sourcechild
- the node we are interested in- Returns:
- the index of the child in the parent, or -1 if either the parent
or the child is
null
-
getChild
Returns the child of parent at index index in the parent's child array. parent must be a node previously obtained from this data source. This should not return null if index is a valid index for parent (that is index >= 0 && index < getChildCount( parent )).- Parameters:
parent
- a node in the tree, obtained from this data source- Returns:
- the child of parent at index index
-
getChildCount
Returns the number of children of parent . Returns 0 if the node is a leaf or if it has no children. parent must be a node previously obtained from this data source.- Parameters:
parent
- a node in the tree, obtained from this data source- Returns:
- the number of children of the node parent
-
isLeaf
Returns whether the specified node is a leaf node. The way the test is performed depends on theaskAllowsChildren
setting.- Parameters:
node
- the node to check- Returns:
- true if the node is a leaf node
-
insert
Inserts thecells
and connections into the model, and passesattributes
to the views. Notifies the model- and undo listeners of the change. -
remove
Removescells
from the model. Notifies the model- and undo listeners of the change. -
edit
Applies thepropertyMap
and the connection changes to the model. The initialedits
that triggered the call are considered to be part of this transaction. Notifies the model- and undo listeners of the change. Note: If onlyedits
is non-null, the edits are directly passed to the UndoableEditListeners. -
beginUpdate
void beginUpdate()Indicates the start of one level of an executable change -
endUpdate
void endUpdate()Indicates the end of the current level of an executable change -
execute
Executes the specified executable change on this graph model- Parameters:
change
- the change to be executed
-
cloneCells
Returns a map of (cell, clone)-pairs for allcells
and their children. Special care should be taken to replace references between cells. -
valueForCellChanged
Messaged when the value of the cell has changed, eg from within the edit method. -
toBack
Sendscells
to back. -
toFront
Bringscells
to front. -
addGraphModelListener
Adds a listener for the GraphModelEvent posted after the model changes. -
removeGraphModelListener
Removes a listener previously added with addGraphModelListener() . -
addUndoableEditListener
Adds an undo listener for notification of any changes. Undo/Redo operations performed on theUndoableEdit
will cause the appropriate ModelEvent to be fired to keep the view(s) in sync with the model. -
removeUndoableEditListener
Removes an undo listener.
-