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.
This commit is contained in:
@@ -93,6 +93,16 @@ public class Application
|
|||||||
|
|
||||||
/** Where to point the user for help with install errors. */
|
/** Where to point the user for help with install errors. */
|
||||||
public String installError;
|
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
|
/** 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) {
|
for (String jvmarg : _jvmargs) {
|
||||||
if (jvmarg.startsWith("-D")) {
|
if (jvmarg.startsWith("-D")) {
|
||||||
jvmarg = processArg(jvmarg.substring(2));
|
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 {
|
try {
|
||||||
Class<?> appclass = loader.loadClass(_class);
|
Class<?> appclass = loader.loadClass(_class);
|
||||||
Method main = appclass.getMethod("main", SA_PROTO.getClass());
|
Method main = appclass.getMethod("main", SA_PROTO.getClass());
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package com.threerings.getdown.launcher;
|
|||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.EventQueue;
|
import java.awt.EventQueue;
|
||||||
|
import java.awt.Image;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@@ -93,6 +94,7 @@ public abstract class Getdown extends Thread
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
_ifc = _app.init(true);
|
_ifc = _app.init(true);
|
||||||
|
createInterface(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.warning("Failed to preinit: " + e);
|
Log.warning("Failed to preinit: " + e);
|
||||||
}
|
}
|
||||||
@@ -544,14 +546,28 @@ public abstract class Getdown extends Thread
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// load up our background and progress bar images
|
EventQueue.invokeLater(new Runnable() {
|
||||||
BufferedImage bgimg = loadImage(_ifc.backgroundImage);
|
public void run () {
|
||||||
BufferedImage barimg = loadImage(_ifc.progressImage);
|
if (_status == null) {
|
||||||
|
_container = createContainer();
|
||||||
|
_status = new StatusPanel(_msgs);
|
||||||
|
_container.add(_status, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
_status.init(_ifc, getBackgroundImage(),
|
||||||
|
getProgressImage());
|
||||||
|
showContainer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_container = createContainer();
|
protected Image getBackgroundImage ()
|
||||||
_status = new StatusPanel(_msgs, _ifc, bgimg, barimg);
|
{
|
||||||
_container.add(_status, BorderLayout.CENTER);
|
return loadImage(_ifc.backgroundImage);
|
||||||
showContainer();
|
}
|
||||||
|
|
||||||
|
protected Image getProgressImage ()
|
||||||
|
{
|
||||||
|
return loadImage(_ifc.progressImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleWindowClose ()
|
protected void handleWindowClose ()
|
||||||
|
|||||||
@@ -4,8 +4,12 @@
|
|||||||
package com.threerings.getdown.launcher;
|
package com.threerings.getdown.launcher;
|
||||||
|
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
|
import java.awt.EventQueue;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
import javax.swing.JApplet;
|
import javax.swing.JApplet;
|
||||||
|
import javax.swing.JPanel;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import java.io.IOException;
|
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
|
// record a few things for posterity
|
||||||
Log.info("------------------ VM Info ------------------");
|
Log.info("------------------ VM Info ------------------");
|
||||||
Log.info("-- OS Name: " + System.getProperty("os.name"));
|
Log.info("-- OS Name: " + System.getProperty("os.name"));
|
||||||
@@ -92,25 +107,25 @@ public class GetdownApplet extends JApplet
|
|||||||
return getContentPane();
|
return getContentPane();
|
||||||
}
|
}
|
||||||
protected void showContainer () {
|
protected void showContainer () {
|
||||||
invalidate();
|
((JPanel)getContentPane()).revalidate();
|
||||||
}
|
}
|
||||||
protected void disposeContainer () {
|
protected void disposeContainer () {
|
||||||
|
// nothing to do as we're in an applet
|
||||||
}
|
}
|
||||||
protected boolean invokeDirect () {
|
protected boolean invokeDirect () {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
protected Image getBackgroundImage () {
|
||||||
|
return _bgimage == null ?
|
||||||
|
super.getBackgroundImage() : _bgimage;
|
||||||
|
}
|
||||||
protected void exit (int exitCode) {
|
protected void exit (int exitCode) {
|
||||||
Log.info("Applet \"exiting\".");
|
|
||||||
// don't exit as we're in an applet
|
// don't exit as we're in an applet
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
SwingUtilities.invokeAndWait(new Runnable() {
|
// set up our user interface immediately
|
||||||
public void run () {
|
_getdown.preInit();
|
||||||
_getdown.preInit();
|
|
||||||
_getdown.createInterface(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.logStackTrace(e);
|
Log.logStackTrace(e);
|
||||||
@@ -134,4 +149,5 @@ public class GetdownApplet extends JApplet
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Getdown _getdown;
|
protected Getdown _getdown;
|
||||||
|
protected Image _bgimage;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.awt.Dimension;
|
|||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Image;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
@@ -30,10 +31,13 @@ import com.threerings.getdown.data.Application.UpdateInterface;
|
|||||||
*/
|
*/
|
||||||
public class StatusPanel extends JComponent
|
public class StatusPanel extends JComponent
|
||||||
{
|
{
|
||||||
public StatusPanel (ResourceBundle msgs, UpdateInterface ifc,
|
public StatusPanel (ResourceBundle msgs)
|
||||||
BufferedImage bgimg, BufferedImage barimg)
|
|
||||||
{
|
{
|
||||||
_msgs = msgs;
|
_msgs = msgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init (UpdateInterface ifc, Image bgimg, Image barimg)
|
||||||
|
{
|
||||||
_ifc = ifc;
|
_ifc = ifc;
|
||||||
_bgimg = bgimg;
|
_bgimg = bgimg;
|
||||||
if (bgimg == null) {
|
if (bgimg == null) {
|
||||||
@@ -41,7 +45,7 @@ public class StatusPanel extends JComponent
|
|||||||
bounds.grow(5, 5);
|
bounds.grow(5, 5);
|
||||||
_psize = bounds.getSize();
|
_psize = bounds.getSize();
|
||||||
} else {
|
} else {
|
||||||
_psize = new Dimension(bgimg.getWidth(), bgimg.getHeight());
|
_psize = new Dimension(bgimg.getWidth(null), bgimg.getHeight(null));
|
||||||
}
|
}
|
||||||
_barimg = barimg;
|
_barimg = barimg;
|
||||||
}
|
}
|
||||||
@@ -236,7 +240,7 @@ public class StatusPanel extends JComponent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BufferedImage _bgimg, _barimg;
|
protected Image _bgimg, _barimg;
|
||||||
protected Dimension _psize;
|
protected Dimension _psize;
|
||||||
|
|
||||||
protected ResourceBundle _msgs;
|
protected ResourceBundle _msgs;
|
||||||
|
|||||||
Reference in New Issue
Block a user