Class Component

java.lang.Object
megalodonte.base.components.Component
All Implemented Interfaces:
ComponentInterface<Component>, megalodonte.contracts.ComponentContract<Component>

public abstract class Component extends Object implements ComponentInterface<Component>, megalodonte.contracts.ComponentContract<Component>
Base class for all UI components. Wraps a JavaFX Node and provides a React-inspired API for building component trees.

Subclasses override getJavaFxNode() to return the underlying node. Use CreateFromJavaFxNode(Node) to wrap an existing node as a component.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Functional interface for screen enter/exit transition animations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final javafx.scene.Node
    The underlying JavaFX node.
    Optional properties applied to this component.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Component(javafx.scene.Node node)
    Creates a component wrapping the given node.
    protected
    Component(javafx.scene.Node node, PropsInterface props)
    Creates a component wrapping the given node and applies the given props.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Component
    CreateFromJavaFxNode(javafx.scene.Node node)
    Factory method to create a wrapper Component around an existing JavaFX Node.
    fromJavaFxNode(javafx.scene.Node newNode)
    Creates a new component wrapping the given node.
    javafx.scene.Node
    Returns the underlying JavaFX node.
    <T extends Component>
    Component
    ref(Ref<T> ref)
    Binds this component to a Ref, making it accessible from the parent scope.
    <T extends Component>
    Component
    ref(megalodonte.contracts.RefContract<T> ref)
     

    Methods inherited from class Object

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

    • node

      protected final javafx.scene.Node node
      The underlying JavaFX node.
    • props

      public PropsInterface props
      Optional properties applied to this component.
  • Constructor Details

    • Component

      protected Component(javafx.scene.Node node)
      Creates a component wrapping the given node.
      Parameters:
      node - the JavaFX node to wrap
    • Component

      protected Component(javafx.scene.Node node, PropsInterface props)
      Creates a component wrapping the given node and applies the given props.
      Parameters:
      node - the JavaFX node to wrap
      props - the properties to apply
  • Method Details

    • getJavaFxNode

      public javafx.scene.Node getJavaFxNode()
      Description copied from interface: ComponentInterface
      Returns the underlying JavaFX node. @return the JavaFX node
      Specified by:
      getJavaFxNode in interface ComponentInterface<Component>
    • fromJavaFxNode

      public Component fromJavaFxNode(javafx.scene.Node newNode)
      Description copied from interface: ComponentInterface
      Creates a new component wrapping the given node.
      Specified by:
      fromJavaFxNode in interface ComponentInterface<Component>
      Parameters:
      newNode - the JavaFX node to wrap
      Returns:
      a new component wrapping the node
    • CreateFromJavaFxNode

      public static Component CreateFromJavaFxNode(javafx.scene.Node node)
      Factory method to create a wrapper Component around an existing JavaFX Node.
      Parameters:
      node - the JavaFX node to wrap (must not be null)
      Returns:
      a new component wrapping the given node
      Throws:
      IllegalArgumentException - if node is null
    • ref

      public <T extends Component> Component ref(Ref<T> ref)
      Binds this component to a Ref, making it accessible from the parent scope.
      Parameters:
      ref - the reference to bind to
      Returns:
      this component for chaining
    • ref

      public <T extends Component> Component ref(megalodonte.contracts.RefContract<T> ref)
      Specified by:
      ref in interface megalodonte.contracts.ComponentContract<Component>