From 71f78110e825fce3838bcf30edf23add4bd761ce Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 7 Jun 2006 02:04:33 +0000 Subject: [PATCH] More work on applet mode. Fixed up first time operation, made it possible to pass an image from the applet for use as the background image. --- .../threerings/getdown/data/Application.java | 23 +++++++++++++ .../threerings/getdown/launcher/Getdown.java | 30 +++++++++++++---- .../getdown/launcher/GetdownApplet.java | 32 ++++++++++++++----- .../getdown/launcher/StatusPanel.java | 12 ++++--- 4 files changed, 78 insertions(+), 19 deletions(-) diff --git a/src/java/com/threerings/getdown/data/Application.java b/src/java/com/threerings/getdown/data/Application.java index 00bac5d..45bb0c6 100644 --- a/src/java/com/threerings/getdown/data/Application.java +++ b/src/java/com/threerings/getdown/data/Application.java @@ -93,6 +93,16 @@ public class Application /** Where to point the user for help with install errors. */ public String installError; + + /** Generates a string representation of this instance. */ + public String toString () + { + return "[name=" + name + ", bg=" + backgroundImage + + ", pi=" + progressImage + ", prect=" + progress + + ", pt=" + progressText + ", pb=" + progressBar + + ", srect=" + status + ", st=" + statusText + + ", shadow=" + textShadow + ", err=" + installError + "]"; + } } /** Used by {@link #verifyMetadata} to communicate status in @@ -520,6 +530,7 @@ public class Application } }; + // configure any system properties that we can for (String jvmarg : _jvmargs) { if (jvmarg.startsWith("-D")) { jvmarg = processArg(jvmarg.substring(2)); @@ -533,6 +544,18 @@ public class Application } } + // pass along any pass-through arguments + for (Map.Entry entry : System.getProperties().entrySet()) { + String key = (String)entry.getKey(); + if (key.startsWith(PROP_PASSTHROUGH_PREFIX)) { + key = key.substring(PROP_PASSTHROUGH_PREFIX.length()); + System.setProperty(key, (String)entry.getValue()); + } + } + + // make a note that we're running in "applet" mode + System.setProperty("applet", "true"); + try { Class appclass = loader.loadClass(_class); Method main = appclass.getMethod("main", SA_PROTO.getClass()); diff --git a/src/java/com/threerings/getdown/launcher/Getdown.java b/src/java/com/threerings/getdown/launcher/Getdown.java index c601ce4..aed1726 100644 --- a/src/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/java/com/threerings/getdown/launcher/Getdown.java @@ -6,6 +6,7 @@ package com.threerings.getdown.launcher; import java.awt.BorderLayout; import java.awt.Container; import java.awt.EventQueue; +import java.awt.Image; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; @@ -93,6 +94,7 @@ public abstract class Getdown extends Thread { try { _ifc = _app.init(true); + createInterface(true); } catch (Exception e) { Log.warning("Failed to preinit: " + e); } @@ -544,14 +546,28 @@ public abstract class Getdown extends Thread return; } - // load up our background and progress bar images - BufferedImage bgimg = loadImage(_ifc.backgroundImage); - BufferedImage barimg = loadImage(_ifc.progressImage); + EventQueue.invokeLater(new Runnable() { + public void run () { + if (_status == null) { + _container = createContainer(); + _status = new StatusPanel(_msgs); + _container.add(_status, BorderLayout.CENTER); + } + _status.init(_ifc, getBackgroundImage(), + getProgressImage()); + showContainer(); + } + }); + } - _container = createContainer(); - _status = new StatusPanel(_msgs, _ifc, bgimg, barimg); - _container.add(_status, BorderLayout.CENTER); - showContainer(); + protected Image getBackgroundImage () + { + return loadImage(_ifc.backgroundImage); + } + + protected Image getProgressImage () + { + return loadImage(_ifc.progressImage); } protected void handleWindowClose () diff --git a/src/java/com/threerings/getdown/launcher/GetdownApplet.java b/src/java/com/threerings/getdown/launcher/GetdownApplet.java index cb80680..7b7c742 100644 --- a/src/java/com/threerings/getdown/launcher/GetdownApplet.java +++ b/src/java/com/threerings/getdown/launcher/GetdownApplet.java @@ -4,8 +4,12 @@ package com.threerings.getdown.launcher; import java.awt.Container; +import java.awt.EventQueue; +import java.awt.Image; +import java.net.URL; import javax.swing.JApplet; +import javax.swing.JPanel; import javax.swing.SwingUtilities; import java.io.IOException; @@ -73,6 +77,17 @@ public class GetdownApplet extends JApplet } } + // if a background image was specified, grabbit + String imgpath = getParameter("bgimage"); + try { + if (!StringUtil.isBlank(imgpath)) { + _bgimage = getImage(new URL(getDocumentBase(), imgpath)); + } + } catch (Exception e) { + Log.info("Failed to load background image [path=" + imgpath + "]."); + Log.logStackTrace(e); + } + // record a few things for posterity Log.info("------------------ VM Info ------------------"); Log.info("-- OS Name: " + System.getProperty("os.name")); @@ -92,25 +107,25 @@ public class GetdownApplet extends JApplet return getContentPane(); } protected void showContainer () { - invalidate(); + ((JPanel)getContentPane()).revalidate(); } protected void disposeContainer () { + // nothing to do as we're in an applet } protected boolean invokeDirect () { return true; } + protected Image getBackgroundImage () { + return _bgimage == null ? + super.getBackgroundImage() : _bgimage; + } protected void exit (int exitCode) { - Log.info("Applet \"exiting\"."); // don't exit as we're in an applet } }; - SwingUtilities.invokeAndWait(new Runnable() { - public void run () { - _getdown.preInit(); - _getdown.createInterface(false); - } - }); + // set up our user interface immediately + _getdown.preInit(); } catch (Exception e) { Log.logStackTrace(e); @@ -134,4 +149,5 @@ public class GetdownApplet extends JApplet } protected Getdown _getdown; + protected Image _bgimage; } diff --git a/src/java/com/threerings/getdown/launcher/StatusPanel.java b/src/java/com/threerings/getdown/launcher/StatusPanel.java index 30a819c..38e5488 100644 --- a/src/java/com/threerings/getdown/launcher/StatusPanel.java +++ b/src/java/com/threerings/getdown/launcher/StatusPanel.java @@ -7,6 +7,7 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Graphics; +import java.awt.Image; import java.awt.Rectangle; import java.awt.image.BufferedImage; @@ -30,10 +31,13 @@ import com.threerings.getdown.data.Application.UpdateInterface; */ public class StatusPanel extends JComponent { - public StatusPanel (ResourceBundle msgs, UpdateInterface ifc, - BufferedImage bgimg, BufferedImage barimg) + public StatusPanel (ResourceBundle msgs) { _msgs = msgs; + } + + public void init (UpdateInterface ifc, Image bgimg, Image barimg) + { _ifc = ifc; _bgimg = bgimg; if (bgimg == null) { @@ -41,7 +45,7 @@ public class StatusPanel extends JComponent bounds.grow(5, 5); _psize = bounds.getSize(); } else { - _psize = new Dimension(bgimg.getWidth(), bgimg.getHeight()); + _psize = new Dimension(bgimg.getWidth(null), bgimg.getHeight(null)); } _barimg = barimg; } @@ -236,7 +240,7 @@ public class StatusPanel extends JComponent } } - protected BufferedImage _bgimg, _barimg; + protected Image _bgimg, _barimg; protected Dimension _psize; protected ResourceBundle _msgs;