Record Class MarkerSymbols

java.lang.Object
java.lang.Record
com.dua3.utility.fx.controls.MarkerSymbols
Record Components:
optionalEmpty - symbol for optional fields that are empty
optionalFilled - symbol for optional fields that are filled
optionalError - symbol for optional fields that have an error
requiredEmpty - symbol for required fields that are empty
requiredFilled - symbol for required fields that are filled
requiredError - symbol for required fields that have an error

public record MarkerSymbols(String optionalEmpty, String optionalFilled, String optionalError, String requiredEmpty, String requiredFilled, String requiredError) extends Record
A record that represents a set of marker symbols used for various states of required and optional fields. These symbols can be used in UI components to visually indicate the state of a field.
  • Constructor Details

    • MarkerSymbols

      public MarkerSymbols(String optionalEmpty, String optionalFilled, String optionalError, String requiredEmpty, String requiredFilled, String requiredError)
      Creates an instance of a MarkerSymbols record class.
      Parameters:
      optionalEmpty - the value for the optionalEmpty record component
      optionalFilled - the value for the optionalFilled record component
      optionalError - the value for the optionalError record component
      requiredEmpty - the value for the requiredEmpty record component
      requiredFilled - the value for the requiredFilled record component
      requiredError - the value for the requiredError record component
  • Method Details

    • defaultSymbols

      public static MarkerSymbols defaultSymbols()
      Returns a MarkerSymbols instance with a predefined set of default symbols for optional and required fields.

      The default symbols are: - Optional empty: (empty string) - Optional filled: (empty string) - Optional error: ⚠ - Required empty: * - Required filled: * - Required error: ⚠

      Returns:
      a MarkerSymbols instance representing the default marker symbols
    • onlyErrors

      public static MarkerSymbols onlyErrors()
      Returns a MarkerSymbols instance configured to only display error symbols for both optional and required fields, while leaving other states blank.
      Returns:
      a MarkerSymbols instance with only error symbols defined for optional and required fields
    • noSymbols

      public static MarkerSymbols noSymbols()
      Creates a new instance of MarkerSymbols with all symbol fields set to empty strings. This can be used to represent a state where no symbols are needed or desired.
      Returns:
      a MarkerSymbols instance with all fields set to empty strings
    • calculateWidth

      public double calculateWidth(Font font, double minWidth)
      Calculates the maximum width required to render any of the marker symbols in the provided font, ensuring it is at least the specified minimum width. The width is determined based on the rendered size of the text for all marker symbols associated with optional and required fields in various states.
      Parameters:
      font - the font used to calculate the rendered text width of the marker symbols
      minWidth - the minimum width to enforce, ensuring the resulting width is at least this value
      Returns:
      the maximum calculated width required to render the marker symbols or the minimum width, whichever is larger
    • getMarker

      public String getMarker(boolean required, boolean filled, boolean error)
      Returns the marker symbol corresponding to the provided field state.
      Parameters:
      required - a boolean indicating whether the field is required (true) or optional (false)
      filled - a boolean indicating whether the field is filled (true) or empty (false)
      error - a boolean indicating whether the field has an error (true) or not (false)
      Returns:
      a string representing the symbol for the field state based on the given parameters
    • hasRequiredSymbols

      public boolean hasRequiredSymbols()
      Determines whether all required marker symbols are defined. A required marker symbol is considered defined if its corresponding field is non-empty. Specifically, this method checks that the fields `requiredEmpty`, `requiredFilled`, and `requiredError` are not empty.
      Returns:
      true if all required marker symbols (`requiredEmpty`, `requiredFilled`, and `requiredError`) are non-empty; false otherwise.
    • getRequiredSymbol

      public String getRequiredSymbol()
      Returns the symbol associated with the 'required' state, prioritizing the 'empty', 'error', and 'filled' states in that order.

      Specifically: - If the requiredEmpty symbol is not empty, it is returned. - Otherwise, if the requiredError symbol is not empty, it is returned. - If neither of the above is true, the requiredFilled symbol is returned.

      Returns:
      a string representing the most appropriate 'required' state symbol based on the priority order of empty, error, and filled.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • optionalEmpty

      public String optionalEmpty()
      Returns the value of the optionalEmpty record component.
      Returns:
      the value of the optionalEmpty record component
    • optionalFilled

      public String optionalFilled()
      Returns the value of the optionalFilled record component.
      Returns:
      the value of the optionalFilled record component
    • optionalError

      public String optionalError()
      Returns the value of the optionalError record component.
      Returns:
      the value of the optionalError record component
    • requiredEmpty

      public String requiredEmpty()
      Returns the value of the requiredEmpty record component.
      Returns:
      the value of the requiredEmpty record component
    • requiredFilled

      public String requiredFilled()
      Returns the value of the requiredFilled record component.
      Returns:
      the value of the requiredFilled record component
    • requiredError

      public String requiredError()
      Returns the value of the requiredError record component.
      Returns:
      the value of the requiredError record component