Package org.jgraph.graph
Class DefaultGraphModel
- java.lang.Object
-
- javax.swing.undo.UndoableEditSupport
-
- org.jgraph.graph.DefaultGraphModel
-
- All Implemented Interfaces:
java.io.Serializable
,GraphModel
public class DefaultGraphModel extends javax.swing.undo.UndoableEditSupport implements java.io.Serializable, GraphModel
The default implementation of a graph model.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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.
-
Field Summary
Fields Modifier and Type Field 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 removedprotected java.util.List
roots
Set that contains all root cells of this model.
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
acceptsSource(java.lang.Object edge, java.lang.Object port)
Returnstrue
ifport
is a valid source foredge
.boolean
acceptsTarget(java.lang.Object edge, java.lang.Object port)
Returnstrue
ifport
is a valid target foredge
.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 changevoid
cellsChanged(java.lang.Object[] cells)
Invoke this method after you've changed how the cells are to be represented in the graph.protected java.lang.Object
cloneCell(java.lang.Object cellObj)
Creates a shallow copy of the cell including a copy of the user object.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.java.util.Map
cloneCells(java.lang.Object[] cells)
Returns a map of (cell, clone)-pairs for allcells
.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 onremove
.boolean
contains(java.lang.Object node)
Returnstrue
ifnode
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 toport
.void
edit(java.lang.Object[] inserted, java.lang.Object[] removed, java.util.Map attributes, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] edits)
Appliesattributes
and the connection changes to the model.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
endUpdate()
Indicates the end of the current level of an executable changevoid
execute(ExecutableChange change)
Executes the specified executable change on this graph modelprotected 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 aMap
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 tocells
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 ofroot
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 incells
by checking if their parent isnull
.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 ofedge
.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 ofedge
.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.UseGraphModel.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)
Appliesattributes
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)
AppliesconnectionSet
to the model.protected java.lang.Object[]
handleInsert(java.lang.Object[] cells)
Insertscells
into the model.protected ParentMap
handleParentMap(ParentMap parentMap)
Appliescells
to the model.protected java.lang.Object[]
handleRemove(java.lang.Object[] cells)
Removescells
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 theroots
and connections into the model.boolean
isEdge(java.lang.Object edge)
Returnstrue
ifedge
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)
Returnstrue
ifport
is a valid port, possibly supporting edge connection.boolean
isRemoveEmptyGroups()
static boolean
isVertex(GraphModel model, java.lang.Object vertex)
Returnstrue
ifvertex
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)
Removescells
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 ofedge
toport
inmodel.
static void
setTargetPort(GraphModel model, java.lang.Object edge, java.lang.Object port)
Helper methods that connects the source ofedge
toport
inmodel.
void
toBack(java.lang.Object[] cells)
Sendscells
to back.void
toFront(java.lang.Object[] cells)
Bringscells
to front.java.lang.Object
valueForCellChanged(java.lang.Object cell, java.lang.Object newValue)
Applies the new value to the specified cell.-
Methods inherited from class javax.swing.undo.UndoableEditSupport
_postEdit, addUndoableEditListener, createCompoundEdit, getUndoableEditListeners, 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
-
listenerList
protected transient javax.swing.event.EventListenerList listenerList
The list of listeners that listen to the model.
-
emptyIterator
protected transient java.util.Iterator emptyIterator
Default instance of an empty iterator.
-
roots
protected java.util.List roots
Set that contains all root cells of this model.
-
asksAllowsChildren
protected boolean asksAllowsChildren
Indicates whether isLeaf is based on a node's allowsChildren value.
-
removeEmptyGroups
protected boolean removeEmptyGroups
Whether or not to remove group cells from the model when all of their children are removed
-
attributes
protected AttributeMap attributes
The model's own attributes as a map. Defaults to an empty Hashtable.
-
-
Constructor Detail
-
DefaultGraphModel
public DefaultGraphModel()
Constructs a model that is not an attribute store.
-
DefaultGraphModel
public DefaultGraphModel(java.util.List roots, AttributeMap attributes)
Constructs a model that is not an attribute store.
-
DefaultGraphModel
public DefaultGraphModel(java.util.List roots, AttributeMap attributes, ConnectionSet cs)
Constructs a model using the specified information to construct the cells, attributes and connection data.
-
-
Method Detail
-
getRoots
public java.util.List getRoots()
-
getRootCount
public int getRootCount()
Returns the number of roots in the model. Returns 0 if the model is empty.- Specified by:
getRootCount
in interfaceGraphModel
- Returns:
- the number of roots in the model
-
getRootAt
public 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()).- Specified by:
getRootAt
in interfaceGraphModel
- Returns:
- the root of at index index
-
getIndexOfRoot
public int getIndexOfRoot(java.lang.Object root)
Returns the index ofroot
in the model. If root isnull
, returns -1.- Specified by:
getIndexOfRoot
in interfaceGraphModel
- 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
public boolean contains(java.lang.Object node)
Returnstrue
ifnode
or one of its ancestors is in the model.- Specified by:
contains
in interfaceGraphModel
- Returns:
true
ifnode
is in the model
-
getAttributes
public AttributeMap getAttributes(java.lang.Object node)
Returns aMap
that represents the attributes for the specified cell. This attributes have precedence over each view's attributes, regardless of isAttributeStore.- Specified by:
getAttributes
in interfaceGraphModel
- Returns:
- attributes of
node
as aMap
-
getValue
public java.lang.Object getValue(java.lang.Object cell)
Description copied from interface:GraphModel
Returns the user object for the specified cell.- Specified by:
getValue
in interfaceGraphModel
- Returns:
- Returns the user object of the given cell. This implementation checks if the cell is a default mutable tree node and returns it's user object.
-
getAttributes
public java.util.Map getAttributes()
Returns the graph model's attribute. Shortcut togetAttributes(null)
.- Returns:
- attributes of
node
as aMap
-
getSource
public java.lang.Object getSource(java.lang.Object edge)
Returns the source ofedge
. edge must be an object previously obtained from this data source.- Specified by:
getSource
in interfaceGraphModel
- Returns:
Object
that represents the source of edge
-
getTarget
public java.lang.Object getTarget(java.lang.Object edge)
Returns the target ofedge
. edge must be an object previously obtained from this data source.- Specified by:
getTarget
in interfaceGraphModel
- Returns:
Object
that represents the target of edge
-
acceptsSource
public boolean acceptsSource(java.lang.Object edge, java.lang.Object port)
Returnstrue
ifport
is a valid source foredge
. edge and port must be objects previously obtained from this data source.- Specified by:
acceptsSource
in interfaceGraphModel
- Returns:
true
ifport
is a valid source foredge
.
-
acceptsTarget
public boolean acceptsTarget(java.lang.Object edge, java.lang.Object port)
Returnstrue
ifport
is a valid target foredge
. edge and port must be objects previously obtained from this data source.- Specified by:
acceptsTarget
in interfaceGraphModel
- Returns:
true
ifport
is a valid target foredge
.
-
edges
public 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.- Specified by:
edges
in interfaceGraphModel
- Parameters:
port
- a port in the graph, obtained from this data source- Returns:
Iterator
that represents the connected edges
-
isEdge
public boolean isEdge(java.lang.Object edge)
Returnstrue
ifedge
is a valid edge.- Specified by:
isEdge
in interfaceGraphModel
- Returns:
true
ifedge
is a valid edge.
-
isPort
public boolean isPort(java.lang.Object port)
Returnstrue
ifport
is a valid port, possibly supporting edge connection.- Specified by:
isPort
in interfaceGraphModel
- Returns:
true
ifport
is a valid port.
-
getConnectionSet
public ConnectionSet getConnectionSet()
A shortcut method to create a connection set that represents the connections in this model. Useful for encoding to avoid writing redundant connection data stored in the cells.
-
cloneCells
public java.util.Map cloneCells(java.lang.Object[] cells)
Returns a map of (cell, clone)-pairs for allcells
. 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 incells
. Use JGraph.getDescendants to get a complete list of all children.- Specified by:
cloneCells
in interfaceGraphModel
-
setParent
protected void setParent(java.lang.Object child, java.lang.Object parent)
Sets the parent of the specified cell.
-
cloneCell
protected java.lang.Object cloneCell(java.lang.Object cellObj)
Creates a shallow copy of the cell including a copy of the user object. Subclassers can override the cloneUserObject to provide a custom user object cloning mechanism.
-
cloneUserObject
protected java.lang.Object cloneUserObject(java.lang.Object userObject)
Clones the user object. Helper method that is invoked from cloneCells. You must use cloneCells (or cloneCell for single cells) to get a deep copy of a clone. Subclassers must override this and valueForCellChanged to implement custom user objects. This implementation returnsobject
.
-
getParent
public 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.- Specified by:
getParent
in interfaceGraphModel
- Parameters:
child
- a node in the graph, obtained from this data source- Returns:
- the parent of child
-
getIndexOfChild
public 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.- Specified by:
getIndexOfChild
in interfaceGraphModel
- 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
public 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 )).- Specified by:
getChild
in interfaceGraphModel
- Parameters:
parent
- a node in the tree, obtained from this data source- Returns:
- the child of parent at index index
-
getChildCount
public 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.- Specified by:
getChildCount
in interfaceGraphModel
- Parameters:
parent
- a node in the tree, obtained from this data source- Returns:
- the number of children of the node parent
-
isLeaf
public boolean isLeaf(java.lang.Object node)
Returns whether the specified node is a leaf node. The way the test is performed depends on the.- Specified by:
isLeaf
in interfaceGraphModel
- Parameters:
node
- the node to check- Returns:
- true if the node is a leaf node
-
insert
public void insert(java.lang.Object[] roots, java.util.Map attributes, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] edits)
Inserts theroots
and connections into the model. Notifies the model- and undo listeners of the change. The passed-in edits are executed if they implement theGraphModelEvent.ExecutableGraphChange
interface in ascending array-order, after execution of the model change. Note: The passed-in propertyMap may containPortView
s which must be turned intoPoint
s when stored in the model.- Specified by:
insert
in interfaceGraphModel
-
remove
public void remove(java.lang.Object[] roots)
Removescells
from the model. Notifies the model- and undo listeners of the change.- Specified by:
remove
in interfaceGraphModel
-
edit
public 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.- Specified by:
edit
in interfaceGraphModel
-
edit
public void edit(java.lang.Object[] inserted, java.lang.Object[] removed, java.util.Map attributes, ConnectionSet cs, ParentMap pm, javax.swing.undo.UndoableEdit[] edits)
Appliesattributes
and the connection changes to the model. The initialedits
that triggered the call are considered to be part of this transaction. The passed-in edits are executed if they implement theGraphModelEvent.ExecutableGraphChange
interface in ascending array-order, after execution of the model change. Notifies the model- and undo listeners of the change. Note: If onlyedits
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.
-
execute
public void execute(ExecutableChange change)
Description copied from interface:GraphModel
Executes the specified executable change on this graph model- Specified by:
execute
in interfaceGraphModel
- Parameters:
change
- the change to be executed
-
getUpdateLevel
public int getUpdateLevel()
- Overrides:
getUpdateLevel
in classjavax.swing.undo.UndoableEditSupport
-
beginUpdate
public void beginUpdate()
Description copied from interface:GraphModel
Indicates the start of one level of an executable change- Specified by:
beginUpdate
in interfaceGraphModel
- Overrides:
beginUpdate
in classjavax.swing.undo.UndoableEditSupport
-
endUpdate
public void endUpdate()
Description copied from interface:GraphModel
Indicates the end of the current level of an executable change- Specified by:
endUpdate
in interfaceGraphModel
- Overrides:
endUpdate
in classjavax.swing.undo.UndoableEditSupport
-
toBack
public void toBack(java.lang.Object[] cells)
Sendscells
to back.- Specified by:
toBack
in interfaceGraphModel
-
toFront
public void toFront(java.lang.Object[] cells)
Bringscells
to front.- Specified by:
toFront
in interfaceGraphModel
-
createLayerEdit
protected DefaultGraphModel.GraphModelLayerEdit createLayerEdit(java.lang.Object[] cells, int layer)
-
createRemoveEdit
protected DefaultGraphModel.GraphModelEdit createRemoveEdit(java.lang.Object[] cells)
Returns an edit that represents a remove.
-
createEdit
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)
-
handleInsert
protected java.lang.Object[] handleInsert(java.lang.Object[] cells)
Insertscells
into the model. Returns the cells that were inserted (including descendants).
-
handleRemove
protected java.lang.Object[] handleRemove(java.lang.Object[] cells)
Removescells
from the model. Returns the cells that were removed as roots.
-
handleParentMap
protected ParentMap handleParentMap(ParentMap parentMap)
Appliescells
to the model. Returns a parent map that may be used to undo this change.
-
handleAttributes
protected java.util.Map handleAttributes(java.util.Map attributes)
Appliesattributes
to the cells specified as keys. Returns theattributes
to undo the change.
-
valueForCellChanged
public java.lang.Object valueForCellChanged(java.lang.Object cell, java.lang.Object newValue)
Applies the new value to the specified cell. Unfortunately for cloning the user object you must still override the attribute map and provide a custom cloneUserObject method. This is because the cloning of a cell is local to the cell, which in turn has a reference to its attribute map.- Specified by:
valueForCellChanged
in interfaceGraphModel
- Parameters:
cell
-newValue
-- Returns:
- the old value for the cell, if any
-
handleConnectionSet
protected ConnectionSet handleConnectionSet(ConnectionSet cs)
AppliesconnectionSet
to the model. Returns a connection set that may be used to undo this change.
-
handleConnection
protected void handleConnection(ConnectionSet.Connection c, boolean establish)
Inserts the specified connection into the model.
-
connect
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 onremove
. Subclassers should override this to update connectivity datastructures.
-
addGraphModelListener
public void addGraphModelListener(GraphModelListener l)
Adds a listener for the GraphModelEvent posted after the graph changes.- Specified by:
addGraphModelListener
in interfaceGraphModel
- Parameters:
l
- the listener to add- See Also:
removeGraphModelListener(org.jgraph.event.GraphModelListener)
-
removeGraphModelListener
public void removeGraphModelListener(GraphModelListener l)
Removes a listener previously added with addGraphModelListener() .- Specified by:
removeGraphModelListener
in interfaceGraphModel
- Parameters:
l
- the listener to remove- See Also:
addGraphModelListener(org.jgraph.event.GraphModelListener)
-
cellsChanged
public void cellsChanged(java.lang.Object[] cells)
Invoke this method after you've changed how the cells are to be represented in the graph.
-
fireGraphChanged
protected void fireGraphChanged(java.lang.Object source, GraphModelEvent.GraphModelChange edit)
-
getGraphModelListeners
public GraphModelListener[] getGraphModelListeners()
Return an array of all GraphModelListeners that were added to this model.
-
cloneCell
public static java.lang.Object cloneCell(GraphModel model, java.lang.Object cell)
Returns a deep clone of the specified cell, including all children.
-
cloneCell
public static java.lang.Object[] cloneCell(GraphModel model, java.lang.Object[] cells)
Returns a deep clone of the specified cells, including all children.
-
setSourcePort
public static void setSourcePort(GraphModel model, java.lang.Object edge, java.lang.Object port)
Helper methods that connects the source ofedge
toport
inmodel.
-
setTargetPort
public static void setTargetPort(GraphModel model, java.lang.Object edge, java.lang.Object port)
Helper methods that connects the source ofedge
toport
inmodel.
-
getSourceVertex
public 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.
-
getTargetVertex
public 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.
-
getUserObject
public static java.lang.Object getUserObject(java.lang.Object cell)
Deprecated.UseGraphModel.getValue(Object)
instead.- Returns:
- Returns the user object of the given cell. This implementation checks if the cell is a default mutable tree node and returns it's user object.
-
isGroup
public static boolean isGroup(GraphModel model, java.lang.Object cell)
Checks whether the cell has at least one child which is not a port. This implementation operates on the model, not taking into account visibility of cells. It returns true for groups regardless of their folded state.- Parameters:
cell
- the cell to check for being a group- Returns:
- Returns true if the cell contains at least one cell which is not a port
-
getAll
public static java.lang.Object[] getAll(GraphModel model)
Returns all cells of the model in an array.- Returns:
- Returns all cells in the model including all descandants.
- See Also:
getDescendants(GraphModel, Object[])
-
getRoots
public static java.lang.Object[] getRoots(GraphModel model)
Returns the roots of the specified model as an array. This implementation uses the GraphModel interface in the general case, but if the model is aDefaultGraphModel
the performance can be improved to linear time.
-
getRootsAsCollection
public static java.util.Collection getRootsAsCollection(GraphModel model)
Returns the roots of the specified model as a collection. This implementation uses the GraphModel interface in the general case, but if the model is aDefaultGraphModel
the performance can be improved to linear time.
-
getRoots
public static java.lang.Object[] getRoots(GraphModel model, java.lang.Object[] cells)
Returns the roots incells
by checking if their parent isnull
. This implementation only uses the GraphModel interface. This method never returns null.
-
getTopmostCells
public static java.lang.Object[] getTopmostCells(GraphModel model, java.lang.Object[] cells)
- Returns:
- Returns the roots of cells, eg. an array that contains no cell having an ancestor in cells.
-
hasAncestorIn
public static boolean hasAncestorIn(GraphModel model, java.util.Set parents, java.lang.Object child)
Returns true if the specified child has an ancestor in parents.
-
getDescendants
public 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. The resulting set contains all cells, which means it contains branches and leafs. Note: This is an iterative implementation. No recursion used.
Note: This returns a linked list, for frequent read operations you should turn this into an array, or at least an array list.
-
order
public static java.lang.Object[] order(GraphModel model, java.lang.Object[] cells)
Orders cells so that they reflect the model order.
-
getEdges
public static java.util.Set getEdges(GraphModel model, java.lang.Object[] cells)
Returns the set of all connected edges tocells
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.
-
getOpposite
public static java.lang.Object getOpposite(GraphModel model, java.lang.Object edge, java.lang.Object cell)
- Returns:
- Returns the opposite port or vertex in
edge
.
-
containsEdgeBetween
public 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.
-
getEdgesBetween
public 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. If directed is true thencell1
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.
-
getOutgoingEdges
public static java.lang.Object[] getOutgoingEdges(GraphModel model, java.lang.Object cell)
Returns the outgoing edges for cell. Cell should be a port or a vertex.
-
getIncomingEdges
public static java.lang.Object[] getIncomingEdges(GraphModel model, java.lang.Object cell)
Returns the incoming edges for cell. Cell should be a port or a vertex.
-
getEdges
public static java.lang.Object[] getEdges(GraphModel model, java.lang.Object cell, boolean incoming)
Returns the incoming or outgoing edges for cell. Cell should be a port or a vertex.
-
isVertex
public static boolean isVertex(GraphModel model, java.lang.Object vertex)
Returnstrue
ifvertex
is a valid vertex.- Returns:
true
ifvertex
is a valid vertex.
-
isRemoveEmptyGroups
public boolean isRemoveEmptyGroups()
- Returns:
- the removeEmptyGroups
-
setRemoveEmptyGroups
public void setRemoveEmptyGroups(boolean removeEmptyGroups)
- Parameters:
removeEmptyGroups
- the removeEmptyGroups to set
-
-