Merge branch 'subtree'
[fanfix.git] / src / jexer / TTimer.java
index 3ec63cba91fe3bc812e7105f5adf4adc77f1a7f1..8007153d679543d17b74fc51cb14663c262ac866 100644 (file)
@@ -3,7 +3,7 @@
  *
  * The MIT License (MIT)
  *
- * Copyright (C) 2017 Kevin Lamonte
+ * Copyright (C) 2019 Kevin Lamonte
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -33,7 +33,11 @@ import java.util.Date;
 /**
  * TTimer implements a simple timer.
  */
-public final class TTimer {
+public class TTimer {
+
+    // ------------------------------------------------------------------------
+    // Variables --------------------------------------------------------------
+    // ------------------------------------------------------------------------
 
     /**
      * If true, re-schedule after every tick.  Note package private access.
@@ -50,6 +54,36 @@ public final class TTimer {
      */
     private Date nextTick;
 
+    /**
+     * The action to perfom on a tick.
+     */
+    private TAction action;
+
+    // ------------------------------------------------------------------------
+    // Constructors -----------------------------------------------------------
+    // ------------------------------------------------------------------------
+
+    /**
+     * Package private constructor.
+     *
+     * @param duration number of milliseconds to wait between ticks
+     * @param recurring if true, re-schedule this timer after every tick
+     * @param action to perform on next tick
+     */
+    TTimer(final long duration, final boolean recurring, final TAction action) {
+
+        this.recurring = recurring;
+        this.duration  = duration;
+        this.action    = action;
+
+        Date now = new Date();
+        nextTick = new Date(now.getTime() + duration);
+    }
+
+    // ------------------------------------------------------------------------
+    // TTimer -----------------------------------------------------------------
+    // ------------------------------------------------------------------------
+
     /**
      * Get the next time this timer needs to be ticked.  Note package private
      * access.
@@ -61,9 +95,13 @@ public final class TTimer {
     }
 
     /**
-     * The action to perfom on a tick.
+     * Set the recurring flag.
+     *
+     * @param recurring if true, re-schedule this timer after every tick
      */
-    private TAction action;
+    public void setRecurring(final boolean recurring) {
+        this.recurring = recurring;
+    }
 
     /**
      * Tick this timer.  Note package private access.
@@ -79,21 +117,4 @@ public final class TTimer {
         }
     }
 
-    /**
-     * Package private constructor.
-     *
-     * @param duration number of milliseconds to wait between ticks
-     * @param recurring if true, re-schedule this timer after every tick
-     * @param action to perform on next tick
-     */
-    TTimer(final long duration, final boolean recurring, final TAction action) {
-
-        this.recurring = recurring;
-        this.duration  = duration;
-        this.action    = action;
-
-        Date now = new Date();
-        nextTick = new Date(now.getTime() + duration);
-    }
-
 }