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
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 Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(ThemeValue<T> o) boolean
get
(GThemeValueMap values) Returns the T value for this instance, following references as needed.getId()
Returns the identifier for this ThemeValue.Returns the stored value.Returns the referencId of another ThemeValue that we inherit its value pr null if we have a valueprotected abstract ThemeValue
<T> getReferredValue
(GThemeValueMap preferredValues, String refId) Returns the ThemeValue referred to by this ThemeValue.abstract String
Returns the "key = value" String for writing this ThemeValue to a fileprotected abstract T
getUnresolvedReferenceValue
(String primaryId, String unresolvedId) Returns the T to be used if the indirect reference couldn't be resolved.int
hashCode()
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.boolean
inheritsFrom
(String ancestorId, GThemeValueMap values) Returns true if this ThemeValue derives its value from the given ancestorId.abstract void
installValue
(ThemeManager themeManager) Install this value as the current value for the applicationabstract boolean
True if this value is one that is one that is defined outside of the application, such as a Java Look and Feel key.boolean
Returns true if this ColorValue gets its value from some other ColorValuetoString()
-
Field Details
-
id
-
value
-
referenceId
-
-
Constructor Details
-
ThemeValue
-
-
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
Returns the identifier for this ThemeValue.- Returns:
- the identifier for this ThemeValue.
-
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
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
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 thehasResolvableValue(GThemeValueMap)
method first.- Parameters:
values
- theGThemeValueMap
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
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
Returns true if this ThemeValue derives its value from the given ancestorId.- Parameters:
ancestorId
- the id to test if this Theme value inherits fromvalues
- 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
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
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 forunresolvedId
- the reference id that couldn't be resolved- Returns:
- the default value to be used if the indirect reference couldn't be resolved.
-
getReferredValue
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
- theGThemeValueMap
to be used to resolve the reference idrefId
- the id of the reference ThemeValue- Returns:
- the ThemeValue referred to by this ThemeValue.
-
compareTo
- Specified by:
compareTo
in interfaceComparable<T>
-
hashCode
public int hashCode() -
equals
-
toString
-
installValue
Install this value as the current value for the application- Parameters:
themeManager
- the application ThemeManager
-