Class SimpleTimer

java.lang.Object
com.vaadin.flow.component.Component
com.flowingcode.vaadin.addons.simpletimer.SimpleTimer
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasElement, HasSize, HasStyle, Serializable

@Tag("simple-timer") @JsModule("./simple-timer/simple-timer.js") public class SimpleTimer extends Component implements HasSize, HasStyle, Serializable
Author:
Leonardo Scardanzan / Flowing Code
See Also:
  • Constructor Details

    • SimpleTimer

      public SimpleTimer()
      Creates a timer
  • Method Details

    • setStartTime

      public void setStartTime(Number startTime)
      Sets the start time, for countdown mode.
      Parameters:
      startTime - value in seconds for the start time
    • setEndTime

      public void setEndTime(Number endTime)
      Sets the end time, for countup mode.
      Parameters:
      endTime - value in seconds for the end time
    • setFractions

      public void setFractions(boolean fractions)
      Enables showing fractions of a second
      Parameters:
      fractions -
    • setMinutes

      public void setMinutes(boolean minutes)
      Enables showing minutes
      Parameters:
      minutes -
    • setHours

      public void setHours(boolean hours)
      Enables showing hours and minutes
      Parameters:
      hours -
    • setDoubleDigitHours

      public void setDoubleDigitHours(boolean doubleDigitHours)
      Use two digits for hours.
      Parameters:
      doubleDigitHours - true to format hours using two digits.
    • start

      public void start()
      Starts or stops the timer if it is already started
    • pause

      public void pause()
      Stops the timer, does nothing if already stopped
    • reset

      public void reset()
      Resets the current value to the start time
    • isRunning

      @Synchronize(property="isRunning", value="is-running-changed") public boolean isRunning()
      Returns the status of the timer
      Returns:
      true if the timer is running, false otherwise.
    • getCurrentTime

      @Synchronize("is-running-changed") public BigDecimal getCurrentTime()
      Returns the last known value of the timer. The value is updated when the CurrentTimeChangeListener executes.
      Returns:
      current value in seconds
    • getCurrentTimeAsync

      public CompletableFuture<BigDecimal> getCurrentTimeAsync()
      Returns the current value of the timer.
      Returns:
      a pending result that completes after retrieving the timer value.
    • addCurrentTimeChangeListener

      public Registration addCurrentTimeChangeListener(PropertyChangeListener listener, long period, TimeUnit periodUnit)
      Adds a property change listener for the currentTime property
      Parameters:
      listener - the property change listener
      period - the minimum period between listener invocations, or 0 to disable throttling
      periodUnit - time duration of throttling period
      Returns:
      this registration, for chaining
    • addTimerEndEvent

      Adds a timer ended listener that will be triggered when the timer reaches 0
      Parameters:
      listener -
      Returns:
      a handle that can be used for removing the listener
    • isVisible

      public boolean isVisible()
      Overrides:
      isVisible in class Component
    • setVisible

      public void setVisible(boolean visible)
      Overrides:
      setVisible in class Component