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
- TheAbstractCalculable
instance 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 GPoint
s, 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
Modifier and TypeClassDescriptionstatic interface
This interface contains all the methods that will be executed after starting, pausing, resuming and stopping a timer. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Tells if the equation will be drawn as a pathRetrieves the calculable object used for the calculations.protected abstract PThread
boolean
isPaused()
Tells if the timer is pausedboolean
Tells if the timer is runningvoid
pause()
Pauses the timer with all of it's threadsprotected void
removeThread
(PThread thread) void
resume()
Resumes the timer and all of it's threadsvoid
setActions
(AbstractTimer.Action action) Sets the actions to be executed at start, stop, pause, resume.void
setDrawAsPath
(boolean drawAsPath) Tells the timer to draw the equation as a path o pointsvoid
setDrawPen
(boolean drawPen) Tells the timer to draw the pen on the last drawn pointvoid
setNumberOfThreads
(int n) Sets the number of threads that will be used for this calculationsvoid
start()
void
stop()
Stops the timer and all of it's running threadsprotected boolean
Tells if all the threads have finished their execution
-
Constructor Details
-
AbstractTimer
- Parameters:
calculable
- object that will be used on the calculations- Throws:
IllegalArgumentException
- ifcalculable
isnull
-
-
Method Details
-
getCalculable
Retrieves the calculable object used for the calculations.- Returns:
AbstractCalculable
object 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
- ifn
is less than oneAlreadyRunningException
- if the Timer was already started
-
threadsEnded
protected boolean threadsEnded()Tells if all the threads have finished their execution- Returns:
true
if there's no running or paused thread andfalse
otherwise
-
setDrawPen
public void setDrawPen(boolean drawPen) Tells the timer to draw the pen on the last drawn point- Parameters:
drawPen
-true
if the pen must be drawn, andfalse
otherwise- 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
-true
if the equation should be drawn as a path, andfalse
in 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:
true
if the equation is drawn as a path andfalse
if it's drawn as points
-
isPaused
public boolean isPaused()Tells if the timer is paused- Returns:
true
if the thread is paused andfalse
otherwise
-
isRunning
public boolean isRunning()Tells if the timer is running- Returns:
true
if the thread is running andfalse
otherwise
-
start
public void start()Starts the timer with all of its threads.
Note: This method will remove all of theGraphicE
of 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
-