org.jgraph.graph

Interface GraphModel

Known Implementing Classes:
DefaultGraphModel

public interface GraphModel

The interface that defines a suitable data model for a JGraph.

Method Summary

boolean
acceptsSource(Object edge, Object port)
Returns true if port is a valid source for edge.
boolean
acceptsTarget(Object edge, Object port)
Returns true if port is a valid target for edge.
void
addGraphModelListener(GraphModelListener l)
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
beginUpdate()
Indicates the start of one level of an executable change
Map
cloneCells(Object[] cells)
Returns a map of (cell, clone)-pairs for all cells and their children.
boolean
contains(Object node)
Returns true if node or one of its ancestors is in the model.
Iterator
edges(Object port)
Returns an iterator of the edges connected to port.
void
edit(Map attributes, ConnectionSet cs, ParentMap pm, UndoableEdit[] e)
Applies the propertyMap and the connection changes to the model.
void
endUpdate()
Indicates the end of the current level of an executable change
void
execute(ExecutableChange change)
Executes the specified executable change on this graph model
AttributeMap
getAttributes(Object node)
Returns a AttributeMap that represents the properties for the specified cell.
Object
getChild(Object parent, int index)
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 of root in the model.
Object
getParent(Object child)
Returns the parent of child in the model.
Object
getRootAt(int index)
Returns the root at index index in the model.
int
getRootCount()
Returns the number of roots in the model.
Object
getSource(Object edge)
Returns the source of edge.
Object
getTarget(Object edge)
Returns the target of edge.
Object
getValue(Object node)
Returns the user object for the specified cell.
void
insert(Object[] roots, Map attributes, ConnectionSet cs, ParentMap pm, UndoableEdit[] e)
Inserts the cells and connections into the model, and passes attributes to the views.
boolean
isEdge(Object edge)
Returns true if edge is a valid edge.
boolean
isLeaf(Object node)
Returns whether the specified node is a leaf node.
boolean
isPort(Object port)
Returns true if port is a valid port, possibly supporting edge connection.
void
remove(Object[] roots)
Removes cells from the model.
void
removeGraphModelListener(GraphModelListener l)
Removes a listener previously added with addGraphModelListener() .
void
removeUndoableEditListener(UndoableEditListener listener)
Removes an undo listener.
void
toBack(Object[] cells)
Sends cells to back.
void
toFront(Object[] cells)
Brings cells to front.
Object
valueForCellChanged(Object cell, Object newValue)
Messaged when the value of the cell has changed, eg from within the edit method.

Method Details

acceptsSource

public boolean acceptsSource(Object edge,
                             Object port)
Returns true if port is a valid source for edge. edge and port must be objects previously obtained from this data source.
Returns:
true if port is a valid source for edge.

acceptsTarget

public boolean acceptsTarget(Object edge,
                             Object port)
Returns true if port is a valid target for edge. edge and port must be objects previously obtained from this data source.
Returns:
true if port is a valid target for edge.

addGraphModelListener

public void addGraphModelListener(GraphModelListener l)
Adds a listener for the GraphModelEvent posted after the model changes.

addUndoableEditListener

public void addUndoableEditListener(UndoableEditListener listener)
Adds an undo listener for notification of any changes. Undo/Redo operations performed on the UndoableEdit will cause the appropriate ModelEvent to be fired to keep the view(s) in sync with the model.

beginUpdate

public void beginUpdate()
Indicates the start of one level of an executable change

cloneCells

public Map cloneCells(Object[] cells)
Returns a map of (cell, clone)-pairs for all cells and their children. Special care should be taken to replace references between cells.

contains

public boolean contains(Object node)
Returns true if node or one of its ancestors is in the model.
Returns:
true if node is in the model

edges

public Iterator edges(Object port)
Returns an iterator of the edges connected to port. 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

edit

public void edit(Map attributes,
                 ConnectionSet cs,
                 ParentMap pm,
                 UndoableEdit[] e)
Applies the propertyMap and the connection changes to the model. The initial edits that triggered the call are considered to be part of this transaction. Notifies the model- and undo listeners of the change. Note: If only edits is non-null, the edits are directly passed to the UndoableEditListeners.

endUpdate

public void endUpdate()
Indicates the end of the current level of an executable change

execute

public void execute(ExecutableChange change)
Executes the specified executable change on this graph model
Parameters:
change - the change to be executed

getAttributes

public AttributeMap getAttributes(Object node)
Returns a AttributeMap that represents the properties for the specified cell.
Returns:
properties of node as a Map

getChild

public Object getChild(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 <32getChildCount( parent )).
Parameters:
parent - a node in the tree, obtained from this data source
Returns:
the child of parent at index index

getChildCount

public int getChildCount(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

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Returns the index of child in parent. If either the parent or child is null, returns -1.
Parameters:
parent - a note in the tree, obtained from this data source
child - 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

getIndexOfRoot

public int getIndexOfRoot(Object root)
Returns the index of root in the model. If root is null, 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

getParent

public Object getParent(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

getRootAt

public 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 <32getRootCount()).
Returns:
the root of at index index

getRootCount

public 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

getSource

public Object getSource(Object edge)
Returns the source of edge. edge must be an object previously obtained from this data source.
Returns:
Object that represents the source of edge

getTarget

public Object getTarget(Object edge)
Returns the target of edge. edge must be an object previously obtained from this data source.
Returns:
Object that represents the target of edge

getValue

public Object getValue(Object node)
Returns the user object for the specified cell.
Returns:
userobject of node

insert

public void insert(Object[] roots,
                   Map attributes,
                   ConnectionSet cs,
                   ParentMap pm,
                   UndoableEdit[] e)
Inserts the cells and connections into the model, and passes attributes to the views. Notifies the model- and undo listeners of the change.

isEdge

public boolean isEdge(Object edge)
Returns true if edge is a valid edge.
Returns:
true if edge is a valid edge.

isLeaf

public boolean isLeaf(Object node)
Returns whether the specified node is a leaf node. The way the test is performed depends on the askAllowsChildren setting.
Parameters:
node - the node to check
Returns:
true if the node is a leaf node

isPort

public boolean isPort(Object port)
Returns true if port is a valid port, possibly supporting edge connection.
Returns:
true if port is a valid port.

remove

public void remove(Object[] roots)
Removes cells from the model. If removeChildren is true, the children are also removed. Notifies the model- and undo listeners of the change.

removeGraphModelListener

public void removeGraphModelListener(GraphModelListener l)
Removes a listener previously added with addGraphModelListener() .

removeUndoableEditListener

public void removeUndoableEditListener(UndoableEditListener listener)
Removes an undo listener.

toBack

public void toBack(Object[] cells)
Sends cells to back.

toFront

public void toFront(Object[] cells)
Brings cells to front.

valueForCellChanged

public Object valueForCellChanged(Object cell,
                                  Object newValue)
Messaged when the value of the cell has changed, eg from within the edit method.

Copyright (C) 2001-2006 Gaudenz Alder. All rights reserved.