Class ToggleSwitch

All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, HasVisibility, IsWidget, LogicalStructure, HasClearHandlers, HasClickHandlers, HasDoubleClickHandlers, HasDragMoveHandlers, HasDragRepositionMoveHandlers, HasDragRepositionStartHandlers, HasDragRepositionStopHandlers, HasDragResizeMoveHandlers, HasDragResizeStartHandlers, HasDragResizeStopHandlers, HasDragStartHandlers, HasDragStopHandlers, HasDropHandlers, HasDropMoveHandlers, HasDropOutHandlers, HasDropOverHandlers, HasFocusChangedHandlers, HasHoverHandlers, HasHoverHiddenHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseStillDownHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasMovedHandlers, HasParentMovedHandlers, HasResizedHandlers, HasRightMouseDownHandlers, HasRuleContextChangedHandlers, HasScrolledHandlers, HasShowContextMenuHandlers, HasToggleValueChangedHandlers, HasVisibilityChangedHandlers

public class ToggleSwitch extends StatefulCanvas implements HasToggleValueChangedHandlers
A simple control that presents a Boolean value as a toggle-switch, where the value can be toggled by clicking with the mouse, or with the Spacebar and left/right arrow-keys when toggleOnKeypress is true.
  • Constructor Details

    • ToggleSwitch

      public ToggleSwitch()
    • ToggleSwitch

      public ToggleSwitch(JavaScriptObject jsObj)
    • ToggleSwitch

      public ToggleSwitch(String title)
  • Method Details

    • getOrCreateRef

      public static ToggleSwitch getOrCreateRef(JavaScriptObject jsObj)
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, Canvas defaults)
      Changes the defaults for Canvas AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - Canvas defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • changeAutoChildDefaults

      public static void changeAutoChildDefaults(String autoChildName, FormItem defaults)
      Changes the defaults for FormItem AutoChildren named autoChildName.
      Parameters:
      autoChildName - name of an AutoChild to customize the defaults for.
      defaults - FormItem defaults to apply. These defaults override any existing properties without destroying or wiping out non-overridden properties. For usage tips on this param, see SGWTProperties.
      See Also:
    • create

      protected JavaScriptObject create()
      Overrides:
      create in class StatefulCanvas
    • setAnimateThumb

      public ToggleSwitch setAnimateThumb(Boolean animateThumb)
      When set to true, animates the movement of the thumb when the value changes.
      Parameters:
      animateThumb - New animateThumb value. Default value is true
      Returns:
      ToggleSwitch instance, for chaining setter calls
      See Also:
    • getAnimateThumb

      public Boolean getAnimateThumb()
      When set to true, animates the movement of the thumb when the value changes.
      Returns:
      Current animateThumb value. Default value is true
      See Also:
    • setAnimateThumbTime

      public ToggleSwitch setAnimateThumbTime(Integer animateThumbTime)
      When animateThumb is true, the time taken to move the thumb from one state to the other.
      Parameters:
      animateThumbTime - New animateThumbTime value. Default value is 200
      Returns:
      ToggleSwitch instance, for chaining setter calls
      See Also:
    • getAnimateThumbTime

      public Integer getAnimateThumbTime()
      When animateThumb is true, the time taken to move the thumb from one state to the other.
      Returns:
      Current animateThumbTime value. Default value is 200
      See Also:
    • setDefaultValue

      public ToggleSwitch setDefaultValue(Boolean defaultValue)
      The default value of this ToggleSwitch.
      Parameters:
      defaultValue - New defaultValue value. Default value is false
      Returns:
      ToggleSwitch instance, for chaining setter calls
      See Also:
    • getDefaultValue

      public Boolean getDefaultValue()
      The default value of this ToggleSwitch.
      Returns:
      Current defaultValue value. Default value is false
      See Also:
    • getThumb

      public Canvas getThumb() throws IllegalStateException
      A canvas used as the thumb of this ToggleSwitch, which can be styled using thumbBaseStyle and otherwise modified according to the AutoChild pattern - thumbConstructor, thumbDefaults and thumbProperties are valid.

      This component is an AutoChild named "thumb". For an overview of how to use and configure AutoChildren, see Using AutoChildren.

      Returns:
      Current thumb value. Default value is null
      Throws:
      IllegalStateException - if this widget has not yet been rendered.
    • setThumbBaseStyle

      public ToggleSwitch setThumbBaseStyle(String thumbBaseStyle)
      The name of the base CSS class to apply to the thumb of this toggle switch - the actual styleName applied will be suffixed "On" or "Off", depending on this widget's current value.
      Parameters:
      thumbBaseStyle - New thumbBaseStyle value. Default value is "toggleSwitchThumb"
      Returns:
      ToggleSwitch instance, for chaining setter calls
      See Also:
    • getThumbBaseStyle

      public String getThumbBaseStyle()
      The name of the base CSS class to apply to the thumb of this toggle switch - the actual styleName applied will be suffixed "On" or "Off", depending on this widget's current value.
      Returns:
      Current thumbBaseStyle value. Default value is "toggleSwitchThumb"
      See Also:
    • setThumbOffset

      public ToggleSwitch setThumbOffset(Integer thumbOffset)
      Spacing to apply inside of this ToggleSwitch, outside of the thumb.
      Parameters:
      thumbOffset - New thumbOffset value. Default value is 2
      Returns:
      ToggleSwitch instance, for chaining setter calls
      See Also:
    • getThumbOffset

      public Integer getThumbOffset()
      Spacing to apply inside of this ToggleSwitch, outside of the thumb.
      Returns:
      Current thumbOffset value. Default value is 2
      See Also:
    • setThumbRadius

      public ToggleSwitch setThumbRadius(String thumbRadius)
      The CSS border-radius for the thumb. The value can be any variant of a CSS border-radius value - that is, from 1 to 4 space-separated px values, where one value affects all corners and 4 values affects individual corners. For example "10px" applies a 10px radius to all corners, where "5px 10px 15px 20px" applies a different radius to each corner, clockwise from Top-Left: "TL TR BR BL".
      Parameters:
      thumbRadius - New thumbRadius value. Default value is null
      Returns:
      ToggleSwitch instance, for chaining setter calls
      See Also:
    • getThumbRadius

      public String getThumbRadius()
      The CSS border-radius for the thumb. The value can be any variant of a CSS border-radius value - that is, from 1 to 4 space-separated px values, where one value affects all corners and 4 values affects individual corners. For example "10px" applies a 10px radius to all corners, where "5px 10px 15px 20px" applies a different radius to each corner, clockwise from Top-Left: "TL TR BR BL".
      Returns:
      Current thumbRadius value. Default value is null
      See Also:
    • setToggleBaseStyle

      public ToggleSwitch setToggleBaseStyle(String toggleBaseStyle)
      The name of the CSS class to apply to this ToggleSwitch - the actual styleName applied will be suffixed "On" or "Off", depending on the widget's current value.
      Parameters:
      toggleBaseStyle - New toggleBaseStyle value. Default value is "toggleSwitch"
      Returns:
      ToggleSwitch instance, for chaining setter calls
      See Also:
    • getToggleBaseStyle

      public String getToggleBaseStyle()
      The name of the CSS class to apply to this ToggleSwitch - the actual styleName applied will be suffixed "On" or "Off", depending on the widget's current value.
      Returns:
      Current toggleBaseStyle value. Default value is "toggleSwitch"
      See Also:
    • setToggleOnKeypress

      public ToggleSwitch setToggleOnKeypress(Boolean toggleOnKeypress)
      When set to true, the value can be toggled by pressing the Spacebar, or changed with the left and right arrow-keys.
      Parameters:
      toggleOnKeypress - New toggleOnKeypress value. Default value is true
      Returns:
      ToggleSwitch instance, for chaining setter calls
      See Also:
    • getToggleOnKeypress

      public Boolean getToggleOnKeypress()
      When set to true, the value can be toggled by pressing the Spacebar, or changed with the left and right arrow-keys.
      Returns:
      Current toggleOnKeypress value. Default value is true
      See Also:
    • setToggleOnThumbClick

      public ToggleSwitch setToggleOnThumbClick(Boolean toggleOnThumbClick)
      When set to true, causes the ToggleSwitch to change value when the thumb is clicked, as well as when clicking in the widget body.
      Parameters:
      toggleOnThumbClick - New toggleOnThumbClick value. Default value is true
      Returns:
      ToggleSwitch instance, for chaining setter calls
      See Also:
    • getToggleOnThumbClick

      public Boolean getToggleOnThumbClick()
      When set to true, causes the ToggleSwitch to change value when the thumb is clicked, as well as when clicking in the widget body.
      Returns:
      Current toggleOnThumbClick value. Default value is true
      See Also:
    • setValue

      public ToggleSwitch setValue(Boolean value)
      The current value of this ToggleSwitch.

      If this method is called after the component has been drawn/initialized: Sets the value of this ToggleSwitch.
      Parameters:
      value - new value for the ToggleSwitch. Default value is false
      Returns:
      ToggleSwitch instance, for chaining setter calls
      See Also:
    • getValue

      public Boolean getValue()
      The current value of this ToggleSwitch.
      Returns:
      Returns the current value of this ToggleSwitch. Default value is false
      See Also:
    • addToggleValueChangedHandler

      public HandlerRegistration addToggleValueChangedHandler(ToggleValueChangedHandler handler)
      Add a toggleValueChanged handler.

      Notification fired when the value changes.

      Specified by:
      addToggleValueChangedHandler in interface HasToggleValueChangedHandlers
      Parameters:
      handler - the toggleValueChanged handler
      Returns:
      HandlerRegistration used to remove this handler
    • setDefaultProperties

      public static void setDefaultProperties(ToggleSwitch toggleSwitchProperties)
      Class level method to set the default properties of this class. If set, then all existing and subsequently created instances of this class will automatically have default properties corresponding to the properties set on the SmartGWT class instance passed to this function before its underlying SmartClient JS object was created. This is a powerful feature that eliminates the need for users to create a separate hierarchy of subclasses that only alter the default properties of this class. Can also be used for skinning / styling purposes.

      Note: This method is intended for setting default attributes only and will affect all instances of the underlying class (including those automatically generated in JavaScript). This method should not be used to apply standard EventHandlers or override methods for a class - use a custom subclass instead. Calling this method after instances have been created can result in undefined behavior, since it bypasses any setters and a class instance may have already examined a particular property and not be expecting any changes through this route.

      Parameters:
      toggleSwitchProperties - properties that should be used as new defaults when instances of this class are created
      See Also:
    • setLogicalStructure

      public LogicalStructureObject setLogicalStructure(ToggleSwitchLogicalStructure s)
      Setter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
    • getLogicalStructure

      public LogicalStructureObject getLogicalStructure()
      Getter implementing the LogicalStructure interface, which supports Eclipse's logical structure debugging facility.
      Specified by:
      getLogicalStructure in interface LogicalStructure
      Overrides:
      getLogicalStructure in class StatefulCanvas