Class ColorResolver

java.lang.Object
com.iizix.prop.ColorResolver

public final class ColorResolver extends Object
Resolves a color reference to the literal it means under a scheme: the one algorithm the server, the Designer and the tests use (design 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
  • Field Details

    • MAX_DEPTH

      public static final int MAX_DEPTH
      The 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

      public static PropCnr getBasePalette()
      Gets the platform base palette.
      Returns:
      The container of PaletteColors named by role, or null when none is installed.
    • setBasePalette

      public static void setBasePalette(PropCnr palette)
      Installs the platform base palette: the last step of every resolution chain.
      Parameters:
      palette - The container of PaletteColors named by role, or null for none.
    • resolveForSend

      public static ColorResolver.Result resolveForSend(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.
      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 - If color is 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 the style folder of that property's module.
      ref - The reference, without the leading %: a property reference such as Module:/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 for PaletteColor.SCHEME_LIGHT.
      basePalette - The platform base palette, a container of PaletteColors 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 for PaletteColor.SCHEME_LIGHT.
      basePalette - The platform base palette, or null for none.
      Returns:
      The result, never null.