TabbedPane: support specifying hiddenTabsNavigation type per tabbedpane via client property (issue #40)

This commit is contained in:
Karl Tauber
2020-10-15 10:41:45 +02:00
parent c58f5a6ca7
commit c0408045ef
4 changed files with 101 additions and 13 deletions

View File

@@ -240,6 +240,30 @@ public interface FlatClientProperties
*/
String TABBED_PANE_TAB_HEIGHT = "JTabbedPane.tabHeight";
/**
* Specifies how to navigate to hidden tabs.
* <p>
* <strong>Component</strong> {@link javax.swing.JTabbedPane}<br>
* <strong>Value type</strong> {@link java.lang.String}
* <strong>Allowed Values</strong> {@link #TABBED_PANE_HIDDEN_TABS_NAVIGATION_MORE_TABS_BUTTON}
* or {@link #TABBED_PANE_HIDDEN_TABS_NAVIGATION_ARROW_BUTTONS}
*/
String TABBED_PANE_HIDDEN_TABS_NAVIGATION = "JTabbedPane.hiddenTabsNavigation";
/**
* Use "more tabs" button for navigation to hidden tabs.
*
* @see #TABBED_PANE_HIDDEN_TABS_NAVIGATION
*/
String TABBED_PANE_HIDDEN_TABS_NAVIGATION_MORE_TABS_BUTTON = "moreTabsButton";
/**
* Use forward/backward buttons for navigation to hidden tabs.
*
* @see #TABBED_PANE_HIDDEN_TABS_NAVIGATION
*/
String TABBED_PANE_HIDDEN_TABS_NAVIGATION_ARROW_BUTTONS = "arrowButtons";
/**
* Specifies whether all text is selected when the text component gains focus.
* <p>

View File

@@ -268,13 +268,27 @@ public class FlatTabbedPaneUI
}
}
// initialize here because used in installHiddenTabsNavigation() before installDefaults() was invoked
hiddenTabsNavigation = parseHiddenTabsNavigation( UIManager.getString( "TabbedPane.hiddenTabsNavigation" ) );
installHiddenTabsNavigation();
}
private void installHiddenTabsNavigation() {
@Override
protected void uninstallComponents() {
// uninstall hidden tabs navigation before invoking super.uninstallComponents() for
// correct uninstallation of BasicTabbedPaneUI tab scroller support
uninstallHiddenTabsNavigation();
super.uninstallComponents();
tabViewport = null;
}
protected void installHiddenTabsNavigation() {
// initialize here because used in installHiddenTabsNavigation() before installDefaults() was invoked
String hiddenTabsNavigationStr = (String) tabPane.getClientProperty( TABBED_PANE_HIDDEN_TABS_NAVIGATION );
if( hiddenTabsNavigationStr == null )
hiddenTabsNavigationStr = UIManager.getString( "TabbedPane.hiddenTabsNavigation" );
hiddenTabsNavigation = parseHiddenTabsNavigation( hiddenTabsNavigationStr );
if( hiddenTabsNavigation != MORE_TABS_BUTTON ||
!isScrollTabLayout() ||
tabViewport == null )
@@ -293,21 +307,16 @@ public class FlatTabbedPaneUI
tabPane.add( moreTabsButton );
}
@Override
protected void uninstallComponents() {
protected void uninstallHiddenTabsNavigation() {
// restore layout manager before invoking super.uninstallComponents() for
// correct uninstallation of BasicTabbedPaneUI tab scroller support
if( tabPane.getLayout() instanceof FlatTabbedPaneScrollLayout )
tabPane.setLayout( ((FlatTabbedPaneScrollLayout)tabPane.getLayout()).delegate );
super.uninstallComponents();
if( moreTabsButton != null ) {
tabPane.remove( moreTabsButton );
moreTabsButton = null;
}
tabViewport = null;
}
@Override
@@ -1276,6 +1285,12 @@ public class FlatTabbedPaneUI
tabPane.revalidate();
tabPane.repaint();
break;
case TABBED_PANE_HIDDEN_TABS_NAVIGATION:
uninstallHiddenTabsNavigation();
installHiddenTabsNavigation();
tabPane.repaint();
break;
}
}