com.monkeycoder.monkeyfractal.base
Class FractalMtWorker

java.lang.Object
  extended by java.util.Observable
      extended by com.monkeycoder.monkeyfractal.base.FractalMtWorker
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
MandelbrotMtWorker

public abstract class FractalMtWorker
extends java.util.Observable
implements java.lang.Runnable

This is the parent class to all Multi-Threaded fractal worker classes. It supplies the basic constructs for managing divided work.

Originally part of the MonkeyFractal project.

Author:
David Stephens

Field Summary
protected  ParameterList params
          Holds the configuration of this plugin in the form of a ParameterList.
 
Constructor Summary
FractalMtWorker()
          FractalMtWorker is abstract and cannot be directly constructed.
FractalMtWorker(int inId)
          This constructor sets the ID of this worker.
 
Method Summary
abstract  FractalBuffer generateFractal()
          This function generates the partial fractal represented by this FractalMtWorker and configured by values passed in through other function calls.
abstract  ComplexRange getComplexRange()
          This function gets the current ComplexRange used internally by the FractalPlugin.
abstract  ComplexRange getComplexRange(java.awt.Rectangle inPixelRect)
          Calculates a new ComplexRange based on a Rectangle of pixels.
 FractalBuffer getFractalBuffer()
          This function returns the generated FractalBuffer.
 int getId()
          Gets the ID for this worker.
 ParameterList getParameterList()
          This function returns the current ParameterList being used by this FractalPlugin.
abstract  void resetParameterList()
          This function creates a default ParameterList for this FractalPlugin.
 void run()
          This manages the process of generating this piece of fractal work.
 void sendUpdate(UpdateMessage inMessage)
          Relays an UpdateMessage to whatever is observing this class.
abstract  void setComplexRange(ComplexRange inComplexRange)
          This function sets the ComplexRange used internally by the FractalPlugin.
abstract  void setComplexRange(java.awt.Rectangle inPixelRect)
          This function sets the ComplexRange used internally by the FractalPlugin.
 void setId(int inId)
          Allows the setting of an ID for this worker.
 void setParameterList(ParameterList inParamList)
          This function takes in a ParameterList that will replace the internal ParameterList being used by this FractalPlugin.
abstract  void setPixelDimensions(java.awt.Dimension inPixelDim)
          This method sets the Dimensions of the FractalBuffer that will be generated by generateFractal().
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

params

protected ParameterList params
Holds the configuration of this plugin in the form of a ParameterList.

Constructor Detail

FractalMtWorker

public FractalMtWorker()
FractalMtWorker is abstract and cannot be directly constructed. Extend this class implement the required abstract methods and instantiate the child class.


FractalMtWorker

public FractalMtWorker(int inId)
This constructor sets the ID of this worker. FractalMtWorker is abstract and cannot be directly constructed. Extend this class implement the required abstract methods and instantiate the child class.

Parameters:
inId - A value used externally to identify this worker.
Method Detail

setId

public void setId(int inId)
Allows the setting of an ID for this worker. This is entirely optional but may be used my multi-threaded fractal plugins for helping to track the work that is being done. This value will be returned with the UpdateMessage.

Parameters:
inId - A value used externally to identify this worker.

getId

public int getId()
Gets the ID for this worker. If the ID of this worker was never set, it will return -1.

Returns:
The ID set for this worker or -1.

getParameterList

public ParameterList getParameterList()
This function returns the current ParameterList being used by this FractalPlugin. If there is not yet an internal ParameterList this method calls resetParameterList() to create one and fill it in with default values.

Returns:
The current ParameterList being used by this FractalPlugin.
See Also:
FractalPlugin.resetParameterList()

setParameterList

public void setParameterList(ParameterList inParamList)
This function takes in a ParameterList that will replace the internal ParameterList being used by this FractalPlugin. The basis for the ParameterList that is passed in via this method should be one that was originally acquired by getParameterList(). No new parameters should be added externally as each plugin will know only its own parameter list.

Parameters:
inParamList - The new ParameterList to be used by this FractalPlugin.
See Also:
FractalPlugin.getParameterList()

resetParameterList

public abstract void resetParameterList()
This function creates a default ParameterList for this FractalPlugin. This ParameterList should replace the one used internally by this FractalPlugin and should contain useful default values.


getComplexRange

public abstract ComplexRange getComplexRange()
This function gets the current ComplexRange used internally by the FractalPlugin.

Returns:
A ComplexRange containing the ranges from the internal ParameterList.

getComplexRange

public abstract ComplexRange getComplexRange(java.awt.Rectangle inPixelRect)
Calculates a new ComplexRange based on a Rectangle of pixels. This method performs its calculation based on the current ParameterList values.

Returns:
A ComplexRange containing the ranges from the internal ParameterList based on the supplied Rectangle of pixels.

setComplexRange

public abstract void setComplexRange(ComplexRange inComplexRange)
This function sets the ComplexRange used internally by the FractalPlugin. The complex range should be loaded into the internal ParameterList for subsequent requests to generateFractal().

Parameters:
inComplexRange - The new ComplexRange to be loaded into the internal ParameterList.
See Also:
FractalPlugin.generateFractal()

setComplexRange

public abstract void setComplexRange(java.awt.Rectangle inPixelRect)
This function sets the ComplexRange used internally by the FractalPlugin. This is a convenience method that processes the Rectangle of pixels through getComplexRange(Rectangle) before passing the result to setComplexRange(ComplexRange).

Parameters:
inPixelRect - A Rectangle of pixels to use to create a new ComplexRange to be loaded into the internal ParameterList.
See Also:
FractalPlugin.getComplexRange(Rectangle), FractalPlugin.setComplexRange(ComplexRange)

setPixelDimensions

public abstract void setPixelDimensions(java.awt.Dimension inPixelDim)
This method sets the Dimensions of the FractalBuffer that will be generated by generateFractal(). The Dimensions passed in should be loaded into the internal ParameterList for subsequent calls to generateFractal().

Parameters:
inPixelDim - A Dimension of pixels that represents how large a FractalBuffer will be generated.
See Also:
FractalPlugin.generateFractal()

run

public void run()
This manages the process of generating this piece of fractal work. This method is called automatically when start() is called on its containing Thread.

Specified by:
run in interface java.lang.Runnable
See Also:
Thread.start()

getFractalBuffer

public FractalBuffer getFractalBuffer()
This function returns the generated FractalBuffer. Calling this method prior to receiving an UpdateMessage.UPDATE_PARTIAL_WORK_COMPLETE will result in receiving an unknown FractalBuffer. It may contain prior renders or be null.

Returns:
The FractalBuffer that was returned by generateFractal() on the FractalPlugin.
See Also:
FractalPlugin.generateFractal()

sendUpdate

public void sendUpdate(UpdateMessage inMessage)
Relays an UpdateMessage to whatever is observing this class.

Parameters:
inMessage - The update that will be sent to observers.

generateFractal

public abstract FractalBuffer generateFractal()
This function generates the partial fractal represented by this FractalMtWorker and configured by values passed in through other function calls. This method needs to be implemented by children of this class.

Returns:
A FractalBuffer containing the results of the calculation.
See Also:
getFractalBuffer(), setComplexRange(ComplexRange), setPixelDimensions(Dimension)