JIDE: JideTabbedPane:

- support selected tab background
- support tab separators
This commit is contained in:
Karl Tauber
2021-03-25 18:49:16 +01:00
parent bf500e46e7
commit bffac60bf8

View File

@@ -17,6 +17,7 @@
package com.formdev.flatlaf.jideoss.ui; package com.formdev.flatlaf.jideoss.ui;
import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_HAS_FULL_BORDER; import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_HAS_FULL_BORDER;
import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_SHOW_TAB_SEPARATORS;
import static com.formdev.flatlaf.FlatClientProperties.clientPropertyBoolean; import static com.formdev.flatlaf.FlatClientProperties.clientPropertyBoolean;
import static com.formdev.flatlaf.util.UIScale.scale; import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Color; import java.awt.Color;
@@ -36,8 +37,8 @@ import java.beans.PropertyChangeListener;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.ui.FlatUIUtils;
import com.formdev.flatlaf.util.UIScale;
import com.jidesoft.plaf.LookAndFeelFactory; import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.plaf.UIDefaultsLookup; import com.jidesoft.plaf.UIDefaultsLookup;
import com.jidesoft.plaf.basic.BasicJideTabbedPaneUI; import com.jidesoft.plaf.basic.BasicJideTabbedPaneUI;
@@ -51,15 +52,19 @@ import com.jidesoft.swing.JideTabbedPane;
public class FlatJideTabbedPaneUI public class FlatJideTabbedPaneUI
extends BasicJideTabbedPaneUI extends BasicJideTabbedPaneUI
{ {
protected Color selectedBackground;
protected Color underlineColor; protected Color underlineColor;
protected Color disabledUnderlineColor; protected Color disabledUnderlineColor;
protected Color hoverColor; protected Color hoverColor;
protected Color focusColor; protected Color focusColor;
protected Color tabSeparatorColor;
protected Color contentAreaColor; protected Color contentAreaColor;
protected int tabHeight; protected int tabHeight;
protected int tabSelectionHeight; protected int tabSelectionHeight;
protected int contentSeparatorHeight; protected int contentSeparatorHeight;
protected boolean showTabSeparators;
protected boolean tabSeparatorsFullHeight;
protected boolean hasFullBorder; protected boolean hasFullBorder;
protected boolean tabsOverlapBorder; protected boolean tabsOverlapBorder;
@@ -79,15 +84,19 @@ public class FlatJideTabbedPaneUI
_background = UIDefaultsLookup.getColor( "JideTabbedPane.background" ); _background = UIDefaultsLookup.getColor( "JideTabbedPane.background" );
selectedBackground = UIManager.getColor( "TabbedPane.selectedBackground" );
underlineColor = UIManager.getColor( "TabbedPane.underlineColor" ); underlineColor = UIManager.getColor( "TabbedPane.underlineColor" );
disabledUnderlineColor = UIManager.getColor( "TabbedPane.disabledUnderlineColor" ); disabledUnderlineColor = UIManager.getColor( "TabbedPane.disabledUnderlineColor" );
hoverColor = UIManager.getColor( "TabbedPane.hoverColor" ); hoverColor = UIManager.getColor( "TabbedPane.hoverColor" );
focusColor = UIManager.getColor( "TabbedPane.focusColor" ); focusColor = UIManager.getColor( "TabbedPane.focusColor" );
tabSeparatorColor = UIManager.getColor( "TabbedPane.tabSeparatorColor" );
contentAreaColor = UIManager.getColor( "TabbedPane.contentAreaColor" ); contentAreaColor = UIManager.getColor( "TabbedPane.contentAreaColor" );
tabHeight = UIManager.getInt( "TabbedPane.tabHeight" ); tabHeight = UIManager.getInt( "TabbedPane.tabHeight" );
tabSelectionHeight = UIManager.getInt( "TabbedPane.tabSelectionHeight" ); tabSelectionHeight = UIManager.getInt( "TabbedPane.tabSelectionHeight" );
contentSeparatorHeight = UIManager.getInt( "TabbedPane.contentSeparatorHeight" ); contentSeparatorHeight = UIManager.getInt( "TabbedPane.contentSeparatorHeight" );
showTabSeparators = UIManager.getBoolean( "TabbedPane.showTabSeparators" );
tabSeparatorsFullHeight = UIManager.getBoolean( "TabbedPane.tabSeparatorsFullHeight" );
hasFullBorder = UIManager.getBoolean( "TabbedPane.hasFullBorder" ); hasFullBorder = UIManager.getBoolean( "TabbedPane.hasFullBorder" );
tabsOverlapBorder = UIManager.getBoolean( "TabbedPane.tabsOverlapBorder" ); tabsOverlapBorder = UIManager.getBoolean( "TabbedPane.tabsOverlapBorder" );
@@ -101,10 +110,12 @@ public class FlatJideTabbedPaneUI
protected void uninstallDefaults() { protected void uninstallDefaults() {
super.uninstallDefaults(); super.uninstallDefaults();
selectedBackground = null;
underlineColor = null; underlineColor = null;
disabledUnderlineColor = null; disabledUnderlineColor = null;
hoverColor = null; hoverColor = null;
focusColor = null; focusColor = null;
tabSeparatorColor = null;
contentAreaColor = null; contentAreaColor = null;
} }
@@ -114,13 +125,17 @@ public class FlatJideTabbedPaneUI
return e -> { return e -> {
superListener.propertyChange( e ); superListener.propertyChange( e );
String propertyName = e.getPropertyName(); switch( e.getPropertyName() ) {
if( JideTabbedPane.PROPERTY_SELECTED_INDEX.equals( propertyName ) ) { case JideTabbedPane.PROPERTY_SELECTED_INDEX:
repaintTab( (Integer) e.getOldValue() ); repaintTab( (Integer) e.getOldValue() );
repaintTab( (Integer) e.getNewValue() ); repaintTab( (Integer) e.getNewValue() );
} else if( FlatClientProperties.TABBED_PANE_HAS_FULL_BORDER.equals( propertyName ) ) { break;
case TABBED_PANE_SHOW_TAB_SEPARATORS:
case TABBED_PANE_HAS_FULL_BORDER:
_tabPane.revalidate(); _tabPane.revalidate();
_tabPane.repaint(); _tabPane.repaint();
break;
} }
}; };
} }
@@ -226,7 +241,9 @@ public class FlatJideTabbedPaneUI
? hoverColor ? hoverColor
: (enabled && isSelected && FlatUIUtils.isPermanentFocusOwner( _tabPane ) : (enabled && isSelected && FlatUIUtils.isPermanentFocusOwner( _tabPane )
? focusColor ? focusColor
: _tabPane.getBackgroundAt( tabIndex )) ); : (selectedBackground != null && enabled && isSelected
? selectedBackground
: _tabPane.getBackgroundAt( tabIndex ))) );
g.fillRect( x, y, w, h ); g.fillRect( x, y, w, h );
} }
@@ -243,10 +260,32 @@ public class FlatJideTabbedPaneUI
protected void paintTabBorder( Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, protected void paintTabBorder( Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h,
boolean isSelected ) boolean isSelected )
{ {
// paint tab separators
if( clientPropertyBoolean( _tabPane, TABBED_PANE_SHOW_TAB_SEPARATORS, showTabSeparators ) &&
!isLastInRun( tabIndex ) )
paintTabSeparator( g, tabPlacement, x, y, w, h );
if( isSelected ) if( isSelected )
paintTabSelection( g, tabPlacement, x, y, w, h ); paintTabSelection( g, tabPlacement, x, y, w, h );
} }
protected void paintTabSeparator( Graphics g, int tabPlacement, int x, int y, int w, int h ) {
float sepWidth = UIScale.scale( 1f );
float offset = tabSeparatorsFullHeight ? 0 : UIScale.scale( 5f );
g.setColor( (tabSeparatorColor != null) ? tabSeparatorColor : contentAreaColor );
if( tabPlacement == LEFT || tabPlacement == RIGHT ) {
// paint tab separator at bottom side
((Graphics2D)g).fill( new Rectangle2D.Float( x + offset, y + h - sepWidth, w - (offset * 2), sepWidth ) );
} else if( _tabPane.getComponentOrientation().isLeftToRight() ) {
// paint tab separator at right side
((Graphics2D)g).fill( new Rectangle2D.Float( x + w - sepWidth, y + offset, sepWidth, h - (offset * 2) ) );
} else {
// paint tab separator at left side
((Graphics2D)g).fill( new Rectangle2D.Float( x, y + offset, sepWidth, h - (offset * 2) ) );
}
}
protected void paintTabSelection( Graphics g, int tabPlacement, int x, int y, int w, int h ) { protected void paintTabSelection( Graphics g, int tabPlacement, int x, int y, int w, int h ) {
// increase clip bounds in scroll-tab-layout to paint over the separator line // increase clip bounds in scroll-tab-layout to paint over the separator line
Rectangle clipBounds = scrollableTabLayoutEnabled() ? g.getClipBounds() : null; Rectangle clipBounds = scrollableTabLayoutEnabled() ? g.getClipBounds() : null;
@@ -386,4 +425,9 @@ public class FlatJideTabbedPaneUI
Rectangle iconRect, Rectangle textRect, boolean isSelected ) Rectangle iconRect, Rectangle textRect, boolean isSelected )
{ {
} }
private boolean isLastInRun( int tabIndex ) {
int run = getRunForTab( _tabPane.getTabCount(), tabIndex );
return lastTabInRun( _tabPane.getTabCount(), run ) == tabIndex;
}
} }