Class NumberItem

All Implemented Interfaces:
Animatable<NumberItem>, CanDrop<NumberItem>, Clickable<NumberItem>, SupportAppend<NumberItem>, SupportHelpIcon<NumberItem>, SupportPlaceholder<NumberItem>, Draggable<NumberItem>, Editable<NumberItem>, Focusable<NumberItem>, HandleHotKey<NumberItem>, HandleKeyboardEvents<NumberItem>, HandleMouseEvents<NumberItem>, Touchable<NumberItem>

Number item

Input field used to enter a numeric value. The component prompts the user to enter a numeric value that is either an integer or a fraction. The component displays an input field where only numeric characters are allowed. A plus and a minus icon are also displayed, used to increment or decrement the component’s value.

The minimum and maximum value for the component. In this case the user is allowed to enter a value only within the specified range, and the increment/decrement steps are specified.

The number item component is a form item which means the component can be placed on the Form component and the form fully supports its functionality. The component may be used as a standalone component, but in this case value and event handling must be implemented from code.

Supported events:

AnimationStart AnimationEnd, Focus FocusOut FocusIn LosesFocus copy cut EnterPressed input paste Click, DoubleClick, MouseDown, MouseDown, MouseLeave, MouseMove, MouseOver, MouseOut, MouseUp, Wheel, KeyPress, KeyUp, KeyDown, TouchCancel, TouchEnd, TouchMove, TouchStart, Drop, DragStart, DragEnd HotKey

Since:
4.0
Author:
JBStrap
See Also:
  • Constructor Details

    • NumberItem

      public NumberItem(String name, String label)
      Creates an input field with the specified name and label.
      Parameters:
      name - Input field name
      label - Input field label. If null is set, the field has no label.
      Throws:
      NullPointerException - Thrown if the name specified for the field is null
    • NumberItem

      public NumberItem(String name, String label, String language)
      Creates a numeric input field with the specified name, label and language code.
      Parameters:
      name - Input field name
      label - Input field label. If null is set, the field has no label.
      language - The language code used to create the field If not specified or set to null, the field is created using the default language of the framework. The default language of the framework is set via the JBStrap parameter JBStrapParamType.DEFAULT_LANGUAGE.
      Throws:
      NullPointerException - Thrown if the name specified for the field is null
    • NumberItem

      public NumberItem(DataDescriptorColumn column)

      Creates a numeric input field using the specified DataDescriptor column.

      The method creates and sets a numeric input field based on the parameter-specified DataDescriptor column. The following parameters of the DataDescriptor are used:

      • DataDescriptorColumn.getTitle - The field label is the one specified for the DataDescriptor column
      • DataDescriptorColumn.isNullable() - If the field gets a value of null, it is not designated as mandatory. If the field value is not set to null, it is designated as a mandatory field.
      • MetaParamName.MIN_VALUE - This parameter specifies the minimum value of the component The parameter must take a value that can be converted to Long. If the parameter is not specified, no lower bound is set for the component value.
      • MetaParamName.MAX_VALUE - This parameter specifies the maximum value of the component. The parameter must take a value that can be converted to Long. If the parameter is not specified, no lower bound is set for the component value.
      • MetaParamName.TOUCHSPIN_STEP - This parameter specifies the increment/decrement step. The default value is 0.1. The parameter must take a value that can be converted to Long
      • MetaParamName.TOUCHSPIN_BUTTONUP_CLASS - This parameter specifies the custom CSS class for the increment button
      • MetaParamName.TOUCHSPIN_BUTTONDOWN_CLASS - This parameter specifies the custom CSS class for the decrement button
      • MetaParamName.TOUCHSPIN_PREFIX - If a text is set in the parameter, it is displayed as a prefix in front of the input field.
      • MetaParamName.TOUCHSPIN_PREFIX_EXTRACLASS - If a prefix is displayed in front of the input field, the custom CSS class containing the prefix is specified here
      • MetaParamName.TOUCHSPIN_POSTFIX - If a text is specified in the parameter, it is displayed after the input field as a postfix.
      • MetaParamName.TOUCHSPIN_POSTFIX_EXTRACLASS - If a postfix comes after the input field, the CSS class for the postfix box is specified here
      • MetaParamName.TOUCHSPIN_VERTICALBUTTONS - If the value is set to true, increment and decrement buttons are displayed below each other on the right side of the component. By default, the decrement button is displayed on the left side of the input field, whereas the increment button is displayed on the right side of the input field.
      • MetaParamName.MOUSEWHEEL - If the parameter is set to true, the user is able to change the component value by using the mouse wheel. This function is disabled by default.
      • MetaParamName.PLACEHOLDER - Placeholder text to be used in the input field. This text is displayed if no other text is entered into the input field.
      • MetaParamName.SIZE - The input field size is set from the value specified here. (Available values: SMALL, MEDIUM, LARGE)
      • MetaParamName.STATE - The input field state is set from these values. (Available values: DEFAULT, ERROR, WARNING, SUCCESS, INFO)
      • MetaParamName.DEFAULT_VALUE - The value specified here is set as the input field’s default value. The value must be specified based on the field’s data type, that is, it must be a text value.
      • MetaParamName.READ_ONLY - If true is set, the field is created as a read-only field. Otherwise the field is created as writable and the user is free to change its content.
      • MetaParamName.ENABLED - If false is set, the field is disabled. Otherwise the field is created as enabled.
      • MetaParamName.HELP - If this parameter is specified, an icon is displayed next to the input field and the text specified here appears as a help text if the user moves the mouse over it.
      • MetaParamName.HELP_ICON - If an icon name is specified in the parameter, also listed in the enum Icon, the default help text is changed to the icon.
      • MetaParamName.DESCRIPTION - The text specified here will appear below the field, in a smaller, italic font.
      • MetaParamName.TAB_INDEX - The value specified here determines the order of the input focus (when the user presses the Tab key). The smaller the value is, the sooner the field gets focus. The greater the value is, the later the field gets focus. If the parameter is not specified, the field’s tab index receives the focus order value set for the field in the DataDescriptor. If that is also not specified, the focus order is based on which data value was entered earlier into the DataDescriptor.

      Parameters:
      column - The DataDescriptor column based on which the field is created
      Throws:
      NullPointerException - Thrown if the parameter’s specified column is set to null
      NumberFormatException - Thrown if the value of the parameters MIN_VALUE, MAX_VALUE vagy a TOUCHSPIN_STEP cannot be parsed to Long.
    • NumberItem

      public NumberItem(DataDescriptorColumn column, String language)

      Creates a numeric input field based on the specified DataDescriptor column and language code.

      The method creates and sets a numeric input field based on the parameter-specified DataDescriptor column. The following parameters of the DataDescriptor are used:

      • DataDescriptorColumn.getTitle - The field label is the one specified for the DataDescriptor column
      • DataDescriptorColumn.isNullable() - If the field gets a value of null, it is not designated as mandatory. If the field value is not set to null, it is designated as a mandatory field.
      • MetaParamName.MIN_VALUE - This parameter specifies the minimum value of the component The parameter must take a value that can be converted to Long. If the parameter is not specified, no lower bound is set for the component value.
      • MetaParamName.MAX_VALUE - This parameter specifies the maximum value of the component. The parameter must take a value that can be converted to Long. If the parameter is not specified, no lower bound is set for the component value.
      • MetaParamName.TOUCHSPIN_STEP - This parameter specifies the increment/decrement step. The default value is 0.1. The parameter must take a value that can be converted to Long
      • MetaParamName.TOUCHSPIN_BUTTONUP_CLASS - This parameter specifies the custom CSS class for the increment button
      • MetaParamName.TOUCHSPIN_BUTTONDOWN_CLASS - This parameter specifies the custom CSS class for the decrement button
      • MetaParamName.TOUCHSPIN_PREFIX - If a text is set in the parameter, it is displayed as a prefix in front of the input field.
      • MetaParamName.TOUCHSPIN_PREFIX_EXTRACLASS - If a prefix is displayed in front of the input field, the custom CSS class containing the prefix is specified here
      • MetaParamName.TOUCHSPIN_POSTFIX - If a text is specified in the parameter, it is displayed after the input field as a postfix.
      • MetaParamName.TOUCHSPIN_POSTFIX_EXTRACLASS - If a postfix comes after the input field, the CSS class for the postfix box is specified here
      • MetaParamName.TOUCHSPIN_VERTICALBUTTONS - If the value is set to true, increment and decrement buttons are displayed below each other on the right side of the component. By default, the decrement button is displayed on the left side of the input field, whereas the increment button is displayed on the right side of the input field.
      • MetaParamName.MOUSEWHEEL - If the parameter is set to true, the user is able to change the component value by using the mouse wheel. This function is disabled by default.
      • MetaParamName.PLACEHOLDER - Placeholder text to be used in the input field. This text is displayed if no other text is entered into the input field.
      • MetaParamName.SIZE - The input field size is set from the value specified here. (Available values: SMALL, MEDIUM, LARGE)
      • MetaParamName.STATE - The input field state is set from these values. (Available values: DEFAULT, ERROR, WARNING, SUCCESS, INFO)
      • MetaParamName.DEFAULT_VALUE - The value specified here is set as the input field’s default value. The value must be specified based on the field’s data type, that is, it must be a text value.
      • MetaParamName.READ_ONLY - If true is set, the field is created as a read-only field. Otherwise the field is created as writable and the user is free to change its content.
      • MetaParamName.ENABLED - If false is set, the field is disabled. Otherwise the field is created as enabled.
      • MetaParamName.HELP - If this parameter is specified, an icon is displayed next to the input field and the text specified here appears as a help text if the user moves the mouse over it.
      • MetaParamName.HELP_ICON - If an icon name is specified in the parameter, also listed in the enum Icon, the default help text is changed to the icon.
      • MetaParamName.DESCRIPTION - The text specified here will appear below the field, in a smaller, italic font.
      • MetaParamName.TAB_INDEX - The value specified here determines the order of the input focus (when the user presses the Tab key). The smaller the value is, the sooner the field gets focus. The greater the value is, the later the field gets focus. If the parameter is not specified, the field’s tab index receives the focus order value set for the field in the DataDescriptor. If that is also not specified, the focus order is based on which data value was entered earlier into the DataDescriptor.
      • MetaParamName.SHOW_BUTTONS - This parameter determines if the buttons are shown on the component. By default, the buttons are not shown. If true, the buttons will be displayed in the component's input field

      Parameters:
      column - The DataDescriptor column based on which the field is created
      language - The language code used to create the field If not specified or set to null, the field is created using the default language of the framework. The default language of the framework is set via the JBStrap parameter JBStrapParamType.DEFAULT_LANGUAGE.
      Throws:
      NullPointerException - Thrown if the parameter’s specified column is set to null
      NumberFormatException - Thrown if the value of the parameters MIN_VALUE, MAX_VALUE vagy a TOUCHSPIN_STEP cannot be parsed to Long.
  • Method Details

    • setThousandsSeparator

      public final NumberItem setThousandsSeparator(char separator)
      Sets the thousands separator for the numbers. By default the framework’s thousands separator is used. This character is specified by the parameter JBStrapParamType.THOUSANDS_SEPARATOR
      Parameters:
      separator - Thousands separator
      Returns:
      Numeric input component
    • getThousandsSeparator

      public final char getThousandsSeparator()
      Gets the decimal separator.
      Returns:
      The decimal separator
    • setDecimalSeparator

      public final NumberItem setDecimalSeparator(char separator)
      Set the decimal separator. By default the framework’s decimal separator is used. This character is specified by the parameter JBStrapParamType.DECIMAL_SEPARATOR
      Parameters:
      separator - The decimal separator
      Returns:
      Numeric input component
    • getDecimalSeparator

      public final char getDecimalSeparator()
      Gets the decimal separator.
      Returns:
      The decimal separator
    • setDecimalPlaces

      public final NumberItem setDecimalPlaces(int decimalPlaces)
      Sets the number of decimal digits. By default, only 2 decimal digits are displayed.
      Parameters:
      decimalPlaces - The number of decimal digits to be displayed
      Returns:
      Numeric input component
    • getDecimalPalces

      public int getDecimalPalces()
      Gets the number of decimal digits in the component.
      Returns:
      The number of decimal digits to be displayed
    • getMinimumValue

      public final Double getMinimumValue()
      Gets the minimum value for the component
      Returns:
      The minimum value for the component or null if no minimum value is set
    • setMinimumValue

      public final NumberItem setMinimumValue(Number minValue)
      Sets the minimum value for the component.
      Parameters:
      minValue - The minimum value of the component No smaller value is allowed to be set for this component.
      Returns:
      Numeric input component
    • getMaximumValue

      public final Double getMaximumValue()
      Gets the maximum value for the component.
      Returns:
      The maximum value for the component or null if the maximum value is not specified
    • setMaximumValue

      public final NumberItem setMaximumValue(Number maxValue)
      Sets the component’s maximum value.
      Parameters:
      maxValue - The maximum value for the component No greater value is allowed to be set for this component.
      Returns:
      Numeric input component
    • setValue

      public final NumberItem setValue(Double value)
      Sets the current value of the component.
      Overrides:
      setValue in class FormItem<Double,NumberItem>
      Parameters:
      value - The current value of the component
      Returns:
      Numeric input component
    • setOriginalValue

      public final NumberItem setOriginalValue(Double value)
      Sets the original value of the component
      Overrides:
      setOriginalValue in class FormItem<Double,NumberItem>
      Parameters:
      value - The original value of the component
      Returns:
      Numeric input component
    • setObjectValue

      public NumberItem setObjectValue(Object value)
      Description copied from class: FormItem
      Sets the form item’s current value using the object in the parameter.
      Overrides:
      setObjectValue in class FormItem<Double,NumberItem>
      Parameters:
      value - The current value of the component
      Returns:
      Numeric input component
      Throws:
      NumberFormatException - Thrown if the text equivalent of the specified value cannot be converted to Long
    • setOriginalObjectValue

      public NumberItem setOriginalObjectValue(Object value)
      Description copied from class: FormItem
      Sets the form item’s original value using the object in the parameter.
      Overrides:
      setOriginalObjectValue in class FormItem<Double,NumberItem>
      Parameters:
      value - The original value of the component
      Returns:
      Numeric input component
      Throws:
      NumberFormatException - Thrown if the text equivalent of the specified value cannot be converted to Long
    • isShowTouchSpin

      public final boolean isShowTouchSpin()
      Sets if the increment/decrement buttons are displayed on the interface.
      Returns:
      If true, the increment/decrement buttons are visible, otherwise false
    • setShowTouchSpin

      public final NumberItem setShowTouchSpin(boolean showTouchSpin)
      Sets the appearance of the increment/decrement button. By default, the increment/decrement buttons are hidden on the interface.
      Parameters:
      showTouchSpin - If true is set, the increment/decrement buttons are visible If false is set,the increment/decrement buttons are not displayed on the interface.
      Returns:
      Numeric input component
    • setStep

      public final NumberItem setStep(Number step)
      Sets the increment/decrement value specified by the buttons. By default, the value is incremented/decremented in a step of 1.
      Parameters:
      step - Increment/decrement step
      Returns:
      Numeric input component
    • getStep

      public final Number getStep()
      Gets the increment/decrement value set by the buttons.
      Returns:
      Increment/decrement step
    • setPrefix

      public final NumberItem setPrefix(String prefixText)
      Sets the input box prefix.
      Parameters:
      prefixText - Prefix text
      Returns:
      Numeric input component
    • setPrefix

      public final NumberItem setPrefix(String prefixText, String prefixStyleClass)
      Sets the input box prefix and the custom style class of the prefix box.
      Parameters:
      prefixText - Prefix
      prefixStyleClass - Prefix box style class
      Returns:
      Numeric input component
    • getPrefix

      public final String getPrefix()
      Gets the prefix text.
      Returns:
      The prefix text or null if no prefix is set for the component
    • setPostfix

      public final NumberItem setPostfix(String postfixText)
      Sets the postfix text to be displayed after the input box.
      Parameters:
      postfixText - Postfix text
      Returns:
      Numeric input component
    • setPostfix

      public final NumberItem setPostfix(String postfixText, String postfixStyleClass)
      Sets the postfix text and the custom style class for the postfix.
      Parameters:
      postfixText - Postfix text
      postfixStyleClass - The name of the style class for the postfix box
      Returns:
      Numeric input component
    • getpostfix

      public final String getpostfix()
      Gets the postfix text to be displayed after the input box.
      Returns:
      Postfix text or null if no postfix is set for the component
    • setTouchspinButtonClass

      public final NumberItem setTouchspinButtonClass(String upButtonClass, String downButtonClass)
      Custom style class for the increment/decrement buttons.
      Parameters:
      downButtonClass - The style class for the decrement button
      upButtonClass - The style class for the increment button
      Returns:
      Numeric input component
    • getUpButtonStyleClass

      public final String getUpButtonStyleClass()
      Gets the style class for the increment button.
      Returns:
      The style class for the increment button or null if the increment button has no defined custom style class
    • getDownButtonStyleClass

      public final String getDownButtonStyleClass()
      Gets the style class name for the decrement button.
      Returns:
      Style class name for the decrement button or null if the decrement button has no custom syle class defined
    • setTouchSpinVertical

      public final NumberItem setTouchSpinVertical(boolean vertical)
      Sets the alignment of the increment/decrement buttons. By default, increment/decrement buttons are located to the left and right of the input field. This settings may be changed so that buttons are below each other to the right of the input field.
      Parameters:
      vertical - If true is set, increment/decrement buttons are located below each other to the right of the input field. If false is set, the increment/decrement buttons are located to the left and right of the input field.
      Returns:
      Numeric input component
    • isTouchSpinVertical

      public final boolean isTouchSpinVertical()
      Sets if the increment/decrement buttons are displayed below each other.
      Returns:
      If true is set, increment/decrement buttons are located below each other to the left of the input field. Otherwise false.
    • drawEditor

      public void drawEditor(StringWriter writer)
      Description copied from class: FormItem

      Draws the editor component.

      You do not need to use this method during development, but all components extending the form item must implement it. Use the method to generate the input field’s HTML code. This code is then inserted into the corresponding DOM code when drawing the form item.

      Specified by:
      drawEditor in class FormItem<Double,NumberItem>
      Parameters:
      writer - The HTML string writer class instance; write here the HTML code for the input field
    • init

      public void init() throws JavaScriptLoadError
      Description copied from class: Component
      The component initialization method.

      Empty method, only needs to be overwritten when making a custom component, that needs to call an initializing JavaScript on the client side. The method is called by the framework after the component is drawn, but before the afterDraw() method. The use of this method during application development is not allowed. This method is meant for inner use only.

      Overrides:
      init in class FormItem<Double,NumberItem>
      Throws:
      JavaScriptLoadError - If there was a JavaScript error during the initialization.
    • setDefaultValue

      public NumberItem setDefaultValue(Object defaultValue)
      Sets input field default value.
      Specified by:
      setDefaultValue in class FormItem<Double,NumberItem>
      Parameters:
      defaultValue - The default value for the input field
      Returns:
      Form item component
      Throws:
      NumberFormatException - Thrown if the specified value cannot be converted to Long
    • afterDraw

      public void afterDraw()
      Description copied from class: Component
      The operations to be executed after the drawing of the component

      By default, this is an empty method. It has to be overwritten on a component or page if additional operations have to be executed after the drawing process. One such operation is data retrieval, which shouldn't run in constructors so that the user could see results of an operation or navigation process.

      Overrides:
      afterDraw in class FormItem<Double,NumberItem>
    • setReadOnly

      public NumberItem setReadOnly(boolean readOnly)
      Sets if the field is read-only. If the field is set to read-only, the user is not allowed to change or modify the input field value using the increment/decrement buttons. Modifications are allowed by default.
      Overrides:
      setReadOnly in class FormItem<Double,NumberItem>
      Parameters:
      readOnly - If true is set, the field is read-only, otherwise modifications are allowed
      Returns:
      Numeric input component
    • isReadOnly

      public boolean isReadOnly()
      Sets if the input field is read-only.
      Overrides:
      isReadOnly in class FormItem<Double,NumberItem>
      Returns:
      If true is set, the input field is read-only, otherwise modifications are allowed
    • setEnabled

      public NumberItem setEnabled(boolean enabled)
      Enabling/disabling the component on the interface. If the component is disabled, the user is not allowed to use it and change its value. By default the component is enabled.
      Overrides:
      setEnabled in class FormItem<Double,NumberItem>
      Parameters:
      enabled - If true is set, the component is enabled, otherwise disabled
      Returns:
      Numeric input component
    • isEnabled

      public boolean isEnabled()
      Sets if the component is enabled.
      Overrides:
      isEnabled in class Component<NumberItem>
      Returns:
      If true is set, the component is enabled, otherwise disabled
    • setMousewheelSupport

      public final NumberItem setMousewheelSupport(boolean mousewheel)
      Sets if mouse wheel is supported. If the mouse wheel is supported, the input box value can be incremented/decremented using the mouse wheel. This function is disabled by default.
      Parameters:
      mousewheel - If true is set, the mouse wheel can be used to increment/decrement component value, otherwise not.
      Returns:
      Numeric input component
    • isMousewhelSupport

      public final boolean isMousewhelSupport()
      Sets if the component value is allowed to be modified using the mouse wheel.
      Returns:
      If true the component value can be modified using the mouse wheel, otherwise not.