Class CircularSlider
- All Implemented Interfaces:
Animation, Editable, StyleListener
A round slider: a value picked by dragging a thumb along an arc, as on a thermostat or a volume knob.
CircularSlider dial = new CircularSlider(0, 100);
dial.setValue(40);
dial.addActionListener(e -> Log.p("Value " + dial.getValue()));
Angles are in degrees, with 0 at three o'clock and positive values counter
clockwise, the convention of Graphics.drawArc. The default arc starts at 225
(lower left) and sweeps -270 degrees, clockwise over the top to the lower right.
A tap or drag anywhere on the component moves the thumb to the nearest point of
the arc. Left/down and right/up keys change the value by one step. The filled
part uses the accent colour of the UIID CircularSlider, the rest a track colour.
-
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
ConstructorsConstructorDescriptionA slider from 0 to 100.CircularSlider(int min, int max) A slider over a range. -
Method Summary
Modifier and TypeMethodDescriptionvoidListens for the user changing the value.doubleangleForValue(int v) The angle of the thumb for a value.protected DimensionCalculates the preferred size based on component content.Returns the text that describes this component to assistive technologies.intgetMax()The largest value.intgetMin()The smallest value.intWhere the arc starts.intgetStep()The step.intThe extent of the arc.intgetValue()The current value.booleanWhether the user can change the value.protected booleanReturns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries.voidkeyReleased(int keyCode) If this Component is focused, the key released event will call this methodvoidThis 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 methodvoidRemoves a listener.voidsetArc(int startAngle, int sweepAngle) Sets the arc the thumb travels along.voidsetEditable(boolean editable) Whether the user can change the value.voidsetStep(int step) Sets the amount a key press changes the value and the granularity of a drag.voidsetValue(int value) Sets the value without notifying listeners.intvalueAtAngle(double angle) The value at an angle, snapped to the step.Methods inherited from class Component
accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addNativeDragOverListener, addNativeDropListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, canAcceptNativeDrop, cancelRepaints, clearClientProperties, consumesRawTextInput, contains, containsOrOwns, createNativeDragOperation, createStyleAnimation, deinitialize, deinitializeCustomStyle, deregisterFromAnimation, dragEnter, dragExit, dragFinished, draggingOver, dragInitiated, drawDraggedImage, drop, fireClicked, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAcceptedDropActions, getAcceptedDropMimeTypes, getAccessibilityNode, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBottomGap, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getContextMenuCommands, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getGridPosX, getGridPosY, getHeight, getHoverStyle, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeDragOperation, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getSideGap, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getTopLevelContainer, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initLaf, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditing, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHovered, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isNativeDragSource, isNativeDropTarget, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSelectableInteraction, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyPressed, keyRepeated, laidOut, longKeyPress, longPointerPress, mouseWheel, nativeDragEnter, nativeDragExit, nativeDragOver, nativeDrop, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, paramString, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, refreshTheme, registerForAnimation, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removeNativeDragOverListener, removeNativeDropListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAcceptedDropActions, setAcceptedDropMimeTypes, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setContextMenuCommands, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setHovered, setHoverStyle, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNativeDragOperation, setNativeDragSource, setNativeDropTarget, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stopScrollMomentum, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
-
Constructor Details
-
CircularSlider
public CircularSlider()A slider from 0 to 100. -
CircularSlider
public CircularSlider(int min, int max) A slider over a range.
Parameters
-
min: the smallest value -
max: the largest value, greater thanmin
-
-
-
Method Details
-
getMin
public int getMin()The smallest value.
Returns
the minimum
-
getMax
public int getMax()The largest value.
Returns
the maximum
-
getValue
public int getValue()The current value.
Returns
a value from
#getMin()to#getMax() -
setValue
public void setValue(int value) Sets the value without notifying listeners.
Parameters
value: the value, clamped to the range
-
setStep
public void setStep(int step) Sets the amount a key press changes the value and the granularity of a drag.
Parameters
step: a positive step
-
getStep
public int getStep()The step.
Returns
the amount a key press changes the value
-
setArc
public void setArc(int startAngle, int sweepAngle) Sets the arc the thumb travels along.
Parameters
-
startAngle: where the minimum sits, in degrees, 0 at three o'clock -
sweepAngle: the extent of the arc; negative runs clockwise. Its magnitude is 1 to 360
-
-
getStartAngle
public int getStartAngle()Where the arc starts.
Returns
the start angle in degrees
-
getSweepAngle
public int getSweepAngle()The extent of the arc.
Returns
the sweep in degrees, negative for clockwise
-
setEditable
public void setEditable(boolean editable) Whether the user can change the value.
Parameters
editable: false to make the slider display only
-
isEditable
public boolean isEditable()Whether the user can change the value.
Returns
true unless turned off
- Specified by:
isEditablein interfaceEditable- Overrides:
isEditablein classComponent
-
addActionListener
Listens for the user changing the value.
Parameters
l: the listener
-
removeActionListener
Removes a listener.
Parameters
l: the listener
-
valueAtAngle
public int valueAtAngle(double angle) The value at an angle, snapped to the step. An angle outside the arc goes to the nearer end.
Parameters
angle: degrees, 0 at three o'clock, counter clockwise
Returns
the value the thumb would show there
-
angleForValue
public double angleForValue(int v) The angle of the thumb for a value.
Parameters
v: a value in the range
Returns
degrees, 0 at three o'clock, counter clockwise
-
pointerPressed
public void pointerPressed(int x, int y) Description copied from class:ComponentIf 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 classComponent
-
-
pointerDragged
public void pointerDragged(int x, int y) Description copied from class:ComponentIf 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
-
-
keyReleased
public void keyReleased(int keyCode) Description copied from class:ComponentIf this Component is focused, the key released event will call this method
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyReleasedin classComponent
-
isStickyDrag
protected boolean isStickyDrag()Description copied from class:ComponentReturns 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
-
calcPreferredSize
Description copied from class:ComponentCalculates 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 classComponent
-
paint
Description copied from class:ComponentThis 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
-
getAccessibilityText
Description copied from class:ComponentReturns the text that describes this component to assistive technologies. If no text was set explicitly, this method attempts to derive a description from the component's label or content.
Returns
accessibility description or
nullif none- Overrides:
getAccessibilityTextin classComponent
-