Package tripleplay.ui

Class Tabs

All Implemented Interfaces:
Iterable<Element<?>>

public class Tabs extends Composite<Tabs>
A Composite that implements tabbing. Has a horizontal row of buttons along the top and a stretching content group underneath. The buttons are instances of ToggleButton. Each button is associated with a content element. When the button is clicked, its content is shown alone in the content group.

This diagram shows a Tabs with A and B tabs. When A's button is clicked, A's content is shown. B content is not generated or not visible.


   --------------------------------------
   |  -----  -----                      |
   |  |*A*|  | B |                      |  <--- the buttons group, A selected
   |  -----  -----                      |
   |------------------------------------|
   |                                    |  <--- the contentArea group
   |  --------------------------------  |
   |  |         A content            |  |
   |  --------------------------------  |
   |                                    |
   --------------------------------------
 

The tab content associated with a button is supplied on demand via a Supplier instance. The contract of Supplier is obeyed in that Supplier.close() is called whenever the associated tab goes out of scope.

NOTE: The inheritance from Composite means that child elements may not be added or removed directly. It you need, for example, a title bar, just use a Group with the title bar and tabs. TODO: do we care about scrolling buttons? yes

  • Field Details

    • NOOP_HIGHLIGHTER

      public static Tabs.Highlighter NOOP_HIGHLIGHTER
      A no-op highlighter to use if you want to make highlighting do nothing.
    • HIGHLIGHTER

      public static Style<Tabs.Highlighter> HIGHLIGHTER
      Style for highlighting a tab. The default value is a no-op highlighter.
    • buttons

      public final Group buttons
      The row of buttons, one per tab.
    • contentArea

      public final Group contentArea
      The content group.
    • selected

      public final react.Value<Tabs.Tab> selected
      The value containing the currently selected tab.
  • Constructor Details

    • Tabs

      public Tabs()
      Creates a new tabbed container.
  • Method Details

    • textColorHighlighter

      public static Tabs.Highlighter textColorHighlighter(int originalColor, int highlightColor)
      Creates a highlighter that will simply change the button's text color.
      Parameters:
      originalColor - the button text color when unhighlighted
      highlightColor - the button text color when highlighted
    • tabCount

      public int tabCount()
      Gets the number of tabs.
    • tabAt

      public Tabs.Tab tabAt(int index)
      Gets the tab at the given index, or null if the index is out of range.
    • add

      public Tabs.Tab add(String label, Supplier supplier)
      Adds a new tab to the container with the given label and supplier. Adds a new button to the buttons group. The supplier is used to generate an element to put in the contentArea group if and when the tab is selected.
      Returns:
      the newly added tab
    • add

      public Tabs.Tab add(String label, Element<?> panel)
      Adds a new tab to the container with a pre-constructed element for its content. This is a shortcut for calling add(String, Supplier) with a Supplier.auto(tripleplay.ui.Element<?>).
      Returns:
      the newly added tab
    • add

      public Tabs.Tab add(String label, Icon icon, Supplier supplier)
      Adds a new tab to the container with the given label, icon and supplier. Adds a new button to the buttons group. The supplier is used to generate an element to put in the contentArea group when the tab is selected.
      Returns:
      the newly added tab
    • add

      public Tabs.Tab add(String label, Icon icon, Element<?> panel)
      Adds a new tab to the container with a pre-constructed element for its content. See add(String, Supplier).
      Returns:
      the newly added tab
    • repositionTab

      public void repositionTab(Tabs.Tab tab, int position)
      Moves the given tab into the given position.
    • destroyTab

      public void destroyTab(Tabs.Tab tab)
      Removes the given tab and destroys its resources.
    • highlighter

      public Tabs.Highlighter highlighter()
      Gets our highlighter. Resolved from the HIGHLIGHTER style.