public class mxGraphModel extends mxEventSource implements mxIGraphModel, Serializable
edit
property contains the mxUndoableEdit. The changes
property
contains the list of undoable changes inside the undoable edit. The changes
property is deprecated, please use edit.getChanges() instead.
mxEvent.EXECUTE fires between begin- and endUpdate and after an atomic
change was executed in the model. The change
property contains
the atomic change that was executed.
mxEvent.BEGIN_UPDATE fires after the updateLevel was incremented in
beginUpdate. This event contains no properties.
mxEvent.END_UPDATE fires after the updateLevel was decreased in endUpdate
but before any notification or change dispatching. The edit
property contains the current mxUndoableEdit.
mxEvent.BEFORE_UNDO fires before the change is dispatched after the update
level has reached 0 in endUpdate. The edit
property contains
the current mxUndoableEdit.
mxEvent.UNDO fires after the change was dispatched in endUpdate. The
edit
property contains the current mxUndoableEdit.Modifier and Type | Class and Description |
---|---|
static interface |
mxGraphModel.Filter |
static class |
mxGraphModel.mxChildChange |
static class |
mxGraphModel.mxCollapseChange |
static class |
mxGraphModel.mxGeometryChange |
static class |
mxGraphModel.mxRootChange |
static class |
mxGraphModel.mxStyleChange |
static class |
mxGraphModel.mxTerminalChange |
static class |
mxGraphModel.mxValueChange |
static class |
mxGraphModel.mxVisibleChange |
mxEventSource.mxIEventListener
mxIGraphModel.mxAtomicGraphModelChange
Modifier and Type | Field and Description |
---|---|
protected Map<String,Object> |
cells
Maps from Ids to cells.
|
protected boolean |
createIds
Specifies if the model should automatically create Ids for new cells.
|
protected mxUndoableEdit |
currentEdit
Holds the changes for the current transaction.
|
protected boolean |
endingUpdate |
protected boolean |
maintainEdgeParent
Specifies if edges should automatically be moved into the nearest common
ancestor of their terminals.
|
protected int |
nextId
Specifies the next Id to be created.
|
protected mxICell |
root
Holds the root cell, which in turn contains the cells that represent the
layers of the diagram as child cells.
|
protected int |
updateLevel
Counter for the depth of nested transactions.
|
eventListeners, eventsEnabled, eventSource
Constructor and Description |
---|
mxGraphModel()
Constructs a new empty graph model.
|
mxGraphModel(Object root)
Constructs a new graph model.
|
Modifier and Type | Method and Description |
---|---|
Object |
add(Object parent,
Object child,
int index)
Adds the specified child to the parent at the given index.
|
void |
beginUpdate()
Increments the updateLevel by one.
|
protected void |
cellAdded(Object cell)
Invoked after a cell has been added to a parent.
|
protected void |
cellRemoved(Object cell)
Invoked after a cell has been removed from the model.
|
void |
clear()
Sets a new root using createRoot.
|
protected Object |
cloneCell(Object cell,
Map<Object,Object> mapping,
boolean includeChildren)
Inner helper method for cloning cells recursively.
|
Object[] |
cloneCells(Object[] cells,
boolean includeChildren)
Returns an array of clones for the given array of cells.
|
protected boolean |
collapsedStateForCellChanged(Object cell,
boolean collapsed)
Inner callback to update the collapsed state of the
given mxCell using mxCell.setCollapsed and return
the previous collapsed state.
|
boolean |
contains(Object cell)
Returns true if the model contains the given cell.
|
String |
createId(Object cell)
Creates a new Id for the given cell and increments the global counter
for creating new Ids.
|
Object |
createRoot()
Creates a new root cell with a default layer (child 0).
|
protected mxUndoableEdit |
createUndoableEdit()
Creates a new undoable edit.
|
void |
endUpdate()
Decrements the updateLevel by one and fires a notification event if the
updateLevel reaches 0.
|
void |
execute(mxIGraphModel.mxAtomicGraphModelChange change)
Executes the given atomic change and adds it to the current edit.
|
static Object[] |
filterCells(Object[] cells,
mxGraphModel.Filter filter) |
static Collection<Object> |
filterDescendants(mxIGraphModel model,
mxGraphModel.Filter filter)
Creates a collection of cells using the visitor pattern.
|
static Collection<Object> |
filterDescendants(mxIGraphModel model,
mxGraphModel.Filter filter,
Object parent)
Creates a collection of cells using the visitor pattern.
|
protected mxGeometry |
geometryForCellChanged(Object cell,
mxGeometry geometry)
Inner callback to update the mxGeometry of the given mxCell using
mxCell.setGeometry and return the previous mxGeometry.
|
Object |
getCell(String id)
Returns the cell for the specified Id or null if no cell can be
found for the given Id.
|
Map<String,Object> |
getCells()
Returns the internal lookup table that is used to map from Ids to cells.
|
Object |
getChildAt(Object parent,
int index)
Returns the child of the given parent at the given index.
|
static Object[] |
getChildCells(mxIGraphModel model,
Object parent,
boolean vertices,
boolean edges)
Returns the children of the given cell that are vertices and/or edges
depending on the arguments.
|
int |
getChildCount(Object cell)
Returns the number of children in the given cell.
|
static Object[] |
getChildEdges(mxIGraphModel model,
Object parent)
Returns the child edges of the given parent.
|
static Object[] |
getChildren(mxIGraphModel model,
Object parent)
Returns all children of the given cell regardless of their type.
|
static Object[] |
getChildVertices(mxIGraphModel model,
Object parent)
Returns the child vertices of the given parent.
|
static Object[] |
getConnections(mxIGraphModel model,
Object cell)
Returns all edges connected to this cell without loops.
|
static Collection<Object> |
getDescendants(mxIGraphModel model,
Object parent)
Returns a all descendants of the given cell and the cell itself
as a collection.
|
static int |
getDirectedEdgeCount(mxIGraphModel model,
Object cell,
boolean outgoing)
Returns the number of incoming or outgoing edges.
|
static int |
getDirectedEdgeCount(mxIGraphModel model,
Object cell,
boolean outgoing,
Object ignoredEdge)
Returns the number of incoming or outgoing edges, ignoring the given
edge.
|
Object |
getEdgeAt(Object parent,
int index)
Returns the edge of cell at the given index.
|
int |
getEdgeCount(Object cell)
Returns the number of distinct edges connected to the given cell.
|
static Object[] |
getEdges(mxIGraphModel model,
Object cell)
Returns all edges connected to this cell including loops.
|
static Object[] |
getEdges(mxIGraphModel model,
Object cell,
boolean incoming,
boolean outgoing,
boolean includeLoops)
Returns all distinct edges connected to this cell.
|
static Object[] |
getEdgesBetween(mxIGraphModel model,
Object source,
Object target)
Returns all edges from the given source to the given target.
|
static Object[] |
getEdgesBetween(mxIGraphModel model,
Object source,
Object target,
boolean directed)
Returns all edges between the given source and target pair.
|
mxGeometry |
getGeometry(Object cell)
Returns the geometry of the given cell.
|
static Object[] |
getIncomingEdges(mxIGraphModel model,
Object cell)
Returns the incoming edges of the given cell without loops.
|
Object |
getNearestCommonAncestor(Object cell1,
Object cell2)
Returns the nearest common ancestor for the specified cells.
|
static Object[] |
getOpposites(mxIGraphModel model,
Object[] edges,
Object terminal)
Returns all opposite cells of terminal for the given edges.
|
static Object[] |
getOpposites(mxIGraphModel model,
Object[] edges,
Object terminal,
boolean sources,
boolean targets)
Returns all opposite vertices wrt terminal for the given edges, only
returning sources and/or targets as specified.
|
mxPoint |
getOrigin(Object cell)
Returns the absolute, accumulated origin for the children inside the
given parent.
|
static Object[] |
getOutgoingEdges(mxIGraphModel model,
Object cell)
Returns the outgoing edges of the given cell without loops.
|
Object |
getParent(Object child)
Returns the parent of the given cell.
|
static Object[] |
getParents(mxIGraphModel model,
Object[] cells) |
Object |
getRoot()
Returns the root of the model or the topmost parent of the given cell.
|
String |
getStyle(Object cell)
Returns the style of the given cell.
|
Object |
getTerminal(Object edge,
boolean isSource)
Returns the source or target terminal of the given edge depending on the
value of the boolean parameter.
|
static Object[] |
getTopmostCells(mxIGraphModel model,
Object[] cells)
Function: getTopmostCells
Returns the topmost cells of the hierarchy in an array that contains no
desceandants for each
|
int |
getUpdateLevel() |
Object |
getValue(Object cell)
Returns the user object of the given cell.
|
boolean |
isAncestor(Object parent,
Object child)
Returns true if the given parent is an ancestor of the given child.
|
boolean |
isCollapsed(Object cell)
Returns true if the given cell is collapsed.
|
boolean |
isConnectable(Object cell)
Returns true if the given cell is connectable.
|
boolean |
isCreateIds()
Returns true if the model automatically creates Ids and resolves Id
collisions.
|
boolean |
isEdge(Object cell)
Returns true if the given cell is an edge.
|
boolean |
isMaintainEdgeParent()
Returns true if the model automatically update parents of edges so that
the edge is contained in the nearest-common-ancestor of its terminals.
|
boolean |
isVertex(Object cell)
Returns true if the given cell is a vertex.
|
boolean |
isVisible(Object cell)
Returns true if the given cell is visible.
|
void |
mergeChildren(mxICell from,
mxICell to,
boolean cloneAllEdges)
Merges the children of the given cell into the given target cell inside
this model.
|
protected void |
mergeChildrenImpl(mxICell from,
mxICell to,
boolean cloneAllEdges,
Hashtable<Object,Object> mapping)
Clones the children of the source cell into the given target cell in
this model and adds an entry to the mapping that maps from the source
cell to the target cell with the same id or the clone of the source cell
that was inserted into this model.
|
protected Object |
parentForCellChanged(Object cell,
Object parent,
int index)
Inner callback to update the parent of a cell using mxCell.insert
on the parent and return the previous parent.
|
Object |
remove(Object cell)
Removes the specified cell from the model.
|
protected void |
restoreClone(Object clone,
Object cell,
Map<Object,Object> mapping)
Inner helper method for restoring the connections in
a network of cloned cells.
|
protected Object |
rootChanged(Object root)
Inner callback to change the root of the model and update the internal
datastructures, such as cells and nextId.
|
boolean |
setCollapsed(Object cell,
boolean collapsed)
Sets the collapsed state of the given cell.
|
void |
setCreateIds(boolean value)
Specifies if the model automatically creates Ids for new cells and
resolves Id collisions.
|
mxGeometry |
setGeometry(Object cell,
mxGeometry geometry)
Sets the geometry of the given cell.
|
void |
setMaintainEdgeParent(boolean maintainEdgeParent)
Specifies if the model automatically updates parents of edges so that
the edge is contained in the nearest-common-ancestor of its terminals.
|
Object |
setRoot(Object root)
Sets the root of the model and resets all structures.
|
String |
setStyle(Object cell,
String style)
Sets the style of the given cell.
|
Object |
setTerminal(Object edge,
Object terminal,
boolean isSource)
Sets the source or target terminal of the given edge using.
|
static void |
setTerminals(mxIGraphModel model,
Object edge,
Object source,
Object target)
Sets the source and target of the given edge in a single atomic change.
|
Object |
setValue(Object cell,
Object value)
Sets the user object of then given cell.
|
boolean |
setVisible(Object cell,
boolean visible)
Sets the visible state of the given cell.
|
protected String |
styleForCellChanged(Object cell,
String style)
Inner callback to update the style of the given mxCell
using mxCell.setStyle and return the previous style.
|
protected Object |
terminalForCellChanged(Object edge,
Object terminal,
boolean isSource)
Inner helper function to update the terminal of the edge using
mxCell.insertEdge and return the previous terminal.
|
void |
updateEdgeParent(Object edge,
Object root)
Inner helper method to update the parent of the specified edge to the
nearest-common-ancestor of its two terminals.
|
void |
updateEdgeParents(Object cell)
Updates the parents of the edges connected to the given cell and all its
descendants so that each edge is contained in the nearest common
ancestor.
|
void |
updateEdgeParents(Object cell,
Object root)
Updates the parents of the edges connected to the given cell and all its
descendants so that the edge is contained in the nearest-common-ancestor.
|
protected Object |
valueForCellChanged(Object cell,
Object value)
Inner callback to update the user object of the given mxCell
using mxCell.setValue and return the previous value,
that is, the return value of mxCell.getValue.
|
protected boolean |
visibleStateForCellChanged(Object cell,
boolean visible)
Sets the visible state of the given mxCell using mxVisibleChange and
adds the change to the current transaction.
|
addListener, fireEvent, fireEvent, getEventSource, isEventsEnabled, removeListener, removeListener, setEventsEnabled, setEventSource
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addListener, removeListener, removeListener
protected mxICell root
protected boolean maintainEdgeParent
protected boolean createIds
protected int nextId
protected transient mxUndoableEdit currentEdit
protected transient int updateLevel
protected transient boolean endingUpdate
public mxGraphModel()
public mxGraphModel(Object root)
root
- Cell that represents the root cell.public void clear()
public int getUpdateLevel()
public Object createRoot()
public Map<String,Object> getCells()
public Object getCell(String id)
id
- A string representing the Id of the cell.public boolean isMaintainEdgeParent()
public void setMaintainEdgeParent(boolean maintainEdgeParent)
maintainEdgeParent
- Boolean indicating if the model should
maintain edge parents.public boolean isCreateIds()
public void setCreateIds(boolean value)
value
- Boolean indicating if the model should created Ids.public Object getRoot()
mxIGraphModel
getRoot
in interface mxIGraphModel
public Object setRoot(Object root)
mxIGraphModel
setRoot
in interface mxIGraphModel
root
- Cell that specifies the new root.protected Object rootChanged(Object root)
protected mxUndoableEdit createUndoableEdit()
public Object[] cloneCells(Object[] cells, boolean includeChildren)
mxIGraphModel
cloneCells
in interface mxIGraphModel
cells
- Array of cells to be cloned.includeChildren
- Boolean indicating if the cells should be cloned
with all descendants.protected Object cloneCell(Object cell, Map<Object,Object> mapping, boolean includeChildren) throws CloneNotSupportedException
CloneNotSupportedException
protected void restoreClone(Object clone, Object cell, Map<Object,Object> mapping)
public boolean isAncestor(Object parent, Object child)
mxIGraphModel
isAncestor
in interface mxIGraphModel
parent
- Cell that specifies the parent.child
- Cell that specifies the child.public boolean contains(Object cell)
mxIGraphModel
contains
in interface mxIGraphModel
cell
- Cell to be checked.public Object getParent(Object child)
mxIGraphModel
getParent
in interface mxIGraphModel
child
- Cell whose parent should be returned.public Object add(Object parent, Object child, int index)
mxIGraphModel
add
in interface mxIGraphModel
parent
- Cell that specifies the parent to contain the child.child
- Cell that specifies the child to be inserted.index
- Integer that specifies the index of the child.protected void cellAdded(Object cell)
cell
- Cell that has been added.public String createId(Object cell)
cell
- Cell for which a new Id should be created.public Object remove(Object cell)
mxIGraphModel
remove
in interface mxIGraphModel
cell
- Cell that should be removed.protected void cellRemoved(Object cell)
cell
- Cell that has been removed.protected Object parentForCellChanged(Object cell, Object parent, int index)
public int getChildCount(Object cell)
mxIGraphModel
getChildCount
in interface mxIGraphModel
cell
- Cell whose number of children should be returned.public Object getChildAt(Object parent, int index)
mxIGraphModel
getChildAt
in interface mxIGraphModel
parent
- Cell that represents the parent.index
- Integer that specifies the index of the child to be
returned.public Object getTerminal(Object edge, boolean isSource)
mxIGraphModel
getTerminal
in interface mxIGraphModel
edge
- Cell that specifies the edge.isSource
- Boolean indicating which end of the edge should be
returned.public Object setTerminal(Object edge, Object terminal, boolean isSource)
mxIGraphModel
setTerminal
in interface mxIGraphModel
edge
- Cell that specifies the edge.terminal
- Cell that specifies the new terminal.isSource
- Boolean indicating if the terminal is the new source or
target terminal of the edge.protected Object terminalForCellChanged(Object edge, Object terminal, boolean isSource)
public void updateEdgeParents(Object cell)
cell
- Cell whose edges should be checked and updated.public void updateEdgeParents(Object cell, Object root)
cell
- Cell whose edges should be checked and updated.root
- Root of the cell hierarchy that contains all cells.public void updateEdgeParent(Object edge, Object root)
edge
- Specifies the edge to be updated.root
- Current root of the model.public mxPoint getOrigin(Object cell)
public Object getNearestCommonAncestor(Object cell1, Object cell2)
cell1
- Cell that specifies the first cell in the tree.cell2
- Cell that specifies the second cell in the tree.public int getEdgeCount(Object cell)
mxIGraphModel
getEdgeCount
in interface mxIGraphModel
cell
- Cell that represents the vertex.public Object getEdgeAt(Object parent, int index)
mxIGraphModel
getEdgeAt
in interface mxIGraphModel
parent
- Cell that specifies the vertex.index
- Integer that specifies the index of the edge to return.public boolean isVertex(Object cell)
mxIGraphModel
isVertex
in interface mxIGraphModel
cell
- Cell that represents the possible vertex.public boolean isEdge(Object cell)
mxIGraphModel
isEdge
in interface mxIGraphModel
cell
- Cell that represents the possible edge.public boolean isConnectable(Object cell)
mxIGraphModel
isConnectable
in interface mxIGraphModel
cell
- Cell whose connectable state should be returned.public Object getValue(Object cell)
mxIGraphModel
getValue
in interface mxIGraphModel
cell
- Cell whose user object should be returned.public Object setValue(Object cell, Object value)
mxIGraphModel
setValue
in interface mxIGraphModel
cell
- Cell whose user object should be changed.value
- Object that defines the new user object.protected Object valueForCellChanged(Object cell, Object value)
public mxGeometry getGeometry(Object cell)
mxIGraphModel
getGeometry
in interface mxIGraphModel
cell
- Cell whose geometry should be returned.public mxGeometry setGeometry(Object cell, mxGeometry geometry)
mxIGraphModel
setGeometry
in interface mxIGraphModel
cell
- Cell whose geometry should be changed.geometry
- Object that defines the new geometry.protected mxGeometry geometryForCellChanged(Object cell, mxGeometry geometry)
public String getStyle(Object cell)
mxIGraphModel
getStyle
in interface mxIGraphModel
cell
- Cell whose style should be returned.public String setStyle(Object cell, String style)
mxIGraphModel
setStyle
in interface mxIGraphModel
cell
- Cell whose style should be changed.style
- String of the form stylename[;key=value] to specify
the new cell style.protected String styleForCellChanged(Object cell, String style)
public boolean isCollapsed(Object cell)
mxIGraphModel
isCollapsed
in interface mxIGraphModel
cell
- Cell whose collapsed state should be returned.public boolean setCollapsed(Object cell, boolean collapsed)
mxIGraphModel
setCollapsed
in interface mxIGraphModel
cell
- Cell whose collapsed state should be changed.collapsed
- Boolean that specifies the new collpased state.protected boolean collapsedStateForCellChanged(Object cell, boolean collapsed)
public boolean isVisible(Object cell)
mxIGraphModel
isVisible
in interface mxIGraphModel
cell
- Cell whose visible state should be returned.public boolean setVisible(Object cell, boolean visible)
mxIGraphModel
setVisible
in interface mxIGraphModel
cell
- Cell whose visible state should be changed.visible
- Boolean that specifies the new visible state.protected boolean visibleStateForCellChanged(Object cell, boolean visible)
public void execute(mxIGraphModel.mxAtomicGraphModelChange change)
change
- Atomic change to be executed.public void beginUpdate()
mxIGraphModel
beginUpdate
in interface mxIGraphModel
public void endUpdate()
mxIGraphModel
endUpdate
in interface mxIGraphModel
public void mergeChildren(mxICell from, mxICell to, boolean cloneAllEdges) throws CloneNotSupportedException
from
- to
- cloneAllEdges
- CloneNotSupportedException
protected void mergeChildrenImpl(mxICell from, mxICell to, boolean cloneAllEdges, Hashtable<Object,Object> mapping) throws CloneNotSupportedException
CloneNotSupportedException
public static int getDirectedEdgeCount(mxIGraphModel model, Object cell, boolean outgoing)
model
- Graph model that contains the connection data.cell
- Cell whose edges should be counted.outgoing
- Boolean that specifies if the number of outgoing or
incoming edges should be returned.public static int getDirectedEdgeCount(mxIGraphModel model, Object cell, boolean outgoing, Object ignoredEdge)
model
- Graph model that contains the connection data.cell
- Cell whose edges should be counted.outgoing
- Boolean that specifies if the number of outgoing or
incoming edges should be returned.ignoredEdge
- Object that represents an edge to be ignored.public static Object[] getEdges(mxIGraphModel model, Object cell)
model
- Model that contains the connection information.cell
- Cell whose connections should be returned.public static Object[] getConnections(mxIGraphModel model, Object cell)
model
- Model that contains the connection information.cell
- Cell whose connections should be returned.public static Object[] getIncomingEdges(mxIGraphModel model, Object cell)
model
- Graphmodel that contains the edges.cell
- Cell whose incoming edges should be returned.public static Object[] getOutgoingEdges(mxIGraphModel model, Object cell)
model
- Graphmodel that contains the edges.cell
- Cell whose outgoing edges should be returned.public static Object[] getEdges(mxIGraphModel model, Object cell, boolean incoming, boolean outgoing, boolean includeLoops)
model
- Model that contains the connection information.cell
- Cell whose connections should be returned.incoming
- Specifies if incoming edges should be returned.outgoing
- Specifies if outgoing edges should be returned.includeLoops
- Specifies if loops should be returned.public static Object[] getEdgesBetween(mxIGraphModel model, Object source, Object target)
model
- The graph model that contains the graph.source
- Object that defines the source cell.target
- Object that defines the target cell.public static Object[] getEdgesBetween(mxIGraphModel model, Object source, Object target, boolean directed)
model
- The graph model that contains the graph.source
- Object that defines the source cell.target
- Object that defines the target cell.directed
- Boolean that specifies if the direction of the edge
should be taken into account.public static Object[] getOpposites(mxIGraphModel model, Object[] edges, Object terminal)
model
- Model that contains the connection information.edges
- Array of edges to be examined.terminal
- Cell that specifies the known end of the edges.public static Object[] getOpposites(mxIGraphModel model, Object[] edges, Object terminal, boolean sources, boolean targets)
model
- Model that contains the connection information.edges
- Array of edges to be examined.terminal
- Cell that specifies the known end of the edges.sources
- Boolean that specifies if source terminals should
be contained in the result. Default is true.targets
- Boolean that specifies if target terminals should
be contained in the result. Default is true.public static void setTerminals(mxIGraphModel model, Object edge, Object source, Object target)
edge
- Cell that specifies the edge.source
- Cell that specifies the new source terminal.target
- Cell that specifies the new target terminal.public static Object[] getChildren(mxIGraphModel model, Object parent)
model
- Model that contains the hierarchical information.parent
- Cell whose child vertices or edges should be returned.public static Object[] getChildVertices(mxIGraphModel model, Object parent)
model
- Model that contains the hierarchical information.parent
- Cell whose child vertices should be returned.public static Object[] getChildEdges(mxIGraphModel model, Object parent)
model
- Model that contains the hierarchical information.parent
- Cell whose child edges should be returned.public static Object[] getChildCells(mxIGraphModel model, Object parent, boolean vertices, boolean edges)
model
- Model that contains the hierarchical information.parent
- Cell whose child vertices or edges should be returned.vertices
- Boolean indicating if child vertices should be returned.edges
- Boolean indicating if child edges should be returned.public static Object[] getParents(mxIGraphModel model, Object[] cells)
public static Object[] filterCells(Object[] cells, mxGraphModel.Filter filter)
public static Collection<Object> getDescendants(mxIGraphModel model, Object parent)
public static Collection<Object> filterDescendants(mxIGraphModel model, mxGraphModel.Filter filter)
public static Collection<Object> filterDescendants(mxIGraphModel model, mxGraphModel.Filter filter, Object parent)
public static Object[] getTopmostCells(mxIGraphModel model, Object[] cells)
Copyright (c) 2010 Gaudenz Alder, David Benson. All rights reserved.