Package com.dkt.graphics.extras.formula
Class AbstractTimer<T extends AbstractCalculable>
java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.extras.formula.AbstractTimer<T>
- Type Parameters:
T- TheAbstractCalculableinstance that will be used
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
CalculableTimer,ParametricCalculableTimer
This class implements an abstract timer mainly used to draw functions on
the canvas.
Please note that there are several ways to improve the speed of this class, for instance using a
Please note that there are several ways to improve the speed of this class, for instance using a
Graphic object for each thread, using
GPointArray instead of an array of GPoints, etc. Those
things will improve the speed and memory quite a bit and the change is almost
trivial... Why don't we improve it? well it's quite simple actually,
we use this classes to draw the functions as a real time drawing, and
in that case, the perceived speed of the application is somewhat more
important than the real speed.- Author:
- Federico Vera <[email protected]>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis interface contains all the methods that will be executed after starting, pausing, resuming and stopping a timer. -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanTells if the equation will be drawn as a pathRetrieves the calculable object used for the calculations.protected abstract PThreadbooleanisPaused()Tells if the timer is pausedbooleanTells if the timer is runningvoidpause()Pauses the timer with all of it's threadsprotected voidremoveThread(PThread thread) voidresume()Resumes the timer and all of it's threadsvoidsetActions(AbstractTimer.Action action) Sets the actions to be executed at start, stop, pause, resume.voidsetDrawAsPath(boolean drawAsPath) Tells the timer to draw the equation as a path o pointsvoidsetDrawPen(boolean drawPen) Tells the timer to draw the pen on the last drawn pointvoidsetNumberOfThreads(int n) Sets the number of threads that will be used for this calculationsvoidstart()voidstop()Stops the timer and all of it's running threadsprotected booleanTells if all the threads have finished their execution
-
Constructor Details
-
AbstractTimer
- Parameters:
calculable- object that will be used on the calculations- Throws:
IllegalArgumentException- ifcalculableisnull
-
-
Method Details
-
getCalculable
Retrieves the calculable object used for the calculations.- Returns:
AbstractCalculableobject used to calculate
-
setNumberOfThreads
public void setNumberOfThreads(int n) Sets the number of threads that will be used for this calculations- Parameters:
n- number of threads- Throws:
InvalidArgumentException- ifnis less than oneAlreadyRunningException- if the Timer was already started
-
threadsEnded
protected boolean threadsEnded()Tells if all the threads have finished their execution- Returns:
trueif there's no running or paused thread andfalseotherwise
-
setDrawPen
public void setDrawPen(boolean drawPen) Tells the timer to draw the pen on the last drawn point- Parameters:
drawPen-trueif the pen must be drawn, andfalseotherwise- Throws:
AlreadyRunningException- if the Timer was already started
-
setDrawAsPath
public void setDrawAsPath(boolean drawAsPath) Tells the timer to draw the equation as a path o points- Parameters:
drawAsPath-trueif the equation should be drawn as a path, andfalsein order to draw only the points- Throws:
AlreadyRunningException- if the Timer was already started
-
drawAsPath
public boolean drawAsPath()Tells if the equation will be drawn as a path- Returns:
trueif the equation is drawn as a path andfalseif it's drawn as points
-
isPaused
public boolean isPaused()Tells if the timer is paused- Returns:
trueif the thread is paused andfalseotherwise
-
isRunning
public boolean isRunning()Tells if the timer is running- Returns:
trueif the thread is running andfalseotherwise
-
start
public void start()Starts the timer with all of its threads.
Note: This method will remove all of theGraphicEof theGraphic- Throws:
AlreadyRunningException- if the Timer was already started- See Also:
-
pause
public void pause()Pauses the timer with all of it's threads- See Also:
-
resume
public void resume()Resumes the timer and all of it's threads- See Also:
-
stop
public void stop()Stops the timer and all of it's running threads- See Also:
-
setActions
Sets the actions to be executed at start, stop, pause, resume.- Parameters:
action- The actions to be executed- See Also:
-
removeThread
-
getThread
-