diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java index bc503667..845a3160 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSliderUI.java @@ -53,7 +53,7 @@ import com.formdev.flatlaf.util.UIScale; * * * @uiDefault Slider.trackWidth int - * @uiDefault Slider.thumbWidth int + * @uiDefault Slider.thumbSize Dimension * @uiDefault Slider.focusWidth int * @uiDefault Slider.trackValueColor Color optional; defaults to Slider.thumbColor * @uiDefault Slider.trackColor Color @@ -73,7 +73,7 @@ public class FlatSliderUI extends BasicSliderUI { protected int trackWidth; - protected int thumbWidth; + protected Dimension thumbSize; protected int focusWidth; protected Color trackValueColor; @@ -106,7 +106,12 @@ public class FlatSliderUI LookAndFeel.installProperty( slider, "opaque", false ); trackWidth = UIManager.getInt( "Slider.trackWidth" ); - thumbWidth = UIManager.getInt( "Slider.thumbWidth" ); + thumbSize = UIManager.getDimension( "Slider.thumbSize" ); + if( thumbSize == null ) { + // fallback for compatibility with old versions + int thumbWidth = UIManager.getInt( "Slider.thumbWidth" ); + thumbSize = new Dimension( thumbWidth, thumbWidth ); + } focusWidth = FlatUIUtils.getUIInt( "Slider.focusWidth", 4 ); trackValueColor = FlatUIUtils.getUIColor( "Slider.trackValueColor", "Slider.thumbColor" ); @@ -187,9 +192,16 @@ public class FlatSliderUI @Override protected Dimension getThumbSize() { + return calcThumbSize( slider, thumbSize, focusWidth ); + } + + public static Dimension calcThumbSize( JSlider slider, Dimension thumbSize, int focusWidth ) { int fw = UIScale.scale( focusWidth ); - int w = UIScale.scale( thumbWidth ) + fw + fw; - return new Dimension( w, w ); + int w = UIScale.scale( thumbSize.width ) + fw + fw; + int h = UIScale.scale( thumbSize.height ) + fw + fw; + return (slider.getOrientation() == JSlider.HORIZONTAL) + ? new Dimension( w, h ) + : new Dimension( h, w ); } @Override @@ -285,23 +297,23 @@ debug*/ // paint thumb focus border if( focused ) { g.setColor( focusedColor ); - g.fillOval( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height ); + ((Graphics2D)g).fill( createRoundThumbShape( thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height ) ); } if( thumbBorderColor != null ) { // paint thumb border g.setColor( thumbBorderColor ); - g.fillOval( x, y, width, height ); + ((Graphics2D)g).fill( createRoundThumbShape( x, y, width, height ) ); // paint thumb background float lw = UIScale.scale( 1f ); g.setColor( thumbColor ); - ((Graphics2D)g).fill( new Ellipse2D.Float( x + lw, y + lw, + ((Graphics2D)g).fill( createRoundThumbShape( x + lw, y + lw, width - lw - lw, height - lw - lw ) ); } else { // paint thumb background g.setColor( thumbColor ); - g.fillOval( x, y, width, height ); + ((Graphics2D)g).fill( createRoundThumbShape( x, y, width, height ) ); } } else { Graphics2D g2 = (Graphics2D) g.create(); @@ -315,13 +327,17 @@ debug*/ g2.translate( thumbRect.width, 0 ); g2.rotate( Math.toRadians( 90 ) ); } + + int temp = width; + width = height; + height = temp; } // paint thumb focus border if( focused ) { g2.setColor( focusedColor ); g2.fill( createDirectionalThumbShape( 0, 0, - thumbRect.width, thumbRect.height + (fw * 0.4142f), fw ) ); + width + fw + fw, height + fw + fw + (fw * 0.4142f), fw ) ); } if( thumbBorderColor != null ) { @@ -345,8 +361,17 @@ debug*/ } } - public static Shape createDirectionalThumbShape( double x, double y, double w, double h, double arc ) { - double wh = w / 2; + public static Shape createRoundThumbShape( float x, float y, float w, float h ) { + if( w == h ) + return new Ellipse2D.Float( x, y, w, h ); + else { + float arc = Math.min( w, h ); + return new RoundRectangle2D.Float( x, y, w, h, arc, arc ); + } + } + + public static Shape createDirectionalThumbShape( float x, float y, float w, float h, float arc ) { + float wh = w / 2; Path2D path = new Path2D.Float(); path.moveTo( x + wh, y + h ); 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 dbf91b85..95015d5c 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -507,7 +507,7 @@ Separator.stripeIndent=1 Slider.focusInsets=0,0,0,0 Slider.trackWidth=2 -Slider.thumbWidth=12 +Slider.thumbSize=12,12 Slider.focusWidth=4 diff --git a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java index 34c7a6d1..aa51b1fe 100644 --- a/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java +++ b/flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatRangeSliderUI.java @@ -43,7 +43,7 @@ public class FlatRangeSliderUI extends BasicRangeSliderUI { protected int trackWidth; - protected int thumbWidth; + protected Dimension thumbSize; protected int focusWidth; protected Color trackValueColor; @@ -105,7 +105,7 @@ public class FlatRangeSliderUI LookAndFeel.installProperty( slider, "opaque", false ); trackWidth = UIManager.getInt( "Slider.trackWidth" ); - thumbWidth = UIManager.getInt( "Slider.thumbWidth" ); + thumbSize = UIManager.getDimension( "Slider.thumbSize" ); focusWidth = FlatUIUtils.getUIInt( "Slider.focusWidth", 4 ); trackValueColor = FlatUIUtils.getUIColor( "Slider.trackValueColor", "Slider.thumbColor" ); @@ -185,9 +185,7 @@ public class FlatRangeSliderUI @Override protected Dimension getThumbSize() { - int fw = UIScale.scale( focusWidth ); - int w = UIScale.scale( thumbWidth ) + fw + fw; - return new Dimension( w, w ); + return FlatSliderUI.calcThumbSize( slider, thumbSize, focusWidth ); } @Override diff --git a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt index 555a57b8..5236f05a 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatDarkLaf_1.8.0_202.txt @@ -858,7 +858,7 @@ Slider.onlyLeftMouseButtonDrag true Slider.pressedThumbColor #2e6296 com.formdev.flatlaf.util.DerivedColor [UI] darken(15% autoInverse) Slider.shadow #646464 javax.swing.plaf.ColorUIResource [UI] Slider.thumbColor #4a88c7 javax.swing.plaf.ColorUIResource [UI] -Slider.thumbWidth 12 +Slider.thumbSize 12,12 javax.swing.plaf.DimensionUIResource [UI] Slider.tickColor #888888 javax.swing.plaf.ColorUIResource [UI] Slider.trackColor #646464 javax.swing.plaf.ColorUIResource [UI] Slider.trackValueColor #4a88c7 javax.swing.plaf.ColorUIResource [UI] diff --git a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt index dc533773..8af0db86 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatLightLaf_1.8.0_202.txt @@ -863,7 +863,7 @@ Slider.onlyLeftMouseButtonDrag true Slider.pressedThumbColor #125ca5 com.formdev.flatlaf.util.DerivedColor [UI] lighten(15% autoInverse) Slider.shadow #c4c4c4 javax.swing.plaf.ColorUIResource [UI] Slider.thumbColor #1e82e6 javax.swing.plaf.ColorUIResource [UI] -Slider.thumbWidth 12 +Slider.thumbSize 12,12 javax.swing.plaf.DimensionUIResource [UI] Slider.tickColor #888888 javax.swing.plaf.ColorUIResource [UI] Slider.trackColor #c4c4c4 javax.swing.plaf.ColorUIResource [UI] Slider.trackValueColor #1e82e6 javax.swing.plaf.ColorUIResource [UI] diff --git a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt index c816d1a4..142a62b6 100644 --- a/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt +++ b/flatlaf-testing/dumps/uidefaults/FlatTestLaf_1.8.0_202.txt @@ -853,7 +853,7 @@ Slider.pressedTrackColor #88ff88 javax.swing.plaf.ColorUIResource [UI] Slider.shadow #a0a0a0 javax.swing.plaf.ColorUIResource [UI] Slider.thumbBorderColor #ff0000 javax.swing.plaf.ColorUIResource [UI] Slider.thumbColor #ffaaaa javax.swing.plaf.ColorUIResource [UI] -Slider.thumbWidth 12 +Slider.thumbSize 12,12 javax.swing.plaf.DimensionUIResource [UI] Slider.tickColor #ff0000 javax.swing.plaf.ColorUIResource [UI] Slider.trackColor #88ff88 javax.swing.plaf.ColorUIResource [UI] Slider.trackWidth 2 diff --git a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt index 87b6b4ff..e09ea5df 100644 --- a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt +++ b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt @@ -600,7 +600,7 @@ Slider.onlyLeftMouseButtonDrag Slider.pressedThumbColor Slider.shadow Slider.thumbColor -Slider.thumbWidth +Slider.thumbSize Slider.tickColor Slider.trackColor Slider.trackValueColor