If specified, swap in a background image from ui.error_background in

getdown.txt or the errorbgimage param in the applet if getdown fails.
This commit is contained in:
Charlie Groves
2008-03-07 06:20:40 +00:00
parent d97c3431e3
commit cb6732e1cb
5 changed files with 78 additions and 29 deletions
@@ -65,7 +65,6 @@ import com.samskivert.util.ArrayIntSet;
import com.samskivert.util.RunAnywhere;
import com.samskivert.util.StringUtil;
import com.threerings.getdown.Log;
import com.threerings.getdown.launcher.MultipleGetdownRunning;
import com.threerings.getdown.launcher.RotatingBackgrounds;
import com.threerings.getdown.util.ConfigUtil;
import com.threerings.getdown.util.FileUtil;
@@ -100,6 +99,9 @@ public class Application
/** Background image specifiers for {@link RotatingBackgrounds}. */
public String[] rotatingBackgrounds;
/** The error background image for {@link RotatingBackgrounds}. */
public String errorBackground;
/** The path (relative to the appdir) to a single background image. */
public String backgroundImage;
@@ -582,6 +584,7 @@ public class Application
}
ui.progressImage = (String)cdata.get("ui.progress_image");
ui.rotatingBackgrounds = ConfigUtil.getMultiValue(cdata, "ui.rotating_background");
ui.errorBackground = (String)cdata.get("ui.error_background");
_dockIconPath = (String)cdata.get("ui.mac_dock_icon");
if (_dockIconPath == null) {
_dockIconPath = "../desktop.icns"; // use a sensible default
@@ -114,8 +114,7 @@ public abstract class Getdown extends Thread
}
String errmsg = "The directory in which this application is installed:\n" + dir +
"\nis invalid. The directory must not contain the '!' character. Please reinstall.";
updateStatus(errmsg);
_dead = true;
fail(errmsg);
}
_app = new Application(appDir, appId, signers, useLocks());
_startup = System.currentTimeMillis();
@@ -151,8 +150,7 @@ public abstract class Getdown extends Thread
if (path.equals(".")) {
path = System.getProperty("user.dir");
}
updateStatus(MessageUtil.tcompose("m.readonly_error", path));
_dead = true;
fail(MessageUtil.tcompose("m.readonly_error", path));
return;
}
@@ -186,8 +184,7 @@ public abstract class Getdown extends Thread
"m.init_error", MessageUtil.taint(msg), _ifc.installError);
}
}
updateStatus(msg);
_dead = true;
fail(msg);
}
}
@@ -477,9 +474,8 @@ public abstract class Getdown extends Thread
}
// Since we're dead, clear off the 'time remaining' label along with displaying the
// error message
setStatus(msg, 0, -1L, true);
fail(msg);
_app.releaseLock();
_dead = true;
}
}
@@ -775,10 +771,12 @@ public abstract class Getdown extends Thread
/**
* Creates our user interface, which we avoid doing unless we actually have to update
* something.
*
* @param reinit - if the interface should be reinitialized if it already exists.
*/
protected void createInterface (boolean force)
protected void createInterface (final boolean reinit)
{
if (_silent || (_container != null && !force)) {
if (_silent || (_container != null && !reinit)) {
return;
}
@@ -788,19 +786,29 @@ public abstract class Getdown extends Thread
_container = createContainer();
_status = new StatusPanel(_msgs);
_container.add(_status, BorderLayout.CENTER);
initInterface();
} else if (reinit) {
initInterface();
}
RotatingBackgrounds newBackgrounds = getBackground();
if (_background == null || newBackgrounds.getNumImages() > 0) {
// Leave the old _background in place if there is an ond one to leave in place
// and the new getdown.txt didn't yield any images.
_background = newBackgrounds;
}
_status.init(_ifc, _background, getProgressImage());
showContainer();
}
});
}
/**
* Initializes the interface with the current UpdateInterface and backgrounds.
*/
protected void initInterface ()
{
RotatingBackgrounds newBackgrounds = getBackground();
if (_background == null || newBackgrounds.getNumImages() > 0) {
// Leave the old _background in place if there is an old one to leave in place
// and the new getdown.txt didn't yield any images.
_background = newBackgrounds;
}
_status.init(_ifc, _background, getProgressImage());
}
protected RotatingBackgrounds getBackground ()
{
if (_ifc.rotatingBackgrounds != null) {
@@ -808,7 +816,8 @@ public abstract class Getdown extends Thread
Log.warning("ui.background_image and ui.rotating_background were both specified. " +
"The rotating images are being used.");
}
return new RotatingBackgrounds(_ifc.rotatingBackgrounds, Getdown.this);
return new RotatingBackgrounds(_ifc.rotatingBackgrounds, _ifc.errorBackground,
Getdown.this);
} else if (_ifc.backgroundImage != null) {
return new RotatingBackgrounds(loadImage(_ifc.backgroundImage));
} else {
@@ -836,6 +845,14 @@ public abstract class Getdown extends Thread
_abort.requestFocus();
}
}
/**
* Update the status to indicate getdown has failed for the reason in <code>message</code>.
*/
protected void fail(String message){
_dead = true;
setStatus(message, 0, -1L, true);
}
protected void setStatus (
final String message, final int percent, final long remaining, boolean createUI)
@@ -847,15 +864,19 @@ public abstract class Getdown extends Thread
EventQueue.invokeLater(new Runnable() {
public void run () {
if (_status == null) {
Log.info("Dropping status '" + message + "'.");
if (message != null) {
Log.info("Dropping status '" + message + "'.");
}
return;
}
if (message != null) {
_status.setStatus(message);
_status.setStatus(message, _dead);
}
if (percent >= 0) {
if (_dead) {
_status.setProgress(0, -1L);
} else if (percent >= 0) {
_status.setProgress(percent, remaining);
}
}
}
});
}
@@ -50,7 +50,8 @@ public class GetdownApplet extends JApplet
// signer
String appbase = getParameter("appbase");
String appname = getParameter("appname");
String imgpath = getParameter("bgimage");;
String imgpath = getParameter("bgimage");
String errorimgpath = getParameter("errorbgimage");
if (appbase == null) {
appbase = "";
}
@@ -62,7 +63,7 @@ public class GetdownApplet extends JApplet
if (imgpath == null) {
bgimages = new RotatingBackgrounds();
} else if (imgpath.indexOf(",") > -1) {
bgimages = new RotatingBackgrounds(imgpath.split(","), this);
bgimages = new RotatingBackgrounds(imgpath.split(","), errorimgpath, this);
} else {
bgimages = new RotatingBackgrounds(loadImage(imgpath));
}
@@ -159,7 +160,7 @@ public class GetdownApplet extends JApplet
public void start ()
{
if (_errmsg != null) {
_getdown.updateStatus(_errmsg);
_getdown.fail(_errmsg);
} else {
try {
_getdown.start();
@@ -21,6 +21,7 @@ public class RotatingBackgrounds
percentages = new int[] { 0 };
minDisplayTime = new int[] { 0 };
images = new Image[] { background };
errorImage = images[0];
}
/**
@@ -32,7 +33,7 @@ public class RotatingBackgrounds
* time when the next should be shown. In that case, it's left up until its been there for its
* minimum display time and then the next one gets to come up.
*/
public RotatingBackgrounds (String[] backgrounds, ImageLoader loader)
public RotatingBackgrounds (String[] backgrounds, String errorBackground, ImageLoader loader)
{
percentages = new int[backgrounds.length];
minDisplayTime = new int[backgrounds.length];
@@ -55,6 +56,11 @@ public class RotatingBackgrounds
}
percentages[ii] = (int)((ii/(float)backgrounds.length) * 100);
}
if (errorBackground == null) {
errorImage = images[0];
} else {
errorImage = loader.loadImage(errorBackground);
}
}
/**
@@ -75,6 +81,14 @@ public class RotatingBackgrounds
return images[current];
}
/**
* Returns the image to display if an error has caused getdown to fail.
*/
public Image getErrorImage ()
{
return errorImage;
}
/**
* @return the number of images in this RotatingBackgrounds
*/
@@ -97,6 +111,9 @@ public class RotatingBackgrounds
protected Image[] images;
/** The image to display if getdown has failed due to an error. */
protected Image errorImage;
/** Percentage at which each image should be displayed. */
protected int[] percentages;
@@ -113,8 +113,9 @@ public class StatusPanel extends JComponent
/**
* Displays the specified status string.
*/
public void setStatus (String status)
public void setStatus (String status, boolean displayError)
{
_displayError = displayError;
status = xlate(status);
_newlab = new Label(status, _ifc.statusText, _font);
_newlab.setTargetWidth(Math.min(_ifc.status.width, getWidth() - _ifc.status.x*2));
@@ -131,7 +132,12 @@ public class StatusPanel extends JComponent
super.paintComponent(g);
Graphics2D gfx = (Graphics2D)g;
Image img = _bg.getImage(_progress);
Image img;
if (_displayError) {
img = _bg.getErrorImage();
} else {
img = _bg.getImage(_progress);
}
if (img != null) {
gfx.drawImage(img, 0, 0, null);
} else {
@@ -263,6 +269,7 @@ public class StatusPanel extends JComponent
protected ResourceBundle _msgs;
protected int _progress = 0;
protected boolean _displayError;
protected Label _label, _newlab;
protected Label _plabel, _newplab;