// --------------------------------------- // Restricted Focus Viewer (RFV) Program // Version 2.1 // Language: Java 2 // March, 2000 // Copyright (C) 2000 Anthony R. Jansen // --------------------------------------- // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // --------------------------------------- // RFV_Timer.java // // Class to implement a millisecond timer // based on the system clock. It can be // reset, paused and the elapsed time can // be read without interrupting the timer. // --------------------------------------- public class RFV_Timer { // Variables needed // ---------------- private long initialTime; private long elapsedTime; private boolean paused; // Constructor which starts the timer // ---------------------------------- public RFV_Timer() { initialTime = System.currentTimeMillis(); paused = false; } // Method to reset the timer to zero // --------------------------------- public void reset() { initialTime = System.currentTimeMillis(); paused = false; } // Returns the time elapsed since timer began (in milliseconds) // Can be called even if timer is currently paused // ------------------------------------------------------------ public long getElapsed() { if (paused) return elapsedTime; else return (System.currentTimeMillis() - initialTime); } // Pauses the timer without reseting it // ------------------------------------ public void pause() { if (!paused) { elapsedTime = System.currentTimeMillis() - initialTime; paused = true; } } // Unpauses the timer // ------------------ public void unpause() { if (paused) { initialTime = System.currentTimeMillis() - elapsedTime; paused = false; } } // Sets the timer to begin with a certain elapsed time // --------------------------------------------------- public void setElapsed(long t) { if (paused) elapsedTime = t; else initialTime = System.currentTimeMillis() - t; } }