Class ColorResolver
THEMING-DESIGN.md section 2.4 as ruled).The chain, per palette color: the value for the active scheme, else the value for the default scheme, else the platform base palette's color of the same name (a role, ColorRoles). A value that is a ColorReference is followed, the requested scheme carried along, at most MAX_DEPTH times; a palette color seen twice is a cycle. The reference of a panel's GColor (GColor.getRef()) is looked up by GProp.getPropFromReference(String); a bare name such as Accent is looked up at the top of the referencing module's style folder, so an application may override a role by defining a palette color of its name there, and then in the base palette.
What does not resolve - not found, no value for the scheme, a cycle, too deep - is reported with its reason and carries GColor.UNRESOLVED magenta as its color. This class logs nothing; resolveForSend(GProp,GColor), the send-time entry used by ColorProp and Color4Prop, logs the warning on the holder, so that the property that carries the broken reference is named. In the Designer a broken ColorReference is a property error on the reference itself.
The platform base palette is a container of PaletteColors named by role. It is data - the shipped themes' values - and is installed by the delivery phase (B2) through setBasePalette(PropCnr); until then a role that no application palette defines is unresolved.
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe result of a resolution: the status, the color and, when not resolved, the reason.static enumThe outcome of a resolution.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe largest number of color references that may be followed, so that a chain of nine fails and a chain of eight passes.Method Summary
Modifier and TypeMethodDescriptionstatic PropCnrGets the platform base palette.static ColorResolver.Resultresolve(GProp<?> anyPropInTree, String ref, String scheme, String defaultScheme, PropCnr basePalette) Resolves a color reference.static ColorResolver.ResultresolveEntry(PaletteColor entry, String scheme, String defaultScheme, PropCnr basePalette) Resolves a palette color directly, without a reference string.static ColorResolver.ResultresolveForSend(GProp<?> holder, GColor color) Resolves a referenced color for sending, against the holder's tree, the default scheme and the installed base palette, and logs a warning on the holder when it does not resolve.static voidsetBasePalette(PropCnr palette) Installs the platform base palette: the last step of every resolution chain.
Field Details
MAX_DEPTH
public static final int MAX_DEPTHThe largest number of color references that may be followed, so that a chain of nine fails and a chain of eight passes.- See Also:
Method Details
getBasePalette
Gets the platform base palette.- Returns:
- The container of
PaletteColors named by role, or null when none is installed.
setBasePalette
Installs the platform base palette: the last step of every resolution chain.- Parameters:
palette- The container ofPaletteColors named by role, or null for none.
resolveForSend
Resolves a referenced color for sending, against the holder's tree, the default scheme and the installed base palette, and logs a warning on the holder when it does not resolve.- Parameters:
holder- The property that holds the color.color- The referenced color.- Returns:
- The result; its color is what travels as the fallback on the wire.
- Throws:
IllegalArgumentException- Ifcoloris not a reference.
resolve
public static ColorResolver.Result resolve(GProp<?> anyPropInTree, String ref, String scheme, String defaultScheme, PropCnr basePalette) Resolves a color reference.- Parameters:
anyPropInTree- Any property in the tree the reference is written in; a bare name is looked up in thestylefolder of that property's module.ref- The reference, without the leading%: a property reference such asModule:/style/Brand/Primary, a module-relative/style/Brand/Primary, or a bare name.scheme- The active scheme, or null for none.defaultScheme- The default scheme, or null forPaletteColor.SCHEME_LIGHT.basePalette- The platform base palette, a container ofPaletteColors named by role, or null for none.- Returns:
- The result, never null.
resolveEntry
public static ColorResolver.Result resolveEntry(PaletteColor entry, String scheme, String defaultScheme, PropCnr basePalette) Resolves a palette color directly, without a reference string.- Parameters:
entry- The palette color to start from.scheme- The active scheme, or null for none.defaultScheme- The default scheme, or null forPaletteColor.SCHEME_LIGHT.basePalette- The platform base palette, or null for none.- Returns:
- The result, never null.