public class OnOffSwitch
ImplementsActionSource, Animation, Editable, Iterable<Component>, StyleListener
Constructors
public OnOffSwitch() | Default constructor |
Methods
protected Dimension calcPreferredSize() | Calculates the preferred size based on component content. |
protected void resetFocusable() | Restores the state of the focusable flag to its default state |
protected boolean isStickyDrag() | Returns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries. |
public void addActionListener(ActionListener l) | Adds a listener to the switch which will cause an event to dispatch on click |
public void removeActionListener(ActionListener l) | Removes the given action listener from the switch |
public Vector getActionListeners() | Deprecated Returns a vector containing the action listeners for this button |
public Collection getListeners() | Returns a collection containing the action listeners for this button |
public void paint(Graphics g) | 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. |
protected void initComponent() | Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state |
protected void deinitialize() | Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. |
public void pointerPressed(int x, int y) | If this Component is focused, the pointer pressed event will call this method |
public void pointerDragged(int x, int y) | If this Component is focused, the pointer dragged event will call this method |
public void pointerReleased(int x, int y) | If this Component is focused, the pointer released event will call this method |
public String getOn() | Label for the on mode |
public void setOn(String on) | Label for the on mode |
public String getOff() | Label for the off mode |
public void setOff(String off) | Label for the off mode |
public boolean isValue() | The value of the switch |
public void setValue(boolean value) | The value of the switch |
public String[] 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 |
public Object getComponentState() | Some components may optionally generate a state which can then be restored using setCompnentState(). |
public void setComponentState(Object state) | If getComponentState returned a value the setter can update the value and restore the prior state. |
public Class[] getPropertyTypes() | Matches the property names method (see that method for further details). |
public Object getPropertyValue(String name) | Returns the current value of the property name, this method is used by the GUI builder |
public String setPropertyValue(String name, Object value) | Sets a new value to the given property, returns an error message if failed and null if successful. |
public boolean isNoTextMode() | iOS 7 changed the switch to not include any text |
public void setNoTextMode(boolean noTextMode) | iOS 7 changed the switch to not include any text |
public Image getSwitchOnImage() | Gets the image that is used for the “On” state of the switch. |
public void setSwitchOnImage(Image switchOnImage) | Sets the image that should be used for the “Off” state. |
public Image getSwitchOffImage() | Gets the image that is used for the “Off” state of the switch. |
public void setSwitchOffImage(Image switchOffImage) | Sets the image that should be used for the “Off” state. |
public Image getSwitchMaskImage() | Gets the image that is used for the mask. |
public void setSwitchMaskImage(Image switchMaskImage) | Sets the image that should be used for the “On” state. |
Inherited fields
From Component
DEFAULT_CURSOR, CROSSHAIR_CURSOR, TEXT_CURSOR, WAIT_CURSOR, SW_RESIZE_CURSOR, SE_RESIZE_CURSOR, NW_RESIZE_CURSOR, NE_RESIZE_CURSOR, N_RESIZE_CURSOR, S_RESIZE_CURSOR, W_RESIZE_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_Y, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_IMMEDIATELY_DRAG_XY, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET, BRB_OTHER, CENTER, TOP, LEFT, BOTTOM, RIGHT, BASELINE
Inherited methods
From Container
encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paintGlass, layoutContainer, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, getComponentAt, findDropTargetAt, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator
From Component
setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyTypeNames, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip
Constructor details
OnOffSwitch
public OnOffSwitch()Method details
calcPreferredSize
protected Dimension calcPreferredSize()Returns
resetFocusable
protected void resetFocusable()isStickyDrag
protected boolean isStickyDrag()Returns
addActionListener
public void addActionListener(ActionListener l)Parameters
lActionListener- implementation of the action listener interface
removeActionListener
public void removeActionListener(ActionListener l)Parameters
lActionListener- implementation of the action listener interface
getActionListeners
public Vector getActionListeners()Returns
getListeners
public Collection getListeners()Returns
paint
public void paint(Graphics g)Parameters
gGraphics- the component graphics
initComponent
protected void initComponent()deinitialize
protected void deinitialize()pointerPressed
public void pointerPressed(int x, int y)Parameters
xint- the pointer x coordinate
yint- the pointer y coordinate
pointerDragged
public void pointerDragged(int x, int y)Parameters
xint- the pointer x coordinate
yint- the pointer y coordinate
pointerReleased
public void pointerReleased(int x, int y)Parameters
xint- the pointer x coordinate
yint- the pointer y coordinate
getOn
public String getOn()Returns
setOn
public void setOn(String on)Parameters
onString- the on to set
getOff
public String getOff()Returns
setOff
public void setOff(String off)Parameters
offString- the off to set
isValue
public boolean isValue()Returns
setValue
public void setValue(boolean value)Parameters
valueboolean- the value to set
getPropertyNames
public String[] getPropertyNames()Returns
getComponentState
public Object getComponentState()Returns
setComponentState
public void setComponentState(Object state)Parameters
stateObject- the non-null state
getPropertyTypes
public Class[] getPropertyTypes()Returns
getPropertyValue
public Object getPropertyValue(String name)Parameters
nameString- the name of the property
Returns
setPropertyValue
public String setPropertyValue(String name, Object value)Parameters
nameString- the name of the property
valueObject- new value for the property
Returns
isNoTextMode
public boolean isNoTextMode()Returns
setNoTextMode
public void setNoTextMode(boolean noTextMode)Parameters
noTextModeboolean- the noTextMode to set
getSwitchOnImage
public Image getSwitchOnImage()Returns
#setSwitchOnImage(com.codename1.ui.Image)
method, then this will return null.setSwitchOnImage
public void setSwitchOnImage(Image switchOnImage)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
switchOnImageImage- the switchOnImage to set
getSwitchOffImage
public Image getSwitchOffImage()Returns
#setSwitchOffImage(com.codename1.ui.Image)
method, then this will return null.setSwitchOffImage
public void setSwitchOffImage(Image switchOffImage)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
switchOffImageImage- the switchOffImage to set
getSwitchMaskImage
public 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
#setSwitchMaskImage(com.codename1.ui.Image)setSwitchMaskImage
public void setSwitchMaskImage(Image switchMaskImage)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
switchMaskImageImage- the switchMaskImage image to set as the mask for the on-off switch.