Package generic.theme

Class ThemeValue<T>

java.lang.Object
generic.theme.ThemeValue<T>
Type Parameters:
T - the base type this ThemeValue works on (i.e., Colors, Fonts, Icons)
All Implemented Interfaces:
Comparable<ThemeValue<T>>
Direct Known Subclasses:
ColorValue, FontValue, IconValue, JavaPropertyValue

public abstract class ThemeValue<T> extends Object implements Comparable<ThemeValue<T>>
A generic class for storing theme values that have a String id (e.g. color.bg.foo) and either a concrete value of type T or a reference id which is the String id of another ThemeValue. So if this class's value is non-null, the refId will be null and if the class's refId is non-null, then the value will be null.
  • Field Details

    • id

      protected final String id
    • value

      protected final T value
    • referenceId

      protected final String referenceId
  • Constructor Details

    • ThemeValue

      protected ThemeValue(String id, String referenceId, T value)
  • Method Details

    • isExternal

      public abstract boolean isExternal()
      True if this value is one that is one that is defined outside of the application, such as a Java Look and Feel key.
      Returns:
      true if external
    • getId

      public String getId()
      Returns the identifier for this ThemeValue.
      Returns:
      the identifier for this ThemeValue.
    • getReferenceId

      public String getReferenceId()
      Returns the referencId of another ThemeValue that we inherit its value pr null if we have a value
      Returns:
      the referencId of another ThemeValue that we inherit its value or null if we have a value
    • getRawValue

      public T getRawValue()
      Returns the stored value. Does not follow referenceIds. Will be null if this instance has a referenceId.
      Returns:
      the stored value. Does not follow referenceIds. Will be null if this instance has a referenceId.
    • get

      public T get(GThemeValueMap values)
      Returns the T value for this instance, following references as needed. Uses the given preferredValues map to resolve references. If the value can't be resolved by following reference chains, an error stack trace will be generated and the default T value will be returned. In rare situations where it is acceptable for the value to not be resolvable, use the hasResolvableValue(GThemeValueMap) method first.
      Parameters:
      values - the GThemeValueMap used to resolve references if this instance doesn't have an actual value.
      Returns:
      the T value for this instance, following references as needed.
    • hasResolvableValue

      public boolean hasResolvableValue(GThemeValueMap values)
      Returns true if the ThemeValue can resolve to the concrete T value (color, font, or icon) from the given set of theme values.
      Parameters:
      values - the set of values to use to try and follow reference chains to ultimately resolve the ThemeValue to a an actual T value
      Returns:
      true if the ThemeValue can resolve to the concrete T value (color, font, or icon) from the given set of theme values.
    • inheritsFrom

      public boolean inheritsFrom(String ancestorId, GThemeValueMap values)
      Returns true if this ThemeValue derives its value from the given ancestorId.
      Parameters:
      ancestorId - the id to test if this Theme value inherits from
      values - the set of values used to resolve indirect references to attempt to trace back to the given ancestor id
      Returns:
      true if this ThemeValue derives its value from the given ancestorId.
    • isIndirect

      public boolean isIndirect()
      Returns true if this ColorValue gets its value from some other ColorValue
      Returns:
      true if this ColorValue gets its value from some other ColorValue
    • getSerializationString

      public abstract String getSerializationString()
      Returns the "key = value" String for writing this ThemeValue to a file
      Returns:
      the "key = value" String for writing this ThemeValue to a file
    • getUnresolvedReferenceValue

      protected abstract T getUnresolvedReferenceValue(String primaryId, String unresolvedId)
      Returns the T to be used if the indirect reference couldn't be resolved.
      Parameters:
      primaryId - the id we are trying to get a value for
      unresolvedId - the reference id that couldn't be resolved
      Returns:
      the default value to be used if the indirect reference couldn't be resolved.
    • getReferredValue

      protected abstract ThemeValue<T> getReferredValue(GThemeValueMap preferredValues, String refId)
      Returns the ThemeValue referred to by this ThemeValue. Needs to be overridden by concrete classes as they know the correct method to call on the preferredValues map.
      Parameters:
      preferredValues - the GThemeValueMap to be used to resolve the reference id
      refId - the id of the reference ThemeValue
      Returns:
      the ThemeValue referred to by this ThemeValue.
    • compareTo

      public int compareTo(ThemeValue<T> o)
      Specified by:
      compareTo in interface Comparable<T>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • installValue

      public abstract void installValue(ThemeManager themeManager)
      Install this value as the current value for the application
      Parameters:
      themeManager - the application ThemeManager