Various purdifications and improvements.

This commit is contained in:
Michael Bayne
2004-07-26 17:52:32 +00:00
parent 9ff27d3c26
commit 119541f527
4 changed files with 78 additions and 22 deletions
@@ -1,8 +1,9 @@
// //
// $Id: Application.java,v 1.14 2004/07/20 07:35:56 mdb Exp $ // $Id: Application.java,v 1.15 2004/07/26 17:52:32 mdb Exp $
package com.threerings.getdown.data; package com.threerings.getdown.data;
import java.awt.Color;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.io.BufferedReader; import java.io.BufferedReader;
@@ -57,9 +58,18 @@ public class Application
/** The dimensions of the progress bar. */ /** The dimensions of the progress bar. */
public Rectangle progress; public Rectangle progress;
/** The color of the progress text. */
public Color progressText;
/** The color of the progress bar. */
public Color progressBar;
/** The dimensions of the status display. */ /** The dimensions of the status display. */
public Rectangle status; public Rectangle status;
/** The color of the status text. */
public Color statusText;
/** The path (relative to the appdir) to the background image. */ /** The path (relative to the appdir) to the background image. */
public String background; public String background;
} }
@@ -265,7 +275,13 @@ public class Application
ui.name = (String)cdata.get("ui.name"); ui.name = (String)cdata.get("ui.name");
ui.progress = parseRect( ui.progress = parseRect(
"ui.progress", (String)cdata.get("ui.progress")); "ui.progress", (String)cdata.get("ui.progress"));
ui.progressText = parseColor(
"ui.progress_text", (String)cdata.get("ui.progress_text"));
ui.progressBar = parseColor(
"ui.progress_bar", (String)cdata.get("ui.progress_bar"));
ui.status = parseRect("ui.progress", (String)cdata.get("ui.status")); ui.status = parseRect("ui.progress", (String)cdata.get("ui.status"));
ui.statusText = parseColor(
"ui.status_text", (String)cdata.get("ui.status_text"));
ui.background = (String)cdata.get("ui.background"); ui.background = (String)cdata.get("ui.background");
return ui; return ui;
} }
@@ -422,6 +438,7 @@ public class Application
// have also changed // have also changed
String olddig = (_digest == null) ? "" : _digest.getMetaDigest(); String olddig = (_digest == null) ? "" : _digest.getMetaDigest();
try { try {
status.updateStatus("m.checking");
downloadControlFile(Digest.DIGEST_FILE); downloadControlFile(Digest.DIGEST_FILE);
_digest = new Digest(_appdir); _digest = new Digest(_appdir);
if (!olddig.equals(_digest.getMetaDigest())) { if (!olddig.equals(_digest.getMetaDigest())) {
@@ -643,6 +660,20 @@ public class Application
return null; return null;
} }
/** Used to parse color specifications from the config file. */
protected Color parseColor (String name, String value)
{
if (!StringUtil.blank(value)) {
try {
return new Color(Integer.parseInt(value, 16));
} catch (Exception e) {
Log.warning("Ignoring invalid '" + name + "' config '" +
value + "'.");
}
}
return Color.white;
}
protected File _appdir; protected File _appdir;
protected File _config; protected File _config;
protected Digest _digest; protected Digest _digest;
@@ -1,5 +1,5 @@
// //
// $Id: Getdown.java,v 1.15 2004/07/20 01:27:32 mdb Exp $ // $Id: Getdown.java,v 1.16 2004/07/26 17:52:32 mdb Exp $
package com.threerings.getdown.launcher; package com.threerings.getdown.launcher;
@@ -46,6 +46,7 @@ public class Getdown extends Thread
super("Getdown"); super("Getdown");
_app = new Application(appDir); _app = new Application(appDir);
_msgs = ResourceBundle.getBundle("com.threerings.getdown.messages"); _msgs = ResourceBundle.getBundle("com.threerings.getdown.messages");
_startup = System.currentTimeMillis();
} }
public void run () public void run ()
@@ -56,8 +57,13 @@ public class Getdown extends Thread
_ifc = _app.init(); _ifc = _app.init();
} catch (IOException ioe) { } catch (IOException ioe) {
Log.warning("Failed to parse 'getdown.txt': " + ioe); Log.warning("Failed to parse 'getdown.txt': " + ioe);
createInterface();
_app.attemptRecovery(); _app.attemptRecovery();
// and re-initalize
_ifc = _app.init(); _ifc = _app.init();
// now clear out our UI as we probably have a new one
_frame.dispose();
_frame = null;
} }
for (int ii = 0; ii < MAX_LOOPS; ii++) { for (int ii = 0; ii < MAX_LOOPS; ii++) {
@@ -209,6 +215,18 @@ public class Getdown extends Thread
try { try {
Process proc = _app.createProcess(); Process proc = _app.createProcess();
// if we have a UI open and we haven't been around for at
// least 5 seconds, don't stick a fork in ourselves straight
// away but give our lovely user a chance to see what we're
// doing
long uptime = System.currentTimeMillis() - _startup;
if (_frame != null && uptime < MIN_EXIST_TIME) {
try {
Thread.sleep(MIN_EXIST_TIME - uptime);
} catch (Exception e) {
}
}
System.exit(0); System.exit(0);
} catch (IOException ioe) { } catch (IOException ioe) {
Log.logStackTrace(ioe); Log.logStackTrace(ioe);
@@ -246,7 +264,7 @@ public class Getdown extends Thread
// create our user interface, and display it // create our user interface, and display it
_frame = new JFrame(StringUtil.blank(_ifc.name) ? "" : _ifc.name); _frame = new JFrame(StringUtil.blank(_ifc.name) ? "" : _ifc.name);
_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); _frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_status = new StatusPanel(_msgs, bounds, bgimg, ppos, spos); _status = new StatusPanel(_msgs, bounds, bgimg, ppos, spos, _ifc);
_frame.getContentPane().add(_status, BorderLayout.CENTER); _frame.getContentPane().add(_status, BorderLayout.CENTER);
_frame.pack(); _frame.pack();
SwingUtil.centerWindow(_frame); SwingUtil.centerWindow(_frame);
@@ -329,7 +347,10 @@ public class Getdown extends Thread
protected JFrame _frame; protected JFrame _frame;
protected StatusPanel _status; protected StatusPanel _status;
protected long _startup;
protected static final int MAX_LOOPS = 5; protected static final int MAX_LOOPS = 5;
protected static final long MIN_EXIST_TIME = 5000L;
protected static final Rectangle DEFAULT_PPOS = protected static final Rectangle DEFAULT_PPOS =
new Rectangle(5, 5, 300, 15); new Rectangle(5, 5, 300, 15);
@@ -1,12 +1,11 @@
// //
// $Id: StatusPanel.java,v 1.5 2004/07/20 01:25:06 mdb Exp $ // $Id: StatusPanel.java,v 1.6 2004/07/26 17:52:32 mdb Exp $
package com.threerings.getdown.launcher; package com.threerings.getdown.launcher;
import java.awt.AlphaComposite;
import java.awt.Color; import java.awt.Color;
import java.awt.Composite;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Rectangle; import java.awt.Rectangle;
@@ -24,6 +23,7 @@ import com.samskivert.text.MessageUtil;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import com.threerings.getdown.Log; import com.threerings.getdown.Log;
import com.threerings.getdown.data.Application.UpdateInterface;
/** /**
* Displays download and patching status. * Displays download and patching status.
@@ -31,13 +31,15 @@ import com.threerings.getdown.Log;
public class StatusPanel extends JComponent public class StatusPanel extends JComponent
{ {
public StatusPanel (ResourceBundle msgs, Rectangle bounds, public StatusPanel (ResourceBundle msgs, Rectangle bounds,
BufferedImage bgimg, Rectangle ppos, Rectangle spos) BufferedImage bgimg, Rectangle ppos, Rectangle spos,
UpdateInterface ifc)
{ {
_msgs = msgs; _msgs = msgs;
_bgimg = bgimg; _bgimg = bgimg;
_psize = new Dimension(bounds.width, bounds.height); _psize = new Dimension(bounds.width, bounds.height);
_ppos = ppos; _ppos = ppos;
_spos = spos; _spos = spos;
_ifc = ifc;
} }
/** /**
@@ -46,11 +48,17 @@ public class StatusPanel extends JComponent
public void setProgress (int percent, long remaining) public void setProgress (int percent, long remaining)
{ {
_progress = percent; _progress = percent;
String msg = (remaining > 1) ? "m.complete_remain" : "m.complete"; String msg = "m.complete";
int minutes = 0, seconds = 0;
if (remaining > 1) {
msg = "m.complete_remain";
minutes = (int)(remaining / 60);
seconds = (int)(remaining % 60);
}
msg = get(msg); msg = get(msg);
String label = MessageFormat.format(msg, new Object[] { String label = MessageFormat.format(msg, new Object[] {
new Integer(percent), new Long(remaining) }); new Integer(percent), new Integer(minutes), new Integer(seconds) });
_newplab = new Label(label); _newplab = new Label(label, _ifc.progressText, _pfont);
repaint(); repaint();
} }
@@ -60,7 +68,7 @@ public class StatusPanel extends JComponent
public void setStatus (String status) public void setStatus (String status)
{ {
status = xlate(status); status = xlate(status);
_newlab = new Label(status, _lcolor, null); _newlab = new Label(status, _ifc.statusText, _sfont);
_newlab.setTargetWidth(_spos.width); _newlab.setTargetWidth(_spos.width);
repaint(); repaint();
} }
@@ -91,20 +99,15 @@ public class StatusPanel extends JComponent
_newplab = null; _newplab = null;
} }
Composite ocomp = gfx.getComposite(); gfx.setColor(_ifc.progressBar);
gfx.setComposite(PROGRESS_ALPHA);
gfx.setColor(Color.black);
gfx.fillRect(_ppos.x, _ppos.y, _progress * _ppos.width / 100, gfx.fillRect(_ppos.x, _ppos.y, _progress * _ppos.width / 100,
_ppos.height); _ppos.height);
gfx.setComposite(ocomp);
gfx.setColor(_lcolor);
if (_plabel != null) { if (_plabel != null) {
int xmarg = (_ppos.width - _plabel.getSize().width)/2; int xmarg = (_ppos.width - _plabel.getSize().width)/2;
int ymarg = (_ppos.height - _plabel.getSize().height)/2; int ymarg = (_ppos.height - _plabel.getSize().height)/2;
_plabel.render(gfx, _ppos.x + xmarg, _ppos.y + ymarg); _plabel.render(gfx, _ppos.x + xmarg, _ppos.y + ymarg);
} }
gfx.draw(_ppos);
if (_label != null) { if (_label != null) {
_label.render(gfx, _spos.x, _spos.y); _label.render(gfx, _spos.x, _spos.y);
@@ -182,8 +185,8 @@ public class StatusPanel extends JComponent
protected Label _plabel, _newplab; protected Label _plabel, _newplab;
protected Color _lcolor = new Color(0xD7C94F); protected Color _lcolor = new Color(0xD7C94F);
protected UpdateInterface _ifc;
/** The alpha level at which to paint the progress bar. */ protected static final Font _sfont = new Font("SansSerif", Font.PLAIN, 12);
protected static final Composite PROGRESS_ALPHA = protected static final Font _pfont = new Font("SansSerif", Font.BOLD, 12);
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25f);
} }
@@ -1,5 +1,5 @@
# #
# $Id: messages.properties,v 1.4 2004/07/19 12:39:08 mdb Exp $ # $Id: messages.properties,v 1.5 2004/07/26 17:52:31 mdb Exp $
# #
# Getdown translation messages # Getdown translation messages
@@ -7,12 +7,13 @@ m.resolving = Resolving downloads...
m.downloading = Downloading data... m.downloading = Downloading data...
m.failure = Download failed: {0} m.failure = Download failed: {0}
m.checking = Checking for update...
m.validating = Validating... m.validating = Validating...
m.patching = Patching... m.patching = Patching...
m.launching = Launching... m.launching = Launching...
m.complete = {0}% complete m.complete = {0}% complete
m.complete_remain = {0}% complete {1}s remaining m.complete_remain = {0}% complete {1}:{2} remaining
m.updating_metadata = Downloading control files... m.updating_metadata = Downloading control files...