Package org.jgraph.graph
Interface GraphModel
-
- All Known Implementing Classes:
DefaultGraphModel
public interface GraphModelThe interface that defines a suitable data model for a JGraph.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanacceptsSource(java.lang.Object edge, java.lang.Object port)Returnstrueifportis a valid source foredge.booleanacceptsTarget(java.lang.Object edge, java.lang.Object port)Returnstrueifportis a valid target foredge.voidaddGraphModelListener(GraphModelListener l)Adds a listener for the GraphModelEvent posted after the model changes.voidaddUndoableEditListener(javax.swing.event.UndoableEditListener listener)Adds an undo listener for notification of any changes.voidbeginUpdate()Indicates the start of one level of an executable changejava.util.MapcloneCells(java.lang.Object[] cells)Returns a map of (cell, clone)-pairs for allcellsand their children.booleancontains(java.lang.Object node)Returnstrueifnodeor one of its ancestors is in the model.java.util.Iteratoredges(java.lang.Object port)Returns an iterator of the edges connected toport.voidedit(java.util.Map attributes, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] e)Applies thepropertyMapand the connection changes to the model.voidendUpdate()Indicates the end of the current level of an executable changevoidexecute(ExecutableChange change)Executes the specified executable change on this graph modelAttributeMapgetAttributes(java.lang.Object node)Returns aAttributeMapthat represents the properties for the specified cell.java.lang.ObjectgetChild(java.lang.Object parent, int index)Returns the child of parent at index index in the parent's child array.intgetChildCount(java.lang.Object parent)Returns the number of children of parent .intgetIndexOfChild(java.lang.Object parent, java.lang.Object child)Returns the index of child in parent.intgetIndexOfRoot(java.lang.Object root)Returns the index ofrootin the model.java.lang.ObjectgetParent(java.lang.Object child)Returns the parent of child in the model.java.lang.ObjectgetRootAt(int index)Returns the root at index index in the model.intgetRootCount()Returns the number of roots in the model.java.lang.ObjectgetSource(java.lang.Object edge)Returns the source ofedge.java.lang.ObjectgetTarget(java.lang.Object edge)Returns the target ofedge.java.lang.ObjectgetValue(java.lang.Object node)Returns the user object for the specified cell.voidinsert(java.lang.Object[] roots, java.util.Map attributes, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] e)Inserts thecellsand connections into the model, and passesattributesto the views.booleanisEdge(java.lang.Object edge)Returnstrueifedgeis a valid edge.booleanisLeaf(java.lang.Object node)Returns whether the specified node is a leaf node.booleanisPort(java.lang.Object port)Returnstrueifportis a valid port, possibly supporting edge connection.voidremove(java.lang.Object[] roots)Removescellsfrom the model.voidremoveGraphModelListener(GraphModelListener l)Removes a listener previously added with addGraphModelListener() .voidremoveUndoableEditListener(javax.swing.event.UndoableEditListener listener)Removes an undo listener.voidtoBack(java.lang.Object[] cells)Sendscellsto back.voidtoFront(java.lang.Object[] cells)Bringscellsto front.java.lang.ObjectvalueForCellChanged(java.lang.Object cell, java.lang.Object newValue)Messaged when the value of the cell has changed, eg from within the edit method.
-
-
-
Method Detail
-
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
java.lang.Object getRootAt(int index)
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
int getIndexOfRoot(java.lang.Object root)
Returns the index ofrootin 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
boolean contains(java.lang.Object node)
Returnstrueifnodeor one of its ancestors is in the model.- Returns:
trueifnodeis in the model
-
getAttributes
AttributeMap getAttributes(java.lang.Object node)
Returns aAttributeMapthat represents the properties for the specified cell.- Returns:
- properties of
nodeas aMap
-
getValue
java.lang.Object getValue(java.lang.Object node)
Returns the user object for the specified cell.- Returns:
- userobject of
node
-
getSource
java.lang.Object getSource(java.lang.Object edge)
Returns the source ofedge. edge must be an object previously obtained from this data source.- Returns:
Objectthat represents the source of edge
-
getTarget
java.lang.Object getTarget(java.lang.Object edge)
Returns the target ofedge. edge must be an object previously obtained from this data source.- Returns:
Objectthat represents the target of edge
-
acceptsSource
boolean acceptsSource(java.lang.Object edge, java.lang.Object port)Returnstrueifportis a valid source foredge. edge and port must be objects previously obtained from this data source.- Returns:
trueifportis a valid source foredge.
-
acceptsTarget
boolean acceptsTarget(java.lang.Object edge, java.lang.Object port)Returnstrueifportis a valid target foredge. edge and port must be objects previously obtained from this data source.- Returns:
trueifportis a valid target foredge.
-
edges
java.util.Iterator edges(java.lang.Object port)
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:
Iteratorthat represents the connected edges
-
isEdge
boolean isEdge(java.lang.Object edge)
Returnstrueifedgeis a valid edge.- Returns:
trueifedgeis a valid edge.
-
isPort
boolean isPort(java.lang.Object port)
Returnstrueifportis a valid port, possibly supporting edge connection.- Returns:
trueifportis a valid port.
-
getParent
java.lang.Object getParent(java.lang.Object child)
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
int getIndexOfChild(java.lang.Object parent, java.lang.Object child)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
java.lang.Object getChild(java.lang.Object parent, int index)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
int getChildCount(java.lang.Object parent)
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
boolean isLeaf(java.lang.Object node)
Returns whether the specified node is a leaf node. The way the test is performed depends on theaskAllowsChildrensetting.- Parameters:
node- the node to check- Returns:
- true if the node is a leaf node
-
insert
void insert(java.lang.Object[] roots, java.util.Map attributes, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] e)Inserts thecellsand connections into the model, and passesattributesto the views. Notifies the model- and undo listeners of the change.
-
remove
void remove(java.lang.Object[] roots)
Removescellsfrom the model. Notifies the model- and undo listeners of the change.
-
edit
void edit(java.util.Map attributes, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] e)Applies thepropertyMapand the connection changes to the model. The initialeditsthat triggered the call are considered to be part of this transaction. Notifies the model- and undo listeners of the change. Note: If onlyeditsis 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
void execute(ExecutableChange change)
Executes the specified executable change on this graph model- Parameters:
change- the change to be executed
-
cloneCells
java.util.Map cloneCells(java.lang.Object[] cells)
Returns a map of (cell, clone)-pairs for allcellsand their children. Special care should be taken to replace references between cells.
-
valueForCellChanged
java.lang.Object valueForCellChanged(java.lang.Object cell, java.lang.Object newValue)Messaged when the value of the cell has changed, eg from within the edit method.
-
toBack
void toBack(java.lang.Object[] cells)
Sendscellsto back.
-
toFront
void toFront(java.lang.Object[] cells)
Bringscellsto front.
-
addGraphModelListener
void addGraphModelListener(GraphModelListener l)
Adds a listener for the GraphModelEvent posted after the model changes.
-
removeGraphModelListener
void removeGraphModelListener(GraphModelListener l)
Removes a listener previously added with addGraphModelListener() .
-
addUndoableEditListener
void addUndoableEditListener(javax.swing.event.UndoableEditListener listener)
Adds an undo listener for notification of any changes. Undo/Redo operations performed on theUndoableEditwill cause the appropriate ModelEvent to be fired to keep the view(s) in sync with the model.
-
removeUndoableEditListener
void removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)
Removes an undo listener.
-
-