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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEvent that gets triggered when the timer reaches 0 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddCurrentTimeChangeListener(PropertyChangeListener listener, long period, TimeUnit periodUnit) Adds a property change listener for thecurrentTimepropertyAdds a timer ended listener that will be triggered when the timer reaches 0Returns the last known value of the timer.Returns the current value of the timer.booleanReturns the status of the timerbooleanvoidpause()Stops the timer, does nothing if already stoppedvoidreset()Resets the current value to the start timevoidsetDoubleDigitHours(boolean doubleDigitHours) Use two digits for hours.voidsetEndTime(Number endTime) Sets the end time, for countup mode.voidsetFractions(boolean fractions) Enables showing fractions of a secondvoidsetHours(boolean hours) Enables showing hours and minutesvoidsetMinutes(boolean minutes) Enables showing minutesvoidsetStartTime(Number startTime) Sets the start time, for countdown mode.voidsetVisible(boolean visible) voidstart()Starts or stops the timer if it is already startedMethods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, onAttach, onDetach, onEnabledStateChanged, set, setElement, setIdMethods inherited from class java.lang.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.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods 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, setClassName
-
Constructor Details
-
SimpleTimer
public SimpleTimer()Creates a timer
-
-
Method Details
-
setStartTime
Sets the start time, for countdown mode.- Parameters:
startTime- value in seconds for the start time
-
setEndTime
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
Returns the status of the timer- Returns:
trueif the timer is running,falseotherwise.
-
getCurrentTime
Returns the last known value of the timer. The value is updated when the CurrentTimeChangeListener executes.- Returns:
- current value in seconds
-
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 thecurrentTimeproperty- Parameters:
listener- the property change listenerperiod- the minimum period between listener invocations, or 0 to disable throttlingperiodUnit- 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() -
setVisible
public void setVisible(boolean visible) - Overrides:
setVisiblein classComponent
-