public static final class TLcdStatusEvent.Progress<T> extends Object implements AutoCloseable
A few typical use-cases of this class are listed below:
Reporting progress when the exact progress is known:
try (Progress task = TLcdStatusEvent.startProgress(...)) {
// perform task calculations
...
// whenever there is progress:
task.progress(progressAmount);
// more task calculations
...
}
Reporting progress when the progress is undetermined:
try (Progress task = TLcdStatusEvent.startIndeterminateProgress(...)) {
// perform task calculations
...
// whenever you want to update the progress message
task.indeterminateProgress(updatedMessage);
// more task calculations
...
}
Switching from undetermined to known progress:
An example is reporting progress when downloading a file: while the connection is being established, you have no idea how long the actual download will take. As soon as you can determine the file size, you can start reporting known progress by comparing the number of downloaded bytes to the file size.
try (Progress task = TLcdStatusEvent.startIndeterminateProgress(...)) {
// establishing connection
...
// once the file size is known, exact progress reports can be sent
while(downloading){
//download some data
...
//update the progress
task.progress(progressAmount);
}
}
Modifier and Type | Method and Description |
---|---|
void |
close()
Calls
end() |
void |
end()
Creates and dispatches an end status event without a specific message.
|
void |
end(String aMessage)
Creates and dispatches an end status event with the given message.
|
void |
indeterminateProgress()
Creates and dispatches an indeterminate progress status event with the previously used message.
|
void |
indeterminateProgress(String aMessage)
Creates and dispatches an indeterminate progress status event with the given message.
|
void |
progress(double aProgress)
Creates and dispatches a progress status event with the given progress and the previously used message.
|
void |
progress(double aProgress,
String aMessage)
Creates and dispatches a progress status event with the given progress and message.
|
public void progress(double aProgress)
aProgress
- the progress to report. A value between 0 and 1.public void progress(double aProgress, String aMessage)
aProgress
- the progress to report. A value between 0 and 1.aMessage
- the message to reportpublic void indeterminateProgress(String aMessage)
aMessage
- the message to reportpublic void indeterminateProgress()
public void end(String aMessage)
aMessage
- the message to reportpublic void end()
public void close()
end()
close
in interface AutoCloseable