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

public class DefaultGraphModel

  1. Object
  2. AbstractGraphModel
  3. DefaultGraphModel

ImplementsGraphModel

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.

Constructors

public DefaultGraphModel()

Methods

public List<GraphNode> getNodes()Every node, in painting order: later nodes are drawn over earlier ones.
public List<GraphEdge> getEdges()Every edge.
public List<GraphGroup> getGroups()Every group.
public GraphNode getNode(String id)The node with this id, or null.
public GraphEdge getEdge(String id)The edge with this id, or null.
public ConnectionValidator getValidator()The validator connect asks.
public void setValidator(ConnectionValidator validator)Replaces the validator; null restores the default one.
public GraphNode addNode(GraphNode node)Adds a node, replacing one with the same id.
public GraphEdge addEdge(GraphEdge edge)Adds an edge as it is, without asking the validator.
public GraphEdge addEdge(String sourceId, String targetId)Adds an edge between two nodes with a generated id.
public GraphGroup addGroup(GraphGroup group)Adds a group.
public void clear()Removes every node, edge and group.
public List<GraphEdge> getEdges(GraphNode node)The edges that touch a node.
public boolean moveNode(GraphNode node, double x, double y)Moves a node to a world position.
public GraphEdge connect(GraphNode source, GraphPort sourcePort, GraphNode target, GraphPort targetPort)Makes an edge from one node or port to another.
public boolean removeEdge(GraphEdge edge)Removes an edge.
public boolean removeNode(GraphNode node)Removes a node and every edge that touches it.
public boolean renameNode(GraphNode node, String label)Gives a node a new label.
public boolean setCollapsed(GraphGroup group, boolean collapsed)Collapses or expands a group.

Inherited methods

Constructor details

DefaultGraphModel

public DefaultGraphModel()

Method details

getNodes

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

getEdges

public List<GraphEdge> getEdges()
Every edge.

getGroups

public List<GraphGroup> getGroups()
Every group.

getNode

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

getEdge

public GraphEdge getEdge(String id)
The edge with this id, or null.

getValidator

public ConnectionValidator getValidator()
The validator connect asks. Never null.

setValidator

public void setValidator(ConnectionValidator validator)
Replaces the validator; null restores the default one.

addNode

public GraphNode addNode(GraphNode node)
Adds a node, replacing one with the same id.

Returns

the node

addEdge

public GraphEdge addEdge(GraphEdge edge)
Adds an edge as it is, without asking the validator.

Returns

the edge

addEdge

public GraphEdge addEdge(String sourceId, String targetId)
Adds an edge between two nodes with a generated id.

addGroup

public GraphGroup addGroup(GraphGroup group)
Adds a group.

clear

public void clear()
Removes every node, edge and group.

getEdges

public List<GraphEdge> getEdges(GraphNode node)
The edges that touch a node.

moveNode

public 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 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 boolean removeEdge(GraphEdge edge)
Removes an edge.

Returns

false when the model refuses

removeNode

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

Returns

false when the model refuses

renameNode

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

Returns

false when the model refuses

setCollapsed

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

Returns

false when the model refuses