Class UiDefaultsMapper

java.lang.Object
generic.theme.laf.UiDefaultsMapper
Direct Known Subclasses:
FlatUiDefaultsMapper, MotifUiDefaultsMapper, NimbusUiDefaultsMapper

public class UiDefaultsMapper extends Object
The purpose of this class is to introduce multiple levels of indirection into the Java LookAndFeel (LaF), which allows the user to change these values. Further, when introducing this indirection we combine the Java settings into user-friendly system ids to make changing these values easier.

This class defines these user-friendly groups. The default system assignments are based on the BasicLookAndFeel values.

Subclasses can override the mapping of these standard system values for particular LaFs that have different ids or color assignments.

Some basic concepts:

  • UI Defaults - key-value pairs defined by the Java LaF; there are 2 key types, widget keys and Java group/reusable keys (e.g., Button.background; control)
  • UI Indirection - UI Defaults values are changed to point to custom terms we created to allow for indirection (e.g., Button.background -> laf.color.Button.background)
  • Normalized Keys - keys we created to facilitate the UI Indirection, based upon the Java keys (e.g., laf.color.Button.background)
  • System Color/Font Keys - user facing terms for common color or font concepts into an easy-to-change setting (e.g., system.color.fg.text)
  • Palette Keys - dynamically generated color palette keys based on the LaF for any colors and fonts that were not mapped into an system color or font (e.g., laf.palette.color.01)

The mapper performs the following operations:

  1. Extracts all color, font, and icon values from the UI Defaults.
  2. Use the current LaF values to populate the pre-defined system colors and fonts.
  3. Any UI Defaults values not assigned in the previous step will be assigned to a dynamic shared palette color or font.
  4. Update Java UI Defaults to use our indirection and system values.
  • Field Details

    • LAF_COLOR_ID_PREFIX

      public static final String LAF_COLOR_ID_PREFIX
      See Also:
    • LAF_FONT_ID_PREFIX

      public static final String LAF_FONT_ID_PREFIX
      See Also:
    • LAF_ICON_ID_PREFIX

      public static final String LAF_ICON_ID_PREFIX
      See Also:
    • defaults

      protected UIDefaults defaults
    • ignoredLafIds

      protected Set<String> ignoredLafIds
    • viewColorMatcher

      protected generic.theme.laf.UiDefaultsMapper.ColorMatcher viewColorMatcher
    • tooltipColorMatcher

      protected generic.theme.laf.UiDefaultsMapper.ColorMatcher tooltipColorMatcher
    • defaultColorMatcher

      protected generic.theme.laf.UiDefaultsMapper.ColorMatcher defaultColorMatcher
    • viewFontMatcher

      protected generic.theme.laf.UiDefaultsMapper.FontMatcher viewFontMatcher
    • defaultFontMatcher

      protected generic.theme.laf.UiDefaultsMapper.FontMatcher defaultFontMatcher
  • Constructor Details

    • UiDefaultsMapper

      protected UiDefaultsMapper(UIDefaults defaults)
  • Method Details

    • getJavaDefaults

      public GThemeValueMap getJavaDefaults()
      Returns the normalized id to value map that will be installed into the ApplicationThemeManager to be the user changeable values for affecting the Java LookAndFeel colors, fonts, and icons
      Returns:
      a map of changeable values that affect java LookAndFeel values
    • installValuesIntoUIDefaults

      public void installValuesIntoUIDefaults(GThemeValueMap currentValues)
      Updates the UIDefaults file with indirect colors (GColors) and any overridden font or icon values as defined in theme.properites files and saved themes.
      Parameters:
      currentValues - a Map that contains all the values including those the may have been overridden by the theme.properties files or saved themes
    • getNormalizedIdToLafIdMap

      public Map<String,String> getNormalizedIdToLafIdMap()
      Returns a mapping of normalized LaF Ids so that when fonts and icons get changed using the normalized ids that are presented to the user, we know which LaF ids need to be updated in the UiDefaults so that the LookAndFeel will pick up and use the changes.
      Returns:
      a mapping of normalized LaF ids to original LaF ids.
    • registerIgnoredLafIds

      protected void registerIgnoredLafIds()
      Registers any LookAndFeel ids that are not used directly (e.g. "control", "text", etc.) so that these values won't get mapped to any normalized id. There is no need for these values to show up in the theme values, since changing them will have no effect. They are used to seed the values for the system color and fonts. Subclasses should override this method to add additional ids so they won't show up in the theme values.
    • assignSystemColorValues

      protected void assignSystemColorValues()
      Defines the values to assign to all the system color ids based on the best representative value defined in the BasicLookAndFeel
    • assignSystemColorFromLafId

      protected void assignSystemColorFromLafId(String systemColorId, String lafId)
      Assigns the system color id to a color value from the UiDefaults map.
      Parameters:
      systemColorId - the system color id to get a value for
      lafId - the LaF key to use to retrieve a color from the UiDefaults
    • assignSystemColorDirect

      protected void assignSystemColorDirect(String systemColorId, Color color)
      Assigns the system color id to a directly specified color and does not use the LaF to populate the system color.
      Parameters:
      systemColorId - the system color id to assign the given color
      color - the color to be assigned to the system color id
    • assignSystemFontDirect

      protected void assignSystemFontDirect(String systemFontId, Font font)
      Assigns the system font id a directly specified font and does not use the LaF to populate the system font.
      Parameters:
      systemFontId - the system font id to assign the given font
      font - the font to be assigned to the system font id
    • assignSystemFontValues

      protected void assignSystemFontValues()
      Defines the values to use for the system fonts.
    • assignFontMatchersToComponentIds

      protected void assignFontMatchersToComponentIds()
      Assigns the appropriate font matcher to each component in the related component group
    • assignColorMatchersToComponentIds

      protected void assignColorMatchersToComponentIds()
      Assigns the appropriate color matcher to each component in the related component group
    • assignNormalizedColorValues

      protected void assignNormalizedColorValues()
      Populates the GThemeValueMap with normalized color ids. For example it will assign "laf.color.Button.background" to "system.color.bg.control".
    • installGColorsIntoUIDefaults

      protected void installGColorsIntoUIDefaults()
      Replaces UiDefaults values with GColorUIResource values the provide the theme indirection.
    • overrideColor

      protected void overrideColor(String lafId, String sytemId)
    • extractColorFontAndIconValuesFromDefaults

      protected GThemeValueMap extractColorFontAndIconValuesFromDefaults()
      Mines the UiDefaults for all color values.
      Returns:
      a map of id to values for UIDefaults Colors.