Class GraphNode

java.lang.Object
com.codename1.graph.GraphNode

public class GraphNode extends Object

A box in a graph: a position and a size in world units, a label, and optionally ports and a group.

World units are pixels at zoom 1. The position is the top left corner and may be negative: a graph has no origin it must stay to the right of.

  • Constructor Details

    • GraphNode

      public GraphNode(String id, String label)
      A node of the default size, 160 by 64, at the origin.
    • GraphNode

      public GraphNode(String id, String label, double x, double y, double width, double height)
      A node at a position.
  • Method Details

    • getId

      public String getId()
      The id, unique within the model.
    • getLabel

      public String getLabel()
      The title painted on the node.
    • setLabel

      public void setLabel(String label)
      Sets the title.
    • getDescription

      public String getDescription()
      A second line painted under the title, or null.
    • setDescription

      public void setDescription(String description)
      Sets the second line.
    • getX

      public double getX()
      The left edge in world units.
    • getY

      public double getY()
      The top edge in world units.
    • getWidth

      public double getWidth()
      The width in world units.
    • getHeight

      public double getHeight()
      The height in world units.
    • getCenterX

      public double getCenterX()
      The horizontal centre.
    • getCenterY

      public double getCenterY()
      The vertical centre.
    • setPosition

      public void setPosition(double x, double y)
      Moves the node. A model shown by a component is told through GraphModel.moveNode, which calls this and notifies the listeners.
    • setSize

      public void setSize(double width, double height)
      Resizes the node.
    • getGroupId

      public String getGroupId()
      The id of the GraphGroup the node is drawn inside, or null.
    • setGroupId

      public void setGroupId(String groupId)
      Puts the node in a group, or takes it out with null.
    • getStyleKey

      public String getStyleKey()
      A key a renderer may map to a colour or a UIID, or null.
    • setStyleKey

      public void setStyleKey(String styleKey)
      Sets the style key.
    • isPinned

      public boolean isPinned()
      True when automatic arrangements must leave the node where it is.
    • setPinned

      public void setPinned(boolean pinned)
      Pins the node in place for automatic arrangements.
    • getUserData

      public Object getUserData()
      Anything the application keeps with the node.
    • setUserData

      public void setUserData(Object userData)
      Sets the application's data.
    • addPort

      public GraphNode addPort(GraphPort port)

      Adds a port, as an input or an output by its direction.

      Returns

      this node, so calls can be chained

    • addInput

      public GraphNode addInput(String id, String label, String type)
      Adds an input port.
    • addOutput

      public GraphNode addOutput(String id, String label, String type)
      Adds an output port.
    • getInputs

      public List<GraphPort> getInputs()
      The input ports, in order. The list is the node's own; do not change it.
    • getOutputs

      public List<GraphPort> getOutputs()
      The output ports, in order. The list is the node's own; do not change it.
    • hasPorts

      public boolean hasPorts()
      True when the node has any port.
    • getPort

      public GraphPort getPort(String portId)
      The port with this id, or null.
    • contains

      public boolean contains(double px, double py)
      True when the world point lies inside the node.