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
inputelement.
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 doubleFor logarithmic sliders this is the base of the logarithm.protected doubleHelper variable to the logarithm of the slider range.protected doubleMaximum value of slider.protected doubleMinimum value of slider.protected booleantrueif minimum and maximum of slider are reversed.protected HTMLReference to slider.private static final doubleDefault maximum value of slider.private static final doubleDefault minimum value of slider.private static final intDefault number of steps between minimum and maximum of slider.protected intNumber of steps between minimum and maximum value of slider.protected StringTitle 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 frommintomaxwithstepsincrements and initial valueinit.Slider(double min, double max, ChangeHandler handler) Creates a slider ranging frommintomaxwith 100 steps and initial value(min+max)/2as well as a change handler.Slider(int min, int max, int init, int steps, ChangeHandler handler) Creates a slider ranging frommintomaxwithstepsincrements and initial valueinitas well as a change handler.protectedThis constructor may be used by subclasses to explicitly use an existing element.Slider(ChangeHandler handler) -
Method Summary
Modifier and TypeMethodDescriptionprivate void_update()Updates thelogRangeif needed as well as the tooltip of the slider.addChangeHandler(ChangeHandler handler) addInputHandler(InputHandler handler) Adds aInputEventhandler.protected InputElementGet the input element underlying the slider.doublegetValue()Get the value of slider taking its linear or logarithmic scaling into account.private doublelin2log(double x) Helper function to convert from linear to logarithmic scales.private doublelog2lin(double x) Helper function to convert from logarithmic to linear scales.voidonChange(ChangeEvent event) voidonClick(ClickEvent event) voidonInput(InputEvent event) Called when aInputEventis fired.voidonTouchEnd(TouchEndEvent event) voidonTouchMove(TouchMoveEvent event) voidonTouchStart(TouchStartEvent event) voidsetEnabled(boolean enabled) voidSets a linear scale for the slider.voidsetLogBase(double base) Set the base for a logarithmic slider.voidsetRange(double left, double right) Set left and right values of slider.voidsetSteps(int steps) Set the number of steps between the minimum and maximum values of the slider.voidvoidsetValue(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 voidUpdates the tooltip of the slider.static SliderCreates 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, setTabIndexMethods 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, unsinkEventsMethods 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, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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≤0the slider has a linear scale. -
reversed
protected boolean reversedtrueif 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 frommintomaxwith 100 steps and initial value(min+max)/2as 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 frommintomaxwithstepsincrements and initial valueinit.- Parameters:
min- the minimum valuemax- the maximum valueinit- the initial valuesteps- the number of steps
-
Slider
Creates a slider ranging frommintomaxwithstepsincrements and initial valueinitas 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≤0or 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 thelogRangeif 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:
setEnabledin interfaceHasEnabled- Overrides:
setEnabledin 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:HasInputHandlersAdds aInputEventhandler.- Specified by:
addInputHandlerin interfaceHasInputHandlers- Parameters:
handler- the input handler- Returns:
HandlerRegistrationused to remove this handler
-
onInput
Description copied from interface:InputHandlerCalled when aInputEventis fired.- Specified by:
onInputin interfaceInputHandler- Parameters:
event- theInputEventthat was fired
-
onClick
- Specified by:
onClickin interfaceClickHandler
-
onTouchStart
- Specified by:
onTouchStartin interfaceTouchStartHandler
-
onTouchMove
- Specified by:
onTouchMovein interfaceTouchMoveHandler
-
onTouchEnd
- Specified by:
onTouchEndin 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:
addChangeHandlerin interfaceHasChangeHandlers
-
onChange
- Specified by:
onChangein interfaceChangeHandler
-