Package org.evoludo.ui
Class Slider
Object
UIObject
Widget
FocusWidget
Slider
- All Implemented Interfaces:
ChangeHandler
,ClickHandler
,HasAllDragAndDropHandlers
,HasAllFocusHandlers
,HasAllGestureHandlers
,HasAllKeyHandlers
,HasAllMouseHandlers
,HasAllTouchHandlers
,HasBlurHandlers
,HasChangeHandlers
,HasClickHandlers
,HasDoubleClickHandlers
,HasDragEndHandlers
,HasDragEnterHandlers
,HasDragHandlers
,HasDragLeaveHandlers
,HasDragOverHandlers
,HasDragStartHandlers
,HasDropHandlers
,HasFocusHandlers
,HasGestureChangeHandlers
,HasGestureEndHandlers
,HasGestureStartHandlers
,HasKeyDownHandlers
,HasKeyPressHandlers
,HasKeyUpHandlers
,HasMouseDownHandlers
,HasMouseMoveHandlers
,HasMouseOutHandlers
,HasMouseOverHandlers
,HasMouseUpHandlers
,HasMouseWheelHandlers
,HasTouchCancelHandlers
,HasTouchEndHandlers
,HasTouchMoveHandlers
,HasTouchStartHandlers
,TouchEndHandler
,TouchMoveHandler
,TouchStartHandler
,HasAttachHandlers
,EventHandler
,HasHandlers
,EventListener
,Focusable
,HasEnabled
,HasFocus
,HasVisibility
,IsWidget
,SourcesClickEvents
,SourcesFocusEvents
,SourcesKeyboardEvents
,SourcesMouseEvents
,HasInputHandlers
,InputHandler
public class Slider
extends FocusWidget
implements HasChangeHandlers, ChangeHandler, ClickHandler, TouchStartHandler, TouchEndHandler, TouchMoveHandler, HasInputHandlers, InputHandler
A standard slider widget. The slider handles both linear and logarithmic
scales.
CSS Style Rules
- .gwt-Slider
- the
input
element.
Example
public class SliderExample implements EntryPoint { public void onModuleLoad() { // Make a new slider and display its value on label. VerticalPanel p = new VerticalPanel(); Label l = new Label("Move slider..."); Slider s = new Slider(); s.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { l.setText("Slider at " + s.getValue()); } }); p.add(l); p.add(s); // Add it to the root panel. RootPanel.get().add(p); } }
- Author:
- Christoph Hauert
-
Nested Class Summary
Nested classes/interfaces inherited from class UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double
For logarithmic sliders this is the base of the logarithm.protected double
Helper variable to the logarithm of the slider range.protected double
Maximum value of slider.protected double
Minimum value of slider.protected boolean
true
if minimum and maximum of slider are reversed.protected HTML
Reference to slider.private static final double
Default maximum value of slider.private static final double
Default minimum value of slider.private static final int
Default number of steps between minimum and maximum of slider.protected int
Number of steps between minimum and maximum value of slider.protected String
Title of slider.Fields inherited from class UIObject
DEBUG_ID_PREFIX
-
Constructor Summary
ConstructorsModifierConstructorDescriptionSlider()
Slider
(double min, double max) Slider
(double min, double max, double init, int steps) Creates a slider ranging frommin
tomax
withsteps
increments and initial valueinit
.Slider
(double min, double max, ChangeHandler handler) Creates a slider ranging frommin
tomax
with 100 steps and initial value(min+max)/2
as well as a change handler.Slider
(int min, int max, int init, int steps, ChangeHandler handler) Creates a slider ranging frommin
tomax
withsteps
increments and initial valueinit
as well as a change handler.protected
This constructor may be used by subclasses to explicitly use an existing element.Slider
(ChangeHandler handler) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
_update()
Updates thelogRange
if needed as well as the tooltip of the slider.addChangeHandler
(ChangeHandler handler) addInputHandler
(InputHandler handler) Adds aInputEvent
handler.protected InputElement
Get the input element underlying the slider.double
getValue()
Get the value of slider taking its linear or logarithmic scaling into account.private double
lin2log
(double x) Helper function to convert from linear to logarithmic scales.private double
log2lin
(double x) Helper function to convert from logarithmic to linear scales.void
onChange
(ChangeEvent event) void
onClick
(ClickEvent event) void
onInput
(InputEvent event) Called when aInputEvent
is fired.void
onTouchEnd
(TouchEndEvent event) void
onTouchMove
(TouchMoveEvent event) void
onTouchStart
(TouchStartEvent event) void
setEnabled
(boolean enabled) void
Sets a linear scale for the slider.void
setLogBase
(double base) Set the base for a logarithmic slider.void
setRange
(double left, double right) Set left and right values of slider.void
setSteps
(int steps) Set the number of steps between the minimum and maximum values of the slider.void
void
setValue
(double value) Set the value of slider taking its linear or logarithmic scaling into account.private <H extends EventHandler>
voidtouchSlider
(TouchEvent<H> event) Helper function to update the slider value based on touch events.protected void
Updates the tooltip of the slider.static Slider
Creates a Slider widget that wraps an existing <input> element.Methods inherited from class FocusWidget
addBlurHandler, addClickHandler, addClickListener, addDoubleClickHandler, addDragEndHandler, addDragEnterHandler, addDragHandler, addDragLeaveHandler, addDragOverHandler, addDragStartHandler, addDropHandler, addFocusHandler, addFocusListener, addGestureChangeHandler, addGestureEndHandler, addGestureStartHandler, addKeyboardListener, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addMouseDownHandler, addMouseListener, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addMouseWheelListener, addTouchCancelHandler, addTouchEndHandler, addTouchMoveHandler, addTouchStartHandler, getFocusImpl, getTabIndex, isEnabled, onAttach, removeClickListener, removeFocusListener, removeKeyboardListener, removeMouseListener, removeMouseWheelListener, setAccessKey, setFocus, setTabIndex
Methods inherited from class Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
Methods inherited from class UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface HasHandlers
fireEvent
-
Field Details
-
SLIDER_MIN
private static final double SLIDER_MINDefault minimum value of slider.- See Also:
-
SLIDER_MAX
private static final double SLIDER_MAXDefault maximum value of slider.- See Also:
-
SLIDER_STEPS
private static final int SLIDER_STEPSDefault number of steps between minimum and maximum of slider.- See Also:
-
slider
Reference to slider. The <input> element. -
title
Title of slider. This string is displayed as the slider's tooltip and is updated to show the slider's current value. -
logBase
protected double logBaseFor logarithmic sliders this is the base of the logarithm. ForlogBase≤0
the slider has a linear scale. -
reversed
protected boolean reversedtrue
if minimum and maximum of slider are reversed. -
min
protected double minMinimum value of slider.- See Also:
-
max
protected double maxMaximum value of slider.- See Also:
-
steps
protected int stepsNumber of steps between minimum and maximum value of slider.- See Also:
-
logRange
protected double logRangeHelper variable to the logarithm of the slider range. Reduces calls to the fairly expensiveMath.log(double)
.
-
-
Constructor Details
-
Slider
public Slider() -
Slider
Creates a slider ranging from 0.0 to 100.0 with 100 steps and initial value (0.0+100.0)/2 as well as a change handler.- Parameters:
handler
- the change handler
-
Slider
public Slider(double min, double max) - Parameters:
min
- the minimum valuemax
- the maximum value
-
Slider
Creates a slider ranging frommin
tomax
with 100 steps and initial value(min+max)/2
as well as a change handler.- Parameters:
min
- the minimum valuemax
- the maximum valuehandler
- the change handler
-
Slider
public Slider(double min, double max, double init, int steps) Creates a slider ranging frommin
tomax
withsteps
increments and initial valueinit
.- Parameters:
min
- the minimum valuemax
- the maximum valueinit
- the initial valuesteps
- the number of steps
-
Slider
Creates a slider ranging frommin
tomax
withsteps
increments and initial valueinit
as well as a change handler.- Parameters:
min
- the minimum valuemax
- the maximum valueinit
- the initial valuesteps
- the number of stepshandler
- the change handler
-
Slider
This constructor may be used by subclasses to explicitly use an existing element. This element must be a <input> element.- Parameters:
element
- the element to be used
-
-
Method Details
-
wrap
Creates a Slider widget that wraps an existing <input> element. This element must already be attached to the document. If the element is removed from the document, you must call RootPanel.detachNow(Widget).- Parameters:
element
- the element to be wrapped- Returns:
- Slider widget wrapping
element
-
getInputElement
Get the input element underlying the slider.- Returns:
- the
InputElement
-
setRange
public void setRange(double left, double right) Set left and right values of slider. Left values that exceed right values are acceptable.Note: HTML sliders must have the minimum on the left and the maximum on the right. This implementation automatically takes care of the conversion if the maximum is on the left and the minimum on the right.
- Parameters:
left
- the left slider valueright
- the right slider value
-
setSteps
public void setSteps(int steps) Set the number of steps between the minimum and maximum values of the slider.- Parameters:
steps
- the number of steps
-
setLogBase
public void setLogBase(double base) Set the base for a logarithmic slider.- Parameters:
base
- the logarithmic base of slider- Throws:
IllegalArgumentException
- ifbase≤0
or the minimum and/or maximum values of the slider are≤0
-
setLinear
public void setLinear()Sets a linear scale for the slider. -
_update
private void _update()Updates thelogRange
if needed as well as the tooltip of the slider. -
lin2log
private double lin2log(double x) Helper function to convert from linear to logarithmic scales.- Parameters:
x
- linear value- Returns:
- logarithmic value
-
log2lin
private double log2lin(double x) Helper function to convert from logarithmic to linear scales.- Parameters:
x
- logarithmic value- Returns:
- linear value
-
setEnabled
public void setEnabled(boolean enabled) - Specified by:
setEnabled
in interfaceHasEnabled
- Overrides:
setEnabled
in classFocusWidget
-
getValue
public double getValue()Get the value of slider taking its linear or logarithmic scaling into account.- Returns:
- current value of slider
-
setValue
public void setValue(double value) Set the value of slider taking its linear or logarithmic scaling into account.- Parameters:
value
- the new value of the slider
-
setTitle
-
updateTitle
protected void updateTitle()Updates the tooltip of the slider. By default it shows the sliders minimum, maximum and current value. -
addInputHandler
Description copied from interface:HasInputHandlers
Adds aInputEvent
handler.- Specified by:
addInputHandler
in interfaceHasInputHandlers
- Parameters:
handler
- the input handler- Returns:
HandlerRegistration
used to remove this handler
-
onInput
Description copied from interface:InputHandler
Called when aInputEvent
is fired.- Specified by:
onInput
in interfaceInputHandler
- Parameters:
event
- theInputEvent
that was fired
-
onClick
- Specified by:
onClick
in interfaceClickHandler
-
onTouchStart
- Specified by:
onTouchStart
in interfaceTouchStartHandler
-
onTouchMove
- Specified by:
onTouchMove
in interfaceTouchMoveHandler
-
onTouchEnd
- Specified by:
onTouchEnd
in interfaceTouchEndHandler
-
touchSlider
Helper function to update the slider value based on touch events.- Type Parameters:
H
- the handler type- Parameters:
event
- the touch event
-
addChangeHandler
- Specified by:
addChangeHandler
in interfaceHasChangeHandlers
-
onChange
- Specified by:
onChange
in interfaceChangeHandler
-