Package jebl.util
Class CompositeProgressListener
- java.lang.Object
-
- jebl.util.ProgressListener
-
- jebl.util.CompositeProgressListener
-
- All Implemented Interfaces:
Cancelable
public final class CompositeProgressListener extends ProgressListener
AProgressListenerthat is suitable for a task that consists of several subtasks. You specify the relative duration of each subtask, and then the subtasks' setProgress() calls with values between 0 and 1 are translated to reflect the overall progress on the whole (combined) task. In other words, each subtask reports progress as if it were the whole task, and the CompositeProgressListener translates this into overall progress. This also implies that callingsetComplete()orsetProgress(1.0)marks the current subtask rather than the entire task completed. As the combined progress listener cannot know which subtask it is currently being called from, you have to explicitely let it know when a new subtask (not the first) starts, by callingbeginNextSubtask(). Thus when the constructor is passed an array of N doubles as its second argument,beginNextSubtask()should be called precisely N-1 times. Alternatively, instead of callingbeginNextSubtask()after each subtask (except the last), you can instead callbeginSubtask()before each subtask (including the first).- Version:
- $Id: CompositeProgressListener.java 1068 2010-09-08 23:59:59Z matt_kearse $
- Author:
- Tobias Thierer
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jebl.util.ProgressListener
ProgressListener.Wrapper
-
-
Field Summary
-
Fields inherited from class jebl.util.ProgressListener
EMPTY
-
-
Constructor Summary
Constructors Constructor Description CompositeProgressListener(ProgressListener listener, double... operationDuration)construct a new composite ProgressListener.CompositeProgressListener(ProgressListener listener, int numberOfEvenlyWeightedSubTasks)Construct a CompositeProgressListener with a number of evenly weighted subtasks.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFeedbackAction(java.lang.String label, java.lang.String description, SimpleListener listener)Adds an action that can choose to provide feedback.voidaddFeedbackAction(java.lang.String label, SimpleListener listener)Equivalent toaddFeedbackAction(label,"",listener)booleanaddProgress(double fractionCompletedDiff)Increments the progress of the current sub task by this much.voidbeginNextSubtask()begins the next subtask.voidbeginNextSubtask(java.lang.String message)Convenience method to start the next operation AND set a new message.voidbeginSubtask()Used as an alternative tobeginNextSubtask().voidbeginSubtask(java.lang.String message)Used as an alternative tobeginNextSubtask().voidclearAllProgress()Clear all progress, including that of previous subtasks.static CompositeProgressListenerforFiles(ProgressListener listener, java.util.List<java.io.File> files)ProgressListenergetRootProgressListener()booleanhasNextSubtask()booleanisCanceled()This method must be implemented by all subclasses.voidremoveFeedbackAction(java.lang.String label)Removes a feedback action previously added usingProgressListener.addFeedbackAction(String, jebl.util.SimpleListener).booleansetComplete()voidsetTitle(java.lang.String title)Sets a title associated with whatever is being done.-
Methods inherited from class jebl.util.ProgressListener
setImage, setIndeterminateProgress, setMessage, setProgress, setProgress, setProgress
-
-
-
-
Constructor Detail
-
CompositeProgressListener
public CompositeProgressListener(ProgressListener listener, double... operationDuration)
construct a new composite ProgressListener.- Parameters:
listener- the ProgressListener that all progress reports are forwarded to after adjusting them for the currently active sub-taskoperationDuration- a list of relative weightings to give each sub task.
-
CompositeProgressListener
public CompositeProgressListener(ProgressListener listener, int numberOfEvenlyWeightedSubTasks)
Construct a CompositeProgressListener with a number of evenly weighted subtasks.- Parameters:
listener- the ProgressListener that all progress reports are forwarded to after adjusting them for the currently active sub-tasknumberOfEvenlyWeightedSubTasks- the number of evenly weighted sub-tasks.
-
-
Method Detail
-
forFiles
public static CompositeProgressListener forFiles(ProgressListener listener, java.util.List<java.io.File> files)
-
beginSubtask
public void beginSubtask()
Used as an alternative tobeginNextSubtask(). Instead of callingbeginNextSubtask()once after each subtask (except the last), you can instead call beginSubTask at the beginning of every subtask including the first.
-
beginSubtask
public void beginSubtask(java.lang.String message)
Used as an alternative tobeginNextSubtask(). Instead of callingbeginNextSubtask()once after each subtask (except the last), you can instead call beginSubTask at the beginning of every subtask including the first.- Parameters:
message- a message to be displayed to the user as a prefix in the progress message
-
isCanceled
public boolean isCanceled()
Description copied from class:ProgressListenerThis method must be implemented by all subclasses. It is called fromProgressListener.setProgress(double),ProgressListener.setIndeterminateProgress()andProgressListener.setMessage(java.lang.String)to determine the return value of these methods.- Specified by:
isCanceledin interfaceCancelable- Specified by:
isCanceledin classProgressListener- Returns:
- true if the user has requested that this operation be canceled.
-
addProgress
public boolean addProgress(double fractionCompletedDiff)
Increments the progress of the current sub task by this much. Using this method is generally a bad idea. UseProgressListener.setProgress(double)instead.- Parameters:
fractionCompletedDiff- the amount ot increase the current progress by between 0 and 1.- Returns:
- true if canceled.
-
hasNextSubtask
public boolean hasNextSubtask()
- Returns:
- true if there is another subtask available after the current one
-
clearAllProgress
public void clearAllProgress()
Clear all progress, including that of previous subtasks. Note: if the task has already been canceled, this does not reset its status to non-canceled.
-
beginNextSubtask
public void beginNextSubtask(java.lang.String message)
Convenience method to start the next operation AND set a new message.- Parameters:
message- message to set (will be passed to setMessage()
-
beginNextSubtask
public void beginNextSubtask()
begins the next subtask. Should not be called on the first subtask, but should only be called to start tasks after the first one. If you wish to call a begin subtask method for each task including the first, usebeginSubtask()instead.
-
setComplete
public final boolean setComplete()
-
getRootProgressListener
public ProgressListener getRootProgressListener()
- Returns:
- The root
ProgressListenerthat this forwards adjusted progress reports to.
-
addFeedbackAction
public void addFeedbackAction(java.lang.String label, SimpleListener listener)Description copied from class:ProgressListenerEquivalent toaddFeedbackAction(label,"",listener)- Overrides:
addFeedbackActionin classProgressListener
-
addFeedbackAction
public void addFeedbackAction(java.lang.String label, java.lang.String description, SimpleListener listener)Description copied from class:ProgressListenerAdds an action that can choose to provide feedback. For example, an operation may choose to provide a "Skip to next step" button alongside the cancel button. There is no requirement that a ProgressListener actually present this to the user - it may choose to ignore this method, in which caselistenerwill never be fired.- Overrides:
addFeedbackActionin classProgressListener- Parameters:
label- a label describing this feedback action. For example, "Skip to next step"listener- a listener to be notified when the user chooses to invoke this action
-
removeFeedbackAction
public void removeFeedbackAction(java.lang.String label)
Description copied from class:ProgressListenerRemoves a feedback action previously added usingProgressListener.addFeedbackAction(String, jebl.util.SimpleListener).- Overrides:
removeFeedbackActionin classProgressListener- Parameters:
label- The label used as a parameter toProgressListener.addFeedbackAction(String, jebl.util.SimpleListener)
-
setTitle
public void setTitle(java.lang.String title)
Description copied from class:ProgressListenerSets a title associated with whatever is being done. This will not necessarily even be presented to the user, but typically will be presented as the title of a progress window.- Overrides:
setTitlein classProgressListener- Parameters:
title- the title of a progress window (if any). Must not be null.
-
-