Package com.dua3.utility.fx.controls
Record Class MarkerSymbols
java.lang.Object
java.lang.Record
com.dua3.utility.fx.controls.MarkerSymbols
- Record Components:
optionalEmpty- symbol for optional fields that are emptyoptionalFilled- symbol for optional fields that are filledoptionalError- symbol for optional fields that have an errorrequiredEmpty- symbol for required fields that are emptyrequiredFilled- symbol for required fields that are filledrequiredError- 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculateWidth(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.static MarkerSymbolsReturns a MarkerSymbols instance with a predefined set of default symbols for optional and required fields.final booleanIndicates whether some other object is "equal to" this one.getMarker(boolean required, boolean filled, boolean error) Returns the marker symbol corresponding to the provided field state.Returns the symbol associated with the 'required' state, prioritizing the 'empty', 'error', and 'filled' states in that order.final inthashCode()Returns a hash code value for this object.booleanDetermines whether all required marker symbols are defined.static MarkerSymbolsCreates a new instance of MarkerSymbols with all symbol fields set to empty strings.static MarkerSymbolsReturns a MarkerSymbols instance configured to only display error symbols for both optional and required fields, while leaving other states blank.Returns the value of theoptionalEmptyrecord component.Returns the value of theoptionalErrorrecord component.Returns the value of theoptionalFilledrecord component.Returns the value of therequiredEmptyrecord component.Returns the value of therequiredErrorrecord component.Returns the value of therequiredFilledrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
MarkerSymbols
public MarkerSymbols(String optionalEmpty, String optionalFilled, String optionalError, String requiredEmpty, String requiredFilled, String requiredError) Creates an instance of aMarkerSymbolsrecord class.- Parameters:
optionalEmpty- the value for theoptionalEmptyrecord componentoptionalFilled- the value for theoptionalFilledrecord componentoptionalError- the value for theoptionalErrorrecord componentrequiredEmpty- the value for therequiredEmptyrecord componentrequiredFilled- the value for therequiredFilledrecord componentrequiredError- the value for therequiredErrorrecord component
-
-
Method Details
-
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
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
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
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 symbolsminWidth- 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
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
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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
optionalEmpty
Returns the value of theoptionalEmptyrecord component.- Returns:
- the value of the
optionalEmptyrecord component
-
optionalFilled
Returns the value of theoptionalFilledrecord component.- Returns:
- the value of the
optionalFilledrecord component
-
optionalError
Returns the value of theoptionalErrorrecord component.- Returns:
- the value of the
optionalErrorrecord component
-
requiredEmpty
Returns the value of therequiredEmptyrecord component.- Returns:
- the value of the
requiredEmptyrecord component
-
requiredFilled
Returns the value of therequiredFilledrecord component.- Returns:
- the value of the
requiredFilledrecord component
-
requiredError
Returns the value of therequiredErrorrecord component.- Returns:
- the value of the
requiredErrorrecord component
-