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:
    • LAF_PROPERTY_PREFIX

      public static final String LAF_PROPERTY_PREFIX
      A prefix for UIManager properties that are not colors, fonts or icons (e.g., boolean)
      See Also:
    • defaults

      protected UIDefaults defaults
    • ignoredJavaIds

      protected Set<String> ignoredJavaIds
    • viewColorGrouper

      protected generic.theme.laf.UiDefaultsMapper.ColorGrouper viewColorGrouper
    • tooltipColorGrouper

      protected generic.theme.laf.UiDefaultsMapper.ColorGrouper tooltipColorGrouper
    • defaultColorMatcher

      protected generic.theme.laf.UiDefaultsMapper.ColorGrouper defaultColorMatcher
    • viewFontGrouper

      protected generic.theme.laf.UiDefaultsMapper.FontGrouper viewFontGrouper
    • defaultFontMatcher

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

    • UiDefaultsMapper

      protected UiDefaultsMapper(UIDefaults defaults)
  • Method Details

    • getNormalizedJavaDefaults

      public GThemeValueMap getNormalizedJavaDefaults()
      Returns the normalized id to value map that will be installed into the theme manager to be the user changeable values for affecting the Java LookAndFeel colors, fonts, and icons.

      The keys in the returned map have been normalized and all start with 'laf.'

      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.
    • registerIgnoredJavaIds

      protected void registerIgnoredJavaIds()
      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.
    • pickRepresentativeValueForColorGroups

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

      protected void setGroupColorUsingJavaRepresentative(String group, String javaId)
      Assigns the system color id to a color value from the UiDefaults map.
      Parameters:
      group - the system color id to get a value for
      javaId - the LaF key to use to retrieve a color from the UiDefaults
    • setGroupColor

      protected void setGroupColor(String group, Color color)
      This allows clients to hard-code a chosen color for a group
      Parameters:
      group - the system color id to assign the given color
      color - the color to be assigned to the system color id
    • setGroupFont

      protected void setGroupFont(String group, Font font)
      This allows clients to hard-code a chosen font for a group
      Parameters:
      group - the system font id to assign the given font
      font - the font to be assigned to the system font id
    • setComponentFont

      protected void setComponentFont(String componentName, Font font)
    • pickRepresentativeValueForFontGroups

      protected void pickRepresentativeValueForFontGroups()
      Defines the font values to use for each group based upon a chosen Java representative.
    • buildComponentToFontGrouperMap

      protected void buildComponentToFontGrouperMap()
      Sets the font grouper for each component group
    • buildComponentToColorGrouperMap

      protected void buildComponentToColorGrouperMap()
      Sets the color grouper for each 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.