Class CircularSlider

java.lang.Object
com.codename1.ui.Component
com.codename1.components.CircularSlider
All Implemented Interfaces:
Animation, Editable, StyleListener

public class CircularSlider extends Component

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.

  • 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 than min

  • 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:
      isEditable in interface Editable
      Overrides:
      isEditable in class Component
    • addActionListener

      public void addActionListener(ActionListener l)

      Listens for the user changing the value.

      Parameters
      • l: the listener
    • removeActionListener

      public void removeActionListener(ActionListener l)

      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: Component

      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:
      pointerPressed in class Component
    • pointerDragged

      public void pointerDragged(int x, int y)
      Description copied from class: Component

      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:
      pointerDragged in class Component
    • keyReleased

      public void keyReleased(int keyCode)
      Description copied from class: Component

      If this Component is focused, the key released event will call this method

      Parameters
      • keyCode: the key code value to indicate a physical key.
      Overrides:
      keyReleased in class Component
    • isStickyDrag

      protected boolean isStickyDrag()
      Description copied from class: Component

      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:
      isStickyDrag in class Component
    • calcPreferredSize

      protected Dimension calcPreferredSize()
      Description copied from class: Component

      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:
      calcPreferredSize in class Component
    • paint

      public void paint(Graphics g)
      Description copied from class: Component

      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
      Specified by:
      paint in interface Animation
      Overrides:
      paint in class Component
    • getAccessibilityText

      public String getAccessibilityText()
      Description copied from class: Component

      Returns 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 null if none

      Overrides:
      getAccessibilityText in class Component