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.
    • getShape

      public String getShape()
      The outline the node is drawn with, one of the GraphShapes names or a name registered with com.codename1.ui.graph.GraphShapeRegistry. Null, the default, is the view's ordinary box.
    • setShape

      public GraphNode setShape(String shape)

      Sets the outline, for instance GraphShapes.DECISION for the diamond of a flow chart.

      Returns

      this node, so calls can be chained

    • 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.
    • getInput

      public GraphPort getInput(String portId)
      The input port with this id, or null. An input and an output may share an id, so an edge's target port is looked up here and its source port in getOutput(String).
    • getOutput

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

      public GraphPort getPort(String portId)
      The port with this id, inputs searched first, or null.
    • copy

      public GraphNode copy(String newId)
      A node like this one under another id: the same label, bounds, shape, style, group and ports, with their values, and the same user data object. For pasting and duplicating.
    • contains

      public boolean contains(double px, double py)
      True when the world point lies inside the node's bounds.
    • getTooltip

      public String getTooltip()
      The text a NodeGraph shows beside the pointer while it rests on this node, or null for none. Desktop and other hovering pointers only; a touch screen never shows it.
    • setTooltip

      public void setTooltip(String tooltip)
      Sets the hover text; null removes it.