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.

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 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

addChangeListener

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

removeChangeListener

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