com.databasesandlife.util.wicket
Class CountingUpThenAutoRefreshingLabel

java.lang.Object
  extended by org.apache.wicket.Component
      extended by org.apache.wicket.MarkupContainer
          extended by org.apache.wicket.markup.html.WebMarkupContainer
              extended by org.apache.wicket.markup.html.panel.Panel
                  extended by com.databasesandlife.util.wicket.CountingUpThenAutoRefreshingLabel
All Implemented Interfaces:
Serializable, Iterable<Component>, org.apache.wicket.event.IEventSink, org.apache.wicket.event.IEventSource, IConverterLocator, IHeaderContributor, org.apache.wicket.request.component.IRequestableComponent, org.apache.wicket.util.IHierarchical<Component>, IClusterable

public class CountingUpThenAutoRefreshingLabel
extends Panel

A <span> label which firstly counts up towards its model's value, and secondly auto-refreshes that value. The component implements similar functionality to "worldwide members" number on the avaaz homepage.

Usage:

    <!-- In HTML file -->
    <span wicket:id="numberOfUsers"></span>

    // In Java file
    CountingUpThenAutoRefreshingLabel label = new CountingUpThenAutoRefreshingLabel("numberOfUsers");
    label.setDefaultModel(new PropertyModel(dataSource, "userCount")); // model returns Integer
    add(label);

The first phase of the component lasts two minutes, and the value counts up from zero to the target value. It "tends" towards the target value, i.e. moves fast at the beginning, then slows down as it approaches its target value.

The second phase, triggered after the first two minutes, simply refreshes the value periodically from the server. Initially this is refreshed every two seconds, but this refresh interval is gradually slowed down, so that if N users leave their browsers open for a long time, we will not get N requests every two seconds forever.

Various numerical values above may be altered with:

    label.setCountingUpDurationSeconds(120);
    label.setCountingUpRefreshIntervalSeconds(0.1);
    label.setTendencyThreshold(0.001);
    label.setAutoRefreshingInitialIntervalSeconds(2.0);
    label.setAutoRefreshingIntervalMultiplier(1.2); 

Version:
$Revision: 6632 $
Author:
The Java source is copyright Adrian Smith and licensed under the LGPL 3.
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.wicket.markup.html.panel.Panel
PANEL
 
Fields inherited from class org.apache.wicket.Component
ENABLE, PARENT_PATH, PATH_SEPARATOR, RENDER
 
Constructor Summary
CountingUpThenAutoRefreshingLabel(String wicketId)
           
 
Method Summary
 String getJs()
          INTERNAL METHOD -- DO NOT USE
 String getLabelValue()
          INTERNAL METHOD -- DO NOT USE
 void setAutoRefreshingInitialIntervalSeconds(double x)
          During the auto-refresh phase, what should the duration be between server-refreshes, initially?
 void setAutoRefreshingIntervalMultiplier(double x)
          During the auto-refresh phase, by what multiplier should the auto-refresh interval durations increase? For example 2.0 means they double; so for example the first duration might be 10s, the next 20s, the next 40s, etc.
 void setCountingUpDurationSeconds(double x)
          How long should the initial phase of counting up be? Measured in seconds
 void setCountingUpRefreshIntervalSeconds(double x)
          What should the duration between the updates during the counting up phase be? Measured in seconds.
 void setTendencyThreshold(double x)
          How close should the counting up phase get to the target value? A value of 0.01 means it gets within 1% of the target value before switching to the second auto-refresh phase.
 
Methods inherited from class org.apache.wicket.markup.html.WebMarkupContainer
getWebPage, getWebRequest, getWebResponse, getWebSession
 
Methods inherited from class org.apache.wicket.MarkupContainer
add, addOrReplace, autoAdd, contains, get, get, getAssociatedMarkup, getAssociatedMarkupStream, getMarkup, getMarkupType, internalAdd, internalInitialize, iterator, iterator, onComponentTagBody, remove, remove, removeAll, renderAssociatedMarkup, replace, setDefaultModel, size, swap, toString, toString, visitChildren, visitChildren, visitChildren, visitChildren
 
Methods inherited from class org.apache.wicket.Component
add, afterRender, beforeRender, canCallListenerInterface, configure, continueToOriginalDestination, debug, detach, detachModels, determineVisibility, error, fatal, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getId, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getResponse, getSession, getSizeInBytes, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, internalPrepareForRender, internalRenderComponent, isActionAuthorized, isAuto, isEnableAllowed, isEnabled, isEnabledInHierarchy, isRenderAllowed, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, onEvent, prepareForRender, redirectToInterceptPage, remove, remove, render, rendered, renderHead, renderHead, renderHead, replaceWith, sameInnermostModel, sameInnermostModel, send, setDefaultModelObject, setEnabled, setEscapeModelStrings, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, visitParents, warn
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CountingUpThenAutoRefreshingLabel

public CountingUpThenAutoRefreshingLabel(String wicketId)
Method Detail

setCountingUpDurationSeconds

public void setCountingUpDurationSeconds(double x)
How long should the initial phase of counting up be? Measured in seconds


setCountingUpRefreshIntervalSeconds

public void setCountingUpRefreshIntervalSeconds(double x)
What should the duration between the updates during the counting up phase be? Measured in seconds. Can be less than one.


setTendencyThreshold

public void setTendencyThreshold(double x)
How close should the counting up phase get to the target value? A value of 0.01 means it gets within 1% of the target value before switching to the second auto-refresh phase.


setAutoRefreshingInitialIntervalSeconds

public void setAutoRefreshingInitialIntervalSeconds(double x)
During the auto-refresh phase, what should the duration be between server-refreshes, initially?


setAutoRefreshingIntervalMultiplier

public void setAutoRefreshingIntervalMultiplier(double x)
During the auto-refresh phase, by what multiplier should the auto-refresh interval durations increase? For example 2.0 means they double; so for example the first duration might be 10s, the next 20s, the next 40s, etc.


getLabelValue

public String getLabelValue()
INTERNAL METHOD -- DO NOT USE


getJs

public String getJs()
INTERNAL METHOD -- DO NOT USE