Class CheckboxItem

All Implemented Interfaces:
Animatable<CheckboxItem>, CanDrop<CheckboxItem>, Clickable<CheckboxItem>, BooleanValueFormItem, SupportHelpIcon<CheckboxItem>, Draggable<CheckboxItem>, Focusable<CheckboxItem>, HandleMouseEvents<CheckboxItem>, Touchable<CheckboxItem>

Checkbox item

The checkbox item is used to input a logic value. The user can check the box that is displayed, which is interpreted as a true value, if the box is not checked, it is considered a false value. The field does not support the use of the null value.

The Checkbox component is a form item, that can be placed on a Form component, and the form handles it as well. The component can be used on its own, but in that case, the handling of its events and values must be provided by the program code.

Supported events:

AnimationStart AnimationEnd, Focus FocusOut FocusIn LosesFocus Click, DoubleClick, MouseDown, MouseDown, MouseLeave, MouseMove, MouseOver, MouseOut, MouseUp, Wheel, TouchCancel, TouchEnd, TouchMove, TouchStart, Drop, DragStart, DragEnd

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

    • CheckboxItem

      public CheckboxItem(String name, String label)
      Creates a checkbox item, with the specified name and label.
      Parameters:
      name - The name of the item
      label - The label of the item. If null, it won't have a label.
      Throws:
      NullPointerException - If the name is null
    • CheckboxItem

      public CheckboxItem(String name, String label, String language)
      Creates a checkbox item, with the specified name and label, and the specified language code.
      Parameters:
      name - The name of the item
      label - The label of the item. If null, it won't have a label.
      language - The language code, that the form item will use. If not specified, or null, the framework will use the default language. The default language can be set with the JBStrapParamType.DEFAULT_LANGUAGE JBStrap parameter.
      Throws:
      NullPointerException - If the name is null
    • CheckboxItem

      public CheckboxItem(String name, String label, StyleElement... styles)
      Creates a checkbox item, with the specified name, label and style.
      Parameters:
      name - The name of the item
      label - The label of the item. If null, it won't have a label.
      styles - The checkbox style. Usable values: CheckboxShape enum
      Throws:
      NullPointerException - If the name is null
    • CheckboxItem

      public CheckboxItem(String name, String label, String language, StyleElement... styles)
      Creates a checkbox item, with the specified name, label and style, with the specified language code.
      Parameters:
      name - The name of the item
      label - The label of the item. If null, it won't have a label.
      language - The language code, that the form item will use. If not specified, or null, the framework will use the default language. The default language can be set with the JBStrapParamType.DEFAULT_LANGUAGE JBStrap parameter.
      styles - The checkbox style. Usable values: CheckboxShape enum
      Throws:
      NullPointerException - If the name is null
    • CheckboxItem

      public CheckboxItem(DataDescriptorColumn column)

      Createts a checkbox item, based on the specified DataDescriptor column.

      The method creates and sets the checkbox item, based on the DataDescriptor column, specified in the parameters. The following parameters from the DataDescriptor column are used:

      • DataDescriptorColumn.getTitle - The title set in the DataDescriptor column will be used by the input field as its label.
      • DataDescriptorColumn.isNullable() - If the field can a null value, the field will be marked as not mandatory. If it cannot have a null value, the field will be marked as mandatory.
      • MetaParamName.TYPE - The value specifies the checkbox color. (Usable values: DEFAULT, PRIMARY, SUCCESS, INFO, WARNING, DANGER)
      • MetaParamName.SHAPE - The value specifies the checkbox shape. (Usable values: DEFAULT, CIRCLE)
      • MetaParamName.SIZE - The value specified here defines the size of the input field. (Applicable values: SMALL, MEDIUM, LARGE)
      • MetaParamName.STATE - The value specified here defines the state of the input field. (Applicable values: DEFAULT, ERROR, WARNING, SUCCESS, INFO)
      • MetaParamName.DEFAULT_VALUE - The value specified here defines the field's default value. The value must have the type of field, in this case, it must be a boolean value.
      • MetaParamName.READ_ONLY - If true, the field will be read only. Otherwise, the field can have its contents modified by the user.
      • MetaParamName.ENABLED - If false, the field will be disabled (it will be created in an unusable state.) Otherwise, the field will be enabled when created.
      • MetaParamName.HELP - If the parameter is specified, an icon will be displayed next to the field. If the user moves over the icon, the text specified here will be displayed, as a help text.
      • MetaParamName.HELP_ICON - If the icon name is specified (from the Icon enum), then this icon will replace the default "?" 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 order goes in ascending order. If not specified, the component will use the order value from the DataDescriptor. If that not specified either, the order in which it was placed in the DataDescriptor will be used.

      Parameters:
      column - The DataDescriptor column, that will be used as a basis for the form item.
      Throws:
      NullPointerException - If the column was specified as null
    • CheckboxItem

      public CheckboxItem(DataDescriptorColumn column, String language)

      Creates a checkbox item, based on the specified DataDescriptor column and using the specified language code.

      The method creates and sets the checkbox item, based on the DataDescriptor column, specified in the parameters. The following parameters from the DataDescriptor column are used:

      • DataDescriptorColumn.getTitle - The title set in the DataDescriptor column will be used by the input field as its label.
      • DataDescriptorColumn.isNullable() - If the field can a null value, the field will be marked as not mandatory. If it cannot have a null value, the field will be marked as mandatory.
      • MetaParamName.TYPE - The value specifies the checkbox color. (Usable values: DEFAULT, PRIMARY, SUCCESS, INFO, WARNING, DANGER)
      • MetaParamName.SHAPE - The value specifies the checkbox shape. (Usable values: DEFAULT, CIRCLE)
      • MetaParamName.SIZE - The value specified here defines the size of the input field. (Applicable values: SMALL, MEDIUM, LARGE)
      • MetaParamName.STATE - The value specified here defines the state of the input field. (Applicable values: DEFAULT, ERROR, WARNING, SUCCESS, INFO)
      • MetaParamName.DEFAULT_VALUE - The value specified here defines the field's default value. The value must have the type of field, in this case, it must be a boolean value.
      • MetaParamName.READ_ONLY - If true, the field will be read only. Otherwise, the field can have its contents modified by the user.
      • MetaParamName.ENABLED - If false, the field will be disabled (it will be created in an unusable state.) Otherwise, the field will be enabled when created.
      • MetaParamName.HELP - If the parameter is specified, an icon will be displayed next to the field. If the user moves over the icon, the text specified here will be displayed, as a help text.
      • MetaParamName.HELP_ICON - If the icon name is specified (from the Icon enum), then this icon will replace the default "?" 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 order goes in ascending order. If not specified, the component will use the order value from the DataDescriptor. If that not specified either, the order in which it was placed in the DataDescriptor will be used.

      Parameters:
      column - The DataDescriptor column, that will be used as a basis for the form item.
      language - The language code, that the form item will use. If not specified, or null, the framework will use the default language. The default language can be set with the JBStrapParamType.DEFAULT_LANGUAGE JBStrap parameter.
      Throws:
      NullPointerException - If the column was specified as null
  • Method Details

    • setCheckboxType

      public final CheckboxItem setCheckboxType(CheckboxType checkboxType)
      Sets the checkbox type (color). Defaults to DEFAULT
      Parameters:
      checkboxType - The checkbox type. Usable values: CheckboxType enum
      Returns:
      The checkbox item component
    • setCheckboxShape

      public final CheckboxItem setCheckboxShape(CheckboxShape checkboxShape)
      Sets the checkbox shape. The default shape is a rectangular checkbox (DEFAULT).
      Parameters:
      checkboxShape - The checkbox shape. Usable values: CheckboxShape enum
      Returns:
      The checkbox item component
    • isChecked

      public final boolean isChecked()
      Determines if the box is checked.
      Returns:
      If true, it is checked, otherwise false
    • setState

      public CheckboxItem setState(FormItemState formItemState)
      Sets the checkbox state. The default state is DEFAULT
      Overrides:
      setState in class FormItem<Boolean,CheckboxItem>
      Parameters:
      formItemState - The checkbox state. Usable values: FormItemState enum
      Returns:
      The checkbox item component
    • 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<Boolean,CheckboxItem>
      Parameters:
      writer - The HTML string writer class instance; write here the HTML code for the input field
    • setValue

      public CheckboxItem setValue(Boolean value)
      Sets the checkbox value. If null, the checkbox will have a false value.
      Overrides:
      setValue in class FormItem<Boolean,CheckboxItem>
      Parameters:
      value - Current value of the checkbox item
      Returns:
      The checkbox item component
    • setOriginalValue

      public CheckboxItem setOriginalValue(Boolean originalValue)
      Sets the checkbox original value, and actual value at the same time. If the user modifies the checkbox value, the original value won't change. This means that it can be determined if the user has modified the checkbox value.
      Overrides:
      setOriginalValue in class FormItem<Boolean,CheckboxItem>
      Parameters:
      originalValue - The value that will be the original and actual value
      Returns:
      The checkbox item component
    • setObjectValue

      public CheckboxItem 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<Boolean,CheckboxItem>
      Parameters:
      value - The checkbox actual value
      Returns:
      The checkbox item component
    • setOriginalObjectValue

      public CheckboxItem 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<Boolean,CheckboxItem>
      Parameters:
      value - The value that will be the original and actual value
      Returns:
      The checkbox item component
    • setDefaultValue

      public CheckboxItem setDefaultValue(Object defaultValue)
      Sets the default value of the checkbox, following the specified object. The value is interpreted, following these rules:
      • If null, the false value will be set.
      • If the specified value is from Boolean class, then that value will be set.
      • In other cases, the framework will try to interpret the value as a logic value, and set the switch value accordingly. In this case, a true value is set if the specified value is one of the following: 1, 1L, "1", "Y", "YES", "TRUE", "T", "ON". This check is not case-sensitive.
      Specified by:
      setDefaultValue in class FormItem<Boolean,CheckboxItem>
      Parameters:
      defaultValue - The checkbox default value
      Returns:
      The checkbox item component
    • setReadOnly

      public final CheckboxItem setReadOnly(boolean readOnly)
      Sets if the checkbox is read-only. If the checkbox is read-only, the user won't be able to modify the item's value.
      Overrides:
      setReadOnly in class FormItem<Boolean,CheckboxItem>
      Parameters:
      readOnly - true if the checkbox is read-only. Otherwise, the checkbox can be modified.
      Returns:
      The checkbox item component
    • setReverseShow

      public CheckboxItem setReverseShow(boolean reverse)