Class OnOffSwitch
- All Implemented Interfaces:
Animation, Editable, ActionSource, StyleListener, Iterable<Component>
-
Field Summary
Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener to the switch which will cause an event to dispatch on clickprotected DimensionCalculates the preferred size based on component content.protected voidInvoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.Returns a vector containing the action listeners for this buttonSome components may optionally generate a state which can then be restored using setCompnentState().Returns a collection containing the action listeners for this buttongetOff()Label for the off modegetOn()Label for the on modeString[]A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder codeClass[]Matches the property names method (see that method for further details).getPropertyValue(String name) Returns the current value of the property name, this method is used by the GUI builderGets the image that is used for the mask.Gets the image that is used for the "Off" state of the switch.Gets the image that is used for the "On" state of the switch.protected voidAllows subclasses to bind functionality that relies on fully initialized and "ready for action" component statebooleaniOS 7 changed the switch to not include any textprotected booleanReturns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries.booleanisValue()The value of the switchvoidThis method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.voidpointerDragged(int x, int y) If this Component is focused, the pointer dragged event will call this methodvoidpointerPressed(int x, int y) If this Component is focused, the pointer pressed event will call this methodvoidpointerReleased(int x, int y) If this Component is focused, the pointer released event will call this methodvoidRemoves the given action listener from the switchprotected voidRestores the state of the focusable flag to its default statevoidsetComponentState(Object state) If getComponentState returned a value the setter can update the value and restore the prior state.voidsetNoTextMode(boolean noTextMode) iOS 7 changed the switch to not include any textvoidLabel for the off modevoidLabel for the on modesetPropertyValue(String name, Object value) Sets a new value to the given property, returns an error message if failed and null if successful.voidsetSwitchMaskImage(Image switchMaskImage) Sets the image that should be used for the "On" state.voidsetSwitchOffImage(Image switchOffImage) Sets the image that should be used for the "Off" state.voidsetSwitchOnImage(Image switchOnImage) Sets the image that should be used for the "Off" state.voidsetValue(boolean value) The value of the switchMethods inherited from class Container
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paintComponentBackground, paintGlass, paramString, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesMethods inherited from class Component
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyTypeNames, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
OnOffSwitch
public OnOffSwitch()Default constructor
-
-
Method Details
-
calcPreferredSize
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.
Returns
the calculated preferred size based on component content
- Overrides:
calcPreferredSizein classContainer
-
resetFocusable
protected void resetFocusable()Restores the state of the focusable flag to its default state- Overrides:
resetFocusablein classComponent
-
isStickyDrag
protected boolean isStickyDrag()Returns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries. This is useful for spinners etc. where the motion might continue beyond the size of the component
Returns
false by default
- Overrides:
isStickyDragin classComponent
-
addActionListener
Adds a listener to the switch which will cause an event to dispatch on click
Parameters
l: implementation of the action listener interface
- Specified by:
addActionListenerin interfaceActionSource
-
removeActionListener
Removes the given action listener from the switch
Parameters
l: implementation of the action listener interface
- Specified by:
removeActionListenerin interfaceActionSource
-
getActionListeners
Returns a vector containing the action listeners for this button
Returns
the action listeners
Deprecated
use the version that returns a collection
-
getListeners
Returns a collection containing the action listeners for this button
Returns
the action listeners
-
paint
This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.
Parameters
g: the component graphics
-
initComponent
protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state- Overrides:
initComponentin classComponent
-
deinitialize
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.- Overrides:
deinitializein classComponent
-
pointerPressed
public void pointerPressed(int x, int y) If this Component is focused, the pointer pressed event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerPressedin classContainer
-
-
pointerDragged
public void pointerDragged(int x, int y) If this Component is focused, the pointer dragged event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerDraggedin classComponent
-
-
pointerReleased
public void pointerReleased(int x, int y) If this Component is focused, the pointer released event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerReleasedin classComponent
-
-
getOn
Label for the on mode
Returns
the on
-
setOn
Label for the on mode
Parameters
on: the on to set
-
getOff
Label for the off mode
Returns
the off
-
setOff
Label for the off mode
Parameters
off: the off to set
-
isValue
public boolean isValue()The value of the switch
Returns
the value
-
setValue
public void setValue(boolean value) The value of the switch
Parameters
value: the value to set
-
getPropertyNames
A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code
Returns
the property names allowing mutation
- Overrides:
getPropertyNamesin classComponent
-
getComponentState
Some components may optionally generate a state which can then be restored using setCompnentState(). This method is used by the UIBuilder.
Returns
the component state or null for undefined state.
- Overrides:
getComponentStatein classComponent
-
setComponentState
If getComponentState returned a value the setter can update the value and restore the prior state.
Parameters
state: the non-null state
- Overrides:
setComponentStatein classComponent
-
getPropertyTypes
Matches the property names method (see that method for further details).
Returns
the types of the properties
- Overrides:
getPropertyTypesin classComponent
-
getPropertyValue
Returns the current value of the property name, this method is used by the GUI builder
Parameters
name: the name of the property
Returns
the value of said property
- Overrides:
getPropertyValuein classComponent
-
setPropertyValue
Sets a new value to the given property, returns an error message if failed and null if successful. Notice that some builtin properties such as "$designMode" might be sent to components to indicate application state.
Parameters
-
name: the name of the property -
value: new value for the property
Returns
error message or null
- Overrides:
setPropertyValuein classComponent
-
-
isNoTextMode
public boolean isNoTextMode()iOS 7 changed the switch to not include any text
Returns
the noTextMode
-
setNoTextMode
public void setNoTextMode(boolean noTextMode) iOS 7 changed the switch to not include any text
Parameters
noTextMode: the noTextMode to set
-
getSwitchOnImage
Gets the image that is used for the "On" state of the switch.
Returns
- Returns:
The image that will be used for the "On" state. If the "onOffIOSModeBool" theme constant is false and the switchOnImage hasn't been explicitly set by the
#setSwitchOnImage(com.codename1.ui.Image)method, then this will return null.See also
-
#setSwitchOnImage(com.codename1.ui.Image)
-
#getSwitchOffImage()
-
#getSwitchMaskImage()
-
-
setSwitchOnImage
Sets the image that should be used for the "Off" state. Note: This option is only used if the "onOffIOSModeBool" theme constant is enabled.
Note: If the "onOffIOSModeBool" theme constant is false and you set this image, you must also set the "Off" image with
#setSwitchOffImage(com.codename1.ui.Image)and the "Mask" image with#setSwitchMaskImage(com.codename1.ui.Image).Parameters
switchOnImage: the switchOnImage to set
See also
-
#getSwitchOnImage()
-
#setSwitchMaskImage(com.codename1.ui.Image)
-
#setSwitchOffImage(com.codename1.ui.Image)
-
getSwitchOffImage
Gets the image that is used for the "Off" state of the switch.
Returns
- Returns:
The image that will be used for the "Off" state. If the "onOffIOSModeBool" theme constant is false and the switchOffImage hasn't been explicitly set by the
#setSwitchOffImage(com.codename1.ui.Image)method, then this will return null.See also
-
#setSwitchOffImage(com.codename1.ui.Image)
-
#getSwitchOnImage()
-
#getSwitchMaskImage()
-
-
setSwitchOffImage
Sets the image that should be used for the "Off" state. Note: This option is only used if the "onOffIOSModeBool" theme constant is enabled.
Note: If the "onOffIOSModeBool" theme constant is false and you set this image, you must also set the "On" image with
#setSwitchOnImage(com.codename1.ui.Image)and the "Mask" image with#setSwitchMaskImage(com.codename1.ui.Image).Parameters
switchOffImage: the switchOffImage to set
See also
-
#getSwitchOffImage()
-
#setSwitchMaskImage(com.codename1.ui.Image)
-
#setSwitchOnImage(com.codename1.ui.Image)
-
getSwitchMaskImage
Gets the image that is used for the mask. Note: This option is only used if the "onOffIOSModeBool" theme constant is enabled.
This image will generally consist of an opaque border/frame with a transparent center such that the "on" and "off" images can be painted inside the transparent part, and anything that is outside that center will be painted over by the frame, or clipped.
Returns
- Returns:
the switchMaskImage image if the "onOffIOSModeBool" flag is set or the mask image has been explicitly set on this OnOffSwitch using
#setSwitchMaskImage(com.codename1.ui.Image)See also
-
#getSwitchOffImage()
-
#getSwitchOffImage()
-
#setSwitchOnImage(com.codename1.ui.Image)
-
#getSwitchMaskImage()
-
#setSwitchMaskImage(com.codename1.ui.Image)
-
-
setSwitchMaskImage
Sets the image that should be used for the "On" state.
Note: If the "onOffIOSModeBool" is false and you set this mask, you must also set the "On" image with
#setSwitchOnImage(com.codename1.ui.Image)and the "Off" image with#setSwitchOffImage(com.codename1.ui.Image).Parameters
switchMaskImage: @param switchMaskImage the switchMaskImage image to set as the mask for the on-off switch.
-