Skip to content

Commit

Permalink
Third pass for tonal text components
Browse files Browse the repository at this point in the history
For #400
  • Loading branch information
kirill-grouchnikov committed Jan 22, 2025
1 parent 2cfc2fb commit 7452754
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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.
Expand All @@ -1166,6 +1179,10 @@ public String toString() {
public static Set<ContainerColorTokensAssociationKind> values() {
return Collections.unmodifiableSet(values);
}

public ContainerColorTokensAssociationKind getFallback() {
return this.fallback;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7452754

Please sign in to comment.