From c483b1dc648cad13f2f86bf8cc905b12dca16263 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Fri, 1 Jun 2012 22:47:00 +0000 Subject: [PATCH] - Let StatusPanel handle asyncronous loading of background images (ie: when in applet mode) --- .../getdown/launcher/StatusPanel.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/threerings/getdown/launcher/StatusPanel.java b/src/main/java/com/threerings/getdown/launcher/StatusPanel.java index 62f2ad5..3f68170 100644 --- a/src/main/java/com/threerings/getdown/launcher/StatusPanel.java +++ b/src/main/java/com/threerings/getdown/launcher/StatusPanel.java @@ -34,6 +34,7 @@ import java.awt.Image; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.image.ImageObserver; import java.text.MessageFormat; import java.util.MissingResourceException; import java.util.ResourceBundle; @@ -56,6 +57,7 @@ import static com.threerings.getdown.Log.log; * Displays download and patching status. */ public class StatusPanel extends JComponent + implements ImageObserver { public StatusPanel (ResourceBundle msgs) { @@ -79,17 +81,39 @@ public class StatusPanel extends JComponent _ifc = ifc; _bg = bg; Image img = _bg.getImage(_progress); - if (img == null) { + int width = img == null ? -1 : img.getWidth(this); + int height = img == null ? -1 : img.getHeight(this); + if (width == -1 || height == -1) { Rectangle bounds = ifc.progress.union(ifc.status); bounds.grow(5, 5); _psize = bounds.getSize(); } else { - _psize = new Dimension(img.getWidth(null), img.getHeight(null)); + _psize = new Dimension(width, height); } _barimg = barimg; invalidate(); } + @Override + public boolean imageUpdate (Image img, int infoflags, int x, int y, int width, int height) + { + boolean updated = false; + if ((infoflags | WIDTH) != 0) { + _psize.width = width; + updated = true; + } + if ((infoflags | HEIGHT) != 0) { + _psize.height = height; + updated = true; + } + if (updated) { + invalidate(); + setSize(_psize); + getParent().setSize(_psize); + } + return (infoflags | ALLBITS) != 0; + } + /** * Adjusts the progress display to the specified percentage. */