ToggleButton renamed toggle button type "underline" to "tab" (value of client property JButton.buttonType is now tab)

This commit is contained in:
Karl Tauber
2020-01-14 23:59:56 +01:00
parent 74909da110
commit e378576632
8 changed files with 54 additions and 52 deletions

View File

@@ -12,7 +12,9 @@ FlatLaf Change Log
property `JComponent.minimumHeight` to an integer). (issue #44) property `JComponent.minimumHeight` to an integer). (issue #44)
- Button and ToggleButton: Do not apply minimum width if button border was - Button and ToggleButton: Do not apply minimum width if button border was
changed (is no longer an instance of `FlatButtonBorder`). changed (is no longer an instance of `FlatButtonBorder`).
- ToggleButton: No longer use focus width for underline style toggle buttons to - ToggleButton: Renamed toggle button type "underline" to "tab" (value of client
property `JButton.buttonType` is now `tab`).
- ToggleButton: No longer use focus width for tab-style toggle buttons to
compute component size, which reduces/fixes component size in "Flat IntelliJ" compute component size, which reduces/fixes component size in "Flat IntelliJ"
and "Flat Darcula" themes. and "Flat Darcula" themes.

View File

@@ -43,13 +43,13 @@ public interface FlatClientProperties
String BUTTON_TYPE_SQUARE = "square"; String BUTTON_TYPE_SQUARE = "square";
/** /**
* Paint the toggle button in underline style. * Paint the toggle button in tab style.
* <p> * <p>
* <strong>Components</strong> {@link javax.swing.JToggleButton} * <strong>Components</strong> {@link javax.swing.JToggleButton}
* *
* @see #TOGGLE_BUTTON_TYPE * @see #TOGGLE_BUTTON_TYPE
*/ */
String BUTTON_TYPE_UNDERLINE = "underline"; String BUTTON_TYPE_TAB = "tab";
/** /**
* Paint a help button (circle with question mark). * Paint a help button (circle with question mark).

View File

@@ -445,11 +445,11 @@ public class IntelliJTheme
for( Map.Entry<String, String> e : uiKeyMapping.entrySet() ) for( Map.Entry<String, String> e : uiKeyMapping.entrySet() )
uiKeyInverseMapping.put( e.getValue(), e.getKey() ); uiKeyInverseMapping.put( e.getValue(), e.getKey() );
uiKeyCopying.put( "ToggleButton.underline.underlineColor", "TabbedPane.underlineColor" ); uiKeyCopying.put( "ToggleButton.tab.underlineColor", "TabbedPane.underlineColor" );
uiKeyCopying.put( "ToggleButton.underline.disabledUnderlineColor", "TabbedPane.disabledUnderlineColor" ); uiKeyCopying.put( "ToggleButton.tab.disabledUnderlineColor", "TabbedPane.disabledUnderlineColor" );
uiKeyCopying.put( "ToggleButton.underline.selectedBackground", "TabbedPane.selectedBackground" ); uiKeyCopying.put( "ToggleButton.tab.selectedBackground", "TabbedPane.selectedBackground" );
uiKeyCopying.put( "ToggleButton.underline.hoverBackground", "TabbedPane.hoverColor" ); uiKeyCopying.put( "ToggleButton.tab.hoverBackground", "TabbedPane.hoverColor" );
uiKeyCopying.put( "ToggleButton.underline.focusBackground", "TabbedPane.focusColor" ); uiKeyCopying.put( "ToggleButton.tab.focusBackground", "TabbedPane.focusColor" );
checkboxKeyMapping.put( "Checkbox.Background.Default", "CheckBox.icon.background" ); checkboxKeyMapping.put( "Checkbox.Background.Default", "CheckBox.icon.background" );
checkboxKeyMapping.put( "Checkbox.Background.Disabled", "CheckBox.icon.disabledBackground" ); checkboxKeyMapping.put( "Checkbox.Background.Disabled", "CheckBox.icon.disabledBackground" );

View File

@@ -65,7 +65,7 @@ public class FlatButtonBorder
@Override @Override
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) { public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
if( FlatButtonUI.isContentAreaFilled( c ) && !FlatButtonUI.isHelpButton( c ) && !FlatToggleButtonUI.isUnderlineButton( c ) ) if( FlatButtonUI.isContentAreaFilled( c ) && !FlatButtonUI.isHelpButton( c ) && !FlatToggleButtonUI.isTabButton( c ) )
super.paintBorder( c, g, x, y, width, height ); super.paintBorder( c, g, x, y, width, height );
} }
@@ -106,7 +106,7 @@ public class FlatButtonBorder
@Override @Override
protected float getFocusWidth( Component c ) { protected float getFocusWidth( Component c ) {
return FlatToggleButtonUI.isUnderlineButton( c ) ? 0 : super.getFocusWidth(c ); return FlatToggleButtonUI.isTabButton( c ) ? 0 : super.getFocusWidth(c );
} }
@Override @Override

View File

@@ -61,12 +61,12 @@ import com.formdev.flatlaf.util.UIScale;
* @uiDefault ToggleButton.disabledSelectedBackground Color * @uiDefault ToggleButton.disabledSelectedBackground Color
* @uiDefault ToggleButton.toolbar.selectedBackground Color * @uiDefault ToggleButton.toolbar.selectedBackground Color
* *
* @uiDefault ToggleButton.underline.underlineHeight int * @uiDefault ToggleButton.tab.underlineHeight int
* @uiDefault ToggleButton.underline.underlineColor Color * @uiDefault ToggleButton.tab.underlineColor Color
* @uiDefault ToggleButton.underline.disabledUnderlineColor Color * @uiDefault ToggleButton.tab.disabledUnderlineColor Color
* @uiDefault ToggleButton.underline.selectedBackground Color optional * @uiDefault ToggleButton.tab.selectedBackground Color optional
* @uiDefault ToggleButton.underline.hoverBackground Color * @uiDefault ToggleButton.tab.hoverBackground Color
* @uiDefault ToggleButton.underline.focusBackground Color * @uiDefault ToggleButton.tab.focusBackground Color
* *
* *
* @author Karl Tauber * @author Karl Tauber
@@ -80,12 +80,12 @@ public class FlatToggleButtonUI
protected Color toolbarSelectedBackground; protected Color toolbarSelectedBackground;
protected int underlineHeight; protected int tabUnderlineHeight;
protected Color underlineColor; protected Color tabUnderlineColor;
protected Color disabledUnderlineColor; protected Color tabDisabledUnderlineColor;
protected Color underlineSelectedBackground; protected Color tabSelectedBackground;
protected Color underlineHoverBackground; protected Color tabHoverBackground;
protected Color underlineFocusBackground; protected Color tabFocusBackground;
private boolean defaults_initialized = false; private boolean defaults_initialized = false;
@@ -113,12 +113,12 @@ public class FlatToggleButtonUI
toolbarSelectedBackground = UIManager.getColor( "ToggleButton.toolbar.selectedBackground" ); toolbarSelectedBackground = UIManager.getColor( "ToggleButton.toolbar.selectedBackground" );
underlineHeight = UIManager.getInt( "ToggleButton.underline.underlineHeight" ); tabUnderlineHeight = UIManager.getInt( "ToggleButton.tab.underlineHeight" );
underlineColor = UIManager.getColor( "ToggleButton.underline.underlineColor" ); tabUnderlineColor = UIManager.getColor( "ToggleButton.tab.underlineColor" );
disabledUnderlineColor = UIManager.getColor( "ToggleButton.underline.disabledUnderlineColor" ); tabDisabledUnderlineColor = UIManager.getColor( "ToggleButton.tab.disabledUnderlineColor" );
underlineSelectedBackground = UIManager.getColor( "ToggleButton.underline.selectedBackground" ); tabSelectedBackground = UIManager.getColor( "ToggleButton.tab.selectedBackground" );
underlineHoverBackground = UIManager.getColor( "ToggleButton.underline.hoverBackground" ); tabHoverBackground = UIManager.getColor( "ToggleButton.tab.hoverBackground" );
underlineFocusBackground = UIManager.getColor( "ToggleButton.underline.focusBackground" ); tabFocusBackground = UIManager.getColor( "ToggleButton.tab.focusBackground" );
defaults_initialized = true; defaults_initialized = true;
} }
@@ -136,7 +136,7 @@ public class FlatToggleButtonUI
switch( e.getPropertyName() ) { switch( e.getPropertyName() ) {
case BUTTON_TYPE: case BUTTON_TYPE:
if( BUTTON_TYPE_UNDERLINE.equals( e.getOldValue() ) || BUTTON_TYPE_UNDERLINE.equals( e.getNewValue() ) ) { if( BUTTON_TYPE_TAB.equals( e.getOldValue() ) || BUTTON_TYPE_TAB.equals( e.getNewValue() ) ) {
MigLayoutVisualPadding.uninstall( b ); MigLayoutVisualPadding.uninstall( b );
MigLayoutVisualPadding.install( b, getFocusWidth( b ) ); MigLayoutVisualPadding.install( b, getFocusWidth( b ) );
b.revalidate(); b.revalidate();
@@ -147,21 +147,21 @@ public class FlatToggleButtonUI
} }
} }
static boolean isUnderlineButton( Component c ) { static boolean isTabButton( Component c ) {
return c instanceof JToggleButton && clientPropertyEquals( (JToggleButton) c, BUTTON_TYPE, BUTTON_TYPE_UNDERLINE ); return c instanceof JToggleButton && clientPropertyEquals( (JToggleButton) c, BUTTON_TYPE, BUTTON_TYPE_TAB );
} }
@Override @Override
protected void paintBackground( Graphics g, JComponent c ) { protected void paintBackground( Graphics g, JComponent c ) {
if( isUnderlineButton( c ) ) { if( isTabButton( c ) ) {
int height = c.getHeight(); int height = c.getHeight();
int width = c.getWidth(); int width = c.getWidth();
boolean selected = ((AbstractButton)c).isSelected(); boolean selected = ((AbstractButton)c).isSelected();
// paint background // paint background
Color background = buttonStateColor( c, Color background = buttonStateColor( c,
selected ? underlineSelectedBackground : null, selected ? tabSelectedBackground : null,
null, underlineFocusBackground, underlineHoverBackground, null ); null, tabFocusBackground, tabHoverBackground, null );
if( background != null ) { if( background != null ) {
g.setColor( background ); g.setColor( background );
g.fillRect( 0, 0, width, height ); g.fillRect( 0, 0, width, height );
@@ -169,8 +169,8 @@ public class FlatToggleButtonUI
// paint underline if selected // paint underline if selected
if( selected ) { if( selected ) {
int underlineHeight = UIScale.scale( this.underlineHeight ); int underlineHeight = UIScale.scale( tabUnderlineHeight );
g.setColor( c.isEnabled() ? underlineColor : disabledUnderlineColor ); g.setColor( c.isEnabled() ? tabUnderlineColor : tabDisabledUnderlineColor );
g.fillRect( 0, height - underlineHeight, width, underlineHeight ); g.fillRect( 0, height - underlineHeight, width, underlineHeight );
} }
} else } else
@@ -207,6 +207,6 @@ public class FlatToggleButtonUI
@Override @Override
protected int getFocusWidth( JComponent c ) { protected int getFocusWidth( JComponent c ) {
return isUnderlineButton( c ) ? 0 : super.getFocusWidth( c ); return isTabButton( c ) ? 0 : super.getFocusWidth( c );
} }
} }

View File

@@ -439,13 +439,13 @@ ToggleButton.pressedBackground=$Button.pressedBackground
ToggleButton.toolbar.hoverBackground=$Button.toolbar.hoverBackground ToggleButton.toolbar.hoverBackground=$Button.toolbar.hoverBackground
ToggleButton.toolbar.pressedBackground=$Button.toolbar.pressedBackground ToggleButton.toolbar.pressedBackground=$Button.toolbar.pressedBackground
# button type "underline" # button type "tab"
ToggleButton.underline.underlineHeight=2 ToggleButton.tab.underlineHeight=2
ToggleButton.underline.underlineColor=$TabbedPane.underlineColor ToggleButton.tab.underlineColor=$TabbedPane.underlineColor
ToggleButton.underline.disabledUnderlineColor=$TabbedPane.disabledUnderlineColor ToggleButton.tab.disabledUnderlineColor=$TabbedPane.disabledUnderlineColor
ToggleButton.underline.selectedBackground=$?TabbedPane.selectedBackground ToggleButton.tab.selectedBackground=$?TabbedPane.selectedBackground
ToggleButton.underline.hoverBackground=$TabbedPane.hoverColor ToggleButton.tab.hoverBackground=$TabbedPane.hoverColor
ToggleButton.underline.focusBackground=$TabbedPane.focusColor ToggleButton.tab.focusBackground=$TabbedPane.focusColor
#---- ToolBar ---- #---- ToolBar ----

View File

@@ -344,14 +344,14 @@ public class FlatComponentsTest
add(toggleButton4, "cell 4 2"); add(toggleButton4, "cell 4 2");
//---- toggleButton5 ---- //---- toggleButton5 ----
toggleButton5.setText("underline"); toggleButton5.setText("tab");
toggleButton5.putClientProperty("JButton.buttonType", "underline"); toggleButton5.putClientProperty("JButton.buttonType", "tab");
toggleButton5.setSelected(true); toggleButton5.setSelected(true);
add(toggleButton5, "cell 5 2"); add(toggleButton5, "cell 5 2");
//---- toggleButton8 ---- //---- toggleButton8 ----
toggleButton8.setText("underline"); toggleButton8.setText("tab");
toggleButton8.putClientProperty("JButton.buttonType", "underline"); toggleButton8.putClientProperty("JButton.buttonType", "tab");
toggleButton8.setEnabled(false); toggleButton8.setEnabled(false);
toggleButton8.setSelected(true); toggleButton8.setSelected(true);
add(toggleButton8, "cell 5 2"); add(toggleButton8, "cell 5 2");

View File

@@ -171,16 +171,16 @@ new FormModel {
} ) } )
add( new FormComponent( "javax.swing.JToggleButton" ) { add( new FormComponent( "javax.swing.JToggleButton" ) {
name: "toggleButton5" name: "toggleButton5"
"text": "underline" "text": "tab"
"$client.JButton.buttonType": "underline" "$client.JButton.buttonType": "tab"
"selected": true "selected": true
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 2" "value": "cell 5 2"
} ) } )
add( new FormComponent( "javax.swing.JToggleButton" ) { add( new FormComponent( "javax.swing.JToggleButton" ) {
name: "toggleButton8" name: "toggleButton8"
"text": "underline" "text": "tab"
"$client.JButton.buttonType": "underline" "$client.JButton.buttonType": "tab"
"enabled": false "enabled": false
"selected": true "selected": true
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {