home *** CD-ROM | disk | FTP | other *** search
- package sun.applet;
-
- import java.applet.Applet;
- import java.applet.AppletContext;
- import java.applet.AppletStub;
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Panel;
- import java.io.IOException;
- import java.net.URL;
- import java.util.Hashtable;
- import sun.misc.MessageUtils;
-
- public abstract class AppletPanel extends Panel implements AppletStub, Runnable {
- static String propName = "appletloader";
- Applet applet;
- AppletClassLoader loader;
- protected int status;
- Thread handler;
- public static final int APPLET_DISPOSE = 0;
- public static final int APPLET_LOAD = 1;
- public static final int APPLET_INIT = 2;
- public static final int APPLET_START = 3;
- public static final int APPLET_STOP = 4;
- public static final int APPLET_DESTROY = 5;
- public static final int APPLET_QUIT = 6;
- public static final int APPLET_ERROR = 7;
- public static final int APPLET_RESIZE = 51234;
- public static final int APPLET_LOADING = 51235;
- public static final int APPLET_LOADING_COMPLETED = 51236;
- Dimension appletSize = new Dimension(100, 100);
- // $FF: renamed from: mu sun.misc.MessageUtils
- MessageUtils field_0 = new MessageUtils();
- Thread loaderThread;
- boolean loadAbortRequest = false;
- Event queue;
- private static Hashtable classloaders = new Hashtable();
-
- public void init() {
- ((Container)this).setLayout(new BorderLayout());
- String var1 = this.getParameter("width");
- if (var1 != null) {
- this.appletSize.width = Integer.valueOf(var1);
- }
-
- var1 = this.getParameter("height");
- if (var1 != null) {
- this.appletSize.height = Integer.valueOf(var1);
- }
-
- String var2 = "applet-" + this.getParameter("code");
- this.handler = new Thread(new AppletThreadGroup("group " + var2), this, "thread " + var2);
- this.handler.start();
- }
-
- public Dimension minimumSize() {
- return new Dimension(this.appletSize.width, this.appletSize.height);
- }
-
- public Dimension preferredSize() {
- return this.minimumSize();
- }
-
- public void sendEvent(int var1) {
- this.sendEvent(new Event((Object)null, var1, (Object)null));
- }
-
- protected synchronized void sendEvent(Event var1) {
- if (this.queue == null) {
- var1.target = this.queue;
- this.queue = var1;
- this.notifyAll();
- } else {
- Event var2;
- for(var2 = this.queue; var2.target != null; var2 = (Event)var2.target) {
- }
-
- var2.target = var1;
- }
- }
-
- synchronized Event getNextEvent() throws InterruptedException {
- while(this.queue == null) {
- this.wait();
- }
-
- Event var1 = this.queue;
- this.queue = (Event)this.queue.target;
- var1.target = this;
- return var1;
- }
-
- public void run() {
- Thread var1 = Thread.currentThread();
- if (var1 == this.loaderThread) {
- this.runLoader();
- } else {
- int var2 = var1.getPriority();
- var1.setPriority(var2 + 1);
-
- while(true) {
- Event var3;
- try {
- var3 = this.getNextEvent();
- } catch (InterruptedException var5) {
- this.showAppletStatus(propName + ".bail");
- return;
- }
-
- try {
- switch (var3.id) {
- case 0:
- if (this.status != 1) {
- this.showAppletStatus(propName + ".notdestroyed");
- } else {
- this.status = 0;
- ((Container)this).remove(this.applet);
- this.showAppletStatus(propName + ".disposed");
- }
- break;
- case 1:
- if (this.okToLoad() && this.loaderThread == null) {
- this.setLoaderThread(new Thread(this));
- this.loaderThread.setPriority(var2 + 1);
- this.loaderThread.start();
- this.loaderThread.join();
- this.setLoaderThread((Thread)null);
- }
- break;
- case 2:
- if (this.status != 1) {
- this.showAppletStatus(propName + ".notloaded");
- } else {
- this.applet.resize(this.appletSize);
- this.applet.init();
- ((Container)this).validate();
- this.status = 2;
- this.showAppletStatus(propName + ".inited");
- }
- break;
- case 3:
- if (this.status != 2) {
- this.showAppletStatus(propName + ".notinited");
- } else {
- this.applet.resize(this.appletSize);
- this.applet.start();
- ((Container)this).validate();
- this.applet.show();
- this.status = 3;
- this.showAppletStatus(propName + ".started");
- }
- break;
- case 4:
- if (this.status != 3) {
- this.showAppletStatus(propName + ".notstarted");
- } else {
- this.status = 2;
- this.applet.hide();
- this.applet.stop();
- this.showAppletStatus(propName + ".stopped");
- }
- break;
- case 5:
- if (this.status != 2) {
- this.showAppletStatus(propName + ".notstopped");
- } else {
- this.status = 1;
- this.applet.destroy();
- this.showAppletStatus(propName + ".destroyed");
- }
- break;
- case 6:
- return;
- }
- } catch (Exception var6) {
- this.showAppletStatus(MessageUtils.substProp(propName + ".exception2", var6.getClass().getName(), ((Throwable)var6).getMessage()));
- this.showAppletException(var6);
- } catch (ThreadDeath var7) {
- this.showAppletStatus(propName + ".death");
- return;
- } catch (Error var8) {
- this.showAppletStatus(MessageUtils.substProp(propName + ".error2", var8.getClass().getName(), ((Throwable)var8).getMessage()));
- this.showAppletException(var8);
- }
-
- this.clearLoadAbortRequest();
- }
- }
- }
-
- private void runLoader() {
- if (this.status != 0) {
- this.showAppletStatus(propName + ".notdisposed");
- } else {
- ((Component)this).postEvent(new Event(this, 51235, (Object)null));
- this.status = 1;
-
- try {
- this.loader = getClassLoader(this.getCodeBase());
- if (Thread.interrupted()) {
- this.status = 0;
- ((Component)this).postEvent(new Event(this, 51236, (Object)null));
- return;
- }
- } catch (IOException var21) {
- this.status = 7;
- this.showAppletStatus(((Throwable)var21).getMessage());
- this.showAppletLog(((Throwable)var21).getMessage());
- this.showAppletException(var21);
- ((Component)this).postEvent(new Event(this, 51236, (Object)null));
- return;
- }
-
- String var1 = this.getParameter("code");
- if (var1 == null) {
- String var2 = propName + ".nocode";
- this.status = 7;
- this.showAppletStatus(var2);
- this.showAppletLog(var2);
- ((Component)this).repaint();
- } else if (var1.endsWith(".class")) {
- var1 = var1.substring(0, var1.length() - 6).replace('/', '.');
- } else if (var1.endsWith(".java")) {
- var1 = var1.substring(0, var1.length() - 5).replace('/', '.');
- }
-
- label175: {
- try {
- this.applet = (Applet)this.loader.loadClass(var1).newInstance();
- if (!Thread.interrupted()) {
- break label175;
- }
-
- this.status = 0;
- this.applet = null;
- this.showAppletStatus(propName + ".death");
- return;
- } catch (ClassNotFoundException var14) {
- this.status = 7;
- String var23 = MessageUtils.substProp(propName + ".notfound", var1);
- this.showAppletStatus(var23);
- this.showAppletLog(var23);
- this.showAppletException(var14);
- } catch (InstantiationException var15) {
- this.status = 7;
- String var22 = MessageUtils.substProp(propName + ".nocreate", var1);
- this.showAppletStatus(var22);
- this.showAppletLog(var22);
- this.showAppletException(var15);
- return;
- } catch (IllegalAccessException var16) {
- this.status = 7;
- String var5 = MessageUtils.substProp(propName + ".noconstruct", var1);
- this.showAppletStatus(var5);
- this.showAppletLog(var5);
- this.showAppletException(var16);
- return;
- } catch (Exception var17) {
- this.status = 7;
- this.showAppletStatus(MessageUtils.substProp(propName + ".exception", ((Throwable)var17).getMessage()));
- this.showAppletException(var17);
- return;
- } catch (ThreadDeath var18) {
- this.status = 7;
- this.showAppletStatus(propName + ".death");
- return;
- } catch (Error var19) {
- this.status = 7;
- this.showAppletStatus(MessageUtils.substProp(propName + ".error", ((Throwable)var19).getMessage()));
- this.showAppletException(var19);
- return;
- } finally {
- ((Component)this).postEvent(new Event(this, 51236, (Object)null));
- }
-
- return;
- }
-
- this.applet.setStub(this);
- this.applet.hide();
- ((Container)this).add("Center", this.applet);
- this.showAppletStatus(propName + ".loaded");
- ((Container)this).validate();
- }
- }
-
- protected synchronized void stopLoading() {
- if (this.loaderThread != null) {
- this.loaderThread.interrupt();
- } else {
- this.setLoadAbortRequest();
- }
- }
-
- protected synchronized boolean okToLoad() {
- return !this.loadAbortRequest;
- }
-
- protected synchronized void clearLoadAbortRequest() {
- this.loadAbortRequest = false;
- }
-
- protected synchronized void setLoadAbortRequest() {
- this.loadAbortRequest = true;
- }
-
- private synchronized void setLoaderThread(Thread var1) {
- this.loaderThread = var1;
- }
-
- public boolean isActive() {
- return this.status == 3;
- }
-
- public void appletResize(int var1, int var2) {
- this.appletSize.width = var1;
- this.appletSize.height = var2;
- ((Component)this).postEvent(new Event(this, 51234, this.preferredSize()));
- }
-
- public Applet getApplet() {
- return this.applet;
- }
-
- protected void showAppletStatus(String var1) {
- String var2 = System.getProperty(var1);
- if (var2 == null) {
- var2 = var1;
- }
-
- this.getAppletContext().showStatus(var2);
- }
-
- protected void showAppletLog(String var1) {
- String var2 = System.getProperty(var1);
- if (var2 == null) {
- var2 = var1;
- }
-
- System.out.println(var2);
- }
-
- protected void showAppletException(Throwable var1) {
- var1.printStackTrace();
- ((Component)this).repaint();
- }
-
- public static synchronized void flushClassLoader(URL var0) {
- classloaders.remove(var0);
- }
-
- public static synchronized void flushClassLoaders() {
- classloaders = new Hashtable();
- }
-
- static synchronized AppletClassLoader getClassLoader(URL var0) throws IOException {
- AppletClassLoader var1 = (AppletClassLoader)classloaders.get(var0);
- if (var1 == null) {
- var1 = new AppletClassLoader(var0);
- classloaders.put(var0, var1);
- }
-
- return var1;
- }
-
- public abstract URL getDocumentBase();
-
- public abstract URL getCodeBase();
-
- public abstract String getParameter(String var1);
-
- public abstract AppletContext getAppletContext();
- }
-