home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 July / PCO_07_97.ISO / NET_COM / cc32e40.exe / nav40.z / java40.jar / netscape / applet / DerivedAppletFrame.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-06-07  |  10.0 KB  |  464 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.Component;
  8. import java.awt.Container;
  9. import java.awt.Dimension;
  10. import java.awt.Event;
  11. import java.awt.Frame;
  12. import java.awt.Window;
  13. import java.io.PrintStream;
  14. import java.net.URL;
  15. import java.util.Hashtable;
  16. import java.util.Vector;
  17.  
  18. class DerivedAppletFrame extends EmbeddedAppletFrame implements AppletStub, Runnable, AppletPeer {
  19.    Integer appletID;
  20.    // $FF: renamed from: eq netscape.applet.EventQueue
  21.    EventQueue field_0;
  22.    boolean isAlive;
  23.    boolean isModal;
  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.    Thread handler;
  34.    AppletHook hook;
  35.    static final int NULL_EVENT = -1;
  36.    static final int APPLET_DISPOSE = 0;
  37.    static final int APPLET_LOAD = 1;
  38.    static final int APPLET_INIT = 2;
  39.    static final int APPLET_START = 3;
  40.    static final int APPLET_STOP = 4;
  41.    static final int APPLET_DESTROY = 5;
  42.    static final int APPLET_RESIZE = 51234;
  43.    Dimension appletSize = new Dimension(100, 100);
  44.    AppletClassLoader classLoader;
  45.    boolean reloadClasses = false;
  46.    String appletName;
  47.    String currentStatus = "";
  48.    boolean noisy = true;
  49.    String errorReason;
  50.  
  51.    DerivedAppletFrame(URL var1, URL var2, URL var3, Hashtable var4, MozillaAppletContext var5, Integer var6, boolean var7) {
  52.       this.appletID = var6;
  53.       super.pData = var6;
  54.       super.context = var5;
  55.       this.documentURL = var1;
  56.       this.codebaseURL = var2;
  57.       this.archiveURL = var3;
  58.       this.atts = var4;
  59.       ((Container)this).setLayout(new BorderLayout());
  60.       String var8 = this.getParameter("width");
  61.       if (var8 != null) {
  62.          this.appletSize.width = Integer.valueOf(var8);
  63.       }
  64.  
  65.       var8 = this.getParameter("height");
  66.       if (var8 != null) {
  67.          this.appletSize.height = Integer.valueOf(var8);
  68.       }
  69.  
  70.       this.field_0 = new EventQueue();
  71.       this.topLevelWindows = new Vector();
  72.       this.isAlive = true;
  73.       this.isModal = true;
  74.       this.reloadClasses = var7;
  75.    }
  76.  
  77.    void destroy() {
  78.       if (this.classLoader != null) {
  79.          this.classLoader.releaseClassLoader();
  80.          this.classLoader = null;
  81.       }
  82.  
  83.    }
  84.  
  85.    protected void finalize() {
  86.       this.destroy();
  87.    }
  88.  
  89.    void dumpState(PrintStream var1, int var2) {
  90.       MozillaAppletContext.indent(var1, var2);
  91.       var1.println("EmbeddedAppletFrame id=" + super.pData + " applet=" + this.applet);
  92.    }
  93.  
  94.    String statusToString(int var1) {
  95.       switch (var1) {
  96.          case 0:
  97.             return "dispose";
  98.          case 1:
  99.             return "load";
  100.          case 2:
  101.             return "init";
  102.          case 3:
  103.             return "start";
  104.          case 4:
  105.             return "stop";
  106.          case 5:
  107.             return "destroy";
  108.          default:
  109.             return Integer.toString(var1, 10);
  110.       }
  111.    }
  112.  
  113.    public Dimension minimumSize() {
  114.       return new Dimension(this.appletSize.width, this.appletSize.height);
  115.    }
  116.  
  117.    public Dimension preferredSize() {
  118.       return this.minimumSize();
  119.    }
  120.  
  121.    public void requestShutdown() {
  122.       this.field_0.sendEvent(new AppletEvent(4));
  123.       this.field_0.sendEvent(new AppletEvent(5));
  124.       this.field_0.sendEvent(new AppletEvent(0));
  125.    }
  126.  
  127.    public void start() {
  128.       SecurityManager.enablePrivilege("SuperUser");
  129.       this.handler = new Thread(new AppletThreadGroup("applet-" + this.atts.get("code"), this), this);
  130.       SecurityManager.revertPrivilege();
  131.       this.handler.start();
  132.    }
  133.  
  134.    public void run() {
  135.       this.classLoader = AppletClassLoader.getClassLoader(super.context, this.codebaseURL, this.archiveURL, this.getParameter("mayscript") != null, this.reloadClasses);
  136.  
  137.       while(this.isAlive && this.isModal) {
  138.          NEvent var1;
  139.          try {
  140.             var1 = this.field_0.getNextEvent();
  141.          } catch (Exception var20) {
  142.             this.showAppletException(var20, "interrupted, bailing out...");
  143.             return;
  144.          }
  145.  
  146.          try {
  147.             switch (var1.eventId) {
  148.                case 0:
  149.                   if (this.status == 1) {
  150.                      this.status = 0;
  151.                      ((Container)this).remove(this.applet);
  152.                      this.applet = null;
  153.                      this.rightState("disposed");
  154.                      ((Frame)this).dispose();
  155.                      Vector var3 = this.topLevelWindows;
  156.                      synchronized(var3){}
  157.  
  158.                      try {
  159.                         for(int var5 = this.topLevelWindows.size(); var5 > 0; --var5) {
  160.                            ((Window)this.topLevelWindows.elementAt(var5 - 1)).dispose();
  161.                         }
  162.                      } catch (Throwable var29) {
  163.                         throw var29;
  164.                      }
  165.  
  166.                      this.isAlive = false;
  167.                      return;
  168.                   }
  169.  
  170.                   this.wrongState("can't dispose", "applet not destroyed");
  171.                   break;
  172.                case 1:
  173.                   if (this.status != 0) {
  174.                      this.wrongState("can't load", "not disposed");
  175.                   } else {
  176.                      String var2 = this.getParameter("code");
  177.                      if (var2.endsWith(".class")) {
  178.                         var2 = var2.substring(0, var2.length() - 6).replace('/', '.');
  179.                      }
  180.  
  181.                      if (var2.endsWith(".java")) {
  182.                         var2 = var2.substring(0, var2.length() - 5).replace('/', '.');
  183.                      }
  184.  
  185.                      try {
  186.                         this.applet = (Applet)this.classLoader.loadClass(var2).newInstance();
  187.                      } catch (VerifyError var21) {
  188.                         this.showAppletException(var21, "class " + ((Throwable)var21).getMessage() + " got a security violation: method verification error");
  189.                         continue;
  190.                      } catch (SecurityException var22) {
  191.                         this.showAppletException(var22, "class " + var2 + " got a security violation: " + ((Throwable)var22).getMessage());
  192.                         continue;
  193.                      } catch (ClassNotFoundException var23) {
  194.                         this.showAppletException(var23, "class " + var2 + " not found");
  195.                         continue;
  196.                      } catch (InstantiationException var24) {
  197.                         this.showAppletException(var24, "class " + var2 + " can't be instantiated");
  198.                         continue;
  199.                      } catch (IllegalAccessException var25) {
  200.                         this.showAppletException(var25, "class " + var2 + " is not public or has no public constructor");
  201.                         continue;
  202.                      } catch (Exception var26) {
  203.                         this.showAppletException(var26, "exception: " + ((Throwable)var26).toString());
  204.                         continue;
  205.                      } catch (ThreadDeath var27) {
  206.                         this.showAppletStatus("killed");
  207.                         return;
  208.                      } catch (Error var28) {
  209.                         this.showAppletException(var28, "error: " + ((Throwable)var28).toString());
  210.                         continue;
  211.                      }
  212.  
  213.                      this.applet.setStub(this);
  214.                      this.applet.hide();
  215.                      ((Container)this).add("Center", this.applet);
  216.                      this.status = 1;
  217.                      this.rightState("loaded");
  218.                      ((Container)this).validate();
  219.                   }
  220.                   break;
  221.                case 2:
  222.                   if (this.status != 1) {
  223.                      this.wrongState("can't init", "applet not loaded");
  224.                   } else {
  225.                      ((Window)this).pack();
  226.                      ((Window)this).show();
  227.                      this.applet.resize(this.appletSize);
  228.                      AppletDebugger.aboutToInit(this.applet);
  229.                      this.applet.init();
  230.                      ((Container)this).validate();
  231.                      this.status = 2;
  232.                      this.rightState("initialized");
  233.                   }
  234.                   break;
  235.                case 3:
  236.                   if (this.status != 2) {
  237.                      this.wrongState("can't start", "applet not initialized");
  238.                   } else {
  239.                      this.status = 3;
  240.                      this.timestamp = System.currentTimeMillis();
  241.                      this.applet.resize(this.appletSize.width, this.appletSize.height);
  242.                      this.applet.start();
  243.                      this.applet.show();
  244.                      ((Container)this).validate();
  245.                      super.context.mochaOnLoad(0);
  246.                      this.rightState("running");
  247.                   }
  248.                   break;
  249.                case 4:
  250.                   if (this.status != 3) {
  251.                      this.wrongState("can't stop", "applet not started");
  252.                   } else {
  253.                      this.status = 2;
  254.                      this.timestamp = System.currentTimeMillis();
  255.                      this.applet.hide();
  256.                      SecurityManager.enablePrivilege("SuperUser");
  257.                      this.applet.stop();
  258.                      SecurityManager.revertPrivilege();
  259.                      this.rightState("stopped");
  260.                   }
  261.                   break;
  262.                case 5:
  263.                   if (this.status != 2) {
  264.                      this.wrongState("can't destroy", "applet not stopped");
  265.                   } else {
  266.                      this.status = 1;
  267.                      SecurityManager.enablePrivilege("SuperUser");
  268.                      this.applet.destroy();
  269.                      SecurityManager.revertPrivilege();
  270.                      ((Component)this).hide();
  271.                      this.rightState("destroyed");
  272.                   }
  273.                   break;
  274.                case 20:
  275.                   var1.processEvent();
  276.                case 51234:
  277.             }
  278.          } catch (SecurityException var30) {
  279.             this.showAppletException(var30, "security violation: " + ((Throwable)var30).getMessage());
  280.          } catch (Exception var31) {
  281.             this.showAppletException(var31, "exception: " + ((Throwable)var31).toString());
  282.          } catch (ThreadDeath var32) {
  283.             this.showAppletStatus("killed");
  284.             return;
  285.          } catch (Error var33) {
  286.             this.showAppletException(var33, "error: " + ((Throwable)var33).toString());
  287.          }
  288.       }
  289.  
  290.    }
  291.  
  292.    public boolean isActive() {
  293.       return this.status == 3;
  294.    }
  295.  
  296.    public String getParameter(String var1) {
  297.       return (String)this.atts.get(var1.toLowerCase());
  298.    }
  299.  
  300.    public URL getDocumentBase() {
  301.       return this.documentURL;
  302.    }
  303.  
  304.    public URL getCodeBase() {
  305.       return this.codebaseURL;
  306.    }
  307.  
  308.    public AppletContext getAppletContext() {
  309.       return super.context;
  310.    }
  311.  
  312.    public void appletResize(int var1, int var2) {
  313.       this.appletSize.width = var1;
  314.       this.appletSize.height = var2;
  315.       ((Component)this).postEvent(new Event(this, 51234, this.preferredSize()));
  316.    }
  317.  
  318.    public void setAppletSize(int var1, int var2, int var3, int var4) {
  319.    }
  320.  
  321.    public String getAppletName() {
  322.       if (this.appletName == null) {
  323.          try {
  324.             if (this.applet != null) {
  325.                this.appletName = this.applet.getParameter("name");
  326.                if (this.appletName == null) {
  327.                   this.appletName = this.applet.getClass().getName().toString();
  328.                }
  329.             } else {
  330.                this.appletName = this.getParameter("code");
  331.                int var1 = this.appletName.lastIndexOf(".class");
  332.                if (var1 != -1) {
  333.                   this.appletName = this.appletName.substring(0, var1);
  334.                }
  335.             }
  336.          } catch (Exception var2) {
  337.             this.appletName = "?";
  338.          }
  339.       }
  340.  
  341.       return this.appletName;
  342.    }
  343.  
  344.    protected void showAppletStatus(String var1) {
  345.       String var2 = this.getAppletName();
  346.       this.currentStatus = "Applet " + var2 + " " + var1;
  347.       this.getAppletContext().showStatus(this.currentStatus);
  348.       if (MozillaAppletContext.debug >= 1) {
  349.          System.err.println("# " + this.currentStatus);
  350.       }
  351.  
  352.    }
  353.  
  354.    protected void showAppletLog(String var1) {
  355.       if (this.noisy) {
  356.          String var2;
  357.          if (this.applet == null) {
  358.             var2 = "# Applet log: " + var1;
  359.          } else {
  360.             String var3 = this.getAppletName();
  361.             var2 = "# Applet " + var3 + " " + " log: " + var1;
  362.          }
  363.  
  364.          System.err.println(var2);
  365.       }
  366.  
  367.    }
  368.  
  369.    protected void rightState(String var1) {
  370.       this.errorReason = null;
  371.       this.showAppletStatus(var1);
  372.    }
  373.  
  374.    protected void wrongState(String var1, String var2) {
  375.       this.showAppletStatus(var1 + ": " + (this.errorReason != null ? this.errorReason : var2));
  376.       if (MozillaAppletContext.debug >= 7) {
  377.          System.err.println("#   status=" + this.status);
  378.       }
  379.  
  380.    }
  381.  
  382.    protected void showAppletException(Throwable var1, String var2) {
  383.       if (this.noisy) {
  384.          super.context.mochaOnLoad(-1);
  385.          if (var2 == null) {
  386.             var2 = var1.toString();
  387.          }
  388.  
  389.          this.errorReason = var2;
  390.          System.err.println("# Applet exception: " + var2);
  391.          var1.printStackTrace();
  392.          this.showAppletStatus(var2);
  393.       }
  394.  
  395.    }
  396.  
  397.    public boolean mouseEnter(Event var1, int var2, int var3) {
  398.       this.getAppletContext().showStatus(this.currentStatus);
  399.       return true;
  400.    }
  401.  
  402.    public boolean mouseExit(Event var1, int var2, int var3) {
  403.       this.getAppletContext().showStatus("");
  404.       return true;
  405.    }
  406.  
  407.    EventQueue getEventQueue() {
  408.       return this.field_0;
  409.    }
  410.  
  411.    public Thread getAppletThread() {
  412.       return this.handler;
  413.    }
  414.  
  415.    public void sendEvent(NEvent var1) {
  416.       this.field_0.sendEvent(var1);
  417.    }
  418.  
  419.    public void enterModal() {
  420.       this.run();
  421.       this.isModal = true;
  422.    }
  423.  
  424.    public void exitModal() {
  425.       this.isModal = false;
  426.    }
  427.  
  428.    public void addTopLevelWindow(Window var1) {
  429.       Vector var2 = this.topLevelWindows;
  430.       synchronized(var2){}
  431.  
  432.       try {
  433.          if (var1 != this) {
  434.             this.topLevelWindows.addElement(var1);
  435.          }
  436.       } catch (Throwable var4) {
  437.          throw var4;
  438.       }
  439.  
  440.    }
  441.  
  442.    public void removeTopLevelWindow(Window var1) {
  443.       Vector var2 = this.topLevelWindows;
  444.       synchronized(var2){}
  445.  
  446.       try {
  447.          if (var1 != this) {
  448.             this.topLevelWindows.removeElement(var1);
  449.          }
  450.       } catch (Throwable var4) {
  451.          throw var4;
  452.       }
  453.  
  454.    }
  455.  
  456.    public void removeEvents(Object var1) {
  457.       this.field_0.removeEvents(var1);
  458.    }
  459.  
  460.    public void coalesceEvent(NEvent var1) {
  461.       this.field_0.coalesceEvent(var1);
  462.    }
  463. }
  464.