TrustGrapher  r52
A playabale simulator for modelling trust between agents
D:/src/cu/trustGrapher/eventplayer/TimeCounter.java
Go to the documentation of this file.
00001 package cu.trustGrapher.eventplayer;
00002 
00003 import java.awt.event.ActionEvent;
00004 import java.awt.event.ActionListener;
00005 
00006 public class TimeCounter implements ActionListener {
00007         
00008         private long lowerBound;
00009         private long upperBound; 
00010         
00011         private long time;
00012         private long increment;
00013         
00023         public TimeCounter() {
00024                 this(1);
00025         }
00026         
00036         public TimeCounter(long increment) {
00037                 this(increment, 0);
00038         }
00039         
00050         public TimeCounter(long increment, long startTime) {
00051                 this(increment,startTime,0,100);
00052         }
00053         
00066         public TimeCounter(long increment, long startTime, long lowerBound, long upperBound) {
00067                 this.increment = increment;
00068                 this.time = startTime;
00069                 this.lowerBound = lowerBound;
00070                 this.upperBound = upperBound;
00071         }
00072         
00073         public long getTime() {
00074                 return time;
00075         }
00076         
00077         public synchronized void setTime(long time) {
00078                 this.time = time;
00079         }
00080         
00081         public long getIncrement() {
00082                 return increment;
00083         }
00084         
00085         public long getLowerBound() {
00086                 return lowerBound;
00087         }
00088         
00089         public long getUpperBound() {
00090                 return upperBound;
00091         }
00092         
00093         public void setIncrement(long increment) {
00094                 this.increment = increment;
00095         }
00096         
00097         public void setLowerBound(long bound) {
00098                 lowerBound = bound;
00099         }
00100         public void setUpperBound(long bound) {
00101                 upperBound = bound;
00102         }
00103         
00104         public void doIncrement() {
00105                 setTime(time + increment);
00106                 if(time < lowerBound) {
00107                         time = lowerBound;
00108                 }
00109                 else if(time > upperBound) {
00110                         time = upperBound;
00111                 }
00112         }
00113 
00114         @Override
00115         public void actionPerformed(ActionEvent ae) {
00116                 doIncrement();
00117         }
00118 }