Package VASSAL.tools

Class FormattedString

java.lang.Object
VASSAL.tools.FormattedString
All Implemented Interfaces:
Auditable, RecursionLimiter.Loopable
Direct Known Subclasses:
PlayerIdFormattedString

public class FormattedString extends Object implements RecursionLimiter.Loopable
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 Details

  • Constructor Details

    • FormattedString

      public FormattedString()
    • FormattedString

      public FormattedString(String s)
    • FormattedString

      public FormattedString(PropertySource defaultProperties)
    • FormattedString

      public FormattedString(String formatString, PropertySource defaultProperties)
  • Method Details

    • isDynamic

      public static boolean isDynamic(String text)
      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

      public void setFormat(String fs)
    • getFormat

      public String getFormat()
    • setProperty

      public void setProperty(String name, String value)
    • clearProperties

      public void clearProperties()
    • setDefaultProperties

      public void setDefaultProperties(PropertySource defaultProperties)
    • getDefaultProperties

      public PropertySource getDefaultProperties()
    • getText

      @Deprecated(since="2021-12-01") public String getText()
      Evaulate a formatted String and return unlocalized text Use the default property source to find property values
      Returns:
      evaluated formatted String
    • getText

      public String getText(Auditable owner, String fieldKey)
      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(since="2021-12-01") public String getLocalizedText()
      Evaluate a Formatted String and return localized text Use the default property source to find property values
      Returns:
      localized text
    • getLocalizedText

      public String getLocalizedText(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 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(since="2021-12-01") public String getText(PropertySource ps)
      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

      public String getText(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 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

      public String getText(PropertySource ps, Auditable owner, AuditTrail audit)
      Evaulate a formatted String and return unlocalized text Use the supplied property source to find property values
      Parameters:
      ps - Property source to supply property values
      owner - Owning component of this formatted string.
      audit - AuditTrail to use for expression auditing
      Returns:
      evaluated formatted String
    • getText

      @Deprecated(since="2021-12-01") public String getText(PropertySource ps, boolean localized)
      Evaulate a formatted String and return unlocalized text
    • getText

      @Deprecated(since="2021-12-01") public String getText(PropertySource ps, String def)
      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 source
      def - the default if the result is otherwise empty
      Returns:
      Return the resulting string after substituting properties
      See Also:
    • getText

      public String 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 enabled
      Parameters:
      ps - Property source to supply property values
      def - Default value for properties with no value
      owner - Owning component of this formatted string.
      fieldKey - Message key describing the editor field holding this formatted string
      Returns:
      evaluated formatted String
    • getText

      public String getText(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 instead
      Parameters:
      ps - Property source to supply property values
      def - Default value for properties with no value
      owner - Owning component of this formatted string.
      audit - AuditTrail to use for expression auditing
      Returns:
      evaluated formatted String
    • getLocalizedText

      public String 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 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, AuditTrail audit)
      Evaulate a formatted String and return localized text Use the supplied property source to find property values
      Parameters:
      ps - Property source to supply property values
      owner - Owning component of this formatted string.
      audit - AuditTrail to use for expression auditing
      Returns:
      evaluated formatted String
    • getLocalizedText

      @Deprecated(since="2021-12-01") public String getLocalizedText(PropertySource ps)
      Evaulate a formatted String and return localized text
    • getText

      public String getText(PropertySource ps, boolean localized, Auditable owner, AuditTrail audit)
      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 values
      localized - true if getLocalizedProperty() calls should be used to evaluate property values
      owner - Auditable owner of this Formmatted String for reporting purposes
      audit - Audit Trail for Expression evaluation error reporting (may be null)
      Returns:
      Evaluated formatted string
    • getTextAsInt

      public int getTextAsInt(PropertySource ps, String description, EditablePiece source)
      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

      public int getTextAsInt(PropertySource ps, String description, AbstractConfigurable source)
    • debugInfo

      public static String debugInfo(FormattedString fs, String value, String description)
      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 String
      value - Value generated by the formatted string
      description - Description of the String
      Returns:
      error message
    • debugInfo

      public String debugInfo(String value, String description)
    • hashCode

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

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

      public String getComponentTypeName()
      Description copied from interface: Auditable
      Return a description of the Type of trait or Component an Auditable is
      Specified by:
      getComponentTypeName in interface Auditable
      Returns:
      Component Type
    • getComponentName

      public String getComponentName()
      Description copied from interface: Auditable
      Return the name of the trait or Component an Auditable is
      Specified by:
      getComponentName in interface Auditable
      Returns:
      Component name