home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 144 / DPCS0200.iso / Internet / Supanet / system / swing.jar / javax / swing / Timer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-05  |  3.8 KB  |  152 lines

  1. package javax.swing;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.io.Serializable;
  6. import javax.swing.event.EventListenerList;
  7.  
  8. public class Timer implements Serializable {
  9.    int initialDelay;
  10.    int delay;
  11.    boolean repeats = true;
  12.    boolean coalesce = true;
  13.    protected EventListenerList listenerList = new EventListenerList();
  14.    boolean eventQueued = false;
  15.    private static boolean logTimers;
  16.    Runnable doPostEvent = null;
  17.    long expirationTime;
  18.    Timer nextTimer;
  19.    boolean running;
  20.    // $FF: synthetic field
  21.    static Class class$java$awt$event$ActionListener;
  22.  
  23.    public Timer(int var1, ActionListener var2) {
  24.       this.delay = var1;
  25.       this.initialDelay = var1;
  26.       this.doPostEvent = new DoPostEvent(this);
  27.       this.addActionListener(var2);
  28.    }
  29.  
  30.    // $FF: synthetic method
  31.    static boolean access$0() {
  32.       return logTimers;
  33.    }
  34.  
  35.    public void addActionListener(ActionListener var1) {
  36.       this.listenerList.add(class$java$awt$event$ActionListener != null ? class$java$awt$event$ActionListener : (class$java$awt$event$ActionListener = class$("java.awt.event.ActionListener")), var1);
  37.    }
  38.  
  39.    synchronized void cancelEvent() {
  40.       this.eventQueued = false;
  41.    }
  42.  
  43.    // $FF: synthetic method
  44.    static Class class$(String var0) {
  45.       try {
  46.          return Class.forName(var0);
  47.       } catch (ClassNotFoundException var2) {
  48.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  49.       }
  50.    }
  51.  
  52.    protected void fireActionPerformed(ActionEvent var1) {
  53.       Object[] var2 = this.listenerList.getListenerList();
  54.  
  55.       for(int var3 = var2.length - 2; var3 >= 0; var3 -= 2) {
  56.          if (var2[var3] == (class$java$awt$event$ActionListener != null ? class$java$awt$event$ActionListener : (class$java$awt$event$ActionListener = class$("java.awt.event.ActionListener")))) {
  57.             ((ActionListener)var2[var3 + 1]).actionPerformed(var1);
  58.          }
  59.       }
  60.  
  61.    }
  62.  
  63.    public int getDelay() {
  64.       return this.delay;
  65.    }
  66.  
  67.    public int getInitialDelay() {
  68.       return this.initialDelay;
  69.    }
  70.  
  71.    public static boolean getLogTimers() {
  72.       return logTimers;
  73.    }
  74.  
  75.    public boolean isCoalesce() {
  76.       return this.coalesce;
  77.    }
  78.  
  79.    public boolean isRepeats() {
  80.       return this.repeats;
  81.    }
  82.  
  83.    public boolean isRunning() {
  84.       return this.timerQueue().containsTimer(this);
  85.    }
  86.  
  87.    synchronized void post() {
  88.       if (!this.eventQueued) {
  89.          this.eventQueued = true;
  90.          SwingUtilities.invokeLater(this.doPostEvent);
  91.       }
  92.  
  93.    }
  94.  
  95.    public void removeActionListener(ActionListener var1) {
  96.       this.listenerList.remove(class$java$awt$event$ActionListener != null ? class$java$awt$event$ActionListener : (class$java$awt$event$ActionListener = class$("java.awt.event.ActionListener")), var1);
  97.    }
  98.  
  99.    public void restart() {
  100.       this.stop();
  101.       this.start();
  102.    }
  103.  
  104.    public void setCoalesce(boolean var1) {
  105.       this.coalesce = var1;
  106.    }
  107.  
  108.    public void setDelay(int var1) {
  109.       if (var1 < 0) {
  110.          throw new RuntimeException("Invalid initial delay: " + var1);
  111.       } else {
  112.          this.delay = var1;
  113.          if (this.isRunning()) {
  114.             TimerQueue var2 = this.timerQueue();
  115.             var2.removeTimer(this);
  116.             this.cancelEvent();
  117.             var2.addTimer(this, System.currentTimeMillis() + (long)var1);
  118.          }
  119.  
  120.       }
  121.    }
  122.  
  123.    public void setInitialDelay(int var1) {
  124.       if (var1 < 0) {
  125.          throw new RuntimeException("Invalid initial delay: " + var1);
  126.       } else {
  127.          this.initialDelay = var1;
  128.       }
  129.    }
  130.  
  131.    public static void setLogTimers(boolean var0) {
  132.       logTimers = var0;
  133.    }
  134.  
  135.    public void setRepeats(boolean var1) {
  136.       this.repeats = var1;
  137.    }
  138.  
  139.    public void start() {
  140.       this.timerQueue().addTimer(this, System.currentTimeMillis() + (long)this.getInitialDelay());
  141.    }
  142.  
  143.    public void stop() {
  144.       this.timerQueue().removeTimer(this);
  145.       this.cancelEvent();
  146.    }
  147.  
  148.    TimerQueue timerQueue() {
  149.       return TimerQueue.sharedInstance();
  150.    }
  151. }
  152.