From 3f659fb142b0a5c10782a1566492e802b2885cf6 Mon Sep 17 00:00:00 2001 From: Kirill Grouchnikov Date: Thu, 5 Dec 2024 20:03:56 -0500 Subject: [PATCH] Fix animations on tonal radio buttons and checkboxes For #400 --- .../internal/blade/BladeIconUtils.java | 22 ++++++++----------- .../theming/internal/blade/BladeUtils.java | 10 ++++----- .../internal/ui/RadianceCheckBoxUI.java | 3 ++- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/theming/src/main/java/org/pushingpixels/radiance/theming/internal/blade/BladeIconUtils.java b/theming/src/main/java/org/pushingpixels/radiance/theming/internal/blade/BladeIconUtils.java index 1562f6933..62285593b 100644 --- a/theming/src/main/java/org/pushingpixels/radiance/theming/internal/blade/BladeIconUtils.java +++ b/theming/src/main/java/org/pushingpixels/radiance/theming/internal/blade/BladeIconUtils.java @@ -63,13 +63,13 @@ private static class SimplisticSoftBorderReverseFillPainter extends FractionBase private SimplisticSoftBorderReverseFillPainter() { super("Simplistic Soft Border Reverse", - new float[] {0.0f, 0.5f, 1.0f}, - new ColorSchemeSingleColorQuery[] { - ColorSchemeSingleColorQuery.ULTRALIGHT, - scheme -> RadianceColorUtilities.getInterpolatedColor( - scheme.getMidColor(), scheme.getUltraLightColor(), 0.5f), - ColorSchemeSingleColorQuery.MID - } + new float[] {0.0f, 0.5f, 1.0f}, + new ColorSchemeSingleColorQuery[] { + ColorSchemeSingleColorQuery.ULTRALIGHT, + scheme -> RadianceColorUtilities.getInterpolatedColor( + scheme.getMidColor(), scheme.getUltraLightColor(), 0.5f), + ColorSchemeSingleColorQuery.MID + } ); } } @@ -157,14 +157,12 @@ public static void drawCheckBox(Graphics2D g, JComponent component, RadianceFill contourDim, contourDim, cornerRadius, null, 0.0f); - RadianceFillPainter finalFillPainter = componentState.isActive() ? fillPainter - : SimplisticSoftBorderReverseFillPainter.INSTANCE; graphics1X.setComposite(getAlphaComposite(alpha)); Shape contourFill = RadianceOutlineUtilities.getBaseOutline( component.getComponentOrientation(), contourDim + 1, contourDim + 1, cornerRadius, null, 0.5f); - finalFillPainter.paintContourBackground(graphics1X, component, + fillPainter.paintContourBackground(graphics1X, component, contourDim, contourDim, contourFill, renderColorTokens); @@ -292,10 +290,8 @@ public static void drawRadioButton(Graphics2D g, AbstractButton button, Radiance int contourDim = scaledWidth; Shape contourOuter = new Ellipse2D.Float(0.0f, 0.0f, contourDim, contourDim); - RadianceFillPainter finalFillPainter = componentState.isActive() ? fillPainter - : SimplisticSoftBorderReverseFillPainter.INSTANCE; graphics1X.setComposite(getAlphaComposite(alpha)); - finalFillPainter.paintContourBackground(graphics1X, button, + fillPainter.paintContourBackground(graphics1X, button, contourDim, contourDim, new Ellipse2D.Float(0.5f, 0.5f, contourDim, contourDim), renderColorTokens); diff --git a/theming/src/main/java/org/pushingpixels/radiance/theming/internal/blade/BladeUtils.java b/theming/src/main/java/org/pushingpixels/radiance/theming/internal/blade/BladeUtils.java index f17cf550c..f727b265c 100644 --- a/theming/src/main/java/org/pushingpixels/radiance/theming/internal/blade/BladeUtils.java +++ b/theming/src/main/java/org/pushingpixels/radiance/theming/internal/blade/BladeUtils.java @@ -296,7 +296,6 @@ public static void populateColorTokens( ContainerRenderColorTokens currColorTokens = (treatEnabledAsActive && (currState == ComponentState.ENABLED)) ? RadianceColorSchemeUtilities.getActiveRenderColorTokens(component, currState) : RadianceColorSchemeUtilities.getRenderColorTokens(component, associationKind, currState); - Color containerLowest = currColorTokens.getContainerColorTokens().getContainerLowest(); Color containerLow = currColorTokens.getContainerColorTokens().getContainerLow(); Color container = currColorTokens.getContainerColorTokens().getContainer(); @@ -314,7 +313,8 @@ public static void populateColorTokens( if (!currState.isDisabled() && (activeStates != null) && (activeStates.size() > 1)) { for (Map.Entry activeEntry : activeStates.entrySet()) { - if (activeEntry.getKey() == currState) { + ComponentState activeState = activeEntry.getKey(); + if (activeState == currState) { // Already accounted for the currently active state continue; } @@ -324,9 +324,9 @@ public static void populateColorTokens( continue; } // Get the color scheme that matches the contribution state - ContainerRenderColorTokens contributionColorTokens = (treatEnabledAsActive && (activeEntry.getKey() == ComponentState.ENABLED)) - ? RadianceColorSchemeUtilities.getActiveRenderColorTokens(component, activeEntry.getKey()) - : RadianceColorSchemeUtilities.getRenderColorTokens(component, associationKind, activeEntry.getKey()); + ContainerRenderColorTokens contributionColorTokens = (treatEnabledAsActive && (activeState == ComponentState.ENABLED)) + ? RadianceColorSchemeUtilities.getActiveRenderColorTokens(component, activeState) + : RadianceColorSchemeUtilities.getRenderColorTokens(component, associationKind, activeState); // And interpolate the colors containerLowest = RadianceColorUtilities.getInterpolatedColor(containerLowest, diff --git a/theming/src/main/java/org/pushingpixels/radiance/theming/internal/ui/RadianceCheckBoxUI.java b/theming/src/main/java/org/pushingpixels/radiance/theming/internal/ui/RadianceCheckBoxUI.java index d4fbeb944..e12b38972 100644 --- a/theming/src/main/java/org/pushingpixels/radiance/theming/internal/ui/RadianceCheckBoxUI.java +++ b/theming/src/main/java/org/pushingpixels/radiance/theming/internal/ui/RadianceCheckBoxUI.java @@ -120,7 +120,8 @@ public void paintIcon(Component c, Graphics g, int x, int y) { // Populate color schemes based on the current transition state of the check box. BladeUtils.populateColorTokens(mutableRenderColorTokens, button, modelStateInfo, - currState, RadianceThemingSlices.ContainerColorTokensAssociationKind.MARK, false); + currState, RadianceThemingSlices.ContainerColorTokensAssociationKind.MARK, + false); Graphics2D graphics = (Graphics2D) g.create(); graphics.translate(x, y);