CountCircle class represents a circular counter component that can display and animate a numerical value within specified limits. The counter's appearance can be customized with various styles, sizes, and colors. It also provides methods to increment and decrement the value, as well as to set limits and respond to value changes.
Implements:
DateCountDown class is a component that displays a countdown to a specific target date. It breaks down the time remaining into years, months, days, hours, minutes, and seconds, updating in real-time at one-second intervals.
The countdown supports various ways to initialize via factory methods that calculate target dates based on the current time plus the specified duration. Counters for each time unit are instances of CountCircle and can be selectively shown or hidden.
public void CountCircle(int start, int end)
CountCircle with the specified start and end limits for the counter. Initializes the UI elements and sets up the default configuration.
start
the initial value of the counter
end
the maximum value of the counter
public static CountCircle create(int start, int end)
CountCircle with specified start and end values.
start
the initial value of the counter
end
the maximum value of the counter
a new instance of CountCircle
public CountCircle setSize(double radius, double thickness)
radius
the radius of the circle
thickness
the thickness of the counter ring
the current instance for method chaining
public CountCircle setCounterColors(String startColor, String stopColor)
startColor
the start color for the count circle gradient
stopColor
the stop color for the count circle gradient
the current instance for method chaining
public CountCircle setLimits(int start, int end)
IllegalArgumentException is thrown.
start
the starting value of the counter
end
the end value of the counter
the current instance for method chaining
@throws IllegalArgumentException if start is greater than endpublic CountCircle countUp(int increment)
increment
the value to increment the counter by
the current instance for method chaining
public CountCircle countDown(int decrement)
decrement
the value to decrement the counter by
the current instance for method chaining
public void setValue(Integer value)
Sets the value of the counter. If the new value is null , the counter is set to the start value. If the new value is outside the bounds of start and end , it is capped at those limits. Triggers change listeners if they are not paused.
value
the new value to set the counter to
public Integer getValue()
Retrieves the current value of the counter.
public String getTextExpression()
"${value}" .
the current text expression
public CountCircle setTextExpression(String textExpression)
"${value}" .
textExpression
the text expression to set
the current instance for method chaining
public CountCircle pauseChangeListeners()
Pauses the change listeners so that they do not fire when the counter's value changes.
public CountCircle resumeChangeListeners()
Resumes the change listeners so that they will fire when the counter's value changes.
public CountCircle togglePauseChangeListeners(boolean toggle)
Toggles the pause state of the change listeners.
toggle
if true, pauses the change listeners; if false, resumes them
the current instance for method chaining
public Set<ChangeListener<? super Integer>> getChangeListeners()
Retrieves the set of change listeners that are registered on the counter.
public boolean isChangeListenersPaused()
Checks if the change listeners are currently paused.
public CountCircle triggerChangeListeners(Integer oldValue, Integer newValue)
Triggers the change listeners with the old and new values.
oldValue
the old value of the counter
newValue
the new value of the counter
the current instance for method chaining
public CountCircle withMainContainer(ChildHandler<CountCircle, DivElement> handler)
handler
a ChildHandler functional interface to apply to the main container
the current instance for method chaining
public CountCircle withOuterContainer(ChildHandler<CountCircle, DivElement> handler)
handler
a ChildHandler functional interface to apply to the outer container
the current instance for method chaining
public CountCircle withInnerContainer(ChildHandler<CountCircle, DivElement> handler)
handler
a ChildHandler functional interface to apply to the inner container
the current instance for method chaining
public CountCircle withSvgElement(ChildHandler<CountCircle, SvgElement> handler)
handler
a ChildHandler functional interface to apply to the SVG element
the current instance for method chaining
public CountCircle withSvgCircleElement(ChildHandler<CountCircle, CircleElement> handler)
handler
a ChildHandler functional interface to apply to the SVG circle element
the current instance for method chaining
public CountCircle withTextElement(ChildHandler<CountCircle, SpanElement> handler)
handler
a ChildHandler functional interface to apply to the text element
the current instance for method chaining
public CountCircle withValue(Integer value)
Sets the value of the counter, respecting whether change listeners are currently paused.
value
the new value
this instance for method chaining
public CountCircle withValue(Integer value, boolean silent)
Sets the value of the counter with an option to notify change listeners. If silent is true, change listeners will not be notified.
value
the new value to set the counter to
silent
if true, change listeners are not notified; if false, they are notified
the current instance for method chaining
public HTMLDivElement element()
Retrieves the root HTMLDivElement for the counter. This is the main container element of the counter UI.
Returns:
the root HTMLDivElement
public void DateCountDown()
Sets up counters for seconds, minutes, hours, days, months, and years, attaching corresponding change listeners to handle transitions (e.g., when seconds roll over to decrement minutes).
A Timer is also created to update the seconds counter every second.
public static DateCountDown create()
DateCountDown . This method initializes the countdown with default settings (six counters for seconds, minutes, hours, days, months, and years).
a new instance of DateCountDown
public DateCountDown start(int minutes, int seconds)
start method calculates the target end time based on the current date and time plus the given duration.
minutes
the number of minutes to count down from the current time
seconds
the number of seconds to count down in addition to the minutes
The current DateCountDown instance for chaining method calls
public DateCountDown start(int hours, int minutes, int seconds)
start method calculates the target end time based on the current date and time plus the given duration.
hours
the number of hours to count down from the current time
minutes
the number of minutes to count down in addition to the hours
seconds
the number of seconds to count down in addition to the hours and minutes
The current DateCountDown instance for chaining method calls
public DateCountDown start(int days, int hours, int minutes, int seconds)
start method calculates the target end time based on the current date and time plus the given duration.
days
the number of days to count down from the current time
hours
the number of hours to count down in addition to the days
minutes
the number of minutes to count down in addition to the days and hours
seconds
the number of seconds to count down in addition to the days, hours, and minutes
The current DateCountDown instance for chaining method calls
public DateCountDown start(Date targetDate)
targetDate
the date to count down to
The current DateCountDown instance for chaining method calls
public DateCountDown stop()
The current DateCountDown instance for chaining method calls
public DateCountDown withYearCounter(ChildHandler<DateCountDown, CountCircle> handler)
handler
a ChildHandler functional interface to apply to the year counter
The current DateCountDown instance for chaining method calls
public DateCountDown withMonthsCounter(ChildHandler<DateCountDown, CountCircle> handler)
handler
a ChildHandler functional interface to apply to the months counter
The current DateCountDown instance for chaining method calls
public DateCountDown withDaysCounter(ChildHandler<DateCountDown, CountCircle> handler)
handler
a ChildHandler functional interface to apply to the days counter
The current DateCountDown instance for chaining method calls
public DateCountDown withHoursCounter(ChildHandler<DateCountDown, CountCircle> handler)
handler
a ChildHandler functional interface to apply to the hours counter
The current DateCountDown instance for chaining method calls
public DateCountDown withMinutesCounter(ChildHandler<DateCountDown, CountCircle> handler)
handler
a ChildHandler functional interface to apply to the minutes counter
The current DateCountDown instance for chaining method calls
public DateCountDown withSecondsCounter(ChildHandler<DateCountDown, CountCircle> handler)
handler
a ChildHandler functional interface to apply to the seconds counter
The current DateCountDown instance for chaining method calls
public CountCircle getSecondsCounter()
public CountCircle getMinutesCounter()
public CountCircle getHoursCounter()
public CountCircle getDaysCounter()
public CountCircle getMonthsCounter()
public CountCircle getYearsCounter()
public DateCountDown showCounters()
The current DateCountDown instance for chaining method calls
public DateCountDown hideCounters()
The current DateCountDown instance for chaining method calls
public DateCountDown showCounters(DateCountDown.CounterUnits[] units)
units
the time units whose counters should be shown
The current DateCountDown instance for chaining method calls
public DateCountDown hideCounters(DateCountDown.CounterUnits[] units)
units
the time units whose counters should be hidden
The current DateCountDown instance for chaining method calls
public DateCountDown showCounter(CounterUnits unit)
unit
the time unit whose counter should be shown
The current DateCountDown instance for chaining method calls
public DateCountDown hideCounter(CounterUnits unit)
unit
the time unit whose counter should be hidden
The current DateCountDown instance for chaining method calls
public HTMLDivElement element()
Retrieves the root element of the countdown timer as an HTMLDivElement . This is the primary element that contains all the visual components of the countdown timer.