Skip to content

Commit

Permalink
Second step to migrate tonal color scheme bundles to use per-state co…
Browse files Browse the repository at this point in the history
…ntainer tokens

For #400
  • Loading branch information
kirill-grouchnikov committed Jan 5, 2025
1 parent 694c280 commit c4db5c7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
package org.pushingpixels.radiance.theming.api;

import org.pushingpixels.radiance.theming.api.palette.ContainerColorTokens;
import org.pushingpixels.radiance.theming.api.palette.ExtendedContainerColorTokens;
import org.pushingpixels.radiance.theming.api.palette.RadianceColorScheme2;

import java.util.HashMap;
Expand Down Expand Up @@ -129,25 +128,6 @@ public ContainerColorTokens getContainerTokens(ComponentState componentState,
: this.mainColorScheme.getContainerTokens(inactiveContainerType);
}

public ExtendedContainerColorTokens getExtendedContainerTokens(ComponentState componentState,
RadianceThemingSlices.ContainerType inactiveContainerType) {
if (componentState.isDisabled()) {
return getExtendedContainerTokens(componentState.getEnabledMatch(), inactiveContainerType);
}

RadianceColorScheme2 registered = this.colorSchemeMap.get(
RadianceThemingSlices.ContainerColorTokensAssociationKind.DEFAULT).get(componentState);
if (registered != null) {
// If we're here, the component state is guaranteed to be active due to restrictions
// in registerColorScheme
return registered.getExtendedContainerTokens(componentState);
}

return componentState.isActive()
? this.mainColorScheme.getExtendedContainerTokens(componentState)
: this.mainColorScheme.getExtendedContainerTokens(inactiveContainerType);
}

public ContainerColorTokens getSystemContainerTokens(
RadianceThemingSlices.SystemContainerType systemContainerType) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,43 +530,6 @@ public final ContainerColorTokens getContainerTokens(Component comp,
return registered;
}

public final ExtendedContainerColorTokens getExtendedContainerTokens(Component comp,
ComponentState componentState, RadianceThemingSlices.ContainerType inactiveContainerType) {
if (componentState.isDisabled()) {
// TODO: TONAL - finalize this
// Use the enabled match, and alpha will be applied during rendering
return getExtendedContainerTokens(comp, componentState.getEnabledMatch(), inactiveContainerType);
}

// small optimization - lookup the decoration area only if there
// are decoration-specific scheme bundles.
if (this.tonalColorSchemeMap.size() > 1) {
RadianceThemingSlices.DecorationAreaType decorationAreaType = (comp == null) ?
RadianceThemingSlices.DecorationAreaType.NONE :
RadianceThemingCortex.ComponentOrParentChainScope.getDecorationType(comp);
if (this.tonalColorSchemeMap.containsKey(decorationAreaType)) {
ExtendedContainerColorTokens registered = this.tonalColorSchemeMap
.get(decorationAreaType).getExtendedContainerTokens(componentState, inactiveContainerType);
if (registered == null) {
throw new IllegalStateException("Color tokens shouldn't be null here. Please "
+ "report this issue");
}

return registered;
}
}

ExtendedContainerColorTokens registered = this.tonalColorSchemeMap
.get(RadianceThemingSlices.DecorationAreaType.NONE)
.getExtendedContainerTokens(componentState, inactiveContainerType);
if (registered == null) {
throw new IllegalStateException("Color tokens scheme shouldn't be null here. Please report " + "this issue");
}


return registered;
}

public final ContainerColorTokens getSystemContainerTokens(Component comp,
RadianceThemingSlices.SystemContainerType systemContainerType) {
// small optimization - lookup the decoration area only if there
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public void paintOverlay(Graphics2D graphics, Component comp,
RadianceSkin skin) {

Color shadowColor = (skin instanceof TonalSkin)
? RadianceColorSchemeUtilities.getExtendedContainerTokens(comp, ComponentState.ENABLED,
RadianceThemingSlices.ContainerType.NEUTRAL).getBaseContainerTokens()
? RadianceColorSchemeUtilities.getContainerTokens(comp,
ComponentState.ENABLED, RadianceThemingSlices.ContainerType.NEUTRAL)
.getContainerOutline()
:RadianceColorUtilities.deriveByBrightness(
RadianceColorUtilities.getBackgroundFillColor(comp), -0.4f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,6 @@ public interface RadianceColorScheme2 {

ContainerColorTokens getContainerTokensForState(ComponentState componentState);

default ExtendedContainerColorTokens getExtendedContainerTokens(ComponentState componentState) {
RadianceColorScheme2 me = this;
ContainerColorTokens stateTokens = getContainerTokensForState(componentState);

return new ExtendedContainerColorTokens() {
@Override
public Color getSurface() {
return me.getSurface();
}

@Override
public Color getSurfaceDim() {
return me.getSurfaceDim();
}

@Override
public Color getSurfaceBright() {
return me.getSurfaceBright();
}

@Override
public ContainerColorTokens getBaseContainerTokens() {
return stateTokens;
}
};
}

default ContainerColorTokens getContainerTokens(RadianceThemingSlices.ContainerType containerType) {
switch (containerType) {
case MUTED: return this.getMutedContainerTokens();
Expand All @@ -100,16 +73,6 @@ default ContainerColorTokens getContainerTokens(RadianceThemingSlices.ContainerT

ContainerColorTokens getSystemEmergencyContainerTokens();

default ExtendedContainerColorTokens getExtendedContainerTokens(RadianceThemingSlices.ContainerType containerType) {
switch (containerType) {
case MUTED: return this.getExtendedMutedContainerTokens();
case TONAL: return this.getExtendedTonalContainerTokens();
case PRIMARY: return this.getExtendedPrimaryContainerTokens();
case NEUTRAL:
default: return this.getExtendedNeutralContainerTokens();
}
}

default ExtendedContainerColorTokens getExtendedNeutralContainerTokens() {
return getExtendedContainerTokens(getNeutralContainerTokens());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.colorscheme.*;
import org.pushingpixels.radiance.theming.api.palette.ContainerColorTokens;
import org.pushingpixels.radiance.theming.api.palette.ExtendedContainerColorTokens;
import org.pushingpixels.radiance.theming.internal.painter.DecorationPainterUtils;

import javax.swing.*;
Expand Down Expand Up @@ -208,36 +207,6 @@ public static ContainerColorTokens getContainerTokens(Component component,
// return getColorizedScheme(orig, nonColorized, !componentState.isDisabled());
}

public static ExtendedContainerColorTokens getExtendedContainerTokens(Component component,
ComponentState componentState, RadianceThemingSlices.ContainerType inactiveContainerType) {
Component orig = component;
RadianceSkin skin = RadianceCoreUtilities.getSkin(component);
// special case - if the component is marked as flat and
// it is in the default state, or it is a button
// that is never painting its background - get the color scheme of the
// parent
boolean isButtonThatIsNeverPainted = ((component instanceof AbstractButton)
&& RadianceCoreUtilities.isComponentNeverPainted((AbstractButton) component));
if (isButtonThatIsNeverPainted
|| (!componentState.isActive()
&& (RadianceCoreUtilities.hasFlatAppearance(component, false)))) {
// TODO: TONAL - verify that we don't need to use the old logic.
// TODO: TONAL - colorization
return skin.getBackgroundExtendedContainerTokens(DecorationPainterUtils.getDecorationType(component));
// component = component.getParent();
}

if (skin == null) {
RadianceCoreUtilities.traceRadianceApiUsage(component,
"Radiance delegate used when Radiance is not the current LAF");
}
ExtendedContainerColorTokens nonColorized = skin.getExtendedContainerTokens(component,
componentState, inactiveContainerType);
// TODO: TONAL - colorization
return nonColorized;
// return getColorizedScheme(orig, nonColorized, !componentState.isDisabled());
}

/**
* Returns the color scheme of the component.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.palette.ContainerColorTokens;
import org.pushingpixels.radiance.theming.api.palette.ExtendedContainerColorTokens;
import org.pushingpixels.radiance.theming.api.palette.TonalSkin;
import org.pushingpixels.radiance.theming.internal.animation.ModificationAwareUI;
import org.pushingpixels.radiance.theming.internal.animation.StateTransitionTracker;
Expand Down Expand Up @@ -910,12 +909,16 @@ public static Color getStripedBackground(JComponent component, int rowIndex) {

RadianceSkin skin = RadianceCoreUtilities.getSkin(component);
if (skin instanceof TonalSkin) {
ExtendedContainerColorTokens colorTokens = skin.getExtendedContainerTokens(
component,
component.isEnabled() ? ComponentState.ENABLED : ComponentState.DISABLED_UNSELECTED,
RadianceThemingSlices.ContainerType.NEUTRAL);
return (rowIndex % 2 == 0) ? colorTokens.getSurface()
: colorTokens.getBaseContainerTokens().getContainerSurfaceLow();
if (rowIndex % 2 == 0) {
// Surface for even rows
RadianceThemingSlices.DecorationAreaType decorationAreaType =
RadianceThemingCortex.ComponentOrParentChainScope.getDecorationType(component);
return skin.getBackgroundExtendedContainerTokens(decorationAreaType).getSurface();
} else {
// Container surface low for odd rows
return skin.getContainerTokens(component, ComponentState.ENABLED,
RadianceThemingSlices.ContainerType.NEUTRAL).getContainerSurfaceLow();
}
} else {
RadianceColorScheme scheme = skin.getBackgroundColorScheme(
DecorationPainterUtils.getDecorationType(component));
Expand Down

0 comments on commit c4db5c7

Please sign in to comment.