Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public interface GraphModel

Known subtypesAbstractGraphModel, DefaultGraphModel

The nodes, edges and groups a com.codename1.ui.graph.NodeGraph shows.

Every edit a user makes in the view goes through one of the methods below, so a model that refuses an edit (by returning false or null) keeps the graph as it was. AbstractGraphModel refuses all of them; extend DefaultGraphModel for an editable graph in memory.

Write a model of your own by extending AbstractGraphModel, not by implementing this interface: an edit a later component learns to make arrives there as one more method that refuses.

Methods

public abstract List<GraphNode> getNodes()Every node, in painting order: later nodes are drawn over earlier ones.
public abstract List<GraphEdge> getEdges()Every edge.
public abstract List<GraphGroup> getGroups()Every group.
public abstract GraphNode getNode(String id)The node with this id, or null.
public abstract GraphGroup getGroup(String id)The group with this id, or null.
public abstract boolean moveNode(GraphNode node, double x, double y)Moves a node to a world position.
public abstract GraphEdge connect(GraphNode source, GraphPort sourcePort, GraphNode target, GraphPort targetPort)Makes an edge from one node or port to another.
public abstract boolean removeEdge(GraphEdge edge)Removes an edge.
public abstract boolean removeNode(GraphNode node)Removes a node and every edge that touches it.
public abstract boolean renameNode(GraphNode node, String label)Gives a node a new label.
public abstract boolean setCollapsed(GraphGroup group, boolean collapsed)Collapses or expands a group.
public abstract boolean insertNode(GraphNode node, int index)Adds a node the user made, from a palette or by pasting.
public abstract boolean insertEdge(GraphEdge edge, int index)Adds an edge as it is, without the checks connect makes: pasting and undo put back edges that were valid when they were made.
public abstract boolean resizeNode(GraphNode node, double width, double height)Gives a node a new size, in world units.
public abstract boolean setNodeGroup(GraphNode node, String groupId)Moves a node into a group or a lane, or out of every one with null.
public abstract boolean resizeGroup(GraphGroup group, double x, double y, double width, double height)Gives a lane new bounds, in world units.
public abstract boolean setPortValue(GraphPort port, Object value)Sets the value an unconnected input port uses.
public abstract void addChangeListener(GraphChangeListener l)Adds a listener told about every change.
public abstract void removeChangeListener(GraphChangeListener l)Removes a listener.

Method details

getNodes

public abstract List<GraphNode> getNodes()
Every node, in painting order: later nodes are drawn over earlier ones.

getEdges

public abstract List<GraphEdge> getEdges()
Every edge.

getGroups

public abstract List<GraphGroup> getGroups()
Every group.

getNode

public abstract GraphNode getNode(String id)
The node with this id, or null.

getGroup

public abstract GraphGroup getGroup(String id)
The group with this id, or null.

moveNode

public abstract boolean moveNode(GraphNode node, double x, double y)
Moves a node to a world position.

Returns

false when the model refuses the move

connect

public abstract GraphEdge connect(GraphNode source, GraphPort sourcePort, GraphNode target, GraphPort targetPort)
Makes an edge from one node or port to another.

Parameters

source GraphNode
the node the edge leaves
sourcePort GraphPort
its output port, or null
target GraphNode
the node the edge enters
targetPort GraphPort
its input port, or null

Returns

the new edge, or null when the model refuses it

removeEdge

public abstract boolean removeEdge(GraphEdge edge)
Removes an edge.

Returns

false when the model refuses

removeNode

public abstract boolean removeNode(GraphNode node)
Removes a node and every edge that touches it.

Returns

false when the model refuses

renameNode

public abstract boolean renameNode(GraphNode node, String label)
Gives a node a new label.

Returns

false when the model refuses

setCollapsed

public abstract boolean setCollapsed(GraphGroup group, boolean collapsed)
Collapses or expands a group.

Returns

false when the model refuses

insertNode

public abstract boolean insertNode(GraphNode node, int index)
Adds a node the user made, from a palette or by pasting.

Parameters

node GraphNode
the node
index int

where in getNodes it 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.

Returns

false when the model refuses, or already has a node with this id

insertEdge

public abstract boolean insertEdge(GraphEdge edge, int index)
Adds an edge as it is, without the checks connect makes: pasting and undo put back edges that were valid when they were made.

Parameters

edge GraphEdge
the edge
index int
where in getEdges it goes; negative, or past the end, for the end

Returns

false when the model refuses, has an edge with this id, or lacks one of the nodes the edge names

resizeNode

public abstract boolean resizeNode(GraphNode node, double width, double height)
Gives a node a new size, in world units.

Returns

false when the model refuses

setNodeGroup

public abstract boolean setNodeGroup(GraphNode node, String groupId)
Moves a node into a group or a lane, or out of every one with null.

Returns

false when the model refuses

resizeGroup

public abstract boolean resizeGroup(GraphGroup group, double x, double y, double width, double height)
Gives a lane new bounds, in world units.

Returns

false when the model refuses

setPortValue

public abstract boolean setPortValue(GraphPort port, Object value)
Sets the value an unconnected input port uses.

Returns

false when the model refuses

addChangeListener

public abstract void addChangeListener(GraphChangeListener l)
Adds a listener told about every change.

removeChangeListener

public abstract void removeChangeListener(GraphChangeListener l)
Removes a listener.