Class ExpanderGroup

java.lang.Object
limn.components.ExpanderGroup

public final class ExpanderGroup extends Object
Keeps at most one of several Expanders open, an accordion: opening one closes the one that was open. All of them may be closed; closing the open one leaves none open.

When the user opened one, the closing member and then the opening one announce EXPANDED, then each runs its own onChange, and then the group's onSelect runs with the open member's index, as a ButtonGroup's does with the chosen radio's. When code did it, both announce and no handler runs. A group is not a widget: it has no box, no place in the tree and nothing to say to a reader, which hears each section by itself.

Each header stays a tab stop of its own: a section is a button, and a form of five sections is five things to reach, as on every platform.

A section is out of its group for as long as it is out of a scene it was in, as a radio is out of its ButtonGroup: taken out of the tree, or its window closed. The group does not count it, hold it or open it then, and it takes its place again, among the members that are there, when it is back in a scene; if it comes back open while the group opened another meanwhile, it closes, as an adjustment. A section added before it was ever in a scene is a member from the start.

  • Constructor Details

    • ExpanderGroup

      public ExpanderGroup()
  • Method Details

    • add

      public ExpanderGroup add(Expander expander)
      Adds a section. If it is open it becomes the group's open member, and the one that was open closes, saying so as an adjustment: the group closed it, not a caller.
      Parameters:
      expander - the section; one in another group leaves that one first
      Returns:
      this group
    • remove

      public ExpanderGroup remove(Expander expander)
      Takes a section out of the group: it opens and closes by itself from then on, and stays as it is. Nothing happens for one that is not a member.
      Parameters:
      expander - the section
      Returns:
      this group
    • members

      public List<Expander> members()
      Returns:
      the members, in the order they were added; one that is out of the scene it was in is not among them until it is back
    • expanded

      public @Nullable Expander expanded()
      Returns:
      the open member, or null when all are closed
    • expandedIndex

      public int expandedIndex()
      Returns:
      the open member's index, or -1 when all are closed
    • setExpandedIndex

      public ExpanderGroup setExpandedIndex(int index)
      Opens the member at index, closing the one that was open: a caller's write, so both announce EXPANDED/CODE and no handler runs.
      Parameters:
      index - a member in [0, members().size())
      Returns:
      this group
      Throws:
      IndexOutOfBoundsException - if index is not a member
    • collapseAll

      public ExpanderGroup collapseAll()
      Closes the open member, if any: a caller's write, announced, with no handler.
      Returns:
      this group
    • onSelect

      public ExpanderGroup onSelect(@Nullable IntConsumer listener)
      The application's response to the user opening or closing a member, with the index of the one open afterwards, or -1 when the user closed the open one: a click, Space or Enter on a header, or an assistive technology's expand or collapse, once both members' own handlers have run, as ButtonGroup.onSelect is called. Never for setExpandedIndex(int), collapseAll() or a member's Expander.setExpanded(boolean), which are a caller's writes; to hear every change whatever caused it, watch the members.
      Parameters:
      listener - the handler, or null to clear the slot
      Returns:
      this group
      Throws:
      IllegalStateException - if a handler is already registered