|
JGraph |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.undo.UndoableEditSupport
org.jgraph.graph.DefaultGraphModel
public class DefaultGraphModel
A simple implementation of a graph model.
Nested Class Summary | |
---|---|
static class |
DefaultGraphModel.EmptyIterator
|
class |
DefaultGraphModel.GraphModelEdit
An implementation of GraphModelChange that can be added to the model event. |
class |
DefaultGraphModel.GraphModelLayerEdit
An implementation of GraphViewChange. |
Field Summary | |
---|---|
protected boolean |
asksAllowsChildren
Indicates whether isLeaf is based on a node's allowsChildren value. |
protected AttributeMap |
attributes
The model's own attributes as a map. |
protected java.util.Iterator |
emptyIterator
Default instance of an empty iterator. |
protected javax.swing.event.EventListenerList |
listenerList
The list of listeners that listen to the model. |
protected java.util.List |
roots
Set that contains all root cells of this model. |
Fields inherited from class javax.swing.undo.UndoableEditSupport |
---|
compoundEdit, listeners, realSource, updateLevel |
Constructor Summary | |
---|---|
DefaultGraphModel()
Constructs a model that is not an attribute store. |
Method Summary | |
---|---|
boolean |
acceptsSource(java.lang.Object edge,
java.lang.Object port)
Returns true if port is a valid source
for edge . |
boolean |
acceptsTarget(java.lang.Object edge,
java.lang.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 graph changes. |
java.util.Map |
cloneCells(java.lang.Object[] cells)
Returns a map of (cell, clone)-pairs for all cells
and their children. |
protected void |
connect(java.lang.Object edge,
java.lang.Object port,
boolean isSource,
boolean remove)
Connects or disconnects the edge and port in this model based on remove . |
boolean |
contains(java.lang.Object node)
Returns true if node or one of its
ancestors is in the model. |
AttributeMap |
createAttributes()
Creates an empty map. |
protected DefaultGraphModel.GraphModelEdit |
createCellEdit(java.util.Map attributes,
ConnectionSet cs,
ParentMap pm,
javax.swing.undo.UndoableEdit[] edits)
Returns an edit that represents a change. |
protected DefaultGraphModel.GraphModelEdit |
createEdit(java.lang.Object[] inserted,
java.lang.Object[] removed,
java.util.Map attributes,
ConnectionSet cs,
ParentMap pm)
|
protected DefaultGraphModel.GraphModelEdit |
createInsertEdit(java.lang.Object[] cells,
java.util.Map attributeMap,
ConnectionSet cs,
ParentMap pm,
javax.swing.undo.UndoableEdit[] edits)
Returns an edit that represents an insert. |
protected DefaultGraphModel.GraphModelLayerEdit |
createLayerEdit(java.lang.Object[] cells,
int layer)
|
protected DefaultGraphModel.GraphModelEdit |
createRemoveEdit(java.lang.Object[] cells)
Returns an edit that represents a remove. |
java.util.Iterator |
edges(java.lang.Object port)
Returns an iterator of the edges connected to port . |
void |
edit(java.util.Map attributes,
ConnectionSet cs,
ParentMap pm,
javax.swing.undo.UndoableEdit[] edits)
Applies attributes and the connection changes to
the model. |
protected void |
fireGraphChanged(java.lang.Object source,
GraphModelEvent.GraphModelChange edit)
|
java.util.Map |
getAttributes()
Returns the graph model's attribute. |
AttributeMap |
getAttributes(java.lang.Object node)
Returns a Map that represents the attributes for
the specified cell. |
java.lang.Object |
getChild(java.lang.Object parent,
int index)
Returns the child of parent at index index in the parent's child array. |
int |
getChildCount(java.lang.Object parent)
Returns the number of children of parent. |
static java.util.List |
getDescendantList(GraphModel model,
java.lang.Object[] cells)
|
static java.util.Set |
getDescendants(GraphModel model,
java.lang.Object[] cells)
Flattens the given array of root cells by adding the roots and their descandants. |
static java.util.Set |
getEdges(GraphModel model,
java.lang.Object[] cells)
Return the set of edges that are connected to the specified cells. |
GraphModelListener[] |
getGraphModelListeners()
Return an array of all GraphModelListeners that were added to this model. |
int |
getIndexOfChild(java.lang.Object parent,
java.lang.Object child)
Returns the index of child in parent. |
int |
getIndexOfRoot(java.lang.Object root)
Returns the index of root in the model. |
java.lang.Object |
getParent(java.lang.Object child)
Returns the parent of child in the model. |
java.lang.Object |
getRootAt(int index)
Returns the root at index index in the model. |
int |
getRootCount()
Returns the number of roots in the model. |
static java.lang.Object[] |
getRoots(GraphModel model)
Returns the roots of the specified model as an array. |
java.lang.Object |
getSource(java.lang.Object edge)
Returns the source of edge . |
static java.lang.Object |
getSourceVertex(GraphModel model,
java.lang.Object edge)
Returns the source vertex of the edge by calling getParent on getSource on the specified model. |
java.lang.Object |
getTarget(java.lang.Object edge)
Returns the target of edge . |
static java.lang.Object |
getTargetVertex(GraphModel model,
java.lang.Object edge)
Returns the target vertex of the edge by calling getParent on getTarget on the specified model. |
protected java.util.Map |
handleAttributes(java.util.Map attributes)
Applies attributes to the cells specified as keys. |
protected void |
handleConnection(ConnectionSet.Connection c)
Inserts the specified connection into the model. |
protected ConnectionSet |
handleConnectionSet(ConnectionSet cs)
Applies connectionSet to the model. |
protected java.lang.Object[] |
handleInsert(java.lang.Object[] cells)
Inserts cells into the model. |
protected ParentMap |
handleParentMap(ParentMap parentMap)
Applies cells to the model. |
protected java.lang.Object[] |
handleRemove(java.lang.Object[] cells)
Removes cells from the model. |
void |
insert(java.lang.Object[] roots,
java.util.Map attributes,
ConnectionSet cs,
ParentMap pm,
javax.swing.undo.UndoableEdit[] edits)
Inserts the roots and connections into the model. |
boolean |
isEdge(java.lang.Object edge)
Returns true if edge is a valid edge. |
boolean |
isLeaf(java.lang.Object node)
Returns whether the specified node is a leaf node. |
boolean |
isPort(java.lang.Object port)
Returns true if port is a valid
port, possibly supporting edge connection. |
void |
remove(java.lang.Object[] roots)
Removes cells from the model. |
void |
removeGraphModelListener(GraphModelListener l)
Removes a listener previously added with addGraphModelListener(). |
void |
toBack(java.lang.Object[] cells)
Sends cells to back. |
void |
toFront(java.lang.Object[] cells)
Brings cells to front. |
Methods inherited from class javax.swing.undo.UndoableEditSupport |
---|
_postEdit, addUndoableEditListener, beginUpdate, createCompoundEdit, endUpdate, getUndoableEditListeners, getUpdateLevel, postEdit, removeUndoableEditListener, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.jgraph.graph.GraphModel |
---|
addUndoableEditListener, removeUndoableEditListener |
Field Detail |
---|
protected transient javax.swing.event.EventListenerList listenerList
protected transient java.util.Iterator emptyIterator
protected java.util.List roots
protected boolean asksAllowsChildren
protected AttributeMap attributes
Constructor Detail |
---|
public DefaultGraphModel()
Method Detail |
---|
public int getRootCount()
getRootCount
in interface GraphModel
public java.lang.Object getRootAt(int index)
getRootAt
in interface GraphModel
public int getIndexOfRoot(java.lang.Object root)
root
in the model.
If root is null
, returns -1.
getIndexOfRoot
in interface GraphModel
parent
- a root in the model, obtained from this data source
null
public boolean contains(java.lang.Object node)
true
if node
or one of its
ancestors is in the model.
contains
in interface GraphModel
true
if node
is in the modelpublic AttributeMap createAttributes()
Hashtable
.
createAttributes
in interface GraphModel
AttributeMap
public AttributeMap getAttributes(java.lang.Object node)
Map
that represents the attributes for
the specified cell. This attributes have precedence over each
view's attributes, regardless of isAttributeStore.
getAttributes
in interface GraphModel
node
as a Map
public java.util.Map getAttributes()
getAttributes(null)
.
node
as a Map
public java.lang.Object getSource(java.lang.Object edge)
edge
. edge must be an object
previously obtained from this data source.
getSource
in interface GraphModel
Object
that represents the source of edgepublic java.lang.Object getTarget(java.lang.Object edge)
edge
. edge must be an object
previously obtained from this data source.
getTarget
in interface GraphModel
Object
that represents the target of edgepublic boolean acceptsSource(java.lang.Object edge, java.lang.Object port)
true
if port
is a valid source
for edge
. edge and port must be
objects previously obtained from this data source.
acceptsSource
in interface GraphModel
true
if port
is a valid source
for edge
.public boolean acceptsTarget(java.lang.Object edge, java.lang.Object port)
true
if port
is a valid target
for edge
. edge and port must be
objects previously obtained from this data source.
acceptsTarget
in interface GraphModel
true
if port
is a valid target
for edge
.public java.util.Iterator edges(java.lang.Object port)
port
.
port must be a object previously obtained from
this data source. This method never returns null.
edges
in interface GraphModel
port
- a port in the graph, obtained from this data source
Iterator
that represents the connected edgespublic boolean isEdge(java.lang.Object edge)
true
if edge
is a valid edge.
isEdge
in interface GraphModel
true
if edge
is a valid edge.public boolean isPort(java.lang.Object port)
true
if port
is a valid
port, possibly supporting edge connection.
isPort
in interface GraphModel
true
if port
is a valid port.public java.util.Map cloneCells(java.lang.Object[] cells)
cells
and their children. Special care is taken to replace the anchor
references between ports. (Iterative implementation.)
cloneCells
in interface GraphModel
public java.lang.Object getParent(java.lang.Object child)
getParent
in interface GraphModel
child
- a node in the graph, obtained from this data source
public int getIndexOfChild(java.lang.Object parent, java.lang.Object child)
null
, returns -1.
getIndexOfChild
in interface GraphModel
parent
- a note in the tree, obtained from this data sourcechild
- the node we are interested in
null
public java.lang.Object getChild(java.lang.Object parent, int index)
getChild
in interface GraphModel
parent
- a node in the tree, obtained from this data source
public int getChildCount(java.lang.Object parent)
getChildCount
in interface GraphModel
parent
- a node in the tree, obtained from this data source
public boolean isLeaf(java.lang.Object node)
isLeaf
in interface GraphModel
node
- the node to check
public void insert(java.lang.Object[] roots, java.util.Map attributes, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] edits)
roots
and connections into the model.
Notifies the model- and undo listeners of the change. The passed-in
edits are executed if they implement the
GraphModelEvent.ExecutableGraphChange
interface
in ascending array-order, after execution of the model change.
(Note: The external order is important in a
special case: After insertion on a partial view, ie. one that does not
display all cells of the model, the cell is made visible after
it is inserted into the model. This requires the inserting view
to be able to add the cell to the visible set before it is
inserted into the model.)
Note: The passed-in propertyMap may contains PortViews
which must be turned into Points when stored in the model.
insert
in interface GraphModel
public void remove(java.lang.Object[] roots)
cells
from the model.
Notifies the model- and undo listeners of the change.
remove
in interface GraphModel
public void edit(java.util.Map attributes, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] edits)
attributes
and the connection changes to
the model. The initial edits
that triggered the call
are considered to be part of this transaction. The passed-in
edits are executed if they implement the
GraphModelEvent.ExecutableGraphChange
interface
in ascending array-order, after execution of the model change.
Notifies the model- and undo listeners of the change.
Note: If only edits
is non-null, the
edits are directly passed to the UndoableEditListeners.
Note: The passed-in propertyMap may contains PortViews
which must be turned into Points when stored in the model.
edit
in interface GraphModel
public void toBack(java.lang.Object[] cells)
cells
to back.
toBack
in interface GraphModel
public void toFront(java.lang.Object[] cells)
cells
to front.
toFront
in interface GraphModel
protected DefaultGraphModel.GraphModelLayerEdit createLayerEdit(java.lang.Object[] cells, int layer)
protected DefaultGraphModel.GraphModelEdit createInsertEdit(java.lang.Object[] cells, java.util.Map attributeMap, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] edits)
protected DefaultGraphModel.GraphModelEdit createRemoveEdit(java.lang.Object[] cells)
protected DefaultGraphModel.GraphModelEdit createCellEdit(java.util.Map attributes, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] edits)
protected DefaultGraphModel.GraphModelEdit createEdit(java.lang.Object[] inserted, java.lang.Object[] removed, java.util.Map attributes, ConnectionSet cs, ParentMap pm)
protected java.lang.Object[] handleInsert(java.lang.Object[] cells)
cells
into the model. Returns
the cells that were inserted (including descendants).
protected java.lang.Object[] handleRemove(java.lang.Object[] cells)
cells
from the model. Returns
the cells that were removed as roots.
protected ParentMap handleParentMap(ParentMap parentMap)
cells
to the model. Returns
a parent map that may be used to undo this change.
protected java.util.Map handleAttributes(java.util.Map attributes)
attributes
to the cells specified as keys.
Returns the attributes
to undo the change.
protected ConnectionSet handleConnectionSet(ConnectionSet cs)
connectionSet
to the model. Returns
a connection set that may be used to undo this change.
protected void handleConnection(ConnectionSet.Connection c)
protected void connect(java.lang.Object edge, java.lang.Object port, boolean isSource, boolean remove)
remove
. Subclassers should override
this to update connectivity datastructures.
public void addGraphModelListener(GraphModelListener l)
addGraphModelListener
in interface GraphModel
l
- the listener to addremoveGraphModelListener(org.jgraph.event.GraphModelListener)
public void removeGraphModelListener(GraphModelListener l)
removeGraphModelListener
in interface GraphModel
l
- the listener to removeaddGraphModelListener(org.jgraph.event.GraphModelListener)
protected void fireGraphChanged(java.lang.Object source, GraphModelEvent.GraphModelChange edit)
public GraphModelListener[] getGraphModelListeners()
public static java.lang.Object getSourceVertex(GraphModel model, java.lang.Object edge)
public static java.lang.Object getTargetVertex(GraphModel model, java.lang.Object edge)
public static java.lang.Object[] getRoots(GraphModel model)
public static java.util.Set getEdges(GraphModel model, java.lang.Object[] cells)
public static java.util.Set getDescendants(GraphModel model, java.lang.Object[] cells)
public static java.util.List getDescendantList(GraphModel model, java.lang.Object[] cells)
|
JGraph |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |