Class AbstractTimer<T extends AbstractCalculable>

java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.extras.formula.AbstractTimer<T>
Type Parameters:
T - The AbstractCalculable instance that will be used
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
CalculableTimer, ParametricCalculableTimer

public abstract class AbstractTimer<T extends AbstractCalculable> extends GraphicE
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 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 Classes
    Modifier and Type
    Class
    Description
    static interface 
    This interface contains all the methods that will be executed after starting, pausing, resuming and stopping a timer.
  • Field Summary

    Fields inherited from class com.dkt.graphics.elements.GraphicE

    STROKE
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractTimer(T calculable)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Tells if the equation will be drawn as a path
    Retrieves the calculable object used for the calculations.
    protected abstract PThread
    getThread(T calculable, int threadNumber, int threadsTotal, boolean drawPen)
     
    boolean
    Tells if the timer is paused
    boolean
    Tells if the timer is running
    void
    Pauses the timer with all of it's threads
    protected void
     
    void
    Resumes the timer and all of it's threads
    void
    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 points
    void
    setDrawPen(boolean drawPen)
    Tells the timer to draw the pen on the last drawn point
    void
    Sets the number of threads that will be used for this calculations
    void
    Starts the timer with all of its threads.
    Note: This method will remove all of the GraphicE of the Graphic
    void
    Stops the timer and all of it's running threads
    protected boolean
    Tells if all the threads have finished their execution

    Methods inherited from class com.dkt.graphics.elements.GraphicE

    clone, draw, equals, getPaint, getStroke, hashCode, setPaint, setStroke, traslate

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractTimer

      protected AbstractTimer(T calculable)
      Parameters:
      calculable - object that will be used on the calculations
      Throws:
      IllegalArgumentException - if calculable is null
  • Method Details

    • getCalculable

      public T 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 - if n is less than one
      AlreadyRunningException - 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 and false 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, and false 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, and false 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 and false if it's drawn as points
    • isPaused

      public boolean isPaused()
      Tells if the timer is paused
      Returns:
      true if the thread is paused and false otherwise
    • isRunning

      public boolean isRunning()
      Tells if the timer is running
      Returns:
      true if the thread is running and false otherwise
    • start

      public void start()
      Starts the timer with all of its threads.
      Note: This method will remove all of the GraphicE of the Graphic
      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

      public void setActions(AbstractTimer.Action action)
      Sets the actions to be executed at start, stop, pause, resume.
      Parameters:
      action - The actions to be executed
      See Also:
    • removeThread

      protected void removeThread(PThread thread)
    • getThread

      protected abstract PThread getThread(T calculable, int threadNumber, int threadsTotal, boolean drawPen)