Class QuickStat

java.lang.Object
org.apache.juneau.console.views.QuickStat

public final class QuickStat extends Object
One item in a table's quick-stats strip (quickStats.items[]): a plain tile, a meter (one value against a maximum) or a segmented tile (a proportional bar of labelled counts).
Example:

table.quickStats("work-unavailable", QuickStat.of("unavailable", "Work data", "unavailable").tone(QuickStat.Tone.ERROR), QuickStat.meter("inventory", "Inventory", 12, 40).text("12 of 40").statusTone(StatusTone.SUCCESS), QuickStat.segmented("orders", "Orders").segment("Placed", 3).segment("Delivered", 9, StatusTone.SUCCESS));

Since:
10.0.0
  • Field Details

  • Method Details

    • of

      public static QuickStat of(String id, String label, Object value)
      Creates a quick-stat tile.
      Parameters:
      id - This tile's own id, unique within its table. Must not be null or blank.
      label - The tile's label text.
      value - The tile's value, serialized as-is.
      Returns:
      A new QuickStat.
      Throws:
      IllegalArgumentException - If id is null or blank.
    • meter

      public static QuickStat meter(String id, String label, Number value, Number max)
      Creates a meter item: one value drawn against a maximum.

      A value above the maximum is allowed; it paints a full bar with an over-limit cue.

      Parameters:
      id - This item's own id, unique within its table. Must not be null or blank.
      label - The item's label text; it names the meter for assistive technology. Must not be null or blank.
      value - The current value. Must be finite and >= 0.
      max - The maximum. Must be finite and > 0.
      Returns:
      A new QuickStat.
      Throws:
      IllegalArgumentException - If id or label is blank, or value or max is null or out of range.
    • segmented

      public static QuickStat segmented(String id, String label)
      Creates a segmented item: a proportional bar plus a legend of labelled counts.

      Add the segments with segment(String, long); at least one is required by the time the item is built.

      Parameters:
      id - This item's own id, unique within its table. Must not be null or blank.
      label - The item's label text; it names the group for assistive technology. Must not be null or blank.
      Returns:
      A new QuickStat.
      Throws:
      IllegalArgumentException - If id or label is null or blank.
    • segment

      public QuickStat segment(String label, long count)
      Adds an untoned segment to a segmented item.
      Parameters:
      label - The segment label. Must not be null or blank.
      count - The segment count. Must be >= 0.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If this is not a segmented item, the label is blank, the count is negative, or the item already has MAX_SEGMENTS segments.
    • segment

      public QuickStat segment(String label, long count, StatusTone tone)
      Adds a segment to a segmented item.
      Parameters:
      label - The segment label. Must not be null or blank.
      count - The segment count. Must be >= 0.
      tone - The segment tone. Can be null for an untoned segment.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If this is not a segmented item, the label is blank, the count is negative, or the item already has MAX_SEGMENTS segments.
    • text

      public QuickStat text(String text)
      Sets a meter's display text, which replaces the default "value / max".
      Parameters:
      text - The text. Must not be null; blank means the default text is used.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If this is not a meter item, or text is null.
    • statusTone

      Sets the tone of a tile or meter.

      Writes the same tone as tone(Tone); the last call wins.

      Parameters:
      t - The tone. Can be null to unset.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If this is a segmented item (tone each segment instead).
    • tone

      Sets this tile's visual tone.
      Parameters:
      t - The tone. Can be null to unset.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If this is a segmented item (tone each segment instead).
    • toMap

      public JsonMap toMap()
      Builds this item's quickStats.items[] entry.
      Returns:
      A tile {id, label, value, tone?} (no type); a meter {id, type, label, value, max, text?, tone?}; or a segmented item {id, type, label, segments[{label, count, tone?}]}.
      Throws:
      IllegalArgumentException - If this is a segmented item with no segments.