Class Clock
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<Clock>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<Clock>, com.vaadin.flow.component.FocusNotifier<Clock>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Clock, LocalTime>, LocalTime>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Clock, LocalTime>, LocalTime>, Serializable
The clock has two modes controlled by setRunning(boolean):
- Stopped (default): Displays the time set via
setValue(LocalTime) - Running: Time advances in real-time from the base value
When running, the clock tracks elapsed time using precise timestamps to avoid rounding errors. The effective time is: base value + elapsed running time. Setting a new value resets the accumulated running time.
Styling
The clock can be styled using CSS custom properties:
--vaadin-clock-size- Size of the clock (default: 120px)--vaadin-clock-background- Background color (default: #0055AA)--vaadin-clock-face-color- Clock face color (default: #AAAAAA)--vaadin-clock-hour-hand-color- Hour hand color (default: #000000)--vaadin-clock-minute-hand-color- Minute hand color (default: #000000)--vaadin-clock-second-hand-color- Second hand color (default: #FF8800)
Theme Variants
The clock supports theme variants that can be set via addThemeVariants(ClockVariant...):
ClockVariant.LUMO- Modern, clean Lumo appearanceClockVariant.AURA- Refined, professional Aura appearanceClockVariant.DARK- Dark mode (combine with LUMO or AURA)
- Author:
- Infraleap
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C,V> Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E> -
Constructor Summary
ConstructorsConstructorDescriptionClock()Default constructor.Clock(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Clock, LocalTime>> listener) Creates a clock with a value change listener.Creates a clock displaying the specified time.Clock(LocalTime time, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Clock, LocalTime>> listener) Creates a clock displaying the specified time with a value change listener. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddThemeVariants(ClockVariant... variants) Adds theme variants to the component.getLabel()Gets the label of the clock.getMax()Gets the maximum allowed time.getMin()Gets the minimum allowed time.getStep()Gets the time interval for step-based adjustments.getValue()Gets the displayed time.booleanGets whether the clock time can be adjusted by the user.booleanGets whether the clock is disabled.booleanGets whether the clock is readonly.booleanReturns whether the clock is currently running (animating).voidremoveThemeVariants(ClockVariant... variants) Removes theme variants from the component.voidsetAdjustable(boolean adjustable) Sets whether the clock time can be adjusted by the user via dragging clock hands or using keyboard arrow keys.voidsetAriaLabel(String ariaLabel) voidsetAriaLabelledBy(String labelledBy) voidsetClockSize(String size) Sets the size of the clock using the CSS custom property.voidsetDisabled(boolean disabled) Sets the clock to disabled state.voidSets the label for the clock.voidSets the maximum allowed time for user adjustment.voidSets the minimum allowed time for user adjustment.voidsetReadonly(boolean readonly) Sets the clock to readonly state.voidsetRunning(boolean running) Sets whether the clock is running (animating).voidSets the time interval for step-based adjustments when using keyboard arrow keys.voidSets the displayed time.Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEventMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, isEmpty, setModelValue, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
-
Constructor Details
-
Clock
public Clock()Default constructor. Creates a clock that displays the current time. -
Clock
Creates a clock displaying the specified time.- Parameters:
time- the time to display, ornullto display the current time
-
Clock
-
Clock
public Clock(LocalTime time, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Clock, LocalTime>> listener) Creates a clock displaying the specified time with a value change listener.- Parameters:
time- the time to display, ornullto display the current timelistener- the value change listener
-
-
Method Details
-
setLabel
Sets the label for the clock.- Parameters:
label- value for thelabelproperty in the clock
-
getLabel
-
setAriaLabel
- Specified by:
setAriaLabelin interfacecom.vaadin.flow.component.HasAriaLabel
-
getAriaLabel
-
setAriaLabelledBy
- Specified by:
setAriaLabelledByin interfacecom.vaadin.flow.component.HasAriaLabel
-
getAriaLabelledBy
-
setValue
Sets the displayed time. The value will be truncated to second precision.Set to
nullto display the current time.- Specified by:
setValuein interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Clock, LocalTime>, LocalTime>- Overrides:
setValuein classcom.vaadin.flow.component.AbstractField<Clock, LocalTime>- Parameters:
value- the time to display, ornullfor current time
-
getValue
Gets the displayed time.- Specified by:
getValuein interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Clock, LocalTime>, LocalTime>- Overrides:
getValuein classcom.vaadin.flow.component.AbstractField<Clock, LocalTime>- Returns:
- the displayed time, or
nullif displaying current time
-
setMin
Sets the minimum allowed time for user adjustment.- Parameters:
min- the minimum time, ornullto remove the constraint
-
getMin
Gets the minimum allowed time.- Returns:
- the minimum time, or
nullif not set
-
setMax
Sets the maximum allowed time for user adjustment.- Parameters:
max- the maximum time, ornullto remove the constraint
-
getMax
Gets the maximum allowed time.- Returns:
- the maximum time, or
nullif not set
-
setDisabled
public void setDisabled(boolean disabled) Sets the clock to disabled state.- Parameters:
disabled-trueto disable the clock,falseto enable
-
isDisabled
public boolean isDisabled()Gets whether the clock is disabled.- Returns:
trueif disabled,falseotherwise
-
setReadonly
public void setReadonly(boolean readonly) Sets the clock to readonly state.- Parameters:
readonly-trueto set readonly,falseotherwise
-
isReadonly
public boolean isReadonly()Gets whether the clock is readonly.- Returns:
trueif readonly,falseotherwise
-
setAdjustable
public void setAdjustable(boolean adjustable) Sets whether the clock time can be adjusted by the user via dragging clock hands or using keyboard arrow keys.- Parameters:
adjustable-trueto allow user adjustment (default),falseto disable
-
isAdjustable
public boolean isAdjustable()Gets whether the clock time can be adjusted by the user.- Returns:
trueif user adjustment is enabled (default),falseotherwise
-
setStep
Sets the time interval for step-based adjustments when using keyboard arrow keys.The step must evenly divide a day. For example, "15 minutes", "30 minutes", and "2 hours" are valid steps, but "42 minutes" is not valid.
Keyboard arrow keys adjust by at least 1 hour, using the smallest multiple of the step that is at least 1 hour. For example, with a 10-minute step, arrow keys adjust by 1 hour (6 × 10 minutes). With a 90-minute step, arrow keys adjust by 90 minutes.
The default step is 60 seconds (1 minute).
- Parameters:
step- the step duration, notnull- Throws:
IllegalArgumentException- if the step is not a positive duration or does not evenly divide a day
-
getStep
Gets the time interval for step-based adjustments.- Returns:
- the step duration, or
nullif not set (defaults to 60 seconds on the client)
-
setClockSize
Sets the size of the clock using the CSS custom property.- Parameters:
size- the size (e.g., "150px", "10em")
-
setRunning
public void setRunning(boolean running) Sets whether the clock is running (animating).When running, the displayed time advances in real-time from the base value set via
setValue(LocalTime). The elapsed time is tracked precisely using timestamps, so no rounding errors accumulate.When the clock is stopped, the current displayed time (base time plus accumulated running time) is synced back to the Java value, so
getValue()returns the time that was shown when stopped.The default is
false(not running).- Parameters:
running-trueto start running,falseto stop
-
isRunning
public boolean isRunning()Returns whether the clock is currently running (animating).- Returns:
trueif running,falseotherwise
-
addThemeVariants
Adds theme variants to the component.- Parameters:
variants- the theme variants to add
-
removeThemeVariants
Removes theme variants from the component.- Parameters:
variants- the theme variants to remove
-