Class GTabPanel<T>

Type Parameters:
T - The type of values in the tab panel.
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class GTabPanel<T> extends JPanel
Component for displaying a list of items as a series of horizontal tabs where exactly one tab is selected.

If there are too many tabs to display horizontally, a "hidden tabs" control will be displayed that when activated, will display a popup dialog with a scrollable list of all possible values.

It also supports the idea of a highlighted tab which represents a value that is not selected, but is a candidate to be selected. For example, when the tab panel has focus, using the left and right arrows will highlight different tabs. Then pressing enter will cause the highlighted tab to be selected.

The clients of this component can also supply functions for customizing the name, icon, and tooltip for values. They can also add consumers for when the selected value changes or a value is removed from the tab panel. Clients can also install a predicate for the close tab action so they can process it before the value is removed and possibly veto the remove.

See Also:
  • Constructor Details

    • GTabPanel

      public GTabPanel(String tabTypeName)
      Constructor
      Parameters:
      tabTypeName - the name of the type of values in the tab panel. This will be used to set accessible descriptions.
  • Method Details

    • addTab

      public void addTab(T value)
      Add a new tab to the panel for the given value.
      Parameters:
      value - the value for the new tab
    • addTabs

      public void addTabs(List<T> values)
      Add tabs for each value in the given list.
      Parameters:
      values - the values to add tabs for
    • removeTab

      public void removeTab(T value)
      Removes the tab with the given value.
      Parameters:
      value - the value for which to remove its tab
    • removeTabs

      public void removeTabs(Collection<T> values)
      Remove tabs for all values in the given list.
      Parameters:
      values - the values to remove from the tab panel
    • getSelectedTabValue

      public T getSelectedTabValue()
      Returns the currently selected tab. If the panel is not empty, there will always be a selected tab.
      Returns:
      the currently selected tab or null if the panel is empty
    • getHighlightedTabValue

      public T getHighlightedTabValue()
      Returns the currently highlighted tab if a tab is highlighted. Note: the selected tab can never be highlighted.
      Returns:
      the currently highlighted tab or null if no tab is highligted
    • selectTab

      public void selectTab(T value)
      Makes the tab for the given value be the selected tab.
      Parameters:
      value - the value whose tab is to be selected
    • getTabValues

      public List<T> getTabValues()
      Returns a list of values for all the tabs in the panel.
      Returns:
      a list of values for all the tabs in the panel
    • isVisibleTab

      public boolean isVisibleTab(T value)
      Returns true if the tab for the given value is visible on the tab panel.
      Parameters:
      value - the value to test if visible
      Returns:
      true if the tab for the given value is visible on the tab panel
    • getTabCount

      public int getTabCount()
      Returns the total number of tabs both visible and hidden.
      Returns:
      the total number of tabs both visible and hidden.
    • highlightTab

      public void highlightTab(T value)
      Sets the tab for the given value to be highlighted. If the value is selected, then the highlighted tab will be set to null.
      Parameters:
      value - the value to highlight its tab
    • hasHiddenTabs

      public boolean hasHiddenTabs()
      Returns true if not all tabs are visible in the tab panel.
      Returns:
      true if not all tabs are visible in the tab panel
    • getHiddenTabs

      public List<T> getHiddenTabs()
      Returns a list of all tab values that are not visible.
      Returns:
      a list of all tab values that are not visible
    • getVisibleTabs

      public List<T> getVisibleTabs()
      Returns a list of all tab values that are visible.
      Returns:
      a list of all tab values that are visible
    • showTabList

      public void showTabList(boolean show)
      Shows a popup dialog window with a filterable and scrollable list of all tab values.
      Parameters:
      show - true to show the popup list, false to close the popup list
    • highlightNextPreviousTab

      public void highlightNextPreviousTab(boolean forward)
      Moves the highlight to the next or previous tab from the current highlight. If there is no current highlight, it will highlight the next or previous tab from the selected tab.
      Parameters:
      forward - true moves the highlight to the right; otherwise move the highlight to the left
    • refreshTab

      public void refreshTab(T value)
      Informs the tab panel that some displayable property about the value has changed and the tabs label, icon, and tooltip need to be updated.
      Parameters:
      value - the value that has changed
    • setNameFunction

      public void setNameFunction(Function<T,String> nameFunction)
      Sets a function to be used to generated a display name for a given value. The display name is used in the tab, the filter, and the accessible description.
      Parameters:
      nameFunction - the function to generate display names for values
    • setIconFunction

      public void setIconFunction(Function<T,Icon> iconFunction)
      Sets a function to be used to generated an icon for a given value.
      Parameters:
      iconFunction - the function to generate icons for values
    • setToolTipFunction

      public void setToolTipFunction(Function<T,String> toolTipFunction)
      Sets a function to be used to generated an tooltip for a given value.
      Parameters:
      toolTipFunction - the function to generate tooltips for values
    • setCloseTabConsumer

      public void setCloseTabConsumer(Consumer<T> closeTabConsumer)
      Sets the predicate that will be called before removing a tab via the gui close control. Note that that tab panel's default action is to remove the tab value, but if you set your own consumer, you have the responsibility to remove the value.
      Parameters:
      closeTabConsumer - the consumer called when the close gui control is clicked.
    • setSelectedTabConsumer

      public void setSelectedTabConsumer(Consumer<T> selectedTabConsumer)
      Sets the consumer to be notified when the selected tab changes.
      Parameters:
      selectedTabConsumer - the consumer to be notified when the selected tab changes
    • isShowingTabList

      public boolean isShowingTabList()
      Returns true if the popup tab list is showing.
      Returns:
      true if the popup tab list is showing
    • setShowTabsAlways

      public void setShowTabsAlways(boolean b)
      Sets whether or not tabs should be display when there is only one tab.
      Parameters:
      b - true to show one tab; false collapses tab panel when only one tab exists
    • getValueFor

      public T getValueFor(MouseEvent event)
      Returns the value of the tab that generated the given mouse event. If the mouse event is not from one of the tabs, then null is returned.
      Parameters:
      event - the MouseEvent to get a value for
      Returns:
      the value of the tab that generated the mouse event
    • setIgnoreFocus

      public void setIgnoreFocus(boolean ignoreFocusLost)
    • getTab

      public JPanel getTab(T value)