Class Node
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.
- Since:
- 1.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract intReturns the height of the node.final StringgetId()Returns the id of this node.intReturns the x coordinate of the node's origin.intReturns 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.getScene()Returns the scene that this node is in.intReturns the x translation of the node.intReturns the y translation of the node.abstract intgetWidth()Returns the width of the node.booleanReturns whether the node is clipping its children.booleanReturns whether the node is visible.Finds thisNodeor the first sub-node by the given selector.Finds all nodes that match the given selector.Used by Node and Parent to traverse the scene graph to find all nodes that match the given selector.abstract NodenodeAt(int x, int y) Returns the node at the given coordinates.voidrelocate(int layoutX, int layoutY) Moves the node to the specified location.abstract PixelrenderPixelAt(int x, int y) Returns aPixelthat should be rendered at the given coordinates.voidRequests a layout update for this node's parent.voidsetClipping(boolean clipping) Sets whether the node is clipping its children.final voidSets the id of this node.voidsetLayoutX(int layoutX) Sets the x coordinate of the node's origin.voidsetLayoutY(int layoutY) Sets the y coordinate of the node's origin.voidsetOnClick(java.util.function.Consumer<NodeClickContext> onClick) Sets the consumer that is called when the node is clicked.voidsetOnHotBarClick(java.util.function.Consumer<NodeClickContext> onHotBarClick) Sets the consumer that is called when the node receives a hot bar click.voidsetOnLeftClick(java.util.function.Consumer<NodeClickContext> onLeftClick) Sets the consumer that is called when the node is left-clicked.voidsetOnRightClick(java.util.function.Consumer<NodeClickContext> onRightClick) Sets the consumer that is called when the node is right-clicked.voidsetOnShiftClick(java.util.function.Consumer<NodeClickContext> onShiftClick) Sets the consumer that is called when the node is shift-clicked.voidsetTranslateX(int translateX) Sets the x translation of the node.voidsetTranslateY(int translateY) Sets the y translation of the node.voidsetVisible(boolean visible) Sets whether the node is visible.
-
Constructor Details
-
Node
public Node()
-
-
Method Details
-
getScene
Returns the scene that this node is in. If this node is not in a scene, this method returns null.- Returns:
- the scene that this node is in
- Since:
- 2.0.0
-
getParent
Returns the parent of this node. If this node has no parent, this method returns null.- Returns:
- the parent of this node
- Since:
- 1.0.0
-
getId
Returns the id of this node.- Returns:
- the id of this node
- Since:
- 2.0.0
-
setId
Sets the id of this node. While the id should be unique, this uniqueness not enforced.- Parameters:
id- the id of this node- Since:
- 2.0.0
-
lookup
Finds thisNodeor the first sub-node by the given selector.For example, to find a node with the id "my-node", the method can be used like this:
scene.lookup("#my-node").- Parameters:
selector- the selector- Returns:
- the first node that matches the selector, null if none is found
- Since:
- 2.0.0
-
lookupAll
Finds all nodes that match the given selector.For example, to find all nodes with the class "my-class", the method can be used like this:
scene.lookupAll(".my-class").- Parameters:
selector- the selector- Returns:
- a set of nodes that match the selector. This is always non-null and unmodifiable.
- Since:
- 2.0.0
-
lookupAll
Used by Node and Parent to traverse the scene graph to find all nodes that match the given selector.- Parameters:
selector- the selectorresults- the results- Returns:
- a set of nodes that match the selector; null if none is found
- Since:
- 2.0.0
-
requestParentLayout
public void requestParentLayout()Requests a layout update for this node's parent. Layout will be applied on the next layout pass.- Since:
- 2.0.0
-
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
- Since:
- 1.0.0
-
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- Since:
- 1.0.0
-
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
- Since:
- 1.0.0
-
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- Since:
- 1.0.0
-
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 originlayoutY- the y coordinate of the node's origin- Since:
- 1.0.0
-
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
- Since:
- 1.0.0
-
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- Since:
- 1.0.0
-
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
- Since:
- 1.0.0
-
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- Since:
- 1.0.0
-
getWidth
public abstract int getWidth()Returns the width of the node.- Returns:
- the width of the node
- Since:
- 1.0.0
-
getHeight
public abstract int getHeight()Returns the height of the node.- Returns:
- the height of the node
- Since:
- 1.0.0
-
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
- Since:
- 1.0.0
-
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- Since:
- 1.0.0
-
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
- Since:
- 1.0.0
-
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- Since:
- 1.0.0
-
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
- Since:
- 1.0.0
-
setOnClick
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- Since:
- 1.0.0
-
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
- Since:
- 1.0.0
-
setOnLeftClick
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- Since:
- 1.0.0
-
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
- Since:
- 1.0.0
-
setOnRightClick
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- Since:
- 1.0.0
-
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
- Since:
- 1.0.0
-
setOnShiftClick
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- Since:
- 1.0.0
-
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
- Since:
- 1.0.0
-
setOnHotBarClick
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- Since:
- 1.0.0
-
renderPixelAt
Returns aPixelthat should be rendered at the given coordinates. The coordinates are relative to this parent's bounds.- Parameters:
x- the x coordinatey- the y coordinate- Returns:
- the pixel at the given coordinates, or null if there is no pixel at the given coordinates
- Since:
- 2.0.0
-
nodeAt
Returns the node at the given coordinates. The coordinates are relative to this parent's bounds.- Parameters:
x- the x coordinatey- the y coordinate- Returns:
- the node at the given coordinates, or null if there is no node at the given coordinates
- Since:
- 1.0.0
-