Typo: inspect_jpegs, not inspect-jpegs in form
[privoxy.git] / src / java / org / privoxy / activityconsole / StatWidgetThread.java
1 /*********************************************************************
2  *
3  * File        :  $Source$
4  *
5  * Purpose     :  Part of the StatWidget, the thread that manages the
6  *                timing of the swatch of color.
7  *
8  * Copyright   :  Written by and Copyright (C) 2003 the SourceForge
9  *                Privoxy team. http://www.privoxy.org/
10  *
11  *                Based on the Internet Junkbuster originally written
12  *                by and Copyright (C) 1997 Anonymous Coders and
13  *                Junkbusters Corporation.  http://www.junkbusters.com
14  *
15  *                This program is free software; you can redistribute it
16  *                and/or modify it under the terms of the GNU General
17  *                Public License as published by the Free Software
18  *                Foundation; either version 2 of the License, or (at
19  *                your option) any later version.
20  *
21  *                This program is distributed in the hope that it will
22  *                be useful, but WITHOUT ANY WARRANTY; without even the
23  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
24  *                PARTICULAR PURPOSE.  See the GNU General Public
25  *                License for more details.
26  *
27  *                The GNU General Public License should be included with
28  *                this file.  If not, you can view it at
29  *                http://www.gnu.org/copyleft/gpl.html
30  *                or write to the Free Software Foundation, Inc., 59
31  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
32  *
33  * Revisions   :
34  *    $Log$
35  *********************************************************************/
36
37 package org.privoxy.activityconsole;
38
39 import  java.io.*;
40 import  java.util.*;
41
42 /** 
43  * The thread that manages the timing of the swatch of color of the StatWidget.
44  * @author Last Modified By: $Author$
45  * @version $Rev$-$Date$$State$
46  */
47 public class StatWidgetThread extends Thread
48 {
49   private static final String
50     COPYRIGHT = org.privoxy.activityconsole.Copyright.COPYRIGHT;
51
52   int _statusDurationMillis = 0;
53   Date _nextUpdate = null;
54   StatWidget _parent = null;
55
56   public StatWidgetThread(StatWidget parent, int statusDurationMillis)
57   {
58     _parent = parent;
59     _statusDurationMillis = statusDurationMillis;
60   }
61
62   public final void run()
63   {
64     boolean snooze = false;
65     int sleepFor;
66
67     while (1==1)
68     {
69       /* Check once before we wait at all, just in case... */
70       if (_nextUpdate != null)
71         snooze = checkTimer();
72       if (snooze == true)
73         sleepFor = _statusDurationMillis;
74       else
75         sleepFor = 540000 + (int)(Math.random() * 60000); /* Sit around for 10 minutes plus or minus a minute */
76       try
77       {
78         sleep(sleepFor);
79         if (_nextUpdate != null)
80           snooze = checkTimer();
81       }
82       catch (Throwable t2)
83       {
84         pulse();
85         snooze = true;
86       }
87     }
88   }
89
90   public void pulse()
91   {
92     _nextUpdate = new Date(new Date().getTime() + _statusDurationMillis);
93   }
94
95   public boolean checkTimer()
96   {
97     boolean returnVal = true;
98     Date now = new Date();
99     if (now.after(_nextUpdate))
100     {
101       _parent.timerPop();
102       _nextUpdate = null;
103       returnVal = false;
104     }
105     return returnVal;
106   }
107 }