Interface GraphModel

All Known Implementing Classes:
AbstractGraphModel, DefaultGraphModel

public interface GraphModel

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.

  • Method Details

    • getNodes

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

      List<GraphEdge> getEdges()
      Every edge.
    • getGroups

      List<GraphGroup> getGroups()
      Every group.
    • getNode

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

      GraphGroup getGroup(String id)
      The group with this id, or null.
    • moveNode

      boolean moveNode(GraphNode node, double x, double y)

      Moves a node to a world position.

      Returns

      false when the model refuses the move

    • connect

      GraphEdge connect(GraphNode source, GraphPort sourcePort, GraphNode target, GraphPort targetPort)

      Makes an edge from one node or port to another.

      Parameters
      • source: the node the edge leaves
      • sourcePort: its output port, or null
      • target: the node the edge enters
      • targetPort: its input port, or null
      Returns

      the new edge, or null when the model refuses it

    • removeEdge

      boolean removeEdge(GraphEdge edge)

      Removes an edge.

      Returns

      false when the model refuses

    • removeNode

      boolean removeNode(GraphNode node)

      Removes a node and every edge that touches it.

      Returns

      false when the model refuses

    • renameNode

      boolean renameNode(GraphNode node, String label)

      Gives a node a new label.

      Returns

      false when the model refuses

    • setCollapsed

      boolean setCollapsed(GraphGroup group, boolean collapsed)

      Collapses or expands a group.

      Returns

      false when the model refuses

    • insertNode

      boolean insertNode(GraphNode node, int index)

      Adds 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 node
      • index: 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.

    • insertEdge

      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.

      Returns

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

      Parameters
      • edge: the edge
      • index: where in getEdges it goes; negative, or past the end, for the end
    • resizeNode

      boolean resizeNode(GraphNode node, double width, double height)

      Gives a node a new size, in world units.

      Returns

      false when the model refuses

    • setNodeGroup

      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

      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

      boolean setPortValue(GraphPort port, Object value)

      Sets the value an unconnected input port uses.

      Returns

      false when the model refuses

    • addChangeListener

      void addChangeListener(GraphChangeListener l)
      Adds a listener told about every change.
    • removeChangeListener

      void removeChangeListener(GraphChangeListener l)
      Removes a listener.