Class SegmentedHealthBar

java.lang.Object
zero.community.SegmentedHealthBar

public final class SegmentedHealthBar extends Object
Presents app-owned health in up to ten visible segments. Create and update on the JavaFX application thread. Segment boundaries divide the positive integer maximum as evenly as possible; a segment can be partly filled.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SegmentedHealthBar(int maximum)
    Creates a full segmented bar with caption "Health".
    SegmentedHealthBar(String caption, int maximum)
    Creates a full bar; each segment represents a positive integer capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the last clamped displayed amount.
    int
    Returns this instance's positive maximum.
    void
    setHealth(int health)
    Explicitly updates the amount; values are clamped to 0..maximum.
    javafx.scene.Node
    Returns this instance's stable ordinary JavaFX view.

    Methods inherited from class java.lang.Object

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

    • SegmentedHealthBar

      public SegmentedHealthBar(int maximum)
      Creates a full segmented bar with caption "Health".
      Parameters:
      maximum - positive maximum health
      Throws:
      IllegalArgumentException - if maximum is not positive
    • SegmentedHealthBar

      public SegmentedHealthBar(String caption, int maximum)
      Creates a full bar; each segment represents a positive integer capacity.
      Parameters:
      caption - non-null display caption
      maximum - positive maximum health
      Throws:
      NullPointerException - if caption is null
      IllegalArgumentException - if maximum is not positive
  • Method Details

    • view

      public javafx.scene.Node view()
      Returns this instance's stable ordinary JavaFX view.
      Returns:
      label and segmented progress controls in a VBox
    • setHealth

      public void setHealth(int health)
      Explicitly updates the amount; values are clamped to 0..maximum.
      Parameters:
      health - requested displayed health
    • getHealth

      public int getHealth()
      Returns the last clamped displayed amount.
      Returns:
      current health
    • getMaximum

      public int getMaximum()
      Returns this instance's positive maximum.
      Returns:
      maximum health