More user interfacely goodness, localized text, added code to attempt to
redownload getdown.txt if we choke while parsing it.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
//
|
||||
// $Id: StatusPanel.java,v 1.1 2004/07/07 08:42:40 mdb Exp $
|
||||
// $Id: StatusPanel.java,v 1.2 2004/07/07 10:45:20 mdb Exp $
|
||||
|
||||
package com.threerings.getdown.launcher;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Graphics;
|
||||
@@ -12,16 +14,21 @@ import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import com.samskivert.swing.Label;
|
||||
import com.samskivert.swing.util.SwingUtil;
|
||||
|
||||
/**
|
||||
* Displays download and patching status.
|
||||
*/
|
||||
public class StatusPanel extends JComponent
|
||||
{
|
||||
public StatusPanel (Rectangle bounds, BufferedImage bgimg,
|
||||
Rectangle ppos, Rectangle spos)
|
||||
public StatusPanel (ResourceBundle msgs, Rectangle bounds,
|
||||
BufferedImage bgimg, Rectangle ppos, Rectangle spos)
|
||||
{
|
||||
_msgs = msgs;
|
||||
_bgimg = bgimg;
|
||||
_psize = new Dimension(bounds.width, bounds.height);
|
||||
_ppos = ppos;
|
||||
@@ -31,9 +38,14 @@ public class StatusPanel extends JComponent
|
||||
/**
|
||||
* Adjusts the progress display to the specified percentage.
|
||||
*/
|
||||
public void setProgress (int percent)
|
||||
public void setProgress (int percent, long remaining)
|
||||
{
|
||||
_progress = percent;
|
||||
String msg = (remaining > 1) ? "m.complete_remain" : "m.complete";
|
||||
msg = _msgs.getString(msg);
|
||||
String label = MessageFormat.format(msg, new Object[] {
|
||||
new Integer(percent), new Long(remaining) });
|
||||
_newplab = new Label(label);
|
||||
repaint();
|
||||
}
|
||||
|
||||
@@ -53,29 +65,46 @@ public class StatusPanel extends JComponent
|
||||
super.paintComponent(g);
|
||||
Graphics2D gfx = (Graphics2D)g;
|
||||
|
||||
// if we have a new label; lay it out
|
||||
if (_newlab != null) {
|
||||
_newlab.layout(gfx);
|
||||
_label = _newlab;
|
||||
_newlab = null;
|
||||
}
|
||||
|
||||
if (_bgimg != null) {
|
||||
gfx.drawImage(_bgimg, 0, 0, null);
|
||||
} else {
|
||||
gfx.fillRect(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
gfx.setColor(Color.blue);
|
||||
Object oalias = SwingUtil.activateAntiAliasing(gfx);
|
||||
|
||||
// if we have new labels; lay them out
|
||||
if (_newlab != null) {
|
||||
_newlab.layout(gfx);
|
||||
_label = _newlab;
|
||||
_newlab = null;
|
||||
}
|
||||
if (_newplab != null) {
|
||||
_newplab.layout(gfx);
|
||||
_plabel = _newplab;
|
||||
_newplab = null;
|
||||
}
|
||||
|
||||
Composite ocomp = gfx.getComposite();
|
||||
gfx.setComposite(PROGRESS_ALPHA);
|
||||
gfx.setColor(Color.black);
|
||||
gfx.fillRect(_ppos.x, _ppos.y, _progress * _ppos.width / 100,
|
||||
_ppos.height);
|
||||
gfx.setComposite(ocomp);
|
||||
|
||||
gfx.setColor(Color.white);
|
||||
if (_plabel != null) {
|
||||
int xmarg = (_ppos.width - _plabel.getSize().width)/2;
|
||||
int ymarg = (_ppos.height - _plabel.getSize().height)/2;
|
||||
_plabel.render(gfx, _ppos.x + xmarg, _ppos.y + ymarg);
|
||||
}
|
||||
gfx.draw(_ppos);
|
||||
|
||||
if (_label != null) {
|
||||
_label.render(gfx, _spos.x, _spos.y);
|
||||
}
|
||||
|
||||
SwingUtil.restoreAntiAliasing(gfx, oalias);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@@ -88,6 +117,13 @@ public class StatusPanel extends JComponent
|
||||
protected Dimension _psize;
|
||||
protected Rectangle _ppos, _spos;
|
||||
|
||||
protected ResourceBundle _msgs;
|
||||
|
||||
protected int _progress = 0;
|
||||
protected Label _label, _newlab;
|
||||
protected Label _plabel, _newplab;
|
||||
|
||||
/** The alpha level at which to paint the progress bar. */
|
||||
protected static final Composite PROGRESS_ALPHA =
|
||||
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25f);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user