From 262ae7865b5dff666361fdd081265a1e58827a9e Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 19 Jun 2020 18:12:23 +0200 Subject: [PATCH] ComboBox and Spinner: support changing arrow button style (issue #114) --- CHANGELOG.md | 4 ++++ .../com/formdev/flatlaf/ui/FlatComboBoxUI.java | 8 ++++++-- .../com/formdev/flatlaf/ui/FlatSpinnerUI.java | 16 +++++++++++----- .../com/formdev/flatlaf/FlatLaf.properties | 2 ++ .../testing/uidefaults/FlatDarkLaf_1.8.0_202.txt | 2 ++ .../uidefaults/FlatLightLaf_1.8.0_202.txt | 2 ++ 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79bb7470..04b63293 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ FlatLaf Change Log - ScrollBar: Support pressed track, thumb and button colors (use UI values `ScrollBar.pressedTrackColor`, `ScrollBar.pressedThumbColor` and `ScrollBar.pressedButtonBackground`). (issue #115) +- ComboBox: Support changing arrow button style (set UI value + `ComboBox.buttonStyle` to `auto` (default), `button` or `none`). (issue #114) +- Spinner: Support changing arrows button style (set UI value + `Spinner.buttonStyle` to `button` (default) or `none`). - TableHeader: Support top/bottom/left positioned sort arrow when using [Glazed Lists](https://github.com/glazedlists/glazedlists). (issue #113) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java index e41bfb21..2b275952 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java @@ -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; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java index 395534cc..7b55f0f0 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java @@ -58,6 +58,7 @@ import com.formdev.flatlaf.FlatClientProperties; * * * @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 ); } diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties index 65ae790c..013439cc 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -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 ---- diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt index 69773a18..4b6562d4 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt @@ -189,6 +189,7 @@ ComboBox.buttonEditableBackground #404445 javax.swing.plaf.ColorUIResource [U ComboBox.buttonHighlight #242424 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonHoverArrowColor #bbbbbb javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonShadow #646464 javax.swing.plaf.ColorUIResource [UI] +ComboBox.buttonStyle auto ComboBox.disabledBackground #3c3f41 javax.swing.plaf.ColorUIResource [UI] ComboBox.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI] ComboBox.editorColumns 0 @@ -850,6 +851,7 @@ Spinner.buttonArrowColor #9a9da1 javax.swing.plaf.ColorUIResource [UI] Spinner.buttonBackground #404445 javax.swing.plaf.ColorUIResource [UI] Spinner.buttonDisabledArrowColor #585858 javax.swing.plaf.ColorUIResource [UI] Spinner.buttonHoverArrowColor #bbbbbb javax.swing.plaf.ColorUIResource [UI] +Spinner.buttonStyle button Spinner.disabledBackground #3c3f41 javax.swing.plaf.ColorUIResource [UI] Spinner.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI] Spinner.editorAlignment 11 diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt index e8e1f3a2..3563280d 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt @@ -193,6 +193,7 @@ ComboBox.buttonEditableBackground #fafafa javax.swing.plaf.ColorUIResource [U ComboBox.buttonHighlight #ffffff javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonHoverArrowColor #999999 javax.swing.plaf.ColorUIResource [UI] ComboBox.buttonShadow #c4c4c4 javax.swing.plaf.ColorUIResource [UI] +ComboBox.buttonStyle auto ComboBox.disabledBackground #f2f2f2 javax.swing.plaf.ColorUIResource [UI] ComboBox.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI] ComboBox.editorColumns 0 @@ -855,6 +856,7 @@ Spinner.buttonArrowColor #666666 javax.swing.plaf.ColorUIResource [UI] Spinner.buttonBackground #fafafa javax.swing.plaf.ColorUIResource [UI] Spinner.buttonDisabledArrowColor #ababab javax.swing.plaf.ColorUIResource [UI] Spinner.buttonHoverArrowColor #999999 javax.swing.plaf.ColorUIResource [UI] +Spinner.buttonStyle button Spinner.disabledBackground #f2f2f2 javax.swing.plaf.ColorUIResource [UI] Spinner.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI] Spinner.editorAlignment 11