Class AbstractGraphModel

java.lang.Object
com.codename1.graph.AbstractGraphModel
All Implemented Interfaces:
GraphModel
Direct Known Subclasses:
DefaultGraphModel

public abstract class AbstractGraphModel extends Object implements GraphModel

The listener list, the lookups and the refusals every read-only model shares.

A subclass supplies getNodes, getEdges and getGroups. Every edit is refused until the matching method is overridden.

  • Constructor Details

    • AbstractGraphModel

      public AbstractGraphModel()
  • Method Details

    • getNode

      public GraphNode getNode(String id)
      Description copied from interface: GraphModel
      The node with this id, or null.
      Specified by:
      getNode in interface GraphModel
    • getGroup

      public GraphGroup getGroup(String id)
      Description copied from interface: GraphModel
      The group with this id, or null.
      Specified by:
      getGroup in interface GraphModel
    • moveNode

      public boolean moveNode(GraphNode node, double x, double y)
      Description copied from interface: GraphModel

      Moves a node to a world position.

      Returns

      false when the model refuses the move

      Specified by:
      moveNode in interface GraphModel
    • connect

      public GraphEdge connect(GraphNode source, GraphPort sourcePort, GraphNode target, GraphPort targetPort)
      Description copied from interface: GraphModel

      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

      Specified by:
      connect in interface GraphModel
    • removeEdge

      public boolean removeEdge(GraphEdge edge)
      Description copied from interface: GraphModel

      Removes an edge.

      Returns

      false when the model refuses

      Specified by:
      removeEdge in interface GraphModel
    • removeNode

      public boolean removeNode(GraphNode node)
      Description copied from interface: GraphModel

      Removes a node and every edge that touches it.

      Returns

      false when the model refuses

      Specified by:
      removeNode in interface GraphModel
    • renameNode

      public boolean renameNode(GraphNode node, String label)
      Description copied from interface: GraphModel

      Gives a node a new label.

      Returns

      false when the model refuses

      Specified by:
      renameNode in interface GraphModel
    • setCollapsed

      public boolean setCollapsed(GraphGroup group, boolean collapsed)
      Description copied from interface: GraphModel

      Collapses or expands a group.

      Returns

      false when the model refuses

      Specified by:
      setCollapsed in interface GraphModel
    • addChangeListener

      public void addChangeListener(GraphChangeListener l)
      Description copied from interface: GraphModel
      Adds a listener told about every change.
      Specified by:
      addChangeListener in interface GraphModel
    • removeChangeListener

      public void removeChangeListener(GraphChangeListener l)
      Description copied from interface: GraphModel
      Removes a listener.
      Specified by:
      removeChangeListener in interface GraphModel
    • fireChanged

      protected void fireChanged()
      Tells every listener the model changed.