home *** CD-ROM | disk | FTP | other *** search
- import stardiv.tools.SjProtocolWindow;
-
- public class SJTimer implements Runnable {
- private Thread aTimerThread;
- private boolean bTriggerEvent;
- private boolean bTimerThreadRunning;
- private boolean bTriggerEndless;
- private boolean bStopTimer;
- private int nNoOfTriggers;
- private int nDelayIn_ms;
-
- public SJTimer(int var1) {
- this(var1, 0);
- this.bTriggerEndless = true;
- }
-
- public SJTimer(int var1, int var2) {
- this.bTriggerEvent = false;
- this.bTimerThreadRunning = false;
- this.bTriggerEndless = false;
- this.bStopTimer = false;
- this.nNoOfTriggers = var2;
- this.nDelayIn_ms = var1;
- this.aTimerThread = new Thread(this, "SJTimer-Thread");
- }
-
- public final void StopTimer() {
- this.bStopTimer = true;
- }
-
- public final synchronized int WaitForTrigger() {
- if (this.bTimerThreadRunning) {
- return -1;
- } else {
- try {
- while(!this.bTriggerEvent) {
- SjProtocolWindow.AddWaitEvent(this, "SJTimer.WaitForTrigger()");
- this.wait();
- SjProtocolWindow.AddWaitEventDONE(this, "SJTimer.WaitForTrigger()");
- }
- } catch (InterruptedException var1) {
- }
-
- this.bTriggerEvent = false;
- return this.nNoOfTriggers;
- }
- }
-
- private final synchronized void TriggerEvent() {
- this.bTriggerEvent = true;
- SjProtocolWindow.AddNotifyEvent(this, "SJTimer.TriggerEvent()");
- this.notifyAll();
- SjProtocolWindow.AddNotifyEventDONE(this, "SJTimer.TriggerEvent()");
- }
-
- public void run() {
- this.bTimerThreadRunning = true;
-
- while(!this.bStopTimer && (this.bTriggerEndless || this.nNoOfTriggers > 0)) {
- try {
- Thread.sleep((long)this.nDelayIn_ms);
- if (!this.bTriggerEndless) {
- --this.nNoOfTriggers;
- }
-
- this.TriggerEvent();
- } catch (InterruptedException var1) {
- }
- }
-
- this.bTimerThreadRunning = false;
- }
- }
-