Package com.storedobject.vaadin.util
Class NumericField<T extends Number>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.customfield.CustomField<T>,T>
com.vaadin.flow.component.customfield.CustomField<T>
com.storedobject.vaadin.CustomField<T>
com.storedobject.vaadin.CustomTextField<T>
com.storedobject.vaadin.util.NumericField<T>
- Type Parameters:
T- The numeric type handled by the field, extendsNumber.
- All Implemented Interfaces:
DisablePaste,HasStyle,com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.customfield.CustomField<T>>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.Focusable<com.vaadin.flow.component.customfield.CustomField<T>>,com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.customfield.CustomField<T>>,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasHelper,com.vaadin.flow.component.HasLabel,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasTheme,com.vaadin.flow.component.HasValidation,com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,,T>, T> com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,,T>, T> com.vaadin.flow.component.shared.HasPrefix,com.vaadin.flow.component.shared.HasSuffix,com.vaadin.flow.component.shared.HasTooltip,com.vaadin.flow.component.shared.HasValidationProperties,com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T>,,T>, T> com.vaadin.flow.component.textfield.HasAutocomplete,Serializable
- Direct Known Subclasses:
BigDecimalField,DoubleField,IntegerField,LongField
An abstract class representing a numeric text field with support for various configurations,
such as grouping, allowance of negative values, formatting, and specified width constraints.
This class serves as a base class for creating type-specific numeric fields.
- Author:
- Syam
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V> Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanIndicates whether negative values are allowed for the numeric input field.protected booleanDetermines whether the numeric field should apply grouping of digits (e.g., thousand-separators) when displaying numbers.protected intRepresents the width of the numeric field in terms of the number of characters allowed.Fields inherited from interface com.vaadin.flow.component.textfield.HasAutocomplete
AUTOCOMPLETE_ATTRIBUTE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedNumericField(T defaultValue) Constructs a NumericField with a specified default value. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringFormat the value to display it as a string.final booleanRetrieves the current configuration indicating whether negative numbers are allowed in this numeric field.protected StringRetrieves the country code associated with the current application context.intRetrieves the number of decimal places allowed for the numeric field.protected abstract intRetrieves the default length for the numeric field.final intRetrieves the length of the numeric field.final booleanChecks whether grouping is enabled for the numeric field.voidsetAllowNegative(boolean allowNegative) Sets whether the numeric field allows negative values.voidsetGrouping(boolean grouping) Sets whether grouping is enabled for the numeric field.final voidsetLength(int width) Sets the maximum length of the numeric field.voidMethods inherited from class com.storedobject.vaadin.CustomTextField
alignRight, createField, customizeTextField, disablePaste, generateModelValue, getAutocomplete, getField, getInternalElement, getModelValue, getPrefixComponent, getSuffixComponent, isAutoselect, onAttach, setAutocomplete, setAutoselect, setEmptyDisplay, setEnabled, setHeight, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setPlaceholder, setPrefixComponent, setPresentationValue, setReadOnly, setSuffixComponent, setWidthMethods inherited from class com.storedobject.vaadin.CustomField
addField, addField, focusMethods inherited from class com.vaadin.flow.component.customfield.CustomField
add, addThemeVariants, getLabel, remove, removeThemeVariants, setLabel, updateValueMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeightFull, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidthFullMethods inherited from interface com.storedobject.vaadin.HasStyle
getClassName, getClassNames, getStyle, setClassNameMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, hasClassName, removeClassName, removeClassNames, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipTextMethods inherited from interface com.vaadin.flow.component.HasValidation
setManualValidationMethods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalidMethods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmptyMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setRequiredIndicatorVisible
-
Field Details
-
grouping
protected boolean groupingDetermines whether the numeric field should apply grouping of digits (e.g., thousand-separators) when displaying numbers. -
allowNegative
protected boolean allowNegativeIndicates whether negative values are allowed for the numeric input field. This variable determines if the field should accept negative numeric input. -
width
protected int widthRepresents the width of the numeric field in terms of the number of characters allowed. This variable controls the maximum visible or editable width of the field.
-
-
Constructor Details
-
NumericField
Constructs a NumericField with a specified default value.- Parameters:
defaultValue- the default value of the numeric field
-
-
Method Details
-
isGrouping
public final boolean isGrouping()Checks whether grouping is enabled for the numeric field.- Returns:
- true if grouping is enabled, false otherwise
-
setGrouping
public void setGrouping(boolean grouping) Sets whether grouping is enabled for the numeric field. Grouping typically refers to the separation of digits into groups, such as by thousands, for easier readability (e.g., 1,000,000 for one million).- Parameters:
grouping- a boolean value wheretrueenables grouping, andfalsedisables grouping
-
getAllowNegative
public final boolean getAllowNegative()Retrieves the current configuration indicating whether negative numbers are allowed in this numeric field.- Returns:
- true if negative numbers are allowed; false otherwise
-
setAllowNegative
public void setAllowNegative(boolean allowNegative) Sets whether the numeric field allows negative values.- Parameters:
allowNegative- a boolean specifying if negative values are allowed. If true, negative values are permitted; otherwise, they are not.
-
setValue
- Specified by:
setValuein interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.customfield.CustomField<T extends Number>,T extends Number>, T extends Number> - Overrides:
setValuein classcom.vaadin.flow.component.AbstractField<com.vaadin.flow.component.customfield.CustomField<T extends Number>,T extends Number>
-
getLength
public final int getLength()Retrieves the length of the numeric field.- Returns:
- the length of the numeric field as an integer.
-
getDecimals
public int getDecimals()Retrieves the number of decimal places allowed for the numeric field.- Returns:
- the number of decimals as an integer
-
format
Description copied from class:CustomTextFieldFormat the value to display it as a string.- Overrides:
formatin classCustomTextField<T extends Number>- Parameters:
value- Value to format.- Returns:
- Displayable string.
-
getDefaultLength
protected abstract int getDefaultLength()Retrieves the default length for the numeric field. The default length typically represents a predefined or initial configuration for the field's width.- Returns:
- the default length of the numeric field as an integer
-
setLength
public final void setLength(int width) Sets the maximum length of the numeric field. The length is adjusted based on certain criteria such as whether negative values are allowed and the number of decimal places. If the specified length is less than 1, a default value of 18 is used. The minimum length is dynamically calculated based on whether negative values are allowed and the number of decimal places. If the specified length is less than the calculated minimum length, the minimum length is used instead.- Parameters:
width- the desired maximum length for the numeric field. If the value is less than the calculated minimum or a default value, it will be adjusted accordingly.
-
getCountry
Retrieves the country code associated with the current application context. If no application context is available, the default country code "US" is returned.- Returns:
- the country code as a string, defaulting to "US" if the application context is unavailable.
-