ComboBox and Spinner: support changing arrow button style (issue #114)

This commit is contained in:
Karl Tauber
2020-06-19 18:12:23 +02:00
parent 84cc86bef7
commit 262ae7865b
6 changed files with 27 additions and 7 deletions

View File

@@ -80,6 +80,7 @@ import com.formdev.flatlaf.util.UIScale;
*
* @uiDefault ComboBox.minimumWidth int
* @uiDefault ComboBox.editorColumns int
* @uiDefault ComboBox.buttonStyle String auto (default), button or none
* @uiDefault Component.arrowType String triangle (default) or chevron
* @uiDefault Component.isIntelliJTheme boolean
* @uiDefault Component.borderColor Color
@@ -100,6 +101,7 @@ public class FlatComboBoxUI
{
protected int minimumWidth;
protected int editorColumns;
protected String buttonStyle;
protected String arrowType;
protected boolean isIntelliJTheme;
protected Color borderColor;
@@ -154,6 +156,7 @@ public class FlatComboBoxUI
minimumWidth = UIManager.getInt( "ComboBox.minimumWidth" );
editorColumns = UIManager.getInt( "ComboBox.editorColumns" );
buttonStyle = UIManager.getString( "ComboBox.buttonStyle" );
arrowType = UIManager.getString( "Component.arrowType" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
borderColor = UIManager.getColor( "Component.borderColor" );
@@ -350,6 +353,7 @@ public class FlatComboBoxUI
int height = c.getHeight();
int arrowX = arrowButton.getX();
int arrowWidth = arrowButton.getWidth();
boolean paintButton = (comboBox.isEditable() || "button".equals( buttonStyle )) && !"none".equals( buttonStyle );
boolean enabled = comboBox.isEnabled();
boolean isLeftToRight = comboBox.getComponentOrientation().isLeftToRight();
@@ -361,7 +365,7 @@ public class FlatComboBoxUI
// paint arrow button background
if( enabled ) {
g2.setColor( comboBox.isEditable() ? buttonEditableBackground : buttonBackground );
g2.setColor( paintButton ? buttonEditableBackground : buttonBackground );
Shape oldClip = g2.getClip();
if( isLeftToRight )
g2.clipRect( arrowX, 0, width - arrowX, height );
@@ -372,7 +376,7 @@ public class FlatComboBoxUI
}
// paint vertical line between value and arrow button
if( comboBox.isEditable() ) {
if( paintButton ) {
g2.setColor( enabled ? borderColor : disabledBorderColor );
float lw = scale( 1f );
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;

View File

@@ -58,6 +58,7 @@ import com.formdev.flatlaf.FlatClientProperties;
* <!-- FlatSpinnerUI -->
*
* @uiDefault Component.minimumWidth int
* @uiDefault Spinner.buttonStyle String button (default) or none
* @uiDefault Component.arrowType String triangle (default) or chevron
* @uiDefault Component.isIntelliJTheme boolean
* @uiDefault Component.borderColor Color
@@ -78,6 +79,7 @@ public class FlatSpinnerUI
private Handler handler;
protected int minimumWidth;
protected String buttonStyle;
protected String arrowType;
protected boolean isIntelliJTheme;
protected Color borderColor;
@@ -101,6 +103,7 @@ public class FlatSpinnerUI
LookAndFeel.installProperty( spinner, "opaque", false );
minimumWidth = UIManager.getInt( "Component.minimumWidth" );
buttonStyle = UIManager.getString( "Spinner.buttonStyle" );
arrowType = UIManager.getString( "Component.arrowType" );
isIntelliJTheme = UIManager.getBoolean( "Component.isIntelliJTheme" );
borderColor = UIManager.getColor( "Component.borderColor" );
@@ -258,6 +261,7 @@ public class FlatSpinnerUI
Component nextButton = getHandler().nextButton;
int arrowX = nextButton.getX();
int arrowWidth = nextButton.getWidth();
boolean paintButton = !"none".equals( buttonStyle );
boolean enabled = spinner.isEnabled();
boolean isLeftToRight = spinner.getComponentOrientation().isLeftToRight();
@@ -268,7 +272,7 @@ public class FlatSpinnerUI
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );
// paint arrow buttons background
if( enabled ) {
if( paintButton && enabled ) {
g2.setColor( buttonBackground );
Shape oldClip = g2.getClip();
if( isLeftToRight )
@@ -280,10 +284,12 @@ public class FlatSpinnerUI
}
// paint vertical line between value and arrow buttons
g2.setColor( enabled ? borderColor : disabledBorderColor );
float lw = scale( 1f );
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2) ) );
if( paintButton ) {
g2.setColor( enabled ? borderColor : disabledBorderColor );
float lw = scale( 1f );
float lx = isLeftToRight ? arrowX : arrowX + arrowWidth - lw;
g2.fill( new Rectangle2D.Float( lx, focusWidth, lw, height - 1 - (focusWidth * 2) ) );
}
paint( g, c );
}

View File

@@ -181,6 +181,7 @@ ComboBox.padding=2,6,2,6
ComboBox.minimumWidth=72
ComboBox.editorColumns=0
[mac]ComboBox.showPopupOnNavigation=true
ComboBox.buttonStyle=auto
#---- Component ----
@@ -478,6 +479,7 @@ Spinner.buttonDisabledArrowColor=$ComboBox.buttonDisabledArrowColor
Spinner.buttonHoverArrowColor=$ComboBox.buttonHoverArrowColor
Spinner.padding=@textComponentMargin
Spinner.editorBorderPainted=false
Spinner.buttonStyle=button
#---- SplitPane ----