Class DefaultGraphModel
- All Implemented Interfaces:
GraphModel
An editable graph kept in memory.
Edits made by a user are checked by the ConnectionValidator before an
edge is made. Ids of edges the model makes itself are "e" followed by a
counter, skipping any already taken.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds an edge as it is, without asking the validator.Adds an edge between two nodes with a generated id.addGroup(GraphGroup group) Adds a group.Adds a node, replacing one with the same id.voidclear()Removes every node, edge and group.Makes an edge from one node or port to another.The edge with this id, or null.getEdges()Every edge.The edges that touch a node.Every group.The node with this id, or null.getNodes()Every node, in painting order: later nodes are drawn over earlier ones.The validatorconnectasks.booleaninsertEdge(GraphEdge edge, int index) Adds an edge as it is, without the checksconnectmakes: pasting and undo put back edges that were valid when they were made.booleaninsertNode(GraphNode node, int index) Adds a node the user made, from a palette or by pasting.booleanMoves a node to a world position.booleanremoveEdge(GraphEdge edge) Removes an edge.booleanremoveGroup(GraphGroup group) Removes a group.booleanremoveNode(GraphNode node) Removes a node and every edge that touches it.booleanrenameNode(GraphNode node, String label) Gives a node a new label.booleanresizeGroup(GraphGroup group, double x, double y, double width, double height) Gives a lane new bounds, in world units.booleanresizeNode(GraphNode node, double width, double height) Gives a node a new size, in world units.booleansetCollapsed(GraphGroup group, boolean collapsed) Collapses or expands a group.booleansetNodeGroup(GraphNode node, String groupId) Moves a node into a group or a lane, or out of every one with null.booleansetPortValue(GraphPort port, Object value) Sets the value an unconnected input port uses.voidsetValidator(ConnectionValidator validator) Replaces the validator; null restores the default one.Methods inherited from class AbstractGraphModel
addChangeListener, fireChanged, getGroup, removeChangeListener
-
Constructor Details
-
DefaultGraphModel
public DefaultGraphModel()
-
-
Method Details
-
getNodes
Description copied from interface:GraphModelEvery node, in painting order: later nodes are drawn over earlier ones. -
getEdges
-
getGroups
-
getNode
Description copied from interface:GraphModelThe node with this id, or null.- Specified by:
getNodein interfaceGraphModel- Overrides:
getNodein classAbstractGraphModel
-
getEdge
-
getValidator
The validatorconnectasks. Never null. -
setValidator
Replaces the validator; null restores the default one. -
addNode
-
addEdge
-
addEdge
-
addGroup
Adds a group. -
clear
public void clear()Removes every node, edge and group. -
getEdges
-
moveNode
Description copied from interface:GraphModelMoves a node to a world position.
Returns
false when the model refuses the move
- Specified by:
moveNodein interfaceGraphModel- Overrides:
moveNodein classAbstractGraphModel
-
connect
public GraphEdge connect(GraphNode source, GraphPort sourcePort, GraphNode target, GraphPort targetPort) Description copied from interface:GraphModelMakes an edge from one node or port to another.
Parameters
source: the node the edge leavessourcePort: its output port, or nulltarget: the node the edge enterstargetPort: its input port, or null
Returns
the new edge, or null when the model refuses it
- Specified by:
connectin interfaceGraphModel- Overrides:
connectin classAbstractGraphModel
-
removeEdge
Description copied from interface:GraphModelRemoves an edge.
Returns
false when the model refuses
- Specified by:
removeEdgein interfaceGraphModel- Overrides:
removeEdgein classAbstractGraphModel
-
removeNode
Description copied from interface:GraphModelRemoves a node and every edge that touches it.
Returns
false when the model refuses
- Specified by:
removeNodein interfaceGraphModel- Overrides:
removeNodein classAbstractGraphModel
-
renameNode
Description copied from interface:GraphModelGives a node a new label.
Returns
false when the model refuses
- Specified by:
renameNodein interfaceGraphModel- Overrides:
renameNodein classAbstractGraphModel
-
setCollapsed
Description copied from interface:GraphModelCollapses or expands a group.
Returns
false when the model refuses
- Specified by:
setCollapsedin interfaceGraphModel- Overrides:
setCollapsedin classAbstractGraphModel
-
insertNode
Description copied from interface:GraphModelAdds a node the user made, from a palette or by pasting.
Returns
false when the model refuses, or already has a node with this id
Parameters
node: the nodeindex: where ingetNodesit goes, which is its painting order; negative, or past the end, for the end. Undoing a removal puts a node back where it was.
A view's undo of a delete puts nodes back through this method, so a model that refuses it cannot have its deletes undone.
- Specified by:
insertNodein interfaceGraphModel- Overrides:
insertNodein classAbstractGraphModel
-
insertEdge
Description copied from interface:GraphModelAdds an edge as it is, without the checks
connectmakes: pasting and undo put back edges that were valid when they were made.Returns
false when the model refuses, has an edge with this id, or lacks one of the nodes the edge names
Parameters
edge: the edgeindex: where ingetEdgesit goes; negative, or past the end, for the end
- Specified by:
insertEdgein interfaceGraphModel- Overrides:
insertEdgein classAbstractGraphModel
-
resizeNode
Description copied from interface:GraphModelGives a node a new size, in world units.
Returns
false when the model refuses
- Specified by:
resizeNodein interfaceGraphModel- Overrides:
resizeNodein classAbstractGraphModel
-
setNodeGroup
Description copied from interface:GraphModelMoves a node into a group or a lane, or out of every one with null.
Returns
false when the model refuses
- Specified by:
setNodeGroupin interfaceGraphModel- Overrides:
setNodeGroupin classAbstractGraphModel
-
resizeGroup
Description copied from interface:GraphModelGives a lane new bounds, in world units.
Returns
false when the model refuses
- Specified by:
resizeGroupin interfaceGraphModel- Overrides:
resizeGroupin classAbstractGraphModel
-
setPortValue
Description copied from interface:GraphModelSets the value an unconnected input port uses.
Returns
false when the model refuses
- Specified by:
setPortValuein interfaceGraphModel- Overrides:
setPortValuein classAbstractGraphModel
-
removeGroup
Removes a group. Its members stay, in no group.
Returns
false when the model has no such group
-