home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 June / pcx11_9706.iso / shutils / internet / browser / p32e40b5.exe / nav40.z / java40.jar / netscape / applet / DerivedAppletFrame.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-05-23  |  9.6 KB  |  442 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. public class DerivedAppletFrame extends EmbeddedAppletFrame implements AppletStub, Runnable {
  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 CALLBACK_EVENT = 20;
  43.    static final int APPLET_RESIZE = 51234;
  44.    Dimension appletSize = new Dimension(100, 100);
  45.    AppletClassLoader classLoader;
  46.    boolean reloadClasses = false;
  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 sendEvent(int var1) {
  122.       this.field_0.sendEvent(var1);
  123.    }
  124.  
  125.    public void sendGUIEvent(GUIEvent var1) {
  126.       this.field_0.sendGUIEvent(var1);
  127.    }
  128.  
  129.    public void requestShutdown() {
  130.       this.field_0.sendEvent(4);
  131.       this.field_0.sendEvent(5);
  132.       this.field_0.sendEvent(0);
  133.    }
  134.  
  135.    public void start() {
  136.       SecurityManager.enablePrivilege("SuperUser");
  137.       this.handler = new Thread(new AppletThreadGroup("applet-" + this.atts.get("code"), this), this);
  138.       SecurityManager.revertPrivilege();
  139.       this.handler.start();
  140.    }
  141.  
  142.    public void run() {
  143.       this.classLoader = AppletClassLoader.getClassLoader(super.context, this.codebaseURL, this.archiveURL, this.getParameter("mayscript") != null, this.reloadClasses);
  144.  
  145.       while(this.isAlive && this.isModal) {
  146.          AppletEvent var1;
  147.          try {
  148.             var1 = this.field_0.getNextEvent();
  149.          } catch (Exception var20) {
  150.             this.showAppletException(var20, "interrupted, bailing out...");
  151.             return;
  152.          }
  153.  
  154.          try {
  155.             switch (var1.eventId) {
  156.                case 0:
  157.                   if (this.status == 1) {
  158.                      this.status = 0;
  159.                      ((Container)this).remove(this.applet);
  160.                      this.applet = null;
  161.                      this.rightState("disposed");
  162.                      ((Frame)this).dispose();
  163.                      Vector var3 = this.topLevelWindows;
  164.                      synchronized(var3){}
  165.  
  166.                      try {
  167.                         for(int var5 = this.topLevelWindows.size(); var5 > 0; --var5) {
  168.                            ((Window)this.topLevelWindows.elementAt(var5 - 1)).dispose();
  169.                         }
  170.                      } catch (Throwable var29) {
  171.                         throw var29;
  172.                      }
  173.  
  174.                      this.isAlive = false;
  175.                      return;
  176.                   }
  177.  
  178.                   this.wrongState("can't dispose", "applet not destroyed");
  179.                   break;
  180.                case 1:
  181.                   if (this.status != 0) {
  182.                      this.wrongState("can't load", "not disposed");
  183.                   } else {
  184.                      String var2 = this.getParameter("code");
  185.                      if (var2.endsWith(".class")) {
  186.                         var2 = var2.substring(0, var2.length() - 6).replace('/', '.');
  187.                      }
  188.  
  189.                      if (var2.endsWith(".java")) {
  190.                         var2 = var2.substring(0, var2.length() - 5).replace('/', '.');
  191.                      }
  192.  
  193.                      try {
  194.                         this.applet = (Applet)this.classLoader.loadClass(var2).newInstance();
  195.                      } catch (VerifyError var21) {
  196.                         this.showAppletException(var21, "class " + ((Throwable)var21).getMessage() + " got a security violation: method verification error");
  197.                         continue;
  198.                      } catch (SecurityException var22) {
  199.                         this.showAppletException(var22, "class " + var2 + " got a security violation: " + ((Throwable)var22).getMessage());
  200.                         continue;
  201.                      } catch (ClassNotFoundException var23) {
  202.                         this.showAppletException(var23, "class " + var2 + " not found");
  203.                         continue;
  204.                      } catch (InstantiationException var24) {
  205.                         this.showAppletException(var24, "class " + var2 + " can't be instantiated");
  206.                         continue;
  207.                      } catch (IllegalAccessException var25) {
  208.                         this.showAppletException(var25, "class " + var2 + " is not public or has no public constructor");
  209.                         continue;
  210.                      } catch (Exception var26) {
  211.                         this.showAppletException(var26, "exception: " + ((Throwable)var26).toString());
  212.                         continue;
  213.                      } catch (ThreadDeath var27) {
  214.                         this.showAppletStatus("killed");
  215.                         return;
  216.                      } catch (Error var28) {
  217.                         this.showAppletException(var28, "error: " + ((Throwable)var28).toString());
  218.                         continue;
  219.                      }
  220.  
  221.                      this.applet.setStub(this);
  222.                      this.applet.hide();
  223.                      ((Container)this).add("Center", this.applet);
  224.                      this.status = 1;
  225.                      this.rightState("loaded");
  226.                      ((Container)this).validate();
  227.                   }
  228.                   break;
  229.                case 2:
  230.                   if (this.status != 1) {
  231.                      this.wrongState("can't init", "applet not loaded");
  232.                   } else {
  233.                      ((Window)this).pack();
  234.                      ((Window)this).show();
  235.                      this.applet.resize(this.appletSize);
  236.                      AppletDebugger.aboutToInit(this.applet);
  237.                      this.applet.init();
  238.                      ((Container)this).validate();
  239.                      this.status = 2;
  240.                      this.rightState("initialized");
  241.                   }
  242.                   break;
  243.                case 3:
  244.                   if (this.status != 2) {
  245.                      this.wrongState("can't start", "applet not initialized");
  246.                   } else {
  247.                      this.status = 3;
  248.                      this.timestamp = System.currentTimeMillis();
  249.                      this.applet.resize(this.appletSize.width, this.appletSize.height);
  250.                      this.applet.start();
  251.                      this.applet.show();
  252.                      ((Container)this).validate();
  253.                      super.context.mochaOnLoad(0);
  254.                      this.rightState("running");
  255.                   }
  256.                   break;
  257.                case 4:
  258.                   if (this.status != 3) {
  259.                      this.wrongState("can't stop", "applet not started");
  260.                   } else {
  261.                      this.status = 2;
  262.                      this.timestamp = System.currentTimeMillis();
  263.                      this.applet.hide();
  264.                      SecurityManager.enablePrivilege("SuperUser");
  265.                      this.applet.stop();
  266.                      SecurityManager.revertPrivilege();
  267.                      this.rightState("stopped");
  268.                   }
  269.                   break;
  270.                case 5:
  271.                   if (this.status != 2) {
  272.                      this.wrongState("can't destroy", "applet not stopped");
  273.                   } else {
  274.                      this.status = 1;
  275.                      SecurityManager.enablePrivilege("SuperUser");
  276.                      this.applet.destroy();
  277.                      SecurityManager.revertPrivilege();
  278.                      ((Component)this).hide();
  279.                      this.rightState("destroyed");
  280.                   }
  281.                   break;
  282.                case 20:
  283.                   ((GUIEvent)var1).processEvent();
  284.                case 51234:
  285.             }
  286.          } catch (SecurityException var30) {
  287.             this.showAppletException(var30, "security violation: " + ((Throwable)var30).getMessage());
  288.          } catch (Exception var31) {
  289.             this.showAppletException(var31, "exception: " + ((Throwable)var31).toString());
  290.          } catch (ThreadDeath var32) {
  291.             this.showAppletStatus("killed");
  292.             return;
  293.          } catch (Error var33) {
  294.             this.showAppletException(var33, "error: " + ((Throwable)var33).toString());
  295.          }
  296.       }
  297.  
  298.    }
  299.  
  300.    public boolean isActive() {
  301.       return this.status == 3;
  302.    }
  303.  
  304.    public String getParameter(String var1) {
  305.       return (String)this.atts.get(var1.toLowerCase());
  306.    }
  307.  
  308.    public URL getDocumentBase() {
  309.       return this.documentURL;
  310.    }
  311.  
  312.    public URL getCodeBase() {
  313.       return this.codebaseURL;
  314.    }
  315.  
  316.    public AppletContext getAppletContext() {
  317.       return super.context;
  318.    }
  319.  
  320.    public void appletResize(int var1, int var2) {
  321.       this.appletSize.width = var1;
  322.       this.appletSize.height = var2;
  323.       ((Component)this).postEvent(new Event(this, 51234, this.preferredSize()));
  324.    }
  325.  
  326.    public void setAppletSize(int var1, int var2, int var3, int var4) {
  327.    }
  328.  
  329.    public String getAppletName() {
  330.       String var1 = this.applet.getParameter("name");
  331.       if (var1 == null) {
  332.          var1 = this.applet.getClass().getName().toString();
  333.       }
  334.  
  335.       return var1;
  336.    }
  337.  
  338.    protected void showAppletStatus(String var1) {
  339.       if (this.applet == null) {
  340.          this.currentStatus = "Applet " + var1;
  341.       } else {
  342.          String var2 = this.getAppletName();
  343.          this.currentStatus = "Applet " + var2 + " " + var1;
  344.       }
  345.  
  346.       this.getAppletContext().showStatus(this.currentStatus);
  347.    }
  348.  
  349.    protected void showAppletLog(String var1) {
  350.       if (this.noisy) {
  351.          String var2;
  352.          if (this.applet == null) {
  353.             var2 = "# Applet log: " + var1;
  354.          } else {
  355.             String var3 = this.getAppletName();
  356.             var2 = "# Applet " + var3 + " " + " log: " + var1;
  357.          }
  358.  
  359.          System.err.println(var2);
  360.       }
  361.  
  362.    }
  363.  
  364.    protected void rightState(String var1) {
  365.       this.errorReason = null;
  366.       this.showAppletStatus(var1);
  367.    }
  368.  
  369.    protected void wrongState(String var1, String var2) {
  370.       this.showAppletStatus(var1 + ": " + (this.errorReason != null ? this.errorReason : var2));
  371.    }
  372.  
  373.    protected void showAppletException(Throwable var1, String var2) {
  374.       if (this.noisy) {
  375.          super.context.mochaOnLoad(-1);
  376.          if (var2 == null) {
  377.             var2 = var1.toString();
  378.          }
  379.  
  380.          this.errorReason = var2;
  381.          System.err.println("# Applet exception: " + var2);
  382.          var1.printStackTrace();
  383.          this.showAppletStatus(var2);
  384.       }
  385.  
  386.    }
  387.  
  388.    public boolean mouseEnter(Event var1, int var2, int var3) {
  389.       this.getAppletContext().showStatus(this.currentStatus);
  390.       return true;
  391.    }
  392.  
  393.    public boolean mouseExit(Event var1, int var2, int var3) {
  394.       this.getAppletContext().showStatus("");
  395.       return true;
  396.    }
  397.  
  398.    public void addTopLevelWindow(Window var1) {
  399.       Vector var2 = this.topLevelWindows;
  400.       synchronized(var2){}
  401.  
  402.       try {
  403.          if (var1 != this) {
  404.             this.topLevelWindows.addElement(var1);
  405.          }
  406.       } catch (Throwable var4) {
  407.          throw var4;
  408.       }
  409.  
  410.    }
  411.  
  412.    public void removeTopLevelWindow(Window var1) {
  413.       Vector var2 = this.topLevelWindows;
  414.       synchronized(var2){}
  415.  
  416.       try {
  417.          if (var1 != this) {
  418.             this.topLevelWindows.removeElement(var1);
  419.          }
  420.       } catch (Throwable var4) {
  421.          throw var4;
  422.       }
  423.  
  424.    }
  425.  
  426.    public void exitModal() {
  427.       this.isModal = false;
  428.    }
  429.  
  430.    public void resetModal() {
  431.       this.isModal = true;
  432.    }
  433.  
  434.    public EventQueue getEventQueue() {
  435.       return this.field_0;
  436.    }
  437.  
  438.    public Thread getAppletThread() {
  439.       return this.handler;
  440.    }
  441. }
  442.