Class Clock

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<Clock, LocalTime>
com.vaadin.flow.component.AbstractSinglePropertyField<Clock, LocalTime>
org.vaadin.addons.clock.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

@Tag("vaadin-clock") @JsModule("./vaadin-clock/vaadin-clock.js") public class Clock extends com.vaadin.flow.component.AbstractSinglePropertyField<Clock, LocalTime> implements com.vaadin.flow.component.Focusable<Clock>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme
Clock is a component displaying an analog clock face with an Amiga Workbench 1.2 aesthetic. The clock shows hour, minute, and second hands.

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...):

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

    Constructors
    Constructor
    Description
    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 Type
    Method
    Description
    void
    Adds theme variants to the component.
     
     
    Gets the label of the clock.
    Gets the maximum allowed time.
    Gets the minimum allowed time.
    Gets the time interval for step-based adjustments.
    Gets the displayed time.
    boolean
    Gets whether the clock time can be adjusted by the user.
    boolean
    Gets whether the clock is disabled.
    boolean
    Gets whether the clock is readonly.
    boolean
    Returns whether the clock is currently running (animating).
    void
    Removes theme variants from the component.
    void
    setAdjustable(boolean adjustable)
    Sets whether the clock time can be adjusted by the user via dragging clock hands or using keyboard arrow keys.
    void
    setAriaLabel(String ariaLabel)
     
    void
     
    void
    Sets the size of the clock using the CSS custom property.
    void
    setDisabled(boolean disabled)
    Sets the clock to disabled state.
    void
    Sets the label for the clock.
    void
    Sets the maximum allowed time for user adjustment.
    void
    Sets the minimum allowed time for user adjustment.
    void
    setReadonly(boolean readonly)
    Sets the clock to readonly state.
    void
    setRunning(boolean running)
    Sets whether the clock is running (animating).
    void
    Sets the time interval for step-based adjustments when using keyboard arrow keys.
    void
    Sets the displayed time.

    Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField

    getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent

    Methods inherited from class com.vaadin.flow.component.AbstractField

    addValueChangeListener, getEmptyValue, isEmpty, setModelValue, valueEquals

    Methods 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, setVisible

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.BlurNotifier

    addBlurListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.Focusable

    addFocusShortcut, blur, focus, getTabIndex, setTabIndex

    Methods inherited from interface com.vaadin.flow.component.FocusNotifier

    addFocusListener

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods 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, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.HasTheme

    addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.HasValue

    clear, getOptionalValue

    Methods 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

      public Clock(LocalTime time)
      Creates a clock displaying the specified time.
      Parameters:
      time - the time to display, or null to display the current time
    • Clock

      public Clock(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Clock, LocalTime>> listener)
      Creates a clock with a value change listener.
      Parameters:
      listener - the value change listener
    • 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, or null to display the current time
      listener - the value change listener
  • Method Details

    • setLabel

      public void setLabel(String label)
      Sets the label for the clock.
      Parameters:
      label - value for the label property in the clock
    • getLabel

      public String getLabel()
      Gets the label of the clock.
      Returns:
      the label property of the clock
    • setAriaLabel

      public void setAriaLabel(String ariaLabel)
      Specified by:
      setAriaLabel in interface com.vaadin.flow.component.HasAriaLabel
    • getAriaLabel

      public Optional<String> getAriaLabel()
      Specified by:
      getAriaLabel in interface com.vaadin.flow.component.HasAriaLabel
    • setAriaLabelledBy

      public void setAriaLabelledBy(String labelledBy)
      Specified by:
      setAriaLabelledBy in interface com.vaadin.flow.component.HasAriaLabel
    • getAriaLabelledBy

      public Optional<String> getAriaLabelledBy()
      Specified by:
      getAriaLabelledBy in interface com.vaadin.flow.component.HasAriaLabel
    • setValue

      public void setValue(LocalTime value)
      Sets the displayed time. The value will be truncated to second precision.

      Set to null to display the current time.

      Specified by:
      setValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Clock, LocalTime>, LocalTime>
      Overrides:
      setValue in class com.vaadin.flow.component.AbstractField<Clock, LocalTime>
      Parameters:
      value - the time to display, or null for current time
    • getValue

      public LocalTime getValue()
      Gets the displayed time.
      Specified by:
      getValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Clock, LocalTime>, LocalTime>
      Overrides:
      getValue in class com.vaadin.flow.component.AbstractField<Clock, LocalTime>
      Returns:
      the displayed time, or null if displaying current time
    • setMin

      public void setMin(LocalTime min)
      Sets the minimum allowed time for user adjustment.
      Parameters:
      min - the minimum time, or null to remove the constraint
    • getMin

      public LocalTime getMin()
      Gets the minimum allowed time.
      Returns:
      the minimum time, or null if not set
    • setMax

      public void setMax(LocalTime max)
      Sets the maximum allowed time for user adjustment.
      Parameters:
      max - the maximum time, or null to remove the constraint
    • getMax

      public LocalTime getMax()
      Gets the maximum allowed time.
      Returns:
      the maximum time, or null if not set
    • setDisabled

      public void setDisabled(boolean disabled)
      Sets the clock to disabled state.
      Parameters:
      disabled - true to disable the clock, false to enable
    • isDisabled

      public boolean isDisabled()
      Gets whether the clock is disabled.
      Returns:
      true if disabled, false otherwise
    • setReadonly

      public void setReadonly(boolean readonly)
      Sets the clock to readonly state.
      Parameters:
      readonly - true to set readonly, false otherwise
    • isReadonly

      public boolean isReadonly()
      Gets whether the clock is readonly.
      Returns:
      true if readonly, false otherwise
    • 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 - true to allow user adjustment (default), false to disable
    • isAdjustable

      public boolean isAdjustable()
      Gets whether the clock time can be adjusted by the user.
      Returns:
      true if user adjustment is enabled (default), false otherwise
    • setStep

      public void setStep(Duration step)
      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, not null
      Throws:
      IllegalArgumentException - if the step is not a positive duration or does not evenly divide a day
    • getStep

      public Duration getStep()
      Gets the time interval for step-based adjustments.
      Returns:
      the step duration, or null if not set (defaults to 60 seconds on the client)
    • setClockSize

      public void setClockSize(String size)
      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 - true to start running, false to stop
    • isRunning

      public boolean isRunning()
      Returns whether the clock is currently running (animating).
      Returns:
      true if running, false otherwise
    • addThemeVariants

      public void addThemeVariants(ClockVariant... variants)
      Adds theme variants to the component.
      Parameters:
      variants - the theme variants to add
    • removeThemeVariants

      public void removeThemeVariants(ClockVariant... variants)
      Removes theme variants from the component.
      Parameters:
      variants - the theme variants to remove