Package swingtree

Class UIForSplitButton<B extends JSplitButton>


public final class UIForSplitButton<B extends JSplitButton> extends UIForAnyButton<UIForSplitButton<B>,B>
A SwingTree builder node designed for configuring JSplitButton instances.
  • Method Details

    • _state

      protected swingtree.BuilderState<B> _state()
      Description copied from class: UIForAnything
      Returns the state of the builder, which is a container for the wrapped component as well as it's type and current EventProcessor.
      Specified by:
      _state in class UIForAnything<UIForSplitButton<B extends JSplitButton>,B extends JSplitButton,JComponent>
      Returns:
      The state of the builder.
    • _newBuilderWithState

      protected UIForSplitButton<B> _newBuilderWithState(swingtree.BuilderState<B> newState)
      Description copied from class: UIForAnything
      An internal wither method which creates a new builder instance with the provided BuilderState stored inside it.
      Specified by:
      _newBuilderWithState in class UIForAnything<UIForSplitButton<B extends JSplitButton>,B extends JSplitButton,JComponent>
      Parameters:
      newState - The new state which should be stored inside the new builder instance.
      Returns:
      A new builder instance with the provided state stored inside it.
    • withSelection

      public <E extends Enum<E>> UIForSplitButton<B> withSelection(sprouts.Var<E> selection, sprouts.Event clickEvent)
      Use this to build JSplitButtons where the selectable options are represented by an Enum type, and the click event is handles by an Event instance.
      Type Parameters:
      E - The Enum type defining the selectable options.
      Parameters:
      selection - The Var which holds the currently selected Enum value. This will be updated when the user selects a new value.
      clickEvent - The Event which will be fired when the user clicks on the button.
      Returns:
      A UI builder instance wrapping a JSplitButton.
    • withSelection

      public <E extends Enum<E>> UIForSplitButton<B> withSelection(sprouts.Var<E> selection, sprouts.Event clickEvent, Function<E,String> textProvider)
      Allows you to build JSplitButtons where the selectable options are represented by an Enum type, and the click event is handled by an Event instance as well as a "text provider", which is a function that maps an enum value to a string to be used as the button text displayed to the user.
      Type Parameters:
      E - The Enum type defining the selectable options.
      Parameters:
      selection - The Var which holds the currently selected Enum value. This will be updated when the user selects a new value.
      clickEvent - The Event which will be fired when the user clicks on the button.
      textProvider - A function which provides the text representation of an enum value. If this function throws an exception, the enum value's Enum.toString() method will be used as a fallback. Exceptions are logged as errors.
      Returns:
      The next declarative UI builder for the JSplitButton type.
    • withSelection

      public <E extends Enum<E>> UIForSplitButton<B> withSelection(sprouts.Var<E> selection)
      Use this to build JSplitButtons where the selectable options are represented by an Enum type. Changes to the selected value are propagated to the provided Var instance, and the text representation of the selected value is determined using the Enum.toString() method.
      Type Parameters:
      E - The Enum type defining the selectable options.
      Parameters:
      selection - The Var which holds the currently selected Enum value. This will be updated when the user selects a new value.
      Returns:
      A UI builder instance wrapping a JSplitButton.
    • withSelection

      public <E extends Enum<E>> UIForSplitButton<B> withSelection(sprouts.Var<E> selection, Function<E,String> textProvider)
      Use this to build JSplitButtons where the selectable options are represented by an Enum type. Changes to the selected value are propagated to the provided Var instance, and the text representation of the selected value is dynamically determined through the supplied text provider function.
      Type Parameters:
      E - The Enum type defining the selectable options.
      Parameters:
      selection - The Var which holds the currently selected Enum value. This will be updated when the user selects a new value.
      textProvider - A function which provides the text representation of an enum value. If this function throws an exception, the enum value's Enum.toString() method will be used as a fallback. Exceptions are logged as errors.
      Returns:
      A UI builder instance wrapping a JSplitButton.
    • onSplitClick

      public UIForSplitButton<B> onSplitClick(sprouts.Action<SplitButtonDelegate<JMenuItem>> action)
      Actions registered here will be called when the split part of the JSplitButton was clicked. The provided lambda receives a delegate object with a rich API exposing a lot of context information including not only the current JSplitButton instance, but also the currently selected JMenuItem and a list of all other items.
      Parameters:
      action - The Action which will receive an ComponentDelegate exposing all essential components making up this JSplitButton.
      Returns:
      This very instance, which enables builder-style method chaining.
    • onSelection

      public UIForSplitButton<B> onSelection(sprouts.Action<SplitButtonDelegate<JMenuItem>> action)
      Actions registered here will be called when the user selects a JMenuItem from the popup menu of this JSplitButton. The delegate passed to the provided action lambda exposes a lot of context information including not only the current JSplitButton instance, but also the currently selected JMenuItem and a list of all other items.
      Parameters:
      action - The Action which will receive an SplitItemDelegate exposing all essential components making up this JSplitButton.
      Returns:
      This very instance, which enables builder-style method chaining.
      Throws:
      IllegalArgumentException - if the provided action is null.
    • onButtonClick

      public UIForSplitButton<B> onButtonClick(sprouts.Action<SplitItemDelegate<JMenuItem>> action)
      Use this as an alternative to onClick(Action) to register a button click action with an action lambda having access to a delegate with more context information including not only the current JSplitButton instance, but also the currently selected JMenuItem and a list of all other items.
      Parameters:
      action - The Action which will receive an ComponentDelegate exposing all essential components making up this JSplitButton.
      Returns:
      This very instance, which enables builder-style method chaining.
    • onClick

      public UIForSplitButton<B> onClick(sprouts.Action<ComponentDelegate<B,ActionEvent>> action)
      Use this to register a basic action for when the JSplitButton button is being clicked (not the split part). If you need more context information delegated to the action then consider using onButtonClick(Action).
      Overrides:
      onClick in class UIForAnyButton<UIForSplitButton<B extends JSplitButton>,B extends JSplitButton>
      Parameters:
      action - An Action instance which will be wrapped by an ComponentDelegate and passed to the button component.
      Returns:
      This very instance, which enables builder-style method chaining.
    • onOpen

      public UIForSplitButton<B> onOpen(sprouts.Action<ComponentDelegate<B,PopupMenuEvent>> action)
      Registers a listener to be notified when the split button is opened, meaning its popup menu is shown after the user clicks on the split button drop down button.
      Parameters:
      action - the action to be executed when the split button is opened.
      Returns:
      this very instance, which enables builder-style method chaining.
    • onClose

      public UIForSplitButton<B> onClose(sprouts.Action<ComponentDelegate<B,PopupMenuEvent>> action)
      Registers a listener to be notified when the split button is closed, meaning its popup menu is hidden after the user clicks on the split button drop down button.
      Parameters:
      action - the action to be executed when the split button is closed.
      Returns:
      this very instance, which enables builder-style method chaining.
    • onCancel

      public UIForSplitButton<B> onCancel(sprouts.Action<ComponentDelegate<B,PopupMenuEvent>> action)
      Registers a listener to be notified when the split button options drop down popup is canceled, which typically happens when the user clicks outside the popup menu.
      Parameters:
      action - the action to be executed when the split button popup is canceled.
      Returns:
      this very instance, which enables builder-style method chaining.
    • add

      public <M extends JMenuItem> UIForSplitButton<B> add(UIForMenuItem<M> forItem)
      Use this to add a JMenuItem to the JSplitButton popup menu.
      Type Parameters:
      M - The type of the JMenuItem wrapped by the given UIForMenuItem instance.
      Parameters:
      forItem - The builder whose wrapped JMenuItem will be added to and exposed by the JSplitButton once the split part was pressed.
      Returns:
      This very instance, which enables builder-style method chaining.
    • add

      public UIForSplitButton<B> add(JMenuItem item)
      Use this to add a JMenuItem to the JSplitButton popup menu.
      Parameters:
      item - A JMenuItem which will be exposed by this JSplitButton once the split part was pressed.
      Returns:
      This very instance, which enables builder-style method chaining.
    • add

      public <I extends JMenuItem> UIForSplitButton<B> add(SplitItem<I> splitItem)
      Use this to add a SplitItem to the JSplitButton popup menu.
      Type Parameters:
      I - The JMenuItem type which should be added to this JSplitButton builder.
      Parameters:
      splitItem - The SplitItem instance wrapping a JMenuItem as well as some associated Actions.
      Returns:
      This very instance, which enables builder-style method chaining.