home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2003 January / maximum-cd-2003-01.iso / Software / Apps / OperawithJava / ow32enen700b1j.exe / OPERA.JAR / opera / AppContextAdapter.class (.txt) next >
Encoding:
Java Class File  |  2002-11-07  |  1.9 KB  |  65 lines

  1. package opera;
  2.  
  3. import java.awt.Frame;
  4. import java.lang.reflect.Method;
  5.  
  6. class AppContextAdapter {
  7.    Object appContext = null;
  8.    ThreadGroup threadGroup = null;
  9.    boolean isDisposed = false;
  10.  
  11.    public void create() {
  12.       this.threadGroup = Thread.currentThread().getThreadGroup();
  13.  
  14.       try {
  15.          Class var1 = Class.forName("sun.awt.SunToolkit");
  16.          if (var1 != null) {
  17.             Method var2 = var1.getMethod("createNewAppContext", (Class[])null);
  18.             this.appContext = var2.invoke((Object)null, (Object[])null);
  19.          }
  20.       } catch (Exception var3) {
  21.       }
  22.  
  23.    }
  24.  
  25.    public void dispose() throws IllegalThreadStateException {
  26.       try {
  27.          if (this.appContext != null) {
  28.             Method var1 = this.appContext.getClass().getMethod("dispose", (Class[])null);
  29.             var1.invoke(this.appContext, (Object[])null);
  30.          } else {
  31.             if (this.threadGroup.parentOf(Thread.currentThread().getThreadGroup())) {
  32.                throw new IllegalThreadStateException("Current Thread is contained within AppContext to be disposed.");
  33.             }
  34.  
  35.             synchronized(this) {
  36.                if (this.isDisposed) {
  37.                   return;
  38.                }
  39.  
  40.                this.isDisposed = true;
  41.             }
  42.  
  43.             this.disposeFrames();
  44.             this.interruptThreads();
  45.          }
  46.       } catch (Exception var4) {
  47.          var4.printStackTrace(System.err);
  48.       }
  49.  
  50.    }
  51.  
  52.    private void disposeFrames() {
  53.       Frame[] var1 = Frame.getFrames();
  54.  
  55.       for(int var2 = var1.length - 1; var2 >= 0; --var2) {
  56.          var1[var2].dispose();
  57.       }
  58.  
  59.    }
  60.  
  61.    private void interruptThreads() {
  62.       this.threadGroup.interrupt();
  63.    }
  64. }
  65.