Skip to content

Commit

Permalink
TabbedPane: option to disable tab run rotation in wrap layout (issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed Aug 12, 2022
1 parent 1091408 commit d2f46cd
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,11 @@ FlatLaf Change Log

## 2.5-SNAPSHOT

#### New features and improvements

- TabbedPane: New option to disable tab run rotation in wrap layout. Set UI
value `TabbedPane.rotateTabRuns` to `false`. (issue #574)

#### Fixed bugs

- Fixed missing UI value `MenuItem.acceleratorDelimiter` on macOS. (was `null`,
Expand Down
Expand Up @@ -145,7 +145,7 @@
* @uiDefault TabbedPane.showTabSeparators boolean
* @uiDefault TabbedPane.tabSeparatorsFullHeight boolean
* @uiDefault TabbedPane.hasFullBorder boolean
* @uiDefault TabbedPane.activeTabBorder boolean
* @uiDefault TabbedPane.rotateTabRuns boolean
*
* @uiDefault TabbedPane.tabLayoutPolicy String wrap (default) or scroll
* @uiDefault TabbedPane.tabType String underlined (default) or card
Expand Down Expand Up @@ -220,6 +220,7 @@ public class FlatTabbedPaneUI
@Styleable protected boolean tabSeparatorsFullHeight;
@Styleable protected boolean hasFullBorder;
@Styleable protected boolean tabsOpaque = true;
/** @since 2.5 */ @Styleable protected boolean rotateTabRuns = true;

@Styleable(type=String.class) private int tabType;
@Styleable(type=String.class) private int tabsPopupPolicy;
Expand Down Expand Up @@ -342,6 +343,7 @@ protected void installDefaults() {
tabSeparatorsFullHeight = UIManager.getBoolean( "TabbedPane.tabSeparatorsFullHeight" );
hasFullBorder = UIManager.getBoolean( "TabbedPane.hasFullBorder" );
tabsOpaque = UIManager.getBoolean( "TabbedPane.tabsOpaque" );
rotateTabRuns = FlatUIUtils.getUIBoolean( "TabbedPane.rotateTabRuns", true );

tabType = parseTabType( UIManager.getString( "TabbedPane.tabType" ) );
tabsPopupPolicy = parseTabsPopupPolicy( UIManager.getString( "TabbedPane.tabsPopupPolicy" ) );
Expand Down Expand Up @@ -1092,7 +1094,7 @@ protected void paintTab( Graphics g, int tabPlacement, Rectangle[] rects,

// paint selection indicator
if( isSelected )
paintTabSelection( g, tabPlacement, x, y, w, h );
paintTabSelection( g, tabPlacement, tabIndex, x, y, w, h );

if( tabPane.getTabComponentAt( tabIndex ) != null )
return;
Expand Down Expand Up @@ -1281,14 +1283,19 @@ protected void paintTabSeparator( Graphics g, int tabPlacement, int x, int y, in
}
}

protected void paintTabSelection( Graphics g, int tabPlacement, int x, int y, int w, int h ) {
protected void paintTabSelection( Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h ) {
g.setColor( tabPane.isEnabled()
? (isTabbedPaneOrChildFocused() ? underlineColor : inactiveUnderlineColor)
: disabledUnderlineColor );

// paint underline selection
boolean atBottom = (getTabType() != TAB_TYPE_CARD);
Insets contentInsets = getContentBorderInsets( tabPlacement );
Insets contentInsets = atBottom
? ((!rotateTabRuns && runCount > 1 && !isScrollTabLayout() && getRunForTab( tabPane.getTabCount(), tabIndex ) > 0)
? new Insets( 0, 0, 0, 0 )
: getContentBorderInsets( tabPlacement ))
: null;

int tabSelectionHeight = scale( atBottom ? this.tabSelectionHeight : cardTabSelectionHeight );
int sx, sy;
switch( tabPlacement ) {
Expand Down Expand Up @@ -1447,7 +1454,7 @@ protected void paintContentBorder( Graphics g, int tabPlacement, int selectedInd
else
g.clipRect( 0, vr.y, tabPane.getWidth(), vr.height );

paintTabSelection( g, tabPlacement, tabRect.x, tabRect.y, tabRect.width, tabRect.height );
paintTabSelection( g, tabPlacement, selectedIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height );
g.setClip( oldClip );
}
}
Expand Down Expand Up @@ -1600,6 +1607,11 @@ protected void ensureCurrentLayout() {
super.getTabRunCount( tabPane );
}

@Override
protected boolean shouldRotateTabRuns( int tabPlacement ) {
return rotateTabRuns;
}

private boolean isLastInRun( int tabIndex ) {
int run = getRunForTab( tabPane.getTabCount(), tabIndex );
return lastTabInRun( tabPane.getTabCount(), run ) == tabIndex;
Expand Down
Expand Up @@ -722,6 +722,7 @@ void tabbedPane() {
"tabSeparatorsFullHeight", boolean.class,
"hasFullBorder", boolean.class,
"tabsOpaque", boolean.class,
"rotateTabRuns", boolean.class,

"tabType", String.class,
"tabsPopupPolicy", String.class,
Expand Down
Expand Up @@ -739,6 +739,7 @@ void tabbedPane() {
testBoolean( c, ui, "tabSeparatorsFullHeight", false );
testBoolean( c, ui, "hasFullBorder", false );
testBoolean( c, ui, "tabsOpaque", false );
testBoolean( c, ui, "rotateTabRuns", false );

testString( c, ui, "tabType", "card" );
testString( c, ui, "tabsPopupPolicy", "asNeeded" );
Expand Down
Expand Up @@ -891,6 +891,7 @@ void tabbedPane() {
ui.applyStyle( "tabSeparatorsFullHeight: false" );
ui.applyStyle( "hasFullBorder: false" );
ui.applyStyle( "tabsOpaque: false" );
ui.applyStyle( "rotateTabRuns: false" );

ui.applyStyle( "tabType: card" );
ui.applyStyle( "tabsPopupPolicy: asNeeded" );
Expand Down
Expand Up @@ -840,6 +840,7 @@ TabbedPane.hoverColor
TabbedPane.inactiveUnderlineColor
TabbedPane.labelShift
TabbedPane.light
TabbedPane.rotateTabRuns
TabbedPane.scrollButtonsPlacement
TabbedPane.scrollButtonsPolicy
TabbedPane.selectedBackground
Expand Down

0 comments on commit d2f46cd

Please sign in to comment.