net.sourceforge.jiu.ops

Class Operation

Known Direct Subclasses:
AutoDetectColorType, Histogram1DCreator, Histogram3DCreator, ImageCodec, ImagesToImageOperation, ImageToImageOperation, MeanDifference, TextureAnalysis

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).

Author:
Marco Schmidt

Field Summary

private boolean
abort
private Vector
progressListeners

Constructor Summary

Operation()
This constructor creates two internal empty lists for progress listeners and parameters.

Method Summary

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.

Field Details

abort

private boolean abort

progressListeners

private Vector progressListeners

Constructor Details

Operation

public Operation()
This constructor creates two internal empty lists for progress listeners and parameters.

Method Details

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.
Parameters:
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:
abort status

process

public void process()
            throws MissingParameterException,
                   OperationFailedException,
                   WrongParameterException
This method does the actual work of the operation. It must be called after all parameters have been given to the operation object.
Throws:
WrongParameterException - if at least one of the input parameters was not initialized appropriately (values out of the valid interval, etc.)
MissingParameterException - if any mandatory parameter was not given to the operation
OperationFailedException -

removeProgressListener

public void removeProgressListener(ProgressListener progressListener)
Removes the argument progress listener from the internal list of progress listeners.
Parameters:
progressListener - the progress listener to be removed

setAbort

public void setAbort(boolean newAbortStatus)
Sets a new abort status.
Parameters:
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.
Parameters:
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);.
Parameters:
zeroBasedIndex - the index of the item that was just processed, zero-based
totalItems - the number of items that will be processed