Package com.hybris.cockpitng.components
Class Stopwatch
- java.lang.Object
-
- org.zkoss.zk.ui.AbstractComponent
-
- org.zkoss.zk.ui.HtmlBasedComponent
-
- org.zkoss.zul.impl.XulElement
-
- org.zkoss.zul.Label
-
- com.hybris.cockpitng.components.Stopwatch
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,org.zkoss.zk.ui.Component,org.zkoss.zk.ui.ext.Scope,org.zkoss.zk.ui.sys.ComponentCtrl
public class Stopwatch extends org.zkoss.zul.LabelA component which displays an elapsed time. The time is updated every second on a client side.
By default time is displayed in following way: hh:mm:ss. But it can be modified by settings:setDisplayDays(boolean)setDaysDelimiter(String)setDisplayEmptyHours(boolean)setTimeDelimiter(String)
If
This component should be used display time in the UI.getStartTime()andgetStopTime()are set and stopwatch is not started then it displays difference between these two points in time.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDAYS_DELIMITERstatic java.lang.StringDISPLAY_DAYSstatic java.lang.StringDISPLAY_EMPTY_HOURSstatic java.lang.StringLABEL_RESETstatic java.lang.StringLABEL_RUNNINGstatic java.lang.StringSTART_TIMEstatic java.lang.StringSTOP_TIMEstatic java.lang.StringTIME_DELIMITERstatic intTIME_NOT_SET
-
Constructor Summary
Constructors Constructor Description Stopwatch()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected longgetCurrentTime()java.util.function.Supplier<java.lang.Long>getCurrentTimeSupplier()java.lang.StringgetDaysDelimiter()longgetStartTime()longgetStopTime()java.lang.StringgetTimeDelimiter()booleanisDisplayDays()booleanisDisplayEmptyHours()booleanisRunning()Tells if stopwatch is running.protected voidrenderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)voidreset()Stops timer and resets start and stop timevoidsetCurrentTimeSupplier(java.util.function.Supplier<java.lang.Long> timeSupplier)Sets current time supplier which will be used to obtain current time in milliseconds.voidsetDaysDelimiter(java.lang.String daysDelimiter)Defines delimiter between number of days and hours (default:'d' defined in global label stopwatch.delimiter.days)voidsetDisplayDays(boolean displayDays)Defines if hours should be rounded to 23 and days displayed (default:false)voidsetDisplayEmptyHours(boolean displayEmptyHours)Defines if empty hours should be displayed (default:false).voidsetStartTime(long startTime)voidsetStopTime(long stopTime)voidsetTimeDelimiter(java.lang.String timeDelimiter)Defines delimiter between hours, minutes and seconds (default:':' defined in global label stopwatch.delimiter.time)voidstart()Starts stopwatch - ifgetStartTime()is set then it will count elapsed time from that moment.voidstop()Stops timer (counting elapsed time in the UI) and sets current time as stop time.-
Methods inherited from class org.zkoss.zul.Label
clone, getMaxlength, getPropertyAccess, getValue, getZclass, isChildable, isHyphen, isMultiline, isPre, setHyphen, setMaxlength, setMultiline, setPre, setValue
-
Methods inherited from class org.zkoss.zul.impl.XulElement
getContext, getCtrlKeys, getPopup, getTooltip, setContext, setContext, setContextAttributes, setCtrlKeys, setPopup, setPopup, setPopupAttributes, setTooltip, setTooltip, setTooltipAttributes
-
Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent
addSclass, focus, getAction, getDraggable, getDroppable, getExtraCtrl, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZindex, getZIndex, removeSclass, removeSclass, service, setAction, setClass, setDraggable, setDroppable, setFocus, setHeight, setHeight0, setHeightDirectly, setHflex, setHflex0, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setStyle, setTabindex, setTabindex, setTooltiptext, setTop, setTopDirectly, setVflex, setVflex0, setVflexDirectly, setWidth, setWidth0, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectly
-
Methods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, enableBindingAnnotation, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotation, getAnnotations, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getId, getLastChild, getListenerIterator, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttribute, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, insertBefore, invalidate, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, replace, response, response, response, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setMold, setPage, setPageBefore, setParent, setStubonly, setStubonly, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetAttribute, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
-
-
-
-
Field Detail
-
TIME_NOT_SET
public static final int TIME_NOT_SET
- See Also:
- Constant Field Values
-
START_TIME
public static final java.lang.String START_TIME
- See Also:
- Constant Field Values
-
STOP_TIME
public static final java.lang.String STOP_TIME
- See Also:
- Constant Field Values
-
LABEL_RUNNING
public static final java.lang.String LABEL_RUNNING
- See Also:
- Constant Field Values
-
DISPLAY_EMPTY_HOURS
public static final java.lang.String DISPLAY_EMPTY_HOURS
- See Also:
- Constant Field Values
-
DISPLAY_DAYS
public static final java.lang.String DISPLAY_DAYS
- See Also:
- Constant Field Values
-
TIME_DELIMITER
public static final java.lang.String TIME_DELIMITER
- See Also:
- Constant Field Values
-
DAYS_DELIMITER
public static final java.lang.String DAYS_DELIMITER
- See Also:
- Constant Field Values
-
LABEL_RESET
public static final java.lang.String LABEL_RESET
- See Also:
- Constant Field Values
-
-
Method Detail
-
getStopTime
public long getStopTime()
-
start
public void start()
Starts stopwatch - ifgetStartTime()is set then it will count elapsed time from that moment. IfgetStopTime()was set then it will be removed.
-
stop
public void stop()
Stops timer (counting elapsed time in the UI) and sets current time as stop time.
-
reset
public void reset()
Stops timer and resets start and stop time
-
isRunning
public boolean isRunning()
Tells if stopwatch is running.- Returns:
- true is stopwatch is running.
-
getStartTime
public long getStartTime()
-
setStartTime
public void setStartTime(long startTime)
-
setStopTime
public void setStopTime(long stopTime)
-
isDisplayDays
public boolean isDisplayDays()
-
setDisplayDays
public void setDisplayDays(boolean displayDays)
Defines if hours should be rounded to 23 and days displayed (default:false)- Parameters:
displayDays- - true if days should be displayed.
-
getTimeDelimiter
public java.lang.String getTimeDelimiter()
-
setTimeDelimiter
public void setTimeDelimiter(java.lang.String timeDelimiter)
Defines delimiter between hours, minutes and seconds (default:':' defined in global label stopwatch.delimiter.time)- Parameters:
timeDelimiter- - timeDelimiter.
-
getDaysDelimiter
public java.lang.String getDaysDelimiter()
-
setDaysDelimiter
public void setDaysDelimiter(java.lang.String daysDelimiter)
Defines delimiter between number of days and hours (default:'d' defined in global label stopwatch.delimiter.days)- Parameters:
daysDelimiter- - days delimiter.
-
isDisplayEmptyHours
public boolean isDisplayEmptyHours()
-
setDisplayEmptyHours
public void setDisplayEmptyHours(boolean displayEmptyHours)
Defines if empty hours should be displayed (default:false).- Parameters:
displayEmptyHours- if true then 00:45:26 or 45:26 when false.
-
getCurrentTime
protected long getCurrentTime()
-
setCurrentTimeSupplier
public void setCurrentTimeSupplier(java.util.function.Supplier<java.lang.Long> timeSupplier)
Sets current time supplier which will be used to obtain current time in milliseconds.- Parameters:
timeSupplier- the supplier
-
getCurrentTimeSupplier
public java.util.function.Supplier<java.lang.Long> getCurrentTimeSupplier()
-
renderProperties
protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) throws java.io.IOException- Overrides:
renderPropertiesin classorg.zkoss.zul.Label- Throws:
java.io.IOException
-
-