Class AbstractTimer<T extends AbstractCalculable>

  • Type Parameters:
    T - The AbstractCalculable instance that will be used
    All Implemented Interfaces:
    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.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  AbstractTimer.Action
      This interface contains all the methods that will be executed after starting, pausing, resuming and stopping a timer.
    • Field Summary

    • Constructor Summary

      Modifier Constructor Description
      protected AbstractTimer​(T calculable)  
    • Constructor Detail

      • AbstractTimer

        protected AbstractTimer​(T calculable)
        calculable - object that will be used on the calculations
        java.lang.IllegalArgumentException - if calculable is null
    • Method Detail

      • getCalculable

        public T getCalculable()
        Retrieves the calculable object used for the calculations.
        AbstractCalculable object used to calculate
      • setNumberOfThreads

        public void setNumberOfThreads​(int n)
        Sets the number of threads that will be used for this calculations
        n - number of threads
        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
        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
        drawPen - true if the pen must be drawn, and false otherwise
        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
        drawAsPath - true if the equation should be drawn as a path, and false in order to draw only the points
        AlreadyRunningException - if the Timer was already started
      • drawAsPath

        public boolean drawAsPath()
        Tells if the equation will be drawn as a path
        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
        true if the thread is paused and false otherwise
      • isRunning

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

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

        protected void removeThread​(PThread thread)
        Removes a given Thread from the pool
        thread - PThread to be removed