java.lang.Object
io.github.somesourcecode.someguiapi.scene.Node
Direct Known Subclasses:
GuiItem, Parent

public abstract class Node extends Object
The base class for all nodes in the scene graph. A scene graph is a set of tree data structures where every item has zero or one parent, and each item is either a "leaf" with zero sub-items or a "branch" with zero or more sub-items.

Each item in the scene graph is called a Node. Branch nodes are of type Parent.

If a program adds a child node to a Parent and that node is already a child of a different Parent or the root of a Scene, the node is automatically (and silently) removed from its former parent.

It is possible to rearrange the scene graph, e.g. to move a node or subtree from one location in the scene graph to another. This is normally done by removing the node from its current location before inserting it at the new location. However, a subtree will be automatically removed if it is added to a new parent, as described above.


Coordinate System

The Node class defines a computer graphics "local" coordinate system. Coordinates are specified in integer pixels, with the origin (0,0) in the top-left corner of the node. The x-coordinate increases to the right, and the y-coordinate increases downwards.


Transformations

Translation coordinates are specified in integer pixels, and move the node's origin by the specified amount in the x and y directions. The translation is applied after the layout has been computed, but before the node is rendered.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract int
    Returns the height of the node.
    int
    Returns the x coordinate of the node's origin.
    int
    Returns the y coordinate of the node's origin.
    java.util.function.Consumer<NodeClickContext>
    Returns the consumer that is called when the node is clicked.
    java.util.function.Consumer<NodeClickContext>
    Returns the consumer that is called when the node receives a hot bar click.
    java.util.function.Consumer<NodeClickContext>
    Returns the consumer that is called when the node is left-clicked.
    java.util.function.Consumer<NodeClickContext>
    Returns the consumer that is called when the node is right-clicked.
    java.util.function.Consumer<NodeClickContext>
    Returns the consumer that is called when the node is shift-clicked.
    Returns the parent of this node.
    int
    Returns the x translation of the node.
    int
    Returns the y translation of the node.
    abstract int
    Returns the width of the node.
    boolean
    Returns whether the node is clipping its children.
    boolean
    Returns whether the node is visible.
    abstract Node
    nodeAt(int x, int y)
    Returns the node at the given coordinates.
    abstract org.bukkit.inventory.ItemStack
    pixelAt(int x, int y)
    Returns an ItemStack representing the pixel at the given coordinates.
    void
    relocate(int layoutX, int layoutY)
    Moves the node to the specified location.
    void
    setClipping(boolean clipping)
    Sets whether the node is clipping its children.
    void
    setLayoutX(int layoutX)
    Sets the x coordinate of the node's origin.
    void
    setLayoutY(int layoutY)
    Sets the y coordinate of the node's origin.
    void
    setOnClick(java.util.function.Consumer<NodeClickContext> onClick)
    Sets the consumer that is called when the node is clicked.
    void
    setOnHotBarClick(java.util.function.Consumer<NodeClickContext> onHotBarClick)
    Sets the consumer that is called when the node receives a hot bar click.
    void
    setOnLeftClick(java.util.function.Consumer<NodeClickContext> onLeftClick)
    Sets the consumer that is called when the node is left-clicked.
    void
    setOnRightClick(java.util.function.Consumer<NodeClickContext> onRightClick)
    Sets the consumer that is called when the node is right-clicked.
    void
    setOnShiftClick(java.util.function.Consumer<NodeClickContext> onShiftClick)
    Sets the consumer that is called when the node is shift-clicked.
    protected final void
    setParent(Parent parent)
     
    void
    setTranslateX(int translateX)
    Sets the x translation of the node.
    void
    setTranslateY(int translateY)
    Sets the y translation of the node.
    void
    setVisible(boolean visible)
    Sets whether the node is visible.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Node

      public Node()
  • Method Details

    • getParent

      public Parent getParent()
      Returns the parent of this node. If this node has no parent, this method returns null.
      Returns:
      the parent of this node
    • setParent

      protected final void setParent(Parent parent)
    • getLayoutX

      public int getLayoutX()
      Returns the x coordinate of the node's origin. The origin is the top-left corner of the node.
      Returns:
      the x coordinate of the node's origin
    • setLayoutX

      public void setLayoutX(int layoutX)
      Sets the x coordinate of the node's origin. The origin is the top-left corner of the node.
      Parameters:
      layoutX - the x coordinate of the node's origin
    • getLayoutY

      public int getLayoutY()
      Returns the y coordinate of the node's origin. The origin is the top-left corner of the node.
      Returns:
      the y coordinate of the node's origin
    • setLayoutY

      public void setLayoutY(int layoutY)
      Sets the y coordinate of the node's origin. The origin is the top-left corner of the node.
      Parameters:
      layoutY - the y coordinate of the node's origin
    • relocate

      public void relocate(int layoutX, int layoutY)
      Moves the node to the specified location. This is equivalent to setting the layoutX and layoutY properties.
      Parameters:
      layoutX - the x coordinate of the node's origin
      layoutY - the y coordinate of the node's origin
    • getTranslateX

      public int getTranslateX()
      Returns the x translation of the node. The translation is applied after the layout has been computed, but before the node is rendered.
      Returns:
      the x translation of the node
    • setTranslateX

      public void setTranslateX(int translateX)
      Sets the x translation of the node. The translation is applied after the layout has been computed, but before the node is rendered.
      Parameters:
      translateX - the x translation of the node
    • getTranslateY

      public int getTranslateY()
      Returns the y translation of the node. The translation is applied after the layout has been computed, but before the node is rendered.
      Returns:
      the y translation of the node
    • setTranslateY

      public void setTranslateY(int translateY)
      Sets the y translation of the node. The translation is applied after the layout has been computed, but before the node is rendered.
      Parameters:
      translateY - the y translation of the node
    • getWidth

      public abstract int getWidth()
      Returns the width of the node.
      Returns:
      the width of the node
    • getHeight

      public abstract int getHeight()
      Returns the height of the node.
      Returns:
      the height of the node
    • isVisible

      public boolean isVisible()
      Returns whether the node is visible. If a node is not visible, it will not be rendered, but it will still be considered for layout calculations.
      Returns:
      whether the node is visible
    • setVisible

      public void setVisible(boolean visible)
      Sets whether the node is visible. If a node is not visible, it will not be rendered, but it will still be considered for layout calculations.
      Parameters:
      visible - whether the node is visible
    • isClipping

      public boolean isClipping()
      Returns whether the node is clipping its children. If a node is clipping its children, children that are outside the bounds of the node will not be rendered.
      Returns:
      whether the node is clipping its children
    • setClipping

      public void setClipping(boolean clipping)
      Sets whether the node is clipping its children. If a node is clipping its children, children that are outside the bounds of the node will not be rendered.
      Parameters:
      clipping - whether the node is clipping its children
    • getOnClick

      public java.util.function.Consumer<NodeClickContext> getOnClick()
      Returns the consumer that is called when the node is clicked.

      This consumer will be called when the node is clicked, regardless of the type of click.

      Returns:
      the consumer that is called when the node is clicked
    • setOnClick

      public void setOnClick(java.util.function.Consumer<NodeClickContext> onClick)
      Sets the consumer that is called when the node is clicked.

      This consumer will be called when the node is clicked, regardless of the type of click.

      Parameters:
      onClick - the consumer that is called when the node is clicked
    • getOnLeftClick

      public java.util.function.Consumer<NodeClickContext> getOnLeftClick()
      Returns the consumer that is called when the node is left-clicked.
      Returns:
      the consumer that is called when the node is left-clicked
    • setOnLeftClick

      public void setOnLeftClick(java.util.function.Consumer<NodeClickContext> onLeftClick)
      Sets the consumer that is called when the node is left-clicked.
      Parameters:
      onLeftClick - the consumer that is called when the node is left-clicked
    • getOnRightClick

      public java.util.function.Consumer<NodeClickContext> getOnRightClick()
      Returns the consumer that is called when the node is right-clicked.
      Returns:
      the consumer that is called when the node is right-clicked
    • setOnRightClick

      public void setOnRightClick(java.util.function.Consumer<NodeClickContext> onRightClick)
      Sets the consumer that is called when the node is right-clicked.
      Parameters:
      onRightClick - the consumer that is called when the node is right-clicked
    • getOnShiftClick

      public java.util.function.Consumer<NodeClickContext> getOnShiftClick()
      Returns the consumer that is called when the node is shift-clicked.
      Returns:
      the consumer that is called when the node is shift-clicked
    • setOnShiftClick

      public void setOnShiftClick(java.util.function.Consumer<NodeClickContext> onShiftClick)
      Sets the consumer that is called when the node is shift-clicked.
      Parameters:
      onShiftClick - the consumer that is called when the node is shift-clicked
    • getOnHotBarClick

      public java.util.function.Consumer<NodeClickContext> getOnHotBarClick()
      Returns the consumer that is called when the node receives a hot bar click.
      Returns:
      the consumer that is called when the node receives a hot bar click
    • setOnHotBarClick

      public void setOnHotBarClick(java.util.function.Consumer<NodeClickContext> onHotBarClick)
      Sets the consumer that is called when the node receives a hot bar click.
      Parameters:
      onHotBarClick - the consumer that is called when the node receives a hot bar click
    • pixelAt

      public abstract org.bukkit.inventory.ItemStack pixelAt(int x, int y)
      Returns an ItemStack representing the pixel at the given coordinates. The coordinates are relative to this parent's bounds.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      the ItemStack at the given coordinates, or null if there is no pixel at the given coordinates
    • nodeAt

      public abstract Node nodeAt(int x, int y)
      Returns the node at the given coordinates. The coordinates are relative to this parent's bounds.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      the node at the given coordinates, or null if there is no node at the given coordinates