diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java index f6b5c4c8..1449eb2a 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatBorder.java @@ -79,12 +79,12 @@ public class FlatBorder if( isFocused( c ) ) { g2.setColor( getFocusColor( c ) ); - FlatUIUtils.paintOutlineBorder( g2, x, y, width, height, focusWidth, + FlatUIUtils.paintComponentOuterBorder( g2, x, y, width, height, focusWidth, getLineWidth() + scale( (float) innerFocusWidth ), arc ); } g2.setPaint( getBorderColor( c ) ); - FlatUIUtils.drawRoundRectangle( g2, x, y, width, height, focusWidth, borderWidth, arc ); + FlatUIUtils.paintComponentBorder( g2, x, y, width, height, focusWidth, borderWidth, arc ); } finally { g2.dispose(); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java index 92f73a2f..30530a7f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatButtonUI.java @@ -251,7 +251,7 @@ public class FlatButtonUI g2.setPaint( new GradientPaint( 0, 0, startBg, 0, c.getHeight(), endBg ) ); else FlatUIUtils.setColor( g2, background, def ? defaultBackground : c.getBackground() ); - FlatUIUtils.fillRoundRectangle( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc ); + FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc ); } finally { g2.dispose(); } 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 2ca6f050..2964b41d 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 @@ -316,7 +316,7 @@ public class FlatComboBoxUI g2.setColor( enabled ? (editableBackground != null && comboBox.isEditable() ? editableBackground : c.getBackground()) : getDisabledBackground( comboBox ) ); - FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc ); + FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc ); // paint arrow button background if( enabled ) { @@ -326,7 +326,7 @@ public class FlatComboBoxUI g2.clipRect( arrowX, 0, width - arrowX, height ); else g2.clipRect( 0, 0, arrowX + arrowWidth, height ); - FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc ); + FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc ); g2.setClip( oldClip ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLineBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLineBorder.java index 5c8a3840..355bf01d 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLineBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatLineBorder.java @@ -48,7 +48,7 @@ public class FlatLineBorder try { FlatUIUtils.setRenderingHints( g2 ); g2.setColor( lineColor ); - FlatUIUtils.drawRoundRectangle( g2, x, y, width, height, 0f, scale( 1f ), 0f ); + FlatUIUtils.paintComponentBorder( g2, x, y, width, height, 0f, scale( 1f ), 0f ); } finally { g2.dispose(); } 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 316ba1ea..696571f9 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 @@ -267,7 +267,7 @@ public class FlatSpinnerUI g2.setColor( enabled ? c.getBackground() : (isIntelliJTheme ? FlatUIUtils.getParentBackground( c ) : disabledBackground) ); - FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc ); + FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc ); // paint arrow buttons background if( enabled ) { @@ -277,7 +277,7 @@ public class FlatSpinnerUI g2.clipRect( arrowX, 0, width - arrowX, height ); else g2.clipRect( 0, 0, arrowX + arrowWidth, height ); - FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc ); + FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc ); g2.setClip( oldClip ); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java index 04419ec4..b21f441c 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextFieldUI.java @@ -146,7 +146,7 @@ public class FlatTextFieldUI : (isIntelliJTheme && (!c.isEnabled() || !c.isEditable()) ? FlatUIUtils.getParentBackground( c ) : background) ); - FlatUIUtils.fillRoundRectangle( g2, 0, 0, c.getWidth(), c.getHeight(), fFocusWidth, 0 ); + FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), fFocusWidth, 0 ); } finally { g2.dispose(); } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java index bce0dc22..fe7a2a51 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java @@ -125,9 +125,39 @@ public class FlatUIUtils } /** - * Draws a round rectangle. + * Paints an outer border, which is usually a focus border. + *
+ * The outside bounds of the painted border are {@code x,y,width,height}. + * The line width of the painted border is {@code focusWidth + lineWidth}. + * The given arc diameter refers to the inner rectangle ({@code x,y,width,height} minus {@code focusWidth}). + * + * @see #paintComponentBorder + * @see #paintComponentBackground */ - public static void drawRoundRectangle( Graphics2D g, int x, int y, int width, int height, + public static void paintComponentOuterBorder( Graphics2D g, int x, int y, int width, int height, + float focusWidth, float lineWidth, float arc ) + { + float outerRadius = (arc > 0) ? arc + focusWidth - UIScale.scale( 2f ) : focusWidth; + float ow = focusWidth + lineWidth; + float innerRadius = outerRadius - ow; + + Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD ); + path.append( createRoundRectanglePath( x, y, width, height, outerRadius, outerRadius, outerRadius, outerRadius ), false ); + path.append( createRoundRectanglePath( x + ow, y + ow, width - (ow * 2), height - (ow * 2), innerRadius, innerRadius, innerRadius, innerRadius ), false ); + g.fill( path ); + } + + /** + * Draws the border of a component as round rectangle. + *
+ * The outside bounds of the painted border are + * {@code x + focusWidth, y + focusWidth, width - (focusWidth * 2), height - (focusWidth * 2)}. + * The given arc diameter refers to the painted rectangle (and not to {@code x,y,width,height}). + * + * @see #paintComponentOuterBorder + * @see #paintComponentBackground + */ + public static void paintComponentBorder( Graphics2D g, int x, int y, int width, int height, float focusWidth, float lineWidth, float arc ) { float arc2 = arc > lineWidth ? arc - lineWidth : 0f; @@ -146,9 +176,16 @@ public class FlatUIUtils } /** - * Fills a round rectangle. + * Fills the background of a component with a round rectangle. + *
+ * The bounds of the painted round rectangle are + * {@code x + focusWidth, y + focusWidth, width - (focusWidth * 2), height - (focusWidth * 2)}. + * The given arc diameter refers to the painted rectangle (and not to {@code x,y,width,height}). + * + * @see #paintComponentOuterBorder + * @see #paintComponentBorder */ - public static void fillRoundRectangle( Graphics2D g, int x, int y, int width, int height, + public static void paintComponentBackground( Graphics2D g, int x, int y, int width, int height, float focusWidth, float arc ) { g.fill( new RoundRectangle2D.Float( @@ -189,25 +226,6 @@ public class FlatUIUtils return null; } - /** - * Paints an outline border. - */ - public static void paintOutlineBorder( Graphics2D g, int x, int y, int width, int height, - float focusWidth, float lineWidth, float arc ) - { - float outerArc = (arc > 0) ? arc + focusWidth - UIScale.scale( 2f ) : focusWidth; - float ow = focusWidth + lineWidth; - - Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD ); - path.append( createOutlinePath( x, y, width, height, outerArc ), false ); - path.append( createOutlinePath( x + ow, y + ow, width - (ow * 2), height - (ow * 2), outerArc - ow ), false ); - g.fill( path ); - } - - private static Shape createOutlinePath( float x, float y, float width, float height, float arc ) { - return createRoundRectanglePath( x, y, width, height, arc, arc, arc, arc ); - } - /** * Creates a not-filled rounded rectangle shape and allows specifying the line width and the radius or each corner. */ @@ -222,7 +240,7 @@ public class FlatUIUtils } /** - * Creates a filled rounded rectangle shape and allows specifying the radius or each corner. + * Creates a filled rounded rectangle shape and allows specifying the radius of each corner. */ public static Shape createRoundRectanglePath( float x, float y, float width, float height, float arcTopLeft, float arcTopRight, float arcBottomLeft, float arcBottomRight ) @@ -256,10 +274,16 @@ public class FlatUIUtils return rect; } + /** + * Creates a closed path for the given points. + */ public static Path2D createPath( double... points ) { return createPath( true, points ); } + /** + * Creates a open or closed path for the given points. + */ public static Path2D createPath( boolean close, double... points ) { Path2D path = new Path2D.Float(); path.moveTo( points[0], points[1] ); diff --git a/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatDatePickerUI.java b/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatDatePickerUI.java index a6b29c80..2d50fb5d 100644 --- a/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatDatePickerUI.java +++ b/flatlaf-swingx/src/main/java/com/formdev/flatlaf/swingx/ui/FlatDatePickerUI.java @@ -237,7 +237,7 @@ public class FlatDatePickerUI // paint background g2.setColor( enabled ? c.getBackground() : disabledBackground ); - FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc ); + FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc ); // paint arrow button background if( enabled ) { @@ -247,7 +247,7 @@ public class FlatDatePickerUI g2.clipRect( arrowX, 0, width - arrowX, height ); else g2.clipRect( 0, 0, arrowX + arrowWidth, height ); - FlatUIUtils.fillRoundRectangle( g2, 0, 0, width, height, focusWidth, arc ); + FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc ); g2.setClip( oldClip ); }