com.vaadin.ui.
Class Slider
-
All Implemented Interfaces:
HasValue<Double>
,ContextClickEvent.ContextClickNotifier
,MethodEventSource
,ClientConnector
,Sizeable
,Connector
,Component
,Component.Focusable
,Serializable
public class Slider extends AbstractField<Double>
A component for selecting a numerical value within a range.
Author:
Vaadin Ltd.
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Slider.ValueOutOfBoundsException
Thrown when the value of the slider is about to be set to a value that is outside the valid range of the slider.
-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
-
Nested classes/interfaces inherited from interface com.vaadin.data.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
-
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
-
-
Field Summary
-
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
-
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
-
-
Constructor Summary
Constructors Constructor Description Slider()
Default slider constructor.
Slider(double min, double max, int resolution)
Create a new slider with the given range and resolution.
Slider(int min, int max)
Create a new slider with the given range of integers.
Slider(String caption)
Create a new slider with the caption given as parameter.
Slider(String caption, int min, int max)
Creates a new slider with the given caption and integer range.
-
Method Summary
All Methods Modifier and Type Method Description protected void
doSetValue(Double newValue)
Sets the value of this field.
protected Collection<String>
getCustomAttributes()
Returns a collection of attributes that should not be handled by the basic implementation of the
AbstractComponent.readDesign(Element, DesignContext)
andAbstractComponent.writeDesign(Element, DesignContext)
methods.Double
getEmptyValue()
Returns the value that represents an empty value.
double
getMax()
Gets the maximum slider value.
double
getMin()
Gets the minimum slider value.
SliderOrientation
getOrientation()
Gets the current orientation of the slider (horizontal or vertical).
int
getResolution()
Gets the resolution of the slider.
SliderState
getState()
Returns the shared state bean with information to be sent from the server to the client.
SliderState
getState(boolean markAsDirty)
Returns the shared state for this connector.
Double
getValue()
Returns the current value of this object.
boolean
isUpdateValueOnClick()
Returns whether the slider updates its value on user click.
void
readDesign(org.jsoup.nodes.Element design, DesignContext context)
Reads the component state from the given design.
void
setMax(double max)
Sets the maximum slider value.
void
setMin(double min)
Sets the minimum slider value.
void
setOrientation(SliderOrientation orientation)
Sets the orientation of the slider.
void
setResolution(int resolution)
Set a new resolution for the slider.
void
setUpdateValueOnClick(boolean updateValueOnClick)
Sets the slider to update its value when the user clicks on it.
void
setValue(Double value)
Sets the value of this object.
void
writeDesign(org.jsoup.nodes.Element design, DesignContext context)
Writes the component state to the given design.
-
Methods inherited from class com.vaadin.ui.AbstractField
addValueChangeListener, createValueChange, focus, getTabIndex, isDifferentValue, isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible, setTabIndex, setValue
-
Methods inherited from class com.vaadin.ui.AbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeight, setHeightFull, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthFull, setWidthUndefined
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
Methods inherited from interface com.vaadin.data.HasValue
clear, getDefaultValidator, getOptionalValue, isEmpty
-
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefined
-
-
-
-
Constructor Detail
-
Slider
public Slider()
Default slider constructor.
The range of the slider is set to 0-100 and only integer values are allowed.
-
Slider
public Slider(String caption)
Create a new slider with the caption given as parameter.
The range of the slider is set to 0-100 and only integer values are allowed.
Parameters:
caption
- the caption for this slider (e.g. "Volume")
-
Slider
public Slider(double min, double max, int resolution)
Create a new slider with the given range and resolution.
Parameters:
min
- The minimum value of the slidermax
- The maximum value of the sliderresolution
- The number of digits after the decimal point.
-
Slider
public Slider(int min, int max)
Create a new slider with the given range of integers.
Parameters:
min
- the minimum value of the slidermax
- the maximum value of the slider
-
Slider
public Slider(String caption, int min, int max)
Creates a new slider with the given caption and integer range.
Parameters:
caption
- the caption for the slidermin
- the minimum value of the slidermax
- the maximum value of the slider
-
-
Method Detail
-
getState
public SliderState getState()
Description copied from class:
AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().
Overrides:
getState
in classAbstractField<Double>
Returns:
updated component shared state
-
getState
public SliderState getState(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
getState
in classAbstractField<Double>
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
getMax
public double getMax()
Gets the maximum slider value. The default value is 100.0.
Returns:
the largest value the slider can have
-
setMax
public void setMax(double max)
Sets the maximum slider value. If the current value of the slider is larger than this, the value is set to the new maximum.
Parameters:
max
- The new maximum slider value
-
getMin
public double getMin()
Gets the minimum slider value. The default value is 0.0.
Returns:
the smallest value the slider can have
-
setMin
public void setMin(double min)
Sets the minimum slider value. If the current value of the slider is smaller than this, the value is set to the new minimum.
Parameters:
min
- The new minimum slider value
-
getOrientation
public SliderOrientation getOrientation()
Gets the current orientation of the slider (horizontal or vertical).
-
setOrientation
public void setOrientation(SliderOrientation orientation)
Sets the orientation of the slider.
Parameters:
orientation
- the new orientation, eitherSliderOrientation.HORIZONTAL
orSliderOrientation.VERTICAL
-
getResolution
public int getResolution()
Gets the resolution of the slider. The resolution is the number of digits after the decimal point. The default resolution is 0 (only integers allowed).
Returns:
resolution the number of digits after the decimal point
-
setResolution
public void setResolution(int resolution)
Set a new resolution for the slider. The resolution is the number of digits after the decimal point.
Parameters:
resolution
- the number of digits after the decimal pointThrows:
IllegalArgumentException
- if resolution is negative.
-
setUpdateValueOnClick
public void setUpdateValueOnClick(boolean updateValueOnClick)
Sets the slider to update its value when the user clicks on it. By default, the slider value is updated by dragging the slider's handle or clicking arrows.
Parameters:
updateValueOnClick
-true
to update the value of the slider on click,false
otherwise.Since:
8.8
-
isUpdateValueOnClick
public boolean isUpdateValueOnClick()
Returns whether the slider updates its value on user click.
Returns:
true
if the Slider updates its value on click. By default, returnsfalse
Since:
8.8
-
doSetValue
protected void doSetValue(Double newValue)
Description copied from class:
AbstractField
Sets the value of this field. May do sanitization or throw
IllegalArgumentException
if the value is invalid. Typically saves the value to shared state.Specified by:
doSetValue
in classAbstractField<Double>
Parameters:
newValue
- the new value of the field
-
setValue
public void setValue(Double value)
Sets the value of this object. If the new value is not equal to
getValue()
, fires aHasValue.ValueChangeEvent
. ThrowsNullPointerException
if the value is null.Specified by:
setValue
in interfaceHasValue<Double>
Overrides:
setValue
in classAbstractField<Double>
Parameters:
value
- the new value, notnull
Throws:
NullPointerException
- ifvalue
isnull
-
getValue
public Double getValue()
Description copied from interface:
HasValue
Returns the current value of this object.
Implementation note: the implementing class should document whether null values may be returned or not.
Returns:
the current value
-
getEmptyValue
public Double getEmptyValue()
Description copied from interface:
HasValue
Returns the value that represents an empty value.
By default
HasValue
is expected to supportnull
as empty values. Specific implementations might not support this.Returns:
empty value
See Also:
-
readDesign
public void readDesign(org.jsoup.nodes.Element design, DesignContext context)
Description copied from interface:
Component
Reads the component state from the given design.
The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.
It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.
This method must not modify the design.
Specified by:
readDesign
in interfaceComponent
Overrides:
readDesign
in classAbstractField<Double>
Parameters:
design
- The element to obtain the state fromcontext
- The DesignContext instance used for parsing the design
-
writeDesign
public void writeDesign(org.jsoup.nodes.Element design, DesignContext context)
Description copied from interface:
Component
Writes the component state to the given design.
The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.
This method must not modify the component state.
Specified by:
writeDesign
in interfaceComponent
Overrides:
writeDesign
in classAbstractField<Double>
Parameters:
design
- The element to write the component state to. Any previous attributes or child nodes are not cleared.context
- The DesignContext instance used for writing the design
-
getCustomAttributes
protected Collection<String> getCustomAttributes()
Description copied from class:
AbstractComponent
Returns a collection of attributes that should not be handled by the basic implementation of the
AbstractComponent.readDesign(Element, DesignContext)
andAbstractComponent.writeDesign(Element, DesignContext)
methods. Typically these are handled in a custom way in the overridden versions of the above methodsOverrides:
getCustomAttributes
in classAbstractField<Double>
Returns:
the collection of attributes that are not handled by the basic implementation
-
-