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.Panel;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.ObjectInputStream;
- import java.net.URL;
- import java.util.Hashtable;
- import java.util.StringTokenizer;
- import sun.misc.MessageUtils;
- import sun.misc.Queue;
-
- public abstract class AppletPanel extends Panel implements AppletStub, Runnable {
- static boolean debug;
- Applet applet;
- protected boolean doInit = true;
- AppletClassLoader loader;
- 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;
- protected int status;
- Thread handler;
- Dimension appletSize = new Dimension(100, 100);
- // $FF: renamed from: mu sun.misc.MessageUtils
- MessageUtils field_0 = new MessageUtils();
- Thread loaderThread;
- boolean loadAbortRequest = false;
- private AppletListener listeners;
- private Queue queue;
- private static Hashtable classloaders = new Hashtable();
- private static AppletMessageHandler amh = new AppletMessageHandler("appletpanel");
-
- protected abstract String getCode();
-
- protected abstract int getWidth();
-
- protected abstract int getHeight();
-
- protected abstract String getJarFiles();
-
- protected abstract String getSerializedObject();
-
- public void init() {
- ((Container)this).setLayout(new BorderLayout());
-
- try {
- this.appletSize.width = this.getWidth();
- this.appletSize.height = this.getHeight();
- } catch (NumberFormatException var3) {
- this.status = 7;
- this.showAppletStatus("badattribute.exception");
- this.showAppletLog("badattribute.exception");
- this.showAppletException(var3);
- }
-
- String var1 = "applet-" + this.getCode();
- this.loader = this.getClassLoader(this.getCodeBase());
- ThreadGroup var2 = this.loader.getThreadGroup();
- this.handler = new Thread(var2, this, "thread " + var1);
- this.handler.start();
- }
-
- public Dimension minimumSize() {
- return new Dimension(this.appletSize.width, this.appletSize.height);
- }
-
- public Dimension preferredSize() {
- return this.minimumSize();
- }
-
- public synchronized void addAppletListener(AppletListener var1) {
- this.listeners = AppletEventMulticaster.add(this.listeners, var1);
- }
-
- public synchronized void removeAppletListener(AppletListener var1) {
- this.listeners = AppletEventMulticaster.remove(this.listeners, var1);
- }
-
- public void dispatchAppletEvent(int var1, Object var2) {
- if (this.listeners != null) {
- AppletEvent var3 = new AppletEvent(this, var1, var2);
- this.listeners.appletStateChanged(var3);
- }
-
- }
-
- public synchronized void sendEvent(int var1) {
- if (this.queue == null) {
- this.queue = new Queue();
- }
-
- Integer var2 = new Integer(var1);
- this.queue.enqueue(var2);
- this.notifyAll();
- }
-
- synchronized AppletEvent getNextEvent() throws InterruptedException {
- while(this.queue == null || this.queue.isEmpty()) {
- this.wait();
- }
-
- Integer var1 = (Integer)this.queue.dequeue();
- return new AppletEvent(this, var1, (Object)null);
- }
-
- public void run() {
- Thread var1 = Thread.currentThread();
- if (var1 == this.loaderThread) {
- this.runLoader();
- } else {
- while(true) {
- AppletEvent var2;
- try {
- var2 = this.getNextEvent();
- } catch (InterruptedException var4) {
- this.showAppletStatus("bail");
- return;
- }
-
- try {
- switch (var2.getID()) {
- case 0:
- if (this.status != 1) {
- this.showAppletStatus("notdestroyed");
- } else {
- this.status = 0;
- ((Container)this).remove(this.applet);
- this.applet = null;
- this.showAppletStatus("disposed");
- }
- break;
- case 1:
- if (this.okToLoad() && this.loaderThread == null) {
- this.setLoaderThread(new Thread(this));
- this.loaderThread.start();
- this.loaderThread.join();
- this.setLoaderThread((Thread)null);
- }
- break;
- case 2:
- if (this.status != 1) {
- this.showAppletStatus("notloaded");
- } else {
- this.applet.resize(this.appletSize);
- if (this.doInit) {
- this.applet.init();
- }
-
- this.doInit = true;
- ((Container)this).validate();
- this.status = 2;
- this.showAppletStatus("inited");
- }
- break;
- case 3:
- if (this.status != 2) {
- this.showAppletStatus("notinited");
- } else {
- this.applet.resize(this.appletSize);
- this.applet.start();
- ((Container)this).validate();
- this.applet.show();
- this.status = 3;
- this.showAppletStatus("started");
- }
- break;
- case 4:
- if (this.status != 3) {
- this.showAppletStatus("notstarted");
- } else {
- this.status = 2;
- this.applet.hide();
- this.applet.stop();
- this.showAppletStatus("stopped");
- }
- break;
- case 5:
- if (this.status != 2) {
- this.showAppletStatus("notstopped");
- } else {
- this.status = 1;
- this.applet.destroy();
- this.showAppletStatus("destroyed");
- }
- break;
- case 6:
- this.loader.getThreadGroup().stop();
- return;
- }
- } catch (Exception var5) {
- if (((Throwable)var5).getMessage() != null) {
- this.showAppletStatus("exception2", var5.getClass().getName(), ((Throwable)var5).getMessage());
- } else {
- this.showAppletStatus("exception", var5.getClass().getName());
- }
-
- this.showAppletException(var5);
- } catch (ThreadDeath var6) {
- this.showAppletStatus("death");
- return;
- } catch (Error var7) {
- if (((Throwable)var7).getMessage() != null) {
- this.showAppletStatus("error2", var7.getClass().getName(), ((Throwable)var7).getMessage());
- } else {
- this.showAppletStatus("error", var7.getClass().getName());
- }
-
- this.showAppletException(var7);
- }
-
- this.clearLoadAbortRequest();
- }
- }
- }
-
- private void runLoader() {
- if (this.status != 0) {
- this.showAppletStatus("notdisposed");
- } else {
- this.dispatchAppletEvent(51235, (Object)null);
- this.status = 1;
- this.loader = this.getClassLoader(this.getCodeBase());
- String var1 = this.getCode();
-
- label119: {
- try {
- this.loadJarFiles(this.loader);
- this.applet = this.createApplet(this.loader);
- break label119;
- } catch (ClassNotFoundException var12) {
- this.status = 7;
- this.showAppletStatus("notfound", var1);
- this.showAppletLog("notfound", var1);
- this.showAppletException(var12);
- } catch (InstantiationException var13) {
- this.status = 7;
- this.showAppletStatus("nocreate", var1);
- this.showAppletLog("nocreate", var1);
- this.showAppletException(var13);
- return;
- } catch (IllegalAccessException var14) {
- this.status = 7;
- this.showAppletStatus("noconstruct", var1);
- this.showAppletLog("noconstruct", var1);
- this.showAppletException(var14);
- return;
- } catch (Exception var15) {
- this.status = 7;
- this.showAppletStatus("exception", ((Throwable)var15).getMessage());
- this.showAppletException(var15);
- return;
- } catch (ThreadDeath var16) {
- this.status = 7;
- this.showAppletStatus("death");
- return;
- } catch (Error var17) {
- this.status = 7;
- this.showAppletStatus("error", ((Throwable)var17).getMessage());
- this.showAppletException(var17);
- return;
- } finally {
- this.dispatchAppletEvent(51236, (Object)null);
- }
-
- return;
- }
-
- this.applet.setStub(this);
- this.applet.hide();
- ((Container)this).add("Center", this.applet);
- this.showAppletStatus("loaded");
- ((Container)this).validate();
- }
- }
-
- protected Applet createApplet(AppletClassLoader var1) throws ClassNotFoundException, IllegalAccessException, IOException, InstantiationException, InterruptedException {
- String var2 = this.getSerializedObject();
- String var3 = this.getCode();
- if (var3 != null && var2 != null) {
- System.err.println(amh.getMessage("runloader.err"));
- return null;
- } else {
- if (var3 == null && var2 == null) {
- String var4 = "nocode";
- this.status = 7;
- this.showAppletStatus(var4);
- this.showAppletLog(var4);
- ((Component)this).repaint();
- }
-
- if (var3 != null) {
- this.applet = (Applet)var1.loadCode(var3).newInstance();
- this.doInit = true;
- } else {
- InputStream var9 = var1.getResourceAsStream(var2);
- AppletObjectInputStream var5 = new AppletObjectInputStream(var9, var1);
- Object var6 = ((ObjectInputStream)var5).readObject();
- this.applet = (Applet)var6;
- this.doInit = false;
- }
-
- if (Thread.interrupted()) {
- try {
- this.status = 0;
- this.applet = null;
- this.showAppletStatus("death");
- } finally {
- ;
- }
-
- Thread.currentThread().interrupt();
- return null;
- } else {
- return this.applet;
- }
- }
- }
-
- protected void loadJarFiles(AppletClassLoader var1) throws IOException, InterruptedException {
- debug("AppletPanel:CTOR: get list of JarFiles");
- String var2 = this.getJarFiles();
- if (var2 == null) {
- debug("No jar files specified");
- } else {
- debug("archive parameter is \"" + var2 + "\"");
- AppletResourceLoader var3 = var1.getResourceLoader();
- StringTokenizer var4 = new StringTokenizer(var2, ",", false);
-
- while(var4.hasMoreTokens()) {
- String var5 = var4.nextToken().trim();
- debug("load archive for codebase " + this.getCodeBase() + ", file " + var5);
- var3.loadJar(this.getCodeBase(), var5);
- }
-
- }
- }
-
- 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;
- this.dispatchAppletEvent(51234, this.preferredSize());
- }
-
- public Applet getApplet() {
- return this.applet;
- }
-
- protected void showAppletStatus(String var1) {
- this.getAppletContext().showStatus(amh.getMessage(var1));
- }
-
- protected void showAppletStatus(String var1, Object var2) {
- this.getAppletContext().showStatus(amh.getMessage(var1, var2));
- }
-
- protected void showAppletStatus(String var1, Object var2, Object var3) {
- this.getAppletContext().showStatus(amh.getMessage(var1, var2, var3));
- }
-
- protected void showAppletLog(String var1) {
- System.out.println(amh.getMessage(var1));
- }
-
- protected void showAppletLog(String var1, Object var2) {
- System.out.println(amh.getMessage(var1, 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();
- }
-
- synchronized AppletClassLoader getClassLoader(URL var1) {
- AppletClassLoader var2 = (AppletClassLoader)classloaders.get(var1);
- if (var2 == null) {
- var2 = new AppletClassLoader(var1);
- classloaders.put(var1, var2);
- }
-
- return var2;
- }
-
- public Thread getAppletHandlerThread() {
- return this.handler;
- }
-
- public int getAppletWidth() {
- return this.appletSize.width;
- }
-
- public int getAppletHeight() {
- return this.appletSize.height;
- }
-
- static void debug(String var0) {
- if (debug) {
- System.err.println("AppletPanel:::" + var0);
- }
-
- }
-
- static void debug(String var0, Throwable var1) {
- if (debug) {
- var1.printStackTrace();
- debug(var0);
- }
-
- }
-
- public abstract URL getDocumentBase();
-
- public abstract URL getCodeBase();
-
- public abstract String getParameter(String var1);
-
- public abstract AppletContext getAppletContext();
- }
-