public class DefaultGraphModel extends javax.swing.undo.UndoableEditSupport implements java.io.Serializable, GraphModel
| Modifier and Type | Class and Description |
|---|---|
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.
|
| Modifier and Type | Field and Description |
|---|---|
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 boolean |
removeEmptyGroups
Whether or not to remove group cells from the model when all of their
children are removed
|
protected java.util.List |
roots
Set that contains all root cells of this model.
|
protected java.util.Set |
transAddedCells
Stores nested transaction added cells
|
protected java.util.Map |
transEditAttrs
Stores nested transaction transport attribute maps
|
protected ConnectionSet |
transEditCS
Stores nested transaction connection sets
|
protected ParentMap |
transEditPM
Stores nested transaction parent maps
|
protected java.util.Set |
transRemovedCells
Stores nested transaction removed cells
|
protected int |
updateLevel
Counter for the depth of nested transactions.
|
| Constructor and Description |
|---|
DefaultGraphModel()
Constructs a model that is not an attribute store.
|
DefaultGraphModel(java.util.List roots,
AttributeMap attributes)
Constructs a model that is not an attribute store.
|
DefaultGraphModel(java.util.List roots,
AttributeMap attributes,
ConnectionSet cs)
Constructs a model using the specified information to construct the
cells, attributes and connection data.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
void |
beginUpdate()
Indicates the start of one level of an executable change
|
void |
cellsChanged(java.lang.Object[] cells)
Invoke this method after you've changed how the cells are to be
represented in the graph.
|
static java.lang.Object |
cloneCell(GraphModel model,
java.lang.Object cell)
Returns a deep clone of the specified cell, including all children.
|
static java.lang.Object[] |
cloneCell(GraphModel model,
java.lang.Object[] cells)
Returns a deep clone of the specified cells, including all children.
|
protected java.lang.Object |
cloneCell(java.lang.Object cellObj)
Creates a shallow copy of the cell including a copy of the user object.
|
java.util.Map |
cloneCells(java.lang.Object[] cells)
Returns a map of (cell, clone)-pairs for all
cells. |
protected java.lang.Object |
cloneUserObject(java.lang.Object userObject)
Clones the user object.
|
protected void |
connect(java.lang.Object edge,
java.lang.Object port,
boolean isSource,
boolean insert)
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. |
static boolean |
containsEdgeBetween(GraphModel model,
java.lang.Object v1,
java.lang.Object v2)
Returns true if the given vertices are conntected by a single edge in
this document.
|
protected DefaultGraphModel.GraphModelEdit |
createEdit(java.lang.Object[] inserted,
java.lang.Object[] removed,
java.util.Map attributes,
ConnectionSet cs,
ParentMap pm,
javax.swing.undo.UndoableEdit[] edits) |
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)
Shortcut to the new edit method which allows inserts and removes to go
along with an edit.
|
void |
edit(java.lang.Object[] inserted,
java.lang.Object[] removed,
java.util.Map attributes,
ConnectionSet cs,
ParentMap pm,
javax.swing.undo.UndoableEdit[] edits)
Applies
attributes 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
|
protected void |
fireGraphChanged(java.lang.Object source,
GraphModelEvent.GraphModelChange edit) |
static java.lang.Object[] |
getAll(GraphModel model)
Returns all cells of the model in an array.
|
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 .
|
ConnectionSet |
getConnectionSet()
A shortcut method to create a connection set that represents the
connections in this model.
|
static java.util.List |
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)
Returns the set of all connected edges to
cells or their
descendants. |
static java.lang.Object[] |
getEdges(GraphModel model,
java.lang.Object cell,
boolean incoming)
Returns the incoming or outgoing edges for cell.
|
static java.lang.Object[] |
getEdgesBetween(GraphModel model,
java.lang.Object cell1,
java.lang.Object cell2,
boolean directed)
Returns the edges between two specified ports or two specified vertices.
|
GraphModelListener[] |
getGraphModelListeners()
Return an array of all GraphModelListeners that were added to this model.
|
static java.lang.Object[] |
getIncomingEdges(GraphModel model,
java.lang.Object cell)
Returns the incoming edges for cell.
|
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. |
static java.lang.Object |
getOpposite(GraphModel model,
java.lang.Object edge,
java.lang.Object cell) |
static java.lang.Object[] |
getOutgoingEdges(GraphModel model,
java.lang.Object cell)
Returns the outgoing edges for cell.
|
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.
|
java.util.List |
getRoots() |
static java.lang.Object[] |
getRoots(GraphModel model)
Returns the roots of the specified model as an array.
|
static java.lang.Object[] |
getRoots(GraphModel model,
java.lang.Object[] cells)
Returns the roots in
cells by checking if their parent is
null. |
static java.util.Collection |
getRootsAsCollection(GraphModel model)
Returns the roots of the specified model as a collection.
|
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.
|
static java.lang.Object[] |
getTopmostCells(GraphModel model,
java.lang.Object[] cells) |
int |
getUpdateLevel() |
static java.lang.Object |
getUserObject(java.lang.Object cell)
Deprecated.
Use
GraphModel.getValue(Object) instead. |
java.lang.Object |
getValue(java.lang.Object cell)
Returns the user object for the specified cell.
|
protected java.util.Map |
handleAttributes(java.util.Map attributes)
Applies
attributes to the cells specified as keys. |
protected void |
handleConnection(ConnectionSet.Connection c,
boolean establish)
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. |
static boolean |
hasAncestorIn(GraphModel model,
java.util.Set parents,
java.lang.Object child)
Returns true if the specified child has an ancestor in parents.
|
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. |
static boolean |
isGroup(GraphModel model,
java.lang.Object cell)
Checks whether the cell has at least one child which is not a port.
|
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. |
boolean |
isRemoveEmptyGroups() |
static boolean |
isVertex(GraphModel model,
java.lang.Object vertex)
Returns
true if vertex is a valid vertex. |
static java.lang.Object[] |
order(GraphModel model,
java.lang.Object[] cells)
Orders cells so that they reflect the model order.
|
void |
remove(java.lang.Object[] roots)
Removes
cells from the model. |
void |
removeGraphModelListener(GraphModelListener l)
Removes a listener previously added with addGraphModelListener() .
|
protected void |
setParent(java.lang.Object child,
java.lang.Object parent)
Sets the parent of the specified cell.
|
void |
setRemoveEmptyGroups(boolean removeEmptyGroups) |
static void |
setSourcePort(GraphModel model,
java.lang.Object edge,
java.lang.Object port)
Helper methods that connects the source of
edge to
port in model. |
static void |
setTargetPort(GraphModel model,
java.lang.Object edge,
java.lang.Object port)
Helper methods that connects the source of
edge to
port in model. |
void |
toBack(java.lang.Object[] cells)
Sends
cells to back. |
void |
toFront(java.lang.Object[] cells)
Brings
cells to front. |
protected void |
updateTransaction(java.lang.Object[] inserted,
java.lang.Object[] removed,
java.util.Map attributes,
ConnectionSet cs,
ParentMap pm)
Updates the current state of the various transaction data
|
java.lang.Object |
valueForCellChanged(java.lang.Object cell,
java.lang.Object newValue)
Applies the new value to the specified cell.
|
_postEdit, addUndoableEditListener, createCompoundEdit, getUndoableEditListeners, postEdit, removeUndoableEditListener, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddUndoableEditListener, removeUndoableEditListenerprotected transient javax.swing.event.EventListenerList listenerList
protected transient java.util.Iterator emptyIterator
protected java.util.List roots
protected boolean asksAllowsChildren
protected boolean removeEmptyGroups
protected AttributeMap attributes
protected transient int updateLevel
protected transient java.util.Set transAddedCells
protected transient java.util.Set transRemovedCells
protected transient java.util.Map transEditAttrs
protected transient ConnectionSet transEditCS
protected transient ParentMap transEditPM
public DefaultGraphModel()
public DefaultGraphModel(java.util.List roots,
AttributeMap attributes)
public DefaultGraphModel(java.util.List roots,
AttributeMap attributes,
ConnectionSet cs)
public java.util.List getRoots()
public int getRootCount()
getRootCount in interface GraphModelpublic java.lang.Object getRootAt(int index)
getRootAt in interface GraphModelpublic int getIndexOfRoot(java.lang.Object root)
root in the model. If root is
null, returns -1.getIndexOfRoot in interface GraphModelroot - a root in the model, obtained from this data sourcenullpublic boolean contains(java.lang.Object node)
true if node or one of its
ancestors is in the model.contains in interface GraphModeltrue if node is in the modelpublic 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 GraphModelnode as a Mappublic java.lang.Object getValue(java.lang.Object cell)
GraphModelgetValue in interface GraphModelpublic java.util.Map getAttributes()
getAttributes(null).node as a Mappublic java.lang.Object getSource(java.lang.Object edge)
edge. edge must be an
object previously obtained from this data source.getSource in interface GraphModelObject that represents the source of edge public java.lang.Object getTarget(java.lang.Object edge)
edge. edge must be an
object previously obtained from this data source.getTarget in interface GraphModelObject that represents the target of edge public 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 GraphModeltrue 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 GraphModeltrue 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 GraphModelport - a port in the graph, obtained from this data sourceIterator that represents the connected edgespublic boolean isEdge(java.lang.Object edge)
true if edge is a valid edge.isEdge in interface GraphModeltrue 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 GraphModeltrue if port is a valid port.public ConnectionSet getConnectionSet()
public java.util.Map cloneCells(java.lang.Object[] cells)
cells. In
the new array, all references are replaced with references to the cloned
cells (ie parent or anchor). This method does only include children which
are in cells. Use JGraph.getDescendants to get a complete
list of all children.cloneCells in interface GraphModelprotected void setParent(java.lang.Object child,
java.lang.Object parent)
protected java.lang.Object cloneCell(java.lang.Object cellObj)
protected java.lang.Object cloneUserObject(java.lang.Object userObject)
object.public java.lang.Object getParent(java.lang.Object child)
getParent in interface GraphModelchild - a node in the graph, obtained from this data sourcepublic int getIndexOfChild(java.lang.Object parent,
java.lang.Object child)
null, returns -1.getIndexOfChild in interface GraphModelparent - a note in the tree, obtained from this data sourcechild - the node we are interested innullpublic java.lang.Object getChild(java.lang.Object parent,
int index)
getChild in interface GraphModelparent - a node in the tree, obtained from this data sourcepublic int getChildCount(java.lang.Object parent)
getChildCount in interface GraphModelparent - a node in the tree, obtained from this data sourcepublic boolean isLeaf(java.lang.Object node)
isLeaf in interface GraphModelnode - the node to checkpublic 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
passed-in propertyMap may contain PortView s which must be
turned into Point s when stored in the model.insert in interface GraphModelpublic void remove(java.lang.Object[] roots)
cells from the model. Notifies the model- and undo
listeners of the change.remove in interface GraphModelpublic void edit(java.util.Map attributes,
ConnectionSet cs,
ParentMap pm,
javax.swing.undo.UndoableEdit[] edits)
edit in interface GraphModelpublic void edit(java.lang.Object[] inserted,
java.lang.Object[] removed,
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.public void execute(ExecutableChange change)
GraphModelexecute in interface GraphModelchange - the change to be executedpublic int getUpdateLevel()
getUpdateLevel in class javax.swing.undo.UndoableEditSupportpublic void beginUpdate()
GraphModelbeginUpdate in interface GraphModelbeginUpdate in class javax.swing.undo.UndoableEditSupportpublic void endUpdate()
GraphModelendUpdate in interface GraphModelendUpdate in class javax.swing.undo.UndoableEditSupportprotected void updateTransaction(java.lang.Object[] inserted,
java.lang.Object[] removed,
java.util.Map attributes,
ConnectionSet cs,
ParentMap pm)
inserted - inserted cell to be added to the transactionremoved - removed cells to be removed from the transactionattributes - nested attribute maps to apply to the transactioncs - connection sets to add to the transactionpm - parent maps to add to the transactionpublic void toBack(java.lang.Object[] cells)
cells to back.toBack in interface GraphModelpublic void toFront(java.lang.Object[] cells)
cells to front.toFront in interface GraphModelprotected DefaultGraphModel.GraphModelLayerEdit createLayerEdit(java.lang.Object[] cells, int layer)
protected DefaultGraphModel.GraphModelEdit createRemoveEdit(java.lang.Object[] cells)
protected DefaultGraphModel.GraphModelEdit createEdit(java.lang.Object[] inserted, java.lang.Object[] removed, java.util.Map attributes, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] edits)
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.public java.lang.Object valueForCellChanged(java.lang.Object cell,
java.lang.Object newValue)
valueForCellChanged in interface GraphModelcell - newValue - 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, boolean establish)
protected void connect(java.lang.Object edge,
java.lang.Object port,
boolean isSource,
boolean insert)
remove. Subclassers should override this to update
connectivity datastructures.public void addGraphModelListener(GraphModelListener l)
addGraphModelListener in interface GraphModell - the listener to addremoveGraphModelListener(org.jgraph.event.GraphModelListener)public void removeGraphModelListener(GraphModelListener l)
removeGraphModelListener in interface GraphModell - the listener to removeaddGraphModelListener(org.jgraph.event.GraphModelListener)public void cellsChanged(java.lang.Object[] cells)
protected void fireGraphChanged(java.lang.Object source,
GraphModelEvent.GraphModelChange edit)
public GraphModelListener[] getGraphModelListeners()
public static java.lang.Object cloneCell(GraphModel model, java.lang.Object cell)
public static java.lang.Object[] cloneCell(GraphModel model, java.lang.Object[] cells)
public static void setSourcePort(GraphModel model, java.lang.Object edge, java.lang.Object port)
edge to
port in model.public static void setTargetPort(GraphModel model, java.lang.Object edge, java.lang.Object port)
edge to
port in model.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 getUserObject(java.lang.Object cell)
GraphModel.getValue(Object) instead.public static boolean isGroup(GraphModel model, java.lang.Object cell)
cell - the cell to check for being a grouppublic static java.lang.Object[] getAll(GraphModel model)
getDescendants(GraphModel, Object[])public static java.lang.Object[] getRoots(GraphModel model)
DefaultGraphModel the performance can be improved to
linear time.public static java.util.Collection getRootsAsCollection(GraphModel model)
DefaultGraphModel the performance can be improved to
linear time.public static java.lang.Object[] getRoots(GraphModel model, java.lang.Object[] cells)
cells by checking if their parent is
null. This implementation only uses the GraphModel
interface. This method never returns null.public static java.lang.Object[] getTopmostCells(GraphModel model, java.lang.Object[] cells)
public static boolean hasAncestorIn(GraphModel model, java.util.Set parents, java.lang.Object child)
public static java.util.List getDescendants(GraphModel model, java.lang.Object[] cells)
public static java.lang.Object[] order(GraphModel model, java.lang.Object[] cells)
public static java.util.Set getEdges(GraphModel model, java.lang.Object[] cells)
cells or their
descendants. The passed-in cells are never returned as part of the result
set. This can be used on vertices, edges and ports.public static java.lang.Object getOpposite(GraphModel model, java.lang.Object edge, java.lang.Object cell)
edge.public static boolean containsEdgeBetween(GraphModel model, java.lang.Object v1, java.lang.Object v2)
public static java.lang.Object[] getEdgesBetween(GraphModel model, java.lang.Object cell1, java.lang.Object cell2, boolean directed)
cell1 must be the source of the
returned edges. This method never returns null. If there are no edges
between the specified cells, then an array of length 0 is returned.public static java.lang.Object[] getOutgoingEdges(GraphModel model, java.lang.Object cell)
public static java.lang.Object[] getIncomingEdges(GraphModel model, java.lang.Object cell)
public static java.lang.Object[] getEdges(GraphModel model, java.lang.Object cell, boolean incoming)
public static boolean isVertex(GraphModel model, java.lang.Object vertex)
true if vertex is a valid vertex.true if vertex is a valid vertex.public boolean isRemoveEmptyGroups()
public void setRemoveEmptyGroups(boolean removeEmptyGroups)
removeEmptyGroups - the removeEmptyGroups to setCopyright (C) 2001-2008 Gaudenz Alder. All rights reserved.