net.sourceforge.jiu.ops
Class Operation
java.lang.Object
net.sourceforge.jiu.ops.Operation
public abstract class Operation
extends java.lang.Object
Base class for all operations.
It supports progress notification.
All classes that want to be notified by a new progress level of the operation
(defined as value between 0.0f (nothing has been done so far) to 1.0f
(operation finished)) must implement the
ProgressListener
interface.
An abortion state is stored in each Operation object.
It should be queried by a running operation from time to time
(via
getAbort()
- if it returns
true
,
the operation should terminate and return control to the caller.
The abort state can be modified using
setAbort(boolean)
.
Operation() - This constructor creates two internal empty lists for progress listeners and parameters.
|
void | addProgressListener(ProgressListener progressListener) - Adds the argument progress listener to the internal list of
progress listeners.
|
void | addProgressListeners(Vector progressListeners) - Adds several progress listeners to this operation object.
|
boolean | getAbort() - Returns the current abort status.
|
void | process() - This method does the actual work of the operation.
|
void | removeProgressListener(ProgressListener progressListener) - Removes the argument progress listener from the internal list of
progress listeners.
|
void | setAbort(boolean newAbortStatus) - Sets a new abort status.
|
void | setProgress(float progress) - This method will notify all registered progress listeners
about a new progress level.
|
void | setProgress(int zeroBasedIndex, int totalItems) - This method will notify all registered progress listeners
about a new progress level.
|
abort
private boolean abort
progressListeners
private Vector progressListeners
Operation
public Operation()
This constructor creates two internal empty lists for progress listeners and parameters.
addProgressListener
public void addProgressListener(ProgressListener progressListener)
Adds the argument progress listener to the internal list of
progress listeners.
Does not check if the argument already exists in that list, so you have
to check for duplicates yourself.
progressListener
- the progress listener to be added
addProgressListeners
public void addProgressListeners(Vector progressListeners)
Adds several progress listeners to this operation object.
getAbort
public boolean getAbort()
Returns the current abort status.
If
true
, a running operation should terminate what it is doing
(return from
process()
).
removeProgressListener
public void removeProgressListener(ProgressListener progressListener)
Removes the argument progress listener from the internal list of
progress listeners.
progressListener
- the progress listener to be removed
setAbort
public void setAbort(boolean newAbortStatus)
Sets a new abort status.
newAbortStatus
- the new status
setProgress
public void setProgress(float progress)
This method will notify all registered progress listeners
about a new progress level.
The argument must be from 0.0f to 1.0f where 0.0f marks the
beginning and 1.0f completion.
The progress value should not be smaller than any value that
was previously set.
progress
- new progress value, from 0.0 to 1.0
setProgress
public void setProgress(int zeroBasedIndex,
int totalItems)
This method will notify all registered progress listeners
about a new progress level.
Simply checks the arguments and calls setProgress((float)zeroBasedIndex / (float)totalItems);
.
zeroBasedIndex
- the index of the item that was just processed, zero-basedtotalItems
- the number of items that will be processed