Skip to content

Commit

Permalink
Fourth 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 6, 2025
1 parent ea992e0 commit d3c7b67
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,46 @@ public void registerColorScheme(RadianceColorScheme2 stateColorScheme, Component
states);
}

/**
* Registers the color scheme to be used for the specified visual area of
* controls under the specified states. For example, if the light orange
* scheme has to be used for gradient fill for rollover selected and rollover
* controls, the parameters would be:
*
* <ul>
* <li><code>scheme</code>=light orange scheme</li>
* <li>
* <code>associationKind</code>={@link RadianceThemingSlices.ColorSchemeAssociationKind#FILL}</li>
* <li>
* <code>states</code>={@link ComponentState#ROLLOVER_SELECTED},
* {@link ComponentState#ROLLOVER_UNSELECTED}</li>
* </ul>
*
* @param scheme Color scheme.
* @param associationKind Color scheme association kind that specifies the visual areas
* of controls to be painted with this color scheme.
* @param states Component states that further restrict the usage of the
* specified color scheme.
*/
public void registerColorScheme(RadianceColorScheme2 scheme,
RadianceThemingSlices.ContainerColorTokensAssociationKind associationKind,
ComponentState... states) {
if (scheme == null) {
throw new IllegalArgumentException("Cannot pass null color scheme");
}

if ((states == null) || (states.length == 0)) {
throw new IllegalArgumentException("Must pass at least one state");
}

for (ComponentState state : states) {
if (state.isDisabled() || !state.isActive()) {
throw new IllegalArgumentException("Only active states can have custom color schemes");
}
this.colorTokensForActiveStates.get(associationKind).put(state, scheme.getActiveContainerTokens());
}
}

/**
* Returns the color scheme of the specified component in the specified
* component state.
Expand Down Expand Up @@ -149,46 +189,6 @@ public RadianceColorScheme2 getMainColorScheme() {
return this.mainColorScheme;
}

/**
* Registers the color scheme to be used for the specified visual area of
* controls under the specified states. For example, if the light orange
* scheme has to be used for gradient fill for rollover selected and rollover
* controls, the parameters would be:
*
* <ul>
* <li><code>scheme</code>=light orange scheme</li>
* <li>
* <code>associationKind</code>={@link RadianceThemingSlices.ColorSchemeAssociationKind#FILL}</li>
* <li>
* <code>states</code>={@link ComponentState#ROLLOVER_SELECTED},
* {@link ComponentState#ROLLOVER_UNSELECTED}</li>
* </ul>
*
* @param scheme Color scheme.
* @param associationKind Color scheme association kind that specifies the visual areas
* of controls to be painted with this color scheme.
* @param states Component states that further restrict the usage of the
* specified color scheme.
*/
public void registerColorScheme(RadianceColorScheme2 scheme,
RadianceThemingSlices.ContainerColorTokensAssociationKind associationKind,
ComponentState... states) {
if (scheme == null) {
throw new IllegalArgumentException("Cannot pass null color scheme");
}

if ((states == null) || (states.length == 0)) {
throw new IllegalArgumentException("Must pass at least one state");
}

for (ComponentState state : states) {
if (state.isDisabled() || !state.isActive()) {
throw new IllegalArgumentException("Only active states can have custom color schemes");
}
this.colorTokensForActiveStates.get(associationKind).put(state, scheme.getActiveContainerTokens());
}
}

/**
* Returns the color scheme to be used for painting the specified visual
* area of the component under the specified component state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum ActiveStatesContainerType {
}

private static ContainerColorTokens getContainerTokens(
DynamicScheme dynamicScheme, PaletteContainerColorsResolver tonalContainerColorResolver) {
DynamicScheme dynamicScheme, SchemeContainerColorsResolver tonalContainerColorResolver) {

return new ContainerColorTokens() {
@Override
Expand Down Expand Up @@ -134,44 +134,44 @@ public static RadianceColorScheme2 getLightColorScheme(
/* systemSuccessPalette */ palettes.getSystemSuccessPalette(),
/* systemEmergencyPalette */ palettes.getSystemEmergencyPalette());

PaletteColorResolver paletteColorResolver = PaletteResolverUtils.getPaletteColorResolver();
SchemeColorResolver schemeColorResolver = SchemeResolverUtils.getSchemeColorResolver();

ContainerColorTokens neutralContainerTokens = getContainerTokens(
lightScheme, paletteColorResolver.getNeutralContainerResolver());
lightScheme, schemeColorResolver.getNeutralContainerResolver());
ContainerColorTokens mutedContainerTokens = getContainerTokens(
lightScheme, paletteColorResolver.getMutedContainerResolver());
lightScheme, schemeColorResolver.getMutedContainerResolver());
ContainerColorTokens tonalContainerTokens = getContainerTokens(
lightScheme, paletteColorResolver.getTonalContainerResolver());
lightScheme, schemeColorResolver.getTonalContainerResolver());
ContainerColorTokens primaryContainerTokens = getContainerTokens(
lightScheme, paletteColorResolver.getPrimaryContainerResolver());
lightScheme, schemeColorResolver.getPrimaryContainerResolver());

ContainerColorTokens systemInfoContainerTokens = getContainerTokens(
lightScheme, paletteColorResolver.getSystemInfoContainerResolver());
lightScheme, schemeColorResolver.getSystemInfoContainerResolver());
ContainerColorTokens systemWarningContainerTokens = getContainerTokens(
lightScheme, paletteColorResolver.getSystemWarningContainerResolver());
lightScheme, schemeColorResolver.getSystemWarningContainerResolver());
ContainerColorTokens systemErrorContainerTokens = getContainerTokens(
lightScheme, paletteColorResolver.getSystemErrorContainerResolver());
lightScheme, schemeColorResolver.getSystemErrorContainerResolver());
ContainerColorTokens systemSuccessContainerTokens = getContainerTokens(
lightScheme, paletteColorResolver.getSystemSuccessContainerResolver());
lightScheme, schemeColorResolver.getSystemSuccessContainerResolver());
ContainerColorTokens systemEmergencyContainerTokens = getContainerTokens(
lightScheme, paletteColorResolver.getSystemEmergencyContainerResolver());
lightScheme, schemeColorResolver.getSystemEmergencyContainerResolver());

return new RadianceColorScheme2() {
private HashMap<ComponentState, ContainerColorTokens> stateTokens = new HashMap<>();

@Override
public Color getSurface() {
return paletteColorResolver.getSurface(lightScheme);
return schemeColorResolver.getSurface(lightScheme);
}

@Override
public Color getSurfaceDim() {
return paletteColorResolver.getSurfaceDim(lightScheme);
return schemeColorResolver.getSurfaceDim(lightScheme);
}

@Override
public Color getSurfaceBright() {
return paletteColorResolver.getSurfaceBright(lightScheme);
return schemeColorResolver.getSurfaceBright(lightScheme);
}

@Override
Expand Down Expand Up @@ -306,44 +306,44 @@ public static RadianceColorScheme2 getDarkColorScheme(
/* systemSuccessPalette */ palettes.getSystemSuccessPalette(),
/* systemEmergencyPalette */ palettes.getSystemEmergencyPalette());

PaletteColorResolver paletteColorResolver = PaletteResolverUtils.getPaletteColorResolver();
SchemeColorResolver schemeColorResolver = SchemeResolverUtils.getSchemeColorResolver();

ContainerColorTokens neutralContainerTokens = getContainerTokens(
darkScheme, paletteColorResolver.getNeutralContainerResolver());
darkScheme, schemeColorResolver.getNeutralContainerResolver());
ContainerColorTokens mutedContainerTokens = getContainerTokens(
darkScheme, paletteColorResolver.getMutedContainerResolver());
darkScheme, schemeColorResolver.getMutedContainerResolver());
ContainerColorTokens tonalContainerTokens = getContainerTokens(
darkScheme, paletteColorResolver.getTonalContainerResolver());
darkScheme, schemeColorResolver.getTonalContainerResolver());
ContainerColorTokens primaryContainerTokens = getContainerTokens(
darkScheme, paletteColorResolver.getPrimaryContainerResolver());
darkScheme, schemeColorResolver.getPrimaryContainerResolver());

ContainerColorTokens systemInfoContainerTokens = getContainerTokens(
darkScheme, paletteColorResolver.getSystemInfoContainerResolver());
darkScheme, schemeColorResolver.getSystemInfoContainerResolver());
ContainerColorTokens systemWarningContainerTokens = getContainerTokens(
darkScheme, paletteColorResolver.getSystemWarningContainerResolver());
darkScheme, schemeColorResolver.getSystemWarningContainerResolver());
ContainerColorTokens systemErrorContainerTokens = getContainerTokens(
darkScheme, paletteColorResolver.getSystemErrorContainerResolver());
darkScheme, schemeColorResolver.getSystemErrorContainerResolver());
ContainerColorTokens systemSuccessContainerTokens = getContainerTokens(
darkScheme, paletteColorResolver.getSystemSuccessContainerResolver());
darkScheme, schemeColorResolver.getSystemSuccessContainerResolver());
ContainerColorTokens systemEmergencyContainerTokens = getContainerTokens(
darkScheme, paletteColorResolver.getSystemEmergencyContainerResolver());
darkScheme, schemeColorResolver.getSystemEmergencyContainerResolver());

return new RadianceColorScheme2() {
private HashMap<ComponentState, ContainerColorTokens> stateTokens = new HashMap<>();

@Override
public Color getSurface() {
return paletteColorResolver.getSurface(darkScheme);
return schemeColorResolver.getSurface(darkScheme);
}

@Override
public Color getSurfaceDim() {
return paletteColorResolver.getSurfaceDim(darkScheme);
return schemeColorResolver.getSurfaceDim(darkScheme);
}

@Override
public Color getSurfaceBright() {
return paletteColorResolver.getSurfaceBright(darkScheme);
return schemeColorResolver.getSurfaceBright(darkScheme);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@

import java.awt.*;

public interface PaletteColorResolver {
public interface SchemeColorResolver {
Color getSurface(DynamicScheme dynamicScheme);
Color getSurfaceDim(DynamicScheme dynamicScheme);
Color getSurfaceBright(DynamicScheme dynamicScheme);

PaletteContainerColorsResolver getNeutralContainerResolver();
PaletteContainerColorsResolver getMutedContainerResolver();
PaletteContainerColorsResolver getTonalContainerResolver();
PaletteContainerColorsResolver getPrimaryContainerResolver();
SchemeContainerColorsResolver getNeutralContainerResolver();
SchemeContainerColorsResolver getMutedContainerResolver();
SchemeContainerColorsResolver getTonalContainerResolver();
SchemeContainerColorsResolver getPrimaryContainerResolver();

PaletteContainerColorsResolver getSystemInfoContainerResolver();
PaletteContainerColorsResolver getSystemWarningContainerResolver();
PaletteContainerColorsResolver getSystemErrorContainerResolver();
PaletteContainerColorsResolver getSystemSuccessContainerResolver();
PaletteContainerColorsResolver getSystemEmergencyContainerResolver();
SchemeContainerColorsResolver getSystemInfoContainerResolver();
SchemeContainerColorsResolver getSystemWarningContainerResolver();
SchemeContainerColorsResolver getSystemErrorContainerResolver();
SchemeContainerColorsResolver getSystemSuccessContainerResolver();
SchemeContainerColorsResolver getSystemEmergencyContainerResolver();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import java.awt.*;

public interface PaletteContainerColorsResolver {
public interface SchemeContainerColorsResolver {
Color getContainerSurfaceLowest(DynamicScheme dynamicScheme);
Color getContainerSurfaceLow(DynamicScheme dynamicScheme);
Color getContainerSurface(DynamicScheme dynamicScheme);
Expand Down
Loading

0 comments on commit d3c7b67

Please sign in to comment.