home *** CD-ROM | disk | FTP | other *** search
/ Print Shop Ensemble 3 / the-print-shop-ensemble-iii.iso / worldnet / disk2 / java.z / MOZ2_01.ZIP / sun / awt / ScreenUpdater.class (.txt) next >
Encoding:
Java Class File  |  1996-03-08  |  3.2 KB  |  109 lines

  1. package sun.awt;
  2.  
  3. public class ScreenUpdater extends Thread {
  4.    private final int PRIORITY = 4;
  5.    private ScreenUpdaterEntry first;
  6.    public static final ScreenUpdater updater = new ScreenUpdater(findSystemThreadGroup(), "ScreenUpdater");
  7.  
  8.    static ThreadGroup findSystemThreadGroup() {
  9.       Thread thread = Thread.currentThread();
  10.  
  11.       ThreadGroup group;
  12.       for(group = thread.getThreadGroup(); group != null && !group.getName().equals("main"); group = group.getParent()) {
  13.       }
  14.  
  15.       return group;
  16.    }
  17.  
  18.    private ScreenUpdater(ThreadGroup group, String name) {
  19.       super(group, name);
  20.       ((Thread)this).start();
  21.    }
  22.  
  23.    private ScreenUpdater() {
  24.       ((Thread)this).start();
  25.    }
  26.  
  27.    private synchronized ScreenUpdaterEntry nextEntry() throws InterruptedException {
  28.       while(true) {
  29.          if (this.first == null) {
  30.             ScreenUpdaterEntry entry = null;
  31.             this.wait();
  32.          } else {
  33.             long delay = this.first.when - System.currentTimeMillis();
  34.             if (delay <= 0L) {
  35.                ScreenUpdaterEntry entry = this.first;
  36.                this.first = this.first.next;
  37.                return entry;
  38.             }
  39.  
  40.             ScreenUpdaterEntry entry = null;
  41.             this.wait(delay);
  42.          }
  43.       }
  44.    }
  45.  
  46.    public void run() {
  47.       ((Thread)this).setName("ScreenUpdater");
  48.  
  49.       try {
  50.          while(true) {
  51.             ((Thread)this).setPriority(4);
  52.             ScreenUpdaterEntry entry = this.nextEntry();
  53.             ((Thread)this).setPriority(entry.client.updatePriority());
  54.  
  55.             try {
  56.                entry.client.updateClient(entry.arg);
  57.             } catch (Throwable e) {
  58.                e.printStackTrace();
  59.             }
  60.  
  61.             ScreenUpdaterEntry var5 = null;
  62.          }
  63.       } catch (InterruptedException var4) {
  64.       }
  65.    }
  66.  
  67.    public void notify(UpdateClient client) {
  68.       this.notify(client, 100L, (Object)null);
  69.    }
  70.  
  71.    public synchronized void notify(UpdateClient client, long delay) {
  72.       this.notify(client, delay, (Object)null);
  73.    }
  74.  
  75.    public synchronized void notify(UpdateClient client, long delay, Object arg) {
  76.       long when = System.currentTimeMillis() + delay;
  77.       long nextwhen = this.first != null ? this.first.when : -1L;
  78.       if (this.first != null) {
  79.          if (this.first.client == client) {
  80.             when = Math.min(this.first.when, when);
  81.             this.first = this.first.next;
  82.          } else {
  83.             for(ScreenUpdaterEntry e = this.first; e.next != null; e = e.next) {
  84.                if (e.next.client == client && e.next.arg == arg) {
  85.                   when = Math.min(e.next.when, when);
  86.                   e.next = e.next.next;
  87.                   break;
  88.                }
  89.             }
  90.          }
  91.       }
  92.  
  93.       if (this.first != null && this.first.when <= when) {
  94.          ScreenUpdaterEntry e;
  95.          for(e = this.first; e.next != null && e.next.when <= when; e = e.next) {
  96.          }
  97.  
  98.          e.next = new ScreenUpdaterEntry(client, when, arg, e.next);
  99.       } else {
  100.          this.first = new ScreenUpdaterEntry(client, when, arg, this.first);
  101.       }
  102.  
  103.       if (nextwhen != this.first.when) {
  104.          super.notify();
  105.       }
  106.  
  107.    }
  108. }
  109.