Package VASSAL.tools
Class FormattedString
java.lang.Object
VASSAL.tools.FormattedString
- All Implemented Interfaces:
Auditable
,RecursionLimiter.Loopable
- Direct Known Subclasses:
PlayerIdFormattedString
FormattedString.java
A String that can include options of the form $optionName$. Option values
are maintained in a property list and getText returns the string will all
options replaced by their value.
FormattedStrings are ultimately evaluated using the Beanshell Interpreter, so
a Formatted String can be specified as a valid BeanShell expression surrounded
by {}'s. For this reason, full support is included for generating Expression Audit
Trails to be parsed inward the the Expression interpreter.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionFormattedString
(String formatString, PropertySource defaultProperties) FormattedString
(PropertySource defaultProperties) -
Method Summary
Modifier and TypeMethodDescriptionvoid
static String
debugInfo
(FormattedString fs, String value, String description) Format a standard debug message for use in Decorator bad data reports.boolean
Return the name of the trait or Component an Auditable isReturn a description of the Type of trait or Component an Auditable isDeprecated.Deprecated.getLocalizedText
(PropertySource ps, Auditable owner, String fieldKey) Evaulate a formatted String and return localized text Use the supplied property source to find property values Create an AuditTrail object if expression auditing enabledgetLocalizedText
(PropertySource ps, Auditable owner, String fieldKey, boolean quietly) getLocalizedText
(PropertySource ps, Auditable owner, AuditTrail audit) Evaulate a formatted String and return localized text Use the supplied property source to find property valuesgetLocalizedText
(Auditable owner, String fieldKey) Evaulate a formatted String and return localized text Use the default property source to find property values Create an AuditTrail object if expression auditing enabledgetText()
Deprecated.Deprecated.getText
(PropertySource ps, boolean localized) Deprecated.getText
(PropertySource ps, boolean localized, Auditable owner, AuditTrail audit) Evaluate the supplied Formmatted String, using the supplied property source to replace any property references.getText
(PropertySource ps, boolean localized, Auditable owner, AuditTrail audit, boolean quietly) Core implementation of getText.getText
(PropertySource ps, String def) Deprecated.getText
(PropertySource ps, String def, Auditable owner, String fieldKey) Evaulate a formatted String and return unlocalized text Use the supplied property source to find property values If any property value is found to be null, use the supplied default value instead Create an AuditTrail object if expression auditing enabledgetText
(PropertySource ps, String def, Auditable owner, AuditTrail audit) Evaulate a formatted String and return unlocalized text Use the supplied property source to find property values If any property value is found to be null, use the supplied default value insteadgetText
(PropertySource ps, Auditable owner, String fieldKey) Evaulate a formatted String and return unlocalized text Use the supplied property source to find property values Create an AuditTrail object if expression auditing enabledgetText
(PropertySource ps, Auditable owner, String fieldKey, boolean quietly) Evaluate a formatted String and return unlocalized text Use the supplied property source to find property values Create an AuditTrail object if expression auditing enabledgetText
(PropertySource ps, Auditable owner, AuditTrail audit) Evaulate a formatted String and return unlocalized text Use the supplied property source to find property valuesEvaulate a formatted String and return unlocalized text Use the default property source to find property values Create an AuditTrail object if expression auditing enabledint
getTextAsInt
(PropertySource ps, String description, AbstractConfigurable source) int
getTextAsInt
(PropertySource ps, String description, EditablePiece source) Expand a FormattedString using the supplied propertySource and parse it as an integer.int
getTextAsInt
(PropertySource ps, String description, EditablePiece source, Auditable owner, AuditTrail audit) int
hashCode()
static boolean
Return true if the supplied string contains $$ variables or is a Beanshell expressionvoid
setDefaultProperties
(PropertySource defaultProperties) void
void
setProperty
(String name, String value)
-
Field Details
-
props
-
-
Constructor Details
-
FormattedString
public FormattedString() -
FormattedString
-
FormattedString
-
FormattedString
-
-
Method Details
-
isDynamic
Return true if the supplied string contains $$ variables or is a Beanshell expression- Parameters:
text
- String to check- Returns:
- true if the string needs to be evaluated
-
setFormat
-
getFormat
-
setProperty
-
clearProperties
public void clearProperties() -
setDefaultProperties
-
getDefaultProperties
-
getText
Deprecated.Evaulate a formatted String and return unlocalized text Use the default property source to find property values- Returns:
- evaluated formatted String
-
getText
Evaulate a formatted String and return unlocalized text Use the default property source to find property values Create an AuditTrail object if expression auditing enabled- Parameters:
owner
- Owning component of this formatted string.fieldKey
- Message key describing the editor field holding this formmated string- Returns:
- evaluated formatted String
-
getLocalizedText
Deprecated.Evaluate a Formatted String and return localized text Use the default property source to find property values- Returns:
- localized text
-
getLocalizedText
Evaulate a formatted String and return localized text Use the default property source to find property values Create an AuditTrail object if expression auditing enabled- Parameters:
owner
- Owning component of this formatted string.fieldKey
- Message key describing the editor field holding this formmated string- Returns:
- evaluated formatted String
-
getText
Deprecated.Evaulate a formatted String and return unlocalized text Also, if any property keys match a property in the given GamePiece, substitute the value of that property- Parameters:
ps
- property source- Returns:
- Return the resulting string after substituting properties
-
getText
Evaulate a formatted String and return unlocalized text Use the supplied property source to find property values Create an AuditTrail object if expression auditing enabled- Parameters:
owner
- Owning component of this formatted string.fieldKey
- Message key describing the editor field holding this formatted string- Returns:
- evaluated formatted String
-
getText
Evaluate a formatted String and return unlocalized text Use the supplied property source to find property values Create an AuditTrail object if expression auditing enabled- Parameters:
ps
- Property Source to use to evaluate propertiesowner
- Owning component of this formatted string.fieldKey
- Message key describing the editor field holding this formatted stringquietly
- True to suppress error reporting- Returns:
- evaluated formatted String
-
getText
Evaulate a formatted String and return unlocalized text Use the supplied property source to find property values- Parameters:
ps
- Property source to supply property valuesowner
- Owning component of this formatted string.audit
- AuditTrail to use for expression auditing- Returns:
- evaluated formatted String
-
getText
Deprecated.Evaulate a formatted String and return unlocalized text -
getText
Deprecated.Return the resulting string after substituting properties Also, if any property keys match a property in the given GamePiece, substitute the value of that property. If the resulting string is empty, then the default is returned.- Parameters:
ps
- Property sourcedef
- the default if the result is otherwise empty- Returns:
- Return the resulting string after substituting properties
- See Also:
-
getText
Evaulate a formatted String and return unlocalized text Use the supplied property source to find property values If any property value is found to be null, use the supplied default value instead Create an AuditTrail object if expression auditing enabled- Parameters:
ps
- Property source to supply property valuesdef
- Default value for properties with no valueowner
- Owning component of this formatted string.fieldKey
- Message key describing the editor field holding this formatted string- Returns:
- evaluated formatted String
-
getText
Evaulate a formatted String and return unlocalized text Use the supplied property source to find property values If any property value is found to be null, use the supplied default value instead- Parameters:
ps
- Property source to supply property valuesdef
- Default value for properties with no valueowner
- Owning component of this formatted string.audit
- AuditTrail to use for expression auditing- Returns:
- evaluated formatted String
-
getLocalizedText
Evaulate a formatted String and return localized text Use the supplied property source to find property values Create an AuditTrail object if expression auditing enabled- Parameters:
owner
- Owning component of this formatted string.fieldKey
- Message key describing the editor field holding this formatted string- Returns:
- evaluated formatted String
-
getLocalizedText
public String getLocalizedText(PropertySource ps, Auditable owner, String fieldKey, boolean quietly) -
getLocalizedText
Evaulate a formatted String and return localized text Use the supplied property source to find property values- Parameters:
ps
- Property source to supply property valuesowner
- Owning component of this formatted string.audit
- AuditTrail to use for expression auditing- Returns:
- evaluated formatted String
-
getLocalizedText
Deprecated.Evaulate a formatted String and return localized text -
getText
Evaluate the supplied Formmatted String, using the supplied property source to replace any property references. NOTE that evaluation is handled by the Beanshell Interpreter, so full Beanshell is supported in Formatted Strings (yikes!) Use the supplied owner and audit trail for error reporting purposes.- Parameters:
ps
- Property source to use to supply property valueslocalized
- true if getLocalizedProperty() calls should be used to evaluate property valuesowner
- Auditable owner of this Formmatted String for reporting purposesaudit
- Audit Trail for Expression evaluation error reporting (may be null)- Returns:
- Evaluated formatted string
-
getText
public String getText(PropertySource ps, boolean localized, Auditable owner, AuditTrail audit, boolean quietly) Core implementation of getText. All other call signatures should eventually call this version. Evaluate the supplied Formmatted String, using the supplied property source to replace any property references. NOTE that evaluation is handled by the Beanshell Interpreter, so full Beanshell is supported in Formatted Strings (yikes!) Use the supplied owner and audit trail for error reporting purposes.- Parameters:
ps
- Property source to use to supply property valueslocalized
- true if getLocalizedProperty() calls should be used to evaluate property valuesowner
- Auditable owner of this Formmatted String for reporting purposesaudit
- Audit Trail for Expression evaluation error reporting (may be null)quietly
- True to suppress all error reporting- Returns:
- Evaluated formatted string
-
getTextAsInt
Expand a FormattedString using the supplied propertySource and parse it as an integer. If the expanded string is not an integer, generate a Bad Data Report with debugging information and return a value of 0 -
getTextAsInt
public int getTextAsInt(PropertySource ps, String description, EditablePiece source, Auditable owner, AuditTrail audit) -
getTextAsInt
-
debugInfo
Format a standard debug message for use in Decorator bad data reports. description=value description[format]=value Use format 1 if the generated value is the same as the format Use format 2 if the formatted contains an expression that has been expanded.- Parameters:
fs
- Formatted Stringvalue
- Value generated by the formatted stringdescription
- Description of the String- Returns:
- error message
-
debugInfo
-
hashCode
-
equals
-
getComponentTypeName
Description copied from interface:Auditable
Return a description of the Type of trait or Component an Auditable is- Specified by:
getComponentTypeName
in interfaceAuditable
- Returns:
- Component Type
-
getComponentName
Description copied from interface:Auditable
Return the name of the trait or Component an Auditable is- Specified by:
getComponentName
in interfaceAuditable
- Returns:
- Component name
-
getLocalizedText(Auditable, String)