Skip to content

Commit

Permalink
Completing the first pass for handling disabled tonal states
Browse files Browse the repository at this point in the history
For #400
  • Loading branch information
kirill-grouchnikov committed Dec 3, 2024
1 parent 9401934 commit a40dd2c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
* {@link ComponentState#ENABLED} will fall back to the enabled color scheme.
* The rest of the states will fall back to the active color scheme. To change
* the fallback behavior pass a non-null fallback color scheme to the
* {@link ComponentState#ComponentState(String, ComponentState, RadianceThemingSlices.ComponentStateFacet[], RadianceThemingSlices.ComponentStateFacet[])}
* {@link ComponentState#ComponentState(String, ComponentState, ComponentState, RadianceThemingSlices.ComponentStateFacet[], RadianceThemingSlices.ComponentStateFacet[])}
* constructor as the second parameter.
* </p>
*
Expand All @@ -161,65 +161,25 @@
public final class ComponentState {
private static Set<ComponentState> allStates = new HashSet<>();

/**
* Disabled default. Used for disabled buttons that have been marked as
* <code>default</code> with {@link JRootPane#setDefaultButton(JButton)}
* API.
*/
public static final ComponentState DISABLED_DEFAULT = new ComponentState(
"disabled default",
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.DEFAULT},
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE});

/**
* Default. Used for enabled buttons that have been marked as
* <code>default</code> with {@link JRootPane#setDefaultButton(JButton)}
* API.
*/
public static final ComponentState DEFAULT = new ComponentState("default",
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.DEFAULT,
RadianceThemingSlices.ComponentStateFacet.ENABLE}, null);

/**
* Disabled selected.
*/
public static final ComponentState DISABLED_SELECTED = new ComponentState(
"disabled selected",
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.SELECTION},
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE});

/**
* Disabled and not selected.
*/
public static final ComponentState DISABLED_UNSELECTED = new ComponentState(
"disabled unselected", null, new RadianceThemingSlices.ComponentStateFacet[]{
RadianceThemingSlices.ComponentStateFacet.ENABLE, RadianceThemingSlices.ComponentStateFacet.SELECTION});

/**
* Disabled and indeterminate.
*/
public static final ComponentState DISABLED_INDETERMINATE = new ComponentState(
"disabled indeterminate",
ComponentState.DISABLED_SELECTED,
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.INDETERMINATE},
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE});

/**
* Disabled and determinate.
*/
public static final ComponentState DISABLED_DETERMINATE = new ComponentState(
"disabled determinate",
ComponentState.DISABLED_SELECTED,
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.DETERMINATE},
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE});
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.DEFAULT,
RadianceThemingSlices.ComponentStateFacet.ENABLE}, null);

/**
* Disabled and mixed.
* Disabled default. Used for disabled buttons that have been marked as
* <code>default</code> with {@link JRootPane#setDefaultButton(JButton)}
* API.
*/
public static final ComponentState DISABLED_MIXED = new ComponentState(
"disabled mixed",
ComponentState.DISABLED_SELECTED,
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.MIX},
public static final ComponentState DISABLED_DEFAULT = new ComponentState(
"disabled default",
null,
DEFAULT,
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.DEFAULT},
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE});

/**
Expand All @@ -245,6 +205,7 @@ public final class ComponentState {
public static final ComponentState PRESSED_MIXED = new ComponentState(
"pressed mixed",
ComponentState.PRESSED_SELECTED,
null,
new RadianceThemingSlices.ComponentStateFacet[]{
RadianceThemingSlices.ComponentStateFacet.PRESS, RadianceThemingSlices.ComponentStateFacet.ENABLE,
RadianceThemingSlices.ComponentStateFacet.MIX},
Expand Down Expand Up @@ -283,6 +244,7 @@ public final class ComponentState {
public static final ComponentState ROLLOVER_MIXED = new ComponentState(
"rollover mixed",
ComponentState.ROLLOVER_SELECTED,
null,
new RadianceThemingSlices.ComponentStateFacet[]{
RadianceThemingSlices.ComponentStateFacet.MIX,
RadianceThemingSlices.ComponentStateFacet.ROLLOVER, RadianceThemingSlices.ComponentStateFacet.ENABLE},
Expand Down Expand Up @@ -313,6 +275,7 @@ public final class ComponentState {
public static final ComponentState DETERMINATE = new ComponentState(
"Determinate",
ComponentState.SELECTED,
null,
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE,
RadianceThemingSlices.ComponentStateFacet.DETERMINATE},
null);
Expand All @@ -323,6 +286,7 @@ public final class ComponentState {
public static final ComponentState INDETERMINATE = new ComponentState(
"Indeterminate",
ComponentState.SELECTED,
null,
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE,
RadianceThemingSlices.ComponentStateFacet.INDETERMINATE},
null);
Expand All @@ -333,6 +297,7 @@ public final class ComponentState {
public static final ComponentState MIXED = new ComponentState(
"Mixed",
ComponentState.SELECTED,
null,
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE,
RadianceThemingSlices.ComponentStateFacet.MIX},
null);
Expand All @@ -343,6 +308,53 @@ public final class ComponentState {
public static final ComponentState ENABLED = new ComponentState("enabled",
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE},
null);
/**
* Disabled selected.
*/
public static final ComponentState DISABLED_SELECTED = new ComponentState(
"disabled selected",
null,
ComponentState.SELECTED,
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.SELECTION},
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE});

/**
* Disabled and not selected.
*/
public static final ComponentState DISABLED_UNSELECTED = new ComponentState(
"disabled unselected", null, ComponentState.ENABLED, null, new RadianceThemingSlices.ComponentStateFacet[]{
RadianceThemingSlices.ComponentStateFacet.ENABLE, RadianceThemingSlices.ComponentStateFacet.SELECTION});

/**
* Disabled and indeterminate.
*/
public static final ComponentState DISABLED_INDETERMINATE = new ComponentState(
"disabled indeterminate",
ComponentState.DISABLED_SELECTED,
ComponentState.INDETERMINATE,
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.INDETERMINATE},
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE});

/**
* Disabled and determinate.
*/
public static final ComponentState DISABLED_DETERMINATE = new ComponentState(
"disabled determinate",
ComponentState.DISABLED_SELECTED,
ComponentState.DETERMINATE,
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.DETERMINATE},
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE});

/**
* Disabled and mixed.
*/
public static final ComponentState DISABLED_MIXED = new ComponentState(
"disabled mixed",
ComponentState.DISABLED_SELECTED,
ComponentState.MIXED,
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.MIX},
new RadianceThemingSlices.ComponentStateFacet[]{RadianceThemingSlices.ComponentStateFacet.ENABLE});


/**
* Facets that are turned on for this state. For example,
Expand All @@ -364,6 +376,8 @@ public final class ComponentState {

private ComponentState hardFallback;

private ComponentState enabledMatch;

/**
* Creates a new component state.
*
Expand All @@ -380,7 +394,7 @@ public final class ComponentState {
*/
public ComponentState(String name, RadianceThemingSlices.ComponentStateFacet[] facetsOn,
RadianceThemingSlices.ComponentStateFacet[] facetsOff) {
this(name, null, facetsOn, facetsOff);
this(name, null, null, facetsOn, facetsOff);
}

/**
Expand All @@ -400,14 +414,15 @@ public ComponentState(String name, RadianceThemingSlices.ComponentStateFacet[] f
* {@link RadianceThemingSlices.ComponentStateFacet#ENABLE} and
* {@link RadianceThemingSlices.ComponentStateFacet#SELECTION}.
*/
public ComponentState(String name, ComponentState hardFallback,
public ComponentState(String name, ComponentState hardFallback, ComponentState enabledMatch,
RadianceThemingSlices.ComponentStateFacet[] facetsOn, RadianceThemingSlices.ComponentStateFacet[] facetsOff) {
if (name == null) {
throw new IllegalArgumentException(
"Component state name must be non-null");
}
this.name = name;
this.hardFallback = hardFallback;
this.enabledMatch = enabledMatch;
this.facetsTurnedOn = new HashSet<>();
if (facetsOn != null) {
Collections.addAll(this.facetsTurnedOn, facetsOn);
Expand Down Expand Up @@ -755,7 +770,11 @@ public ComponentState bestFit(Collection<ComponentState> states) {
}

public ComponentState getHardFallback() {
return hardFallback;
return this.hardFallback;
}

public ComponentState getEnabledMatch() {
return this.enabledMatch;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ public final RadianceColorScheme getColorScheme(Component comp,

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

// small optimization - lookup the decoration area only if there
// are decoration-specific scheme bundles.
if (this.tonalColorSchemeMap.size() > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,21 @@ public ContainerRenderColorTokens getPrimaryContainerTokens() {

@Override
public ContainerRenderColorTokens getStateRenderTokens(ComponentState componentState) {
if (componentState.isDisabled()) {
// TODO: TONAL - finalize this
return getStateRenderTokens(componentState.getEnabledMatch());
}

// TODO: TONAL - configurable at the skin definition level
ContainerRenderColorTokens defaultActive = this.getTonalContainerTokens();
if (componentState == ComponentState.PRESSED_UNSELECTED) {
// surface dim on top of muted
if (!stateTokens.containsKey(componentState)) {
stateTokens.put(componentState, getPressedUnselectedTokens(this,
defaultActive));
}
return stateTokens.get(componentState);
}
if (componentState == ComponentState.PRESSED_SELECTED) {
// surface dim on top of active
if (!stateTokens.containsKey(componentState)) {
stateTokens.put(componentState, getPressedSelectedTokens(this,
defaultActive));
Expand All @@ -365,7 +368,6 @@ public ContainerRenderColorTokens getStateRenderTokens(ComponentState componentS
return stateTokens.get(componentState);
}
if (componentState == ComponentState.ROLLOVER_SELECTED) {
// surface bright on top of active
if (!stateTokens.containsKey(componentState)) {
stateTokens.put(componentState, getRolloverSelectedTokens(this,
defaultActive));
Expand All @@ -381,10 +383,6 @@ public ContainerRenderColorTokens getStateRenderTokens(ComponentState componentS
if (componentState == ComponentState.ENABLED) {
return getMutedContainerTokens();
}
if (componentState.isDisabled()) {
// TODO: TONAL - revisit
return getMutedContainerTokens();
}
return defaultActive;
}
};
Expand Down Expand Up @@ -690,18 +688,21 @@ public ContainerRenderColorTokens getPrimaryContainerTokens() {

@Override
public ContainerRenderColorTokens getStateRenderTokens(ComponentState componentState) {
if (componentState.isDisabled()) {
// TODO: TONAL - finalize this
return getStateRenderTokens(componentState.getEnabledMatch());
}

// TODO: TONAL - configurable at the skin definition level
ContainerRenderColorTokens defaultActive = this.getTonalContainerTokens();
if (componentState == ComponentState.PRESSED_UNSELECTED) {
// surface dim on top of muted
if (!stateTokens.containsKey(componentState)) {
stateTokens.put(componentState, getPressedUnselectedTokens(this,
defaultActive));
}
return stateTokens.get(componentState);
}
if (componentState == ComponentState.PRESSED_SELECTED) {
// surface dim on top of active
if (!stateTokens.containsKey(componentState)) {
stateTokens.put(componentState, getPressedSelectedTokens(this,
defaultActive));
Expand All @@ -719,7 +720,6 @@ public ContainerRenderColorTokens getStateRenderTokens(ComponentState componentS
return stateTokens.get(componentState);
}
if (componentState == ComponentState.ROLLOVER_SELECTED) {
// surface bright on top of active
if (!stateTokens.containsKey(componentState)) {
stateTokens.put(componentState, getRolloverSelectedTokens(this,
defaultActive));
Expand All @@ -735,10 +735,6 @@ public ContainerRenderColorTokens getStateRenderTokens(ComponentState componentS
if (componentState == ComponentState.ENABLED) {
return getMutedContainerTokens();
}
if (componentState.isDisabled()) {
// TODO: TONAL - revisit
return getMutedContainerTokens();
}
return defaultActive;
}
};
Expand Down

0 comments on commit a40dd2c

Please sign in to comment.