home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIPHEFT062001.ISO / browser / nc32lyc / comm.z / java40.jar / netscape / applet / DerivedAppletFrame.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-15  |  10.6 KB  |  390 lines

  1. package netscape.applet;
  2.  
  3. import java.applet.Applet;
  4. import java.applet.AppletContext;
  5. import java.applet.AppletStub;
  6. import java.awt.BorderLayout;
  7. import java.awt.Container;
  8. import java.awt.Dialog;
  9. import java.awt.Dimension;
  10. import java.awt.Event;
  11. import java.awt.EventQueue;
  12. import java.awt.Toolkit;
  13. import java.awt.Window;
  14. import java.io.PrintStream;
  15. import java.lang.reflect.Constructor;
  16. import java.net.URL;
  17. import java.util.Hashtable;
  18. import java.util.Vector;
  19.  
  20. class DerivedAppletFrame extends EmbeddedAppletFrame implements AppletStub {
  21.    Integer appletID;
  22.    // $FF: renamed from: eq java.awt.EventQueue
  23.    EventQueue field_0;
  24.    Vector topLevelWindows;
  25.    long timestamp;
  26.    boolean inHistory = false;
  27.    URL documentURL;
  28.    URL codebaseURL;
  29.    URL[] archiveURL;
  30.    Hashtable atts;
  31.    Applet applet;
  32.    int status;
  33.    private AppletEventDispatchThread handler;
  34.    private ThreadGroup handlerThreadGroup;
  35.    AppletHook hook;
  36.    private Object m_statusLock = new Object();
  37.    static final int APPLET_NEW = 1;
  38.    static final int APPLET_LOADED = 2;
  39.    static final int APPLET_STOPPED = 3;
  40.    static final int APPLET_STARTING = 4;
  41.    static final int APPLET_RUNNING = 5;
  42.    static final int APPLET_STOPPING = 6;
  43.    static final int APPLET_DESTROYING = 7;
  44.    static final int APPLET_DESTROYED = 8;
  45.    static final int APPLET_DISPOSED = 9;
  46.    static final int APPLET_ERROR = 0;
  47.    Dimension appletSize = new Dimension(100, 100);
  48.    AppletClassLoader classLoader;
  49.    boolean reloadClasses = false;
  50.    String appletName;
  51.    String currentStatus = "";
  52.    boolean noisy = true;
  53.    String errorReason;
  54.    protected Dialog m_topModalDialog;
  55.  
  56.    DerivedAppletFrame(URL var1, URL var2, URL[] var3, Hashtable var4, MozillaAppletContext var5, Integer var6, boolean var7) {
  57.       this.appletID = var6;
  58.       super.pData = var6;
  59.       super.context = var5;
  60.       this.documentURL = var1;
  61.       this.codebaseURL = var2;
  62.       this.archiveURL = var3;
  63.       this.atts = var4;
  64.       this.status = 1;
  65.       ((Container)this).setLayout(new BorderLayout());
  66.       String var8 = this.getParameter("width");
  67.       if (var8 != null) {
  68.          this.appletSize.width = Integer.valueOf(var8);
  69.       }
  70.  
  71.       var8 = this.getParameter("height");
  72.       if (var8 != null) {
  73.          this.appletSize.height = Integer.valueOf(var8);
  74.       }
  75.  
  76.       this.topLevelWindows = new Vector();
  77.       this.reloadClasses = var7;
  78.    }
  79.  
  80.    void destroy() {
  81.       if (this.status != 9 && MozillaAppletContext.debug >= 7) {
  82.          System.out.println("# Destroying AppletFrame without disposing: " + this);
  83.       }
  84.  
  85.       super.destroy();
  86.       this.appletID = null;
  87.       this.field_0 = null;
  88.       this.topLevelWindows = null;
  89.       this.documentURL = null;
  90.       this.codebaseURL = null;
  91.       this.archiveURL = null;
  92.       this.atts = null;
  93.       this.applet = null;
  94.       this.handler = null;
  95.       this.hook = null;
  96.       this.appletSize = null;
  97.       this.classLoader = null;
  98.       this.appletName = null;
  99.       this.currentStatus = null;
  100.       this.errorReason = null;
  101.    }
  102.  
  103.    protected void finalize() {
  104.       this.destroy();
  105.    }
  106.  
  107.    void dumpState(PrintStream var1, int var2) {
  108.       MozillaAppletContext.indent(var1, var2);
  109.       var1.println("EmbeddedAppletFrame id=" + super.pData + " applet=" + this.applet);
  110.    }
  111.  
  112.    String statusToString(int var1) {
  113.       switch (var1) {
  114.          case 0:
  115.             return "ERROR";
  116.          case 1:
  117.             return "NEW";
  118.          case 2:
  119.             return "LOADED";
  120.          case 3:
  121.             return "STOPPED";
  122.          case 4:
  123.             return "STARTING";
  124.          case 5:
  125.             return "RUNNING";
  126.          case 6:
  127.             return "STOPPING";
  128.          case 7:
  129.          default:
  130.             return Integer.toString(var1, 10);
  131.          case 8:
  132.             return "DESTROYED";
  133.          case 9:
  134.             return "DISPOSED";
  135.       }
  136.    }
  137.  
  138.    public Dimension minimumSize() {
  139.       return new Dimension(this.appletSize.width, this.appletSize.height);
  140.    }
  141.  
  142.    public Dimension preferredSize() {
  143.       return this.minimumSize();
  144.    }
  145.  
  146.    public void requestShutdown() {
  147.       this.stopApplet();
  148.       this.destroyApplet();
  149.       this.disposeApplet();
  150.    }
  151.  
  152.    public void start() {
  153.       SecurityManager.enablePrivilege("UniversalThreadAccess");
  154.       SecurityManager.enablePrivilege("UniversalThreadGroupAccess");
  155.       this.handlerThreadGroup = new AppletThreadGroup("applet-" + this.atts.get("code"), this);
  156.       this.handler = new AppletEventDispatchThread(this, this.handlerThreadGroup);
  157.       String var1 = "noname";
  158.  
  159.       try {
  160.          var1 = Toolkit.getProperty("AWT.EventQueueClass", "java.awt.EventQueue");
  161.          Class[] var2 = new Class[]{Class.forName("java.lang.Thread")};
  162.          Constructor var3 = Class.forName(var1).getConstructor(var2);
  163.          Object[] var4 = new Object[]{this.handler};
  164.          this.field_0 = (EventQueue)var3.newInstance(var4);
  165.       } catch (Exception var5) {
  166.          System.err.println("Failed loading " + var1 + ": " + var5);
  167.          this.field_0 = new EventQueue(this.handler);
  168.       }
  169.  
  170.       this.handler.setEventQueue(this.field_0);
  171.       SecurityManager.revertPrivilege();
  172.       this.handler.start();
  173.    }
  174.  
  175.    public boolean isActive() {
  176.       return this.status == 5;
  177.    }
  178.  
  179.    public String getParameter(String var1) {
  180.       return (String)this.atts.get(var1.toLowerCase());
  181.    }
  182.  
  183.    public URL getDocumentBase() {
  184.       return this.documentURL;
  185.    }
  186.  
  187.    public URL getCodeBase() {
  188.       return this.codebaseURL;
  189.    }
  190.  
  191.    public AppletContext getAppletContext() {
  192.       return super.context;
  193.    }
  194.  
  195.    public void appletResize(int var1, int var2) {
  196.       this.appletSize.width = var1;
  197.       this.appletSize.height = var2;
  198.       this.field_0.postEvent(new ResizeAppletEvent(this, this.preferredSize()));
  199.    }
  200.  
  201.    public void setAppletSize(int var1, int var2, int var3, int var4) {
  202.    }
  203.  
  204.    public String getAppletName() {
  205.       if (this.appletName == null) {
  206.          try {
  207.             if (this.applet != null) {
  208.                this.appletName = this.applet.getParameter("name");
  209.                if (this.appletName == null) {
  210.                   this.appletName = this.applet.getClass().getName().toString();
  211.                }
  212.             } else {
  213.                this.appletName = this.getParameter("code");
  214.                int var1 = this.appletName.lastIndexOf(".class");
  215.                if (var1 != -1) {
  216.                   this.appletName = this.appletName.substring(0, var1);
  217.                }
  218.             }
  219.          } catch (Exception var2) {
  220.             this.appletName = "?";
  221.          }
  222.       }
  223.  
  224.       return this.appletName;
  225.    }
  226.  
  227.    protected void showAppletStatus(String var1) {
  228.       String var2 = this.getAppletName();
  229.       this.currentStatus = "Applet " + var2 + " " + var1;
  230.       this.getAppletContext().showStatus(this.currentStatus);
  231.       if (MozillaAppletContext.debug >= 1) {
  232.          System.err.println("# " + this.currentStatus);
  233.       }
  234.  
  235.    }
  236.  
  237.    protected void showAppletLog(String var1) {
  238.       if (this.noisy) {
  239.          String var2;
  240.          if (this.applet == null) {
  241.             var2 = "# Applet log: " + var1;
  242.          } else {
  243.             String var3 = this.getAppletName();
  244.             var2 = "# Applet " + var3 + " " + " log: " + var1;
  245.          }
  246.  
  247.          System.err.println(var2);
  248.       }
  249.  
  250.    }
  251.  
  252.    protected void rightState(String var1) {
  253.       this.errorReason = null;
  254.       this.showAppletStatus(var1);
  255.    }
  256.  
  257.    protected void wrongState(String var1, String var2) {
  258.       this.showAppletStatus(var1 + ": " + (this.errorReason != null ? this.errorReason : var2));
  259.       if (MozillaAppletContext.debug >= 7) {
  260.          System.err.println("#   status=" + this.status);
  261.       }
  262.  
  263.    }
  264.  
  265.    protected void showAppletException(Throwable var1, String var2) {
  266.       if (this.noisy) {
  267.          super.context.mochaOnLoad(-1);
  268.          if (var2 == null) {
  269.             var2 = var1.toString();
  270.          }
  271.  
  272.          this.errorReason = var2;
  273.          System.err.println("# Applet exception: " + var2);
  274.          var1.printStackTrace();
  275.          this.showAppletStatus(var2);
  276.       }
  277.  
  278.    }
  279.  
  280.    public boolean mouseEnter(Event var1, int var2, int var3) {
  281.       this.getAppletContext().showStatus(this.currentStatus);
  282.       return true;
  283.    }
  284.  
  285.    public boolean mouseExit(Event var1, int var2, int var3) {
  286.       this.getAppletContext().showStatus("");
  287.       return true;
  288.    }
  289.  
  290.    EventQueue getEventQueue() {
  291.       return null;
  292.    }
  293.  
  294.    public void loadApplet() {
  295.       this.field_0.postEvent(new LoadAppletEvent(this, this));
  296.    }
  297.  
  298.    public void initApplet() {
  299.       this.field_0.postEvent(new InitAppletEvent(this));
  300.    }
  301.  
  302.    public void startApplet() {
  303.       this.field_0.postEvent(new StartAppletEvent(this));
  304.    }
  305.  
  306.    public void stopApplet() {
  307.       this.field_0.postEvent(new StopAppletEvent(this));
  308.    }
  309.  
  310.    public void destroyApplet() {
  311.       this.field_0.postEvent(new DestroyAppletEvent(this));
  312.    }
  313.  
  314.    public void disposeApplet() {
  315.       this.field_0.postEvent(new DisposeAppletEvent(this));
  316.    }
  317.  
  318.    public Thread getAppletThread() {
  319.       return this.handler;
  320.    }
  321.  
  322.    public void addTopLevelWindow(Window var1) {
  323.       Vector var2 = this.topLevelWindows;
  324.       synchronized(var2){}
  325.  
  326.       try {
  327.          if (var1 != this) {
  328.             this.topLevelWindows.addElement(var1);
  329.          }
  330.       } catch (Throwable var4) {
  331.          throw var4;
  332.       }
  333.  
  334.    }
  335.  
  336.    public void removeTopLevelWindow(Window var1) {
  337.       Vector var2 = this.topLevelWindows;
  338.       synchronized(var2){}
  339.  
  340.       try {
  341.          if (var1 != this) {
  342.             this.topLevelWindows.removeElement(var1);
  343.          }
  344.       } catch (Throwable var4) {
  345.          throw var4;
  346.       }
  347.  
  348.    }
  349.  
  350.    public Window[] getTopLevelWindows() {
  351.       Vector var2 = this.topLevelWindows;
  352.       synchronized(var2){}
  353.  
  354.       Window[] var1;
  355.       try {
  356.          int var4 = this.topLevelWindows.size();
  357.          Window[] var5 = new Window[var4 + 1];
  358.  
  359.          for(int var6 = 0; var6 < var4; ++var6) {
  360.             var5[var6] = (Window)this.topLevelWindows.elementAt(var6);
  361.          }
  362.  
  363.          var5[var4] = this;
  364.          var1 = var5;
  365.       } catch (Throwable var8) {
  366.          throw var8;
  367.       }
  368.  
  369.       return var1;
  370.    }
  371.  
  372.    public Dialog swapTopModalDialog(Dialog var1) {
  373.       if (var1 != null && !var1.isModal()) {
  374.          throw new IllegalArgumentException("Dialog must be modal.");
  375.       } else {
  376.          Dialog var2 = this.m_topModalDialog;
  377.          this.m_topModalDialog = var1;
  378.          return var2;
  379.       }
  380.    }
  381.  
  382.    protected Thread getThread() {
  383.       return this.handler;
  384.    }
  385.  
  386.    protected ThreadGroup getThreadGroup() {
  387.       return this.handlerThreadGroup;
  388.    }
  389. }
  390.