Class UISlider

All Implemented Interfaces:
UIKeyHandler, Hintable, Savable

public class UISlider extends UIContainer
A widget allowing display and control of a choice from a range of values.
  • Constructor Details

    • UISlider

      public UISlider(Orientation orientation)
      create a slider widget with a default range of [0,100]. Initial value is 50.
      Parameters:
      orientation - the orientation of the slider (Orientation.Horizontal or Orientation.Vertical)
    • UISlider

      public UISlider(Orientation orientation, int minValue, int maxValue, int initialValue)
      create a slider widget with a default range of [minValue,maxOffset] and the given initialValue.
      Parameters:
      orientation - the orientation of the slider (Orientation.Horizontal or Orientation.Vertical)
      minValue - the minimum value the slider can take (inclusive).
      maxValue - the maximum value the slider can take (inclusive). Must be greater than or equal to minValue.
      initialValue - the starting value of the slider. Must be between min and max values.
  • Method Details

    • fireChangeEvent

      public void fireChangeEvent()
      Notifies any listeners that this slider has updated its value.
    • getOrientation

      public Orientation getOrientation()
      Returns:
      our orientation.
    • layout

      public void layout()
      Description copied from class: UIComponent
      Override this to perform actual layout.
      Overrides:
      layout in class UIContainer
    • getUIComponent

      public UIComponent getUIComponent(int x, int y)
      Overrides:
      getUIComponent in class UIContainer
      Parameters:
      x - the x screen coordinate
      y - the y screen coordinate
      Returns:
      this component (or an appropriate child coordinate in the case of a container) if the given screen coordinates fall inside the margin area of this component.
    • updateMinimumSizeFromContents

      public void updateMinimumSizeFromContents()
      Description copied from class: UIComponent
      Ask this component to update its minimum allowed size, based on its contents.
      Overrides:
      updateMinimumSizeFromContents in class UIContainer
    • setValue

      public void setValue(int value)
      Set the value on this slider
      Parameters:
      value - the new value. Clamps between min and max values.
    • getValue

      public int getValue()
      Returns:
      the current data model's current value.
    • getModel

      public SliderModel getModel()
      Returns:
      the data model for the slider.
    • setModel

      public void setModel(DefaultSliderModel model)
      Parameters:
      model - the new data model for this slider. Must not be null.
    • addActionListener

      public void addActionListener(ActionListener listener)
      Add the specified listener to this slider's list of listeners notified when it has changed.
      Parameters:
      listener - the listener to add
    • removeActionListener

      public boolean removeActionListener(ActionListener listener)
      Remove a listener from this slider's list of listeners.
      Parameters:
      listener - the listener to remove
      Returns:
      true if the listener was removed.
    • setEnabled

      public void setEnabled(boolean enabled)
      Overrides:
      setEnabled in class UIComponent
      Parameters:
      enabled - true if this component should be considered "enabled"... a concept that is interpreted by each individual component type.
    • getKnob

      public UISliderKnob getKnob()
      Returns:
      the knob associated with this slider.
    • getBackPanel

      public UIPanel getBackPanel()
      Returns:
      the back panel associated with this slider.
    • setSnapToValues

      public void setSnapToValues(boolean snap)
      Parameters:
      snap - true if we snap the slider to the integer representations on mouse release.
    • isSnapToValues

      public boolean isSnapToValues()
      Returns:
      true if we snap the slider to the integer representations on mouse release.