From 745275443ad9ba9618c42c5339bb32fa0b7af5cf Mon Sep 17 00:00:00 2001 From: Kirill Grouchnikov Date: Wed, 22 Jan 2025 09:49:17 -0500 Subject: [PATCH] Third pass for tonal text components For #400 --- .../api/RadianceColorSchemeBundle2.java | 5 +++ .../theming/api/RadianceThemingSlices.java | 31 +++++++++++++---- .../theming/internal/utils/SkinUtilities.java | 34 ++++++++++++++----- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/theming/src/main/java/org/pushingpixels/radiance/theming/api/RadianceColorSchemeBundle2.java b/theming/src/main/java/org/pushingpixels/radiance/theming/api/RadianceColorSchemeBundle2.java index 7582a3cc0..c7b987b9b 100644 --- a/theming/src/main/java/org/pushingpixels/radiance/theming/api/RadianceColorSchemeBundle2.java +++ b/theming/src/main/java/org/pushingpixels/radiance/theming/api/RadianceColorSchemeBundle2.java @@ -257,6 +257,11 @@ public ContainerColorTokens getContainerTokens( return null; } + RadianceThemingSlices.ContainerColorTokensAssociationKind fallback = associationKind.getFallback(); + if (fallback != null) { + return getContainerTokens(fallback, componentState, allowFallback, inactiveContainerType); + } + return getContainerTokens(componentState, inactiveContainerType); } } diff --git a/theming/src/main/java/org/pushingpixels/radiance/theming/api/RadianceThemingSlices.java b/theming/src/main/java/org/pushingpixels/radiance/theming/api/RadianceThemingSlices.java index bb0cda2bf..aea8fc7c0 100644 --- a/theming/src/main/java/org/pushingpixels/radiance/theming/api/RadianceThemingSlices.java +++ b/theming/src/main/java/org/pushingpixels/radiance/theming/api/RadianceThemingSlices.java @@ -1106,13 +1106,26 @@ public final static class ContainerColorTokensAssociationKind { */ private String name; + /** + * Fallback for this association kind. This is used when no color scheme is associated with + * this kind. For example, {@link #HIGHLIGHT_TEXT} specifies that its fallback is + * {@link #HIGHLIGHT}. When the {@link JTextField} UI delegate is painting its selected + * part, it will try to use the color tokens associated with {@link #HIGHLIGHT_TEXT}. + * If none was registered, it will fall back to use the color tokens associated with + * {@link #HIGHLIGHT}, and if that is not registered as well, will use the color tokens + * associated with {@link #DEFAULT}. + */ + private ContainerColorTokensAssociationKind fallback; + /** * Creates a new association kind. * * @param name Association kind name. */ - public ContainerColorTokensAssociationKind(String name) { + public ContainerColorTokensAssociationKind(String name, + ContainerColorTokensAssociationKind fallback) { this.name = name; + this.fallback = fallback; values.add(this); } @@ -1125,38 +1138,38 @@ public String toString() { * The default visual area that is used for the inner part of most controls. */ public static final ContainerColorTokensAssociationKind DEFAULT = - new ContainerColorTokensAssociationKind("default"); + new ContainerColorTokensAssociationKind("default", null); /** * Fill visual area of the tabs. */ public static final ContainerColorTokensAssociationKind TAB = - new ContainerColorTokensAssociationKind("tab"); + new ContainerColorTokensAssociationKind("tab", DEFAULT); /** * Visual area of marks. Used for painting check marks of checkboxes and radio buttons, as * well as arrow icons of combo boxes, spinners and more. */ public static final ContainerColorTokensAssociationKind MARK = - new ContainerColorTokensAssociationKind("mark"); + new ContainerColorTokensAssociationKind("mark", DEFAULT); /** * Highlight visual areas for lists, tables, trees and menus. */ public static final ContainerColorTokensAssociationKind HIGHLIGHT = - new ContainerColorTokensAssociationKind("highlight"); + new ContainerColorTokensAssociationKind("highlight", DEFAULT); /** * Highlight visual areas for text components. */ public static final ContainerColorTokensAssociationKind HIGHLIGHT_TEXT = - new ContainerColorTokensAssociationKind("highlight_text"); + new ContainerColorTokensAssociationKind("highlight_text", HIGHLIGHT); /** * Visual area of separators. */ public static final ContainerColorTokensAssociationKind SEPARATOR = - new ContainerColorTokensAssociationKind("separator"); + new ContainerColorTokensAssociationKind("separator", DEFAULT); /** * Returns all available association kinds. @@ -1166,6 +1179,10 @@ public String toString() { public static Set values() { return Collections.unmodifiableSet(values); } + + public ContainerColorTokensAssociationKind getFallback() { + return this.fallback; + } } /** diff --git a/theming/src/main/java/org/pushingpixels/radiance/theming/internal/utils/SkinUtilities.java b/theming/src/main/java/org/pushingpixels/radiance/theming/internal/utils/SkinUtilities.java index c3f6ea2df..9a798cd1d 100644 --- a/theming/src/main/java/org/pushingpixels/radiance/theming/internal/utils/SkinUtilities.java +++ b/theming/src/main/java/org/pushingpixels/radiance/theming/internal/utils/SkinUtilities.java @@ -37,6 +37,8 @@ import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme; import org.pushingpixels.radiance.theming.api.inputmap.InputMapSet; import org.pushingpixels.radiance.theming.api.inputmap.RadianceInputMapUtilities; +import org.pushingpixels.radiance.theming.api.palette.ContainerColorTokens; +import org.pushingpixels.radiance.theming.api.palette.TonalSkin; import org.pushingpixels.radiance.theming.api.renderer.RadianceDefaultListCellRenderer; import org.pushingpixels.radiance.theming.internal.blade.BladeIconUtils; import org.pushingpixels.radiance.theming.internal.utils.border.*; @@ -107,17 +109,31 @@ public static void addCustomEntriesToTable(UIDefaults uiDefaults, int lcb = RadianceColorUtilities.getColorBrightness(lineColor.getRGB()); Color lineBwColor = new ColorUIResource(new Color(lcb, lcb, lcb)); - RadianceColorScheme textHighlightColorScheme = skin.getColorScheme( - (Component) null, RadianceThemingSlices.ColorSchemeAssociationKind.HIGHLIGHT_TEXT, - ComponentState.SELECTED); - if (textHighlightColorScheme == null) { - textHighlightColorScheme = skin.getColorScheme(null, - ComponentState.ROLLOVER_SELECTED); - } - Color selectionTextBackgroundColor = new ColorUIResource( + Color selectionTextBackgroundColor; + Color selectionTextForegroundColor; + if (skin instanceof TonalSkin) { + ContainerColorTokens textHighlightColorTokens = skin.getContainerTokens(null, + RadianceThemingSlices.ContainerColorTokensAssociationKind.HIGHLIGHT_TEXT, + ComponentState.SELECTED, RadianceThemingSlices.ContainerType.TONAL); + if (textHighlightColorTokens == null) { + textHighlightColorTokens = skin.getContainerTokens(null, + ComponentState.ROLLOVER_SELECTED, RadianceThemingSlices.ContainerType.TONAL); + } + selectionTextBackgroundColor = new ColorUIResource( + textHighlightColorTokens.getContainerSurfaceLow()); + selectionTextForegroundColor = new ColorUIResource( + textHighlightColorTokens.getOnContainer()); + } else { + RadianceColorScheme textHighlightColorScheme = skin.getColorScheme((Component) null, + RadianceThemingSlices.ColorSchemeAssociationKind.HIGHLIGHT_TEXT, ComponentState.SELECTED); + if (textHighlightColorScheme == null) { + textHighlightColorScheme = skin.getColorScheme(null, ComponentState.ROLLOVER_SELECTED); + } + selectionTextBackgroundColor = new ColorUIResource( textHighlightColorScheme.getSelectionBackgroundColor()); - Color selectionTextForegroundColor = new ColorUIResource( + selectionTextForegroundColor = new ColorUIResource( textHighlightColorScheme.getSelectionForegroundColor()); + } RadianceColorScheme highlightColorScheme = skin.getColorScheme( (Component) null, RadianceThemingSlices.ColorSchemeAssociationKind.HIGHLIGHT,