Skip to content

Commit

Permalink
Third step to migrate tonal color scheme bundles to use per-state con…
Browse files Browse the repository at this point in the history
…tainer tokens

For #400
  • Loading branch information
kirill-grouchnikov committed Jan 5, 2025
1 parent c4db5c7 commit e52e948
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame.setDefaultLookAndFeelDecorated(true);
RadianceThemingCortex.GlobalScope.setFocusKind(RadianceThemingSlices.FocusKind.NONE);
RadianceThemingCortex.GlobalScope.setSkin(new OfficeSilver2007Skin());
RadianceThemingCortex.GlobalScope.setSkin(new OfficeSilver2007Skin.OfficeSilver2007TonalSkin());
new ControlStatesExtended().setVisible(true);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,29 @@
*
* @author Kirill Grouchnikov
* @see RadianceThemingSlices.DecorationAreaType
* @see RadianceThemingSlices.ColorSchemeAssociationKind
* @see RadianceThemingSlices.ContainerColorTokensAssociationKind
* @see RadianceSkin
*/
public class RadianceColorSchemeBundle2 {
// The main color scheme of this bundle
private RadianceColorScheme2 mainColorScheme;

/**
* Maps from color scheme association kinds to the map of color schemes.
* Different visual parts of controls in the specific decoration are can be
* painted with different color schemes. For example, a rollover button can
* use a light orange scheme for the gradient fill and a dark gray scheme
* for the border. In this case, this map will have:
* Maps from color scheme association kinds to the map of color tokens. Controls in the specific
* decoration area can use different colors for different active states, for example yellow
* for rollover and deep orange for pressed. In this case, this map will have an entry with
* {@link RadianceThemingSlices.ContainerColorTokensAssociationKind#DEFAULT} key and a value
* map with two entries:
*
* <ul>
* <li>An entry with key {@link RadianceThemingSlices.ColorSchemeAssociationKind#FILL}. This entry
* has a map entry with key {@link ComponentState#SELECTED} and value that
* points to the light orange scheme.</li>
* <li>An entry with key {@link RadianceThemingSlices.ColorSchemeAssociationKind#BORDER}. This
* entry has a map entry with key {@link ComponentState#SELECTED} and value
* that points to the dark gray scheme.</li>
* <li>A map entry with key {@link ComponentState#ROLLOVER_UNSELECTED} and value that
* points to the yellow color tokens.</li>
* <li>A map entry with key {@link ComponentState#PRESSED_UNSELECTED} and value that
* points to the deep orange color tokens.</li>
* </ul>
*/
private Map<RadianceThemingSlices.ContainerColorTokensAssociationKind,
Map<ComponentState, RadianceColorScheme2>> colorSchemeMap;
Map<ComponentState, ContainerColorTokens>> colorTokensForActiveStates;

public interface Overlay {
void overlay(RadianceColorSchemeBundle2 bundle);
Expand All @@ -82,10 +80,10 @@ public RadianceColorSchemeBundle2(RadianceColorScheme2 mainColorScheme) {

this.mainColorScheme = mainColorScheme;

this.colorSchemeMap = new HashMap<>();
this.colorTokensForActiveStates = new HashMap<>();
for (RadianceThemingSlices.ContainerColorTokensAssociationKind associationKind :
RadianceThemingSlices.ContainerColorTokensAssociationKind.values()) {
this.colorSchemeMap.put(associationKind, new HashMap<>());
this.colorTokensForActiveStates.put(associationKind, new HashMap<>());
}
}

Expand Down Expand Up @@ -115,12 +113,12 @@ public ContainerColorTokens getContainerTokens(ComponentState componentState,
return getContainerTokens(componentState.getEnabledMatch(), inactiveContainerType);
}

RadianceColorScheme2 registered = this.colorSchemeMap.get(
ContainerColorTokens registered = this.colorTokensForActiveStates.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.getActiveContainerTokens();
return registered;
}

return componentState.isActive()
Expand Down Expand Up @@ -187,7 +185,7 @@ public void registerColorScheme(RadianceColorScheme2 scheme,
if (state.isDisabled() || !state.isActive()) {
throw new IllegalArgumentException("Only active states can have custom color schemes");
}
this.colorSchemeMap.get(associationKind).put(state, scheme);
this.colorTokensForActiveStates.get(associationKind).put(state, scheme.getActiveContainerTokens());
}
}

Expand Down Expand Up @@ -219,28 +217,18 @@ public ContainerColorTokens getContainerTokens(
allowFallback, inactiveContainerType);
}

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

RadianceColorScheme2 enabledForAssociationKind =
this.colorSchemeMap.get(associationKind).get(ComponentState.ENABLED);
if (enabledForAssociationKind != null) {
return componentState.isActive()
? enabledForAssociationKind.getContainerTokensForState(componentState)
: enabledForAssociationKind.getContainerTokens(inactiveContainerType);
return registered;
}

if (!allowFallback) {
return null;
}

return getContainerTokens(
RadianceThemingSlices.ContainerColorTokensAssociationKind.DEFAULT, componentState,
true, inactiveContainerType);
return getContainerTokens(componentState, inactiveContainerType);
}
}

0 comments on commit e52e948

Please sign in to comment.