Class SwitchItem
- All Implemented Interfaces:
Animatable<SwitchItem>
,CanDrop<SwitchItem>
,Clickable<SwitchItem>
,BooleanValueFormItem
,SupportHelpIcon<SwitchItem>
,Draggable<SwitchItem>
,Focusable<SwitchItem>
,HandleHotKey<SwitchItem>
,HandleMouseEvents<SwitchItem>
,Touchable<SwitchItem>
Switch item
The switch item allows the user to input a logic value. The item is displayed as a switch, that can be switched left to right.
By default, this is a rectangular switch, that has ON and OFF written on it. This text can be customized, and the switch itself can be set to be rounded.
If the user switches this, it will have a true
value, if switches it off, it will be false
.
The component cannot have a null
value, thus if the component doesn't get a value, it will have a false
value.
The switch 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
,
HotKey
Drop
,
DragStart
,
DragEnd
- Since:
- 4.0
- Author:
- JBStrap
- See Also:
-
Field Summary
Fields inherited from class com.jbstrap.ui.components.form.FormItem
appends, clearButton, column, defaultState, defaultValue, description, formItemSize, helpIcon, label, labelPosition, labelSizes, modified, originalValue, params, prepends, required, showLabel, state, tabIndex, value, visible
Fields inherited from class com.jbstrap.ui.Component
animation, attributes, backgroundColor, borderColor, color, defaultHotKeyHandler, handlers, hotKeys, styleClasses, textAlign, toolTip, toolTipPosition
-
Constructor Summary
ConstructorDescriptionSwitchItem
(DataDescriptorColumn column) Createts a switch item, based on the specified DataDescriptor column.SwitchItem
(DataDescriptorColumn column, String language) Creates a switch item, based on the specified DataDescriptor column and using the specified language code.SwitchItem
(String name, String label) Creates a switch item, with the specified name and label.SwitchItem
(String name, String label, String language) Creates a switch item, with the specified name and label, with the specified language code. -
Method Summary
Modifier and TypeMethodDescriptionaddStyleClass
(String styleClass) Adds the specified CSS class to the componentaddStyleClasses
(String... styleClasses) Adds the specified style classes to the componentboolean
containsStyleClass
(String styleClass) Determines if the specified style class has been assigned to the component.void
drawEditor
(StringWriter writer) Draws the editor component.Gets the text that is displayed when the switch is in the OFF state.Gets the text that is displayed when the switch is in the ON state.Gets a list of every style class that was assigned to the component.getWidth()
Gets the width of the switch.final boolean
Determines if the switch is in the "ON" state.boolean
Determines if the switch is rounded.Removes every specified style class from the componentremoveStyleClass
(String styleClass) Removes the specified style class from the componentsetDefaultValue
(Object defaultValue) Sets the default value of the switch.setObjectValue
(Object value) Sets the form item’s current value using the object in the parameter.setOffText
(String offText) Sets the text that is displayed when the switch is in the OFF state.Sets the text that is displayed when the switch is in the ON state.setOriginalObjectValue
(Object value) Sets the form item’s original value using the object in the parameter.setOriginalValue
(Boolean originalValue) Sets the original value of the switch.setReadOnly
(boolean readOnly) Sets the form item to read-only mode.setReverseShow
(boolean reverse) setRounded
(boolean rounded) Sets the switch to have rounded edges.setState
(FormItemState formItemState) Sets the state of the switch.Sets the text that is displayed when the switch is in the ON and OFF state.Sets the switch value.Sets the width of the switch.Methods inherited from class com.jbstrap.ui.components.form.FormItem
_addComponent, _setReverseShow, _setState, addComponent, addRecalcOnChangeColumn, addRecalcOnChangeColumns, addRecalcOnChangeColumns, addValueChangeHandler, afterDraw, clearValue, convertValueToJavaScript, convertValueToJavaScript, drawComponent, enableClearButton, eraseValue, getCalculateValue, getColumn, getComponents, getDataType, getDefaultState, getDescription, getFormItemSize, getLabel, getLabelPosition, getLabelSize, getLabelSize, getName, getOriginalValue, getParam, getParamAsBoolean, getParamAsDate, getParamAsDate, getParamAsDouble, getParamAsInteger, getParamAsLong, getParamAsNumber, getParamAsString, getRecalcOnChangeColumnsList, getState, getTabIndex, getValue, getValueAsBoolean, getValueAsDate, getValueAsDouble, getValueAsFloat, getValueAsInteger, getValueAsLong, getValueAsString, init, isAssignable, isAutoCalculate, isModified, isReadOnly, isRequired, isReverseShow, isShowLabel, isVisible, onFormItemValueChanged, onHotKeyEventHandler, onShow, redraw, removeParam, resetState, runAfterDrawOnAddon, runOnHideOnAddon, runOnShowOnAddon, setCalculateValue, setDataType, setDataType, setDescription, setEnabled, setFocus, setFormItemSize, setLabel, setLabelPosition, setLabelSize, setLabelSize, setMargin, setModified, setPadding, setParam, setParams, setRequired, setShowLabel, setTabIndex, setVisible, triggerFormChange, writeHTML
Methods inherited from class com.jbstrap.ui.Component
_hide, _setAttribute, addAllowedRole, addComponent, addComponents, addDeniedRole, addHandler, addStyle, clearfix, closeTag, combinateAccess, containsStyle, draw, drawSubComponents, error, flattendComponentTree, getAccess, getAccessMode, getAllowedRoles, getAttribute, getAttributes, getBackgroundColor, getBorderColor, getClient, getComponentById, getComponents, getComponentsByClass, getData, getDeniedRoles, getHandlers, getId, getLanguageCode, getParent, getParent, getRegisteredEvents, getStyle, getTextAlign, getTextColor, getToolTip, getToolTipPosition, getTypeName, getUI, insertComponentAfter, insertComponentBefore, isAccess, isDrawn, isEnabled, isEventBubbling, onHide, openTag, removeAllComponents, removeAllowedRole, removeAttribute, removeComponent, removeComponent, removeComponents, removeDeniedRole, removeHandler, removeStyle, removeStyle, removeStyleClasses, replaceComponent, replaceStyleClass, runAfterDraw, runJavaScript, runJavaScript, runJavaScript, runOnHide, runOnShow, say, setAttribute, setBackgroundColor, setBorder, setBorderColor, setData, setDisplayType, setEventBubbling, setFlex, setFloating, setHeight100, setHeight25, setHeight50, setHeight75, setHeightAuto, setLanguage, setName, setOverflow, setParent, setScrollable, setSelectionType, setShadow, setStyle, setTextAlign, setTextColor, setToolTip, setToolTipPosition, setWidth100, setWidth25, setWidth50, setWidth75, setWidthAuto, showNotification, showNotification, showProcessIndicator, toggleStyleClass
Methods inherited from class com.jbstrap.core.messagebus.MessageBus
closeMessageBus, messageBusOpened, openMessageBus, renewSubscription, sendMessageToMessageBus, subscribeMessageBus, unsubscribeAllListeners, unsubscribeMessageBus
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jbstrap.ui.Animatable
addAnimationEndHandler, addAnimationStartHandler, getAnimation, removeAnimation, setAnimation
Methods inherited from interface com.jbstrap.ui.CanDrop
addDropEventHandler
Methods inherited from interface com.jbstrap.ui.Clickable
addClickHandler, addDoubleClickHandler
Methods inherited from interface com.jbstrap.ui.Draggable
addDragEndEventHandler, addDragStartEventHandler, setDraggable
Methods inherited from interface com.jbstrap.ui.Focusable
addFocusHandler, addFocusInHandler, addFocusOutHandler, addLosesFocusHandler, setFocus
Methods inherited from interface com.jbstrap.ui.HandleHotKey
addHotKey, addHotKey, removeHotKey, removeHotKeys
Methods inherited from interface com.jbstrap.ui.HandleMouseEvents
addMouseDownHandler, addMouseEnterHandler, addMouseLeaveHandler, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler
Methods inherited from interface com.jbstrap.ui.components.form.SupportHelpIcon
getHelpIcon, getHelpText, setHelpIcon, setHelpText
Methods inherited from interface com.jbstrap.ui.Touchable
addTouchCancelHandler, addTouchEndHandler, addTouchMoveHandler, addTouchStartHandler
-
Constructor Details
-
SwitchItem
Creates a switch item, with the specified name and label.- Parameters:
name
- The name of the itemlabel
- The label of the item. Ifnull
, the menu won't have a label.- Throws:
NullPointerException
- If the name isnull
-
SwitchItem
Creates a switch item, with the specified name and label, with the specified language code.- Parameters:
name
- The name of the itemlabel
- The label of the item. Ifnull
, the menu won't have a label.language
- The language code, that the form item will use. If not specified, ornull
, the framework will use the default language. The default language can be set with theJBStrapParamType.DEFAULT_LANGUAGE
JBStrap parameter.- Throws:
NullPointerException
- If the name isnull
-
SwitchItem
Createts a switch item, based on the specified DataDescriptor column.
The method creates and sets the switch 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 anull
value, the field will be marked as not mandatory. If it cannot have anull
value, the field will be marked as mandatory.MetaParamName.ON_TEXT
- This specifies the text that is displayed when the switch is in the ON state.MetaParamName.OFF_TEXT
- This specifies the text that is displayed when the switch is in the OFF state.MetaParamName.WIDTH
- This specifies the switch item's width. The default is 54 px.MetaParamName.PLACEHOLDER
- This text will be used as a placeholder.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 text value.MetaParamName.READ_ONLY
- Iftrue
, the field will be read only. Otherwise, the field can have its contents modified by the user.MetaParamName.ENABLED
- Iffalse
, 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 theIcon
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 asnull
-
SwitchItem
Creates a switch item, based on the specified DataDescriptor column and using the specified language code.
The method creates and sets the switch 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 anull
value, the field will be marked as not mandatory. If it cannot have anull
value, the field will be marked as mandatory.MetaParamName.ON_TEXT
- This specifies the text that is displayed when the switch is in the ON state.MetaParamName.OFF_TEXT
- This specifies the text that is displayed when the switch is in the OFF state.MetaParamName.WIDTH
- This specifies the switch item's width. The default is 54 px.MetaParamName.PLACEHOLDER
- This text will be used as a placeholder.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 text value.MetaParamName.READ_ONLY
- Iftrue
, the field will be read only. Otherwise, the field can have its contents modified by the user.MetaParamName.ENABLED
- Iffalse
, 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 theIcon
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, ornull
, the framework will use the default language. The default language can be set with theJBStrapParamType.DEFAULT_LANGUAGE
JBStrap parameter.- Throws:
NullPointerException
- If the column was specified asnull
-
-
Method Details
-
addStyleClass
Adds the specified CSS class to the component- Overrides:
addStyleClass
in classComponent<SwitchItem>
- Parameters:
styleClass
- The name of the CSS style class- Returns:
- The component
-
setOnText
Sets the text that is displayed when the switch is in the ON state. The default is "ON"- Parameters:
onText
- The text that is displayed when the switch is in the ON state.- Returns:
- The switch component
-
getOnText
Gets the text that is displayed when the switch is in the ON state.- Returns:
- The text that is displayed when the switch is in the ON state or
null
if not set.
-
setOffText
Sets the text that is displayed when the switch is in the OFF state. The default is "OFF"- Parameters:
offText
- The text that is displayed when the switch is in the OFF state.- Returns:
- The switch component
-
getOffText
Gets the text that is displayed when the switch is in the OFF state.- Returns:
- The text that is displayed when the switch is in the OFF state or
null
if not set.
-
setText
Sets the text that is displayed when the switch is in the ON and OFF state.- Parameters:
onText
- The text that is displayed when the switch is in the ON state.offText
- The text that is displayed when the switch is in the OFF state.- Returns:
- The switch component
-
setWidth
Sets the width of the switch. The default is 54 pixels- Parameters:
width
- The width, specified by using CSS3 units.- Returns:
- The switch component
-
getWidth
Gets the width of the switch.- Returns:
- The switch width, or 54px, if the width was not customized.
-
setRounded
Sets the switch to have rounded edges. By default, this is disabled, and the switch is rectangular.- Parameters:
rounded
- Iftrue
, the switch will be rounded, otherwise it will be rectangular.- Returns:
- The switch component
-
isRounded
public boolean isRounded()Determines if the switch is rounded.- Returns:
- If
true
, the switch will be rounded, otherwise it will be rectangular.
-
getStyleClasses
Gets a list of every style class that was assigned to the component.- Overrides:
getStyleClasses
in classComponent<SwitchItem>
- Returns:
- A list of the style classes. If none were assigned to the component, the list will be empty.
-
containsStyleClass
Determines if the specified style class has been assigned to the component.- Overrides:
containsStyleClass
in classComponent<SwitchItem>
- Parameters:
styleClass
- The name of the style class- Returns:
true
if it is assigned, otherwisefalse
-
addStyleClasses
Adds the specified style classes to the component- Overrides:
addStyleClasses
in classComponent<SwitchItem>
- Parameters:
styleClasses
- The name of the style classes- Returns:
- The component
-
removeStyleClass
Removes the specified style class from the component- Overrides:
removeStyleClass
in classComponent<SwitchItem>
- Parameters:
styleClass
- The name of the style class- Returns:
- The component
-
removeAllStyleClasses
Removes every specified style class from the component- Overrides:
removeAllStyleClasses
in classComponent<SwitchItem>
- Returns:
- The component
-
isChecked
public final boolean isChecked()Determines if the switch is in the "ON" state.- Returns:
- If
true
, it is on, otherwisefalse
-
setState
Sets the state of the switch. This setting cannot be used if the switch label is not displayed.- Overrides:
setState
in classFormItem<Boolean,
SwitchItem> - Parameters:
formItemState
- The switch state. The applicable values can be found in theFormItemState
enum.- Returns:
- The switch component
-
drawEditor
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 classFormItem<Boolean,
SwitchItem> - Parameters:
writer
- The HTML string writer class instance; write here the HTML code for the input field
-
setValue
Sets the switch value.- Overrides:
setValue
in classFormItem<Boolean,
SwitchItem> - Parameters:
value
- The switch value. Iftrue
, the switch is on, otherwise it is off.- Returns:
- The switch component
-
setOriginalValue
Sets the original value of the switch.- Overrides:
setOriginalValue
in classFormItem<Boolean,
SwitchItem> - Parameters:
originalValue
- The original value of the switch. Iftrue
, the original value of the switch will betrue
too. Otherwisefalse
- Returns:
- The switch component
-
setObjectValue
Description copied from class:FormItem
Sets the form item’s current value using the object in the parameter.- Overrides:
setObjectValue
in classFormItem<Boolean,
SwitchItem> - Parameters:
value
- The switch actual value- Returns:
- The switch component
-
setOriginalObjectValue
Description copied from class:FormItem
Sets the form item’s original value using the object in the parameter.- Overrides:
setOriginalObjectValue
in classFormItem<Boolean,
SwitchItem> - Parameters:
value
- The value to be assigned for the actual and original value.- Returns:
- The switch component
-
setDefaultValue
Sets the default value of the switch. The following rules are followed when setting the value.- If the value is
null
, then thefalse
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 classFormItem<Boolean,
SwitchItem> - Parameters:
defaultValue
- The default value of the switch.- Returns:
- The switch component
- If the value is
-
setReverseShow
-
setReadOnly
Description copied from class:FormItem
Sets the form item to read-only mode. By default, the form item is displayed as writable and the user can freely modify the form item value. If the component is set to read-only mode, the user is unable to modify the form item value.- Overrides:
setReadOnly
in classFormItem<Boolean,
SwitchItem> - Parameters:
readOnly
- Iftrue
is set, the form item is switched to read-only mode and the user is unable to modify the value. Iffalse
is set, the form item is switched to writable mode and the user is able to modify form item value.- Returns:
- Form item component
-