Class ProgressBar
java.lang.Object
com.codename1.cli.ProgressBar
- All Implemented Interfaces:
AutoCloseable
A progress bar with a percentage, a count, a rate and the time left:
upload ##################-------------- 58% 5.8/10.0 MB 1.2 MB/s 0:03
(drawn with block characters on a UTF-8 terminal).
try (ProgressBar bar = new ProgressBar("upload", files.size())) {
for (File f : files) {
send(f);
bar.step();
}
}
or, for a loop, track(Iterable, String):
for (File f : ProgressBar.track(files, "upload")) {
send(f);
}
Stepping is cheap and safe from any thread. A bar made on its own draws
itself; several at once belong in a MultiProgress. Off a terminal the bar
prints milestone lines instead of redrawing (see MultiProgress).
-
Constructor Summary
ConstructorsConstructorDescriptionProgressBar(String label, long total) A bar on its own, fortotalunits of work; a total of 0 or less is unknown, and the bar then animates without a percentage. -
Method Summary
Modifier and TypeMethodDescriptionbytes()Shows the count, the total and the rate as sizes (5.8 MB) rather than numbers.voidclose()Completes the bar if nothing else did and, for a bar made on its own, stops drawing it.voidcomplete()Marks the work complete: the bar fills and shows the time it took.voidfail()Marks the work failed: the bar stops where it is, in red.longThe amount done.longgetTotal()The total, 0 or less when unknown.booleanisDone()Whether the bar has completed or failed.label()The label.setMessage(String message) Showsmessageafter the numbers: the file being worked on, say.setTotal(long total) Changes the total; 0 or less makes it unknown.step()Advances by one.stepBy(long n) Advances byn.stepTo(long n) Sets the amount done.static <T> Iterable<T> Wrapsitemsso that iterating them steps a bar labelledlabel, which completes when the iteration ends.Units shown after the count,filesin3/10 files.
-
Constructor Details
-
ProgressBar
A bar on its own, fortotalunits of work; a total of 0 or less is unknown, and the bar then animates without a percentage.
-
-
Method Details
-
track
Wrapsitemsso that iterating them steps a bar labelledlabel, which completes when the iteration ends. ACollection's size is the total; any other iterable has an unknown one. -
label
The label. -
unit
Units shown after the count,filesin3/10 files. -
bytes
Shows the count, the total and the rate as sizes (5.8 MB) rather than numbers. -
step
Advances by one. -
stepBy
Advances byn. -
stepTo
Sets the amount done. -
setTotal
Changes the total; 0 or less makes it unknown. -
setMessage
Showsmessageafter the numbers: the file being worked on, say. -
getCurrent
public long getCurrent()The amount done. -
getTotal
public long getTotal()The total, 0 or less when unknown. -
isDone
public boolean isDone()Whether the bar has completed or failed. -
complete
public void complete()Marks the work complete: the bar fills and shows the time it took. -
fail
public void fail()Marks the work failed: the bar stops where it is, in red. -
close
public void close()Completes the bar if nothing else did and, for a bar made on its own, stops drawing it.- Specified by:
closein interfaceAutoCloseable
-