Added support for rendering an image as the progress bar.
This commit is contained in:
@@ -60,6 +60,12 @@ public class Application
|
|||||||
/** The human readable name of this application. */
|
/** The human readable name of this application. */
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
|
/** The path (relative to the appdir) to the background image. */
|
||||||
|
public String backgroundImage;
|
||||||
|
|
||||||
|
/** The path (relative to the appdir) to the progress bar image. */
|
||||||
|
public String progressImage;
|
||||||
|
|
||||||
/** The dimensions of the progress bar. */
|
/** The dimensions of the progress bar. */
|
||||||
public Rectangle progress = new Rectangle(5, 5, 300, 15);
|
public Rectangle progress = new Rectangle(5, 5, 300, 15);
|
||||||
|
|
||||||
@@ -75,9 +81,6 @@ public class Application
|
|||||||
/** The color of the status text. */
|
/** The color of the status text. */
|
||||||
public Color statusText = Color.black;
|
public Color statusText = Color.black;
|
||||||
|
|
||||||
/** The path (relative to the appdir) to the background image. */
|
|
||||||
public String background;
|
|
||||||
|
|
||||||
/** The color of the text shadow. */
|
/** The color of the text shadow. */
|
||||||
public Color textShadow;
|
public Color textShadow;
|
||||||
}
|
}
|
||||||
@@ -326,7 +329,11 @@ public class Application
|
|||||||
ui.status = parseRect(cdata, "ui.status", ui.status);
|
ui.status = parseRect(cdata, "ui.status", ui.status);
|
||||||
ui.statusText = parseColor(cdata, "ui.status_text", ui.statusText);
|
ui.statusText = parseColor(cdata, "ui.status_text", ui.statusText);
|
||||||
ui.textShadow = parseColor(cdata, "ui.text_shadow", ui.textShadow);
|
ui.textShadow = parseColor(cdata, "ui.text_shadow", ui.textShadow);
|
||||||
ui.background = (String)cdata.get("ui.background");
|
ui.backgroundImage = (String)cdata.get("ui.background_image");
|
||||||
|
if (ui.backgroundImage == null) { // support legacy format
|
||||||
|
ui.backgroundImage = (String)cdata.get("ui.background");
|
||||||
|
}
|
||||||
|
ui.progressImage = (String)cdata.get("ui.progress_image");
|
||||||
return ui;
|
return ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -514,17 +514,9 @@ public class Getdown extends Thread
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we have a background image, load it up
|
// load up our background and progress bar images
|
||||||
BufferedImage bgimg = null;
|
BufferedImage bgimg = loadImage(_ifc.backgroundImage);
|
||||||
if (!StringUtil.isBlank(_ifc.background)) {
|
BufferedImage barimg = loadImage(_ifc.progressImage);
|
||||||
File bgpath = _app.getLocalPath(_ifc.background);
|
|
||||||
try {
|
|
||||||
bgimg = ImageIO.read(bgpath);
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
Log.warning("Failed to read UI background [path=" + bgpath +
|
|
||||||
", error=" + ioe + "].");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// create our user interface, and display it
|
// create our user interface, and display it
|
||||||
String title = StringUtil.isBlank(_ifc.name) ? "" : _ifc.name;
|
String title = StringUtil.isBlank(_ifc.name) ? "" : _ifc.name;
|
||||||
@@ -553,7 +545,7 @@ public class Getdown extends Thread
|
|||||||
_frame.getContentPane().removeAll();
|
_frame.getContentPane().removeAll();
|
||||||
}
|
}
|
||||||
_frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
_frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||||
_status = new StatusPanel(_msgs, _ifc, bgimg);
|
_status = new StatusPanel(_msgs, _ifc, bgimg, barimg);
|
||||||
_frame.getContentPane().add(_status, BorderLayout.CENTER);
|
_frame.getContentPane().add(_status, BorderLayout.CENTER);
|
||||||
_frame.pack();
|
_frame.pack();
|
||||||
SwingUtil.centerWindow(_frame);
|
SwingUtil.centerWindow(_frame);
|
||||||
@@ -581,6 +573,21 @@ public class Getdown extends Thread
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected BufferedImage loadImage (String path)
|
||||||
|
{
|
||||||
|
if (StringUtil.isBlank(path)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
File imgpath = _app.getLocalPath(path);
|
||||||
|
try {
|
||||||
|
return ImageIO.read(imgpath);
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
Log.warning("Failed to load image [path=" + imgpath +
|
||||||
|
", error=" + ioe + "].");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main (String[] args)
|
public static void main (String[] args)
|
||||||
{
|
{
|
||||||
// maybe they specified the appdir in a system property
|
// maybe they specified the appdir in a system property
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: StatusPanel.java,v 1.13 2004/07/28 06:01:58 mdb Exp $
|
// $Id$
|
||||||
|
|
||||||
package com.threerings.getdown.launcher;
|
package com.threerings.getdown.launcher;
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ 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, UpdateInterface ifc,
|
||||||
BufferedImage bgimg)
|
BufferedImage bgimg, BufferedImage barimg)
|
||||||
{
|
{
|
||||||
_msgs = msgs;
|
_msgs = msgs;
|
||||||
_ifc = ifc;
|
_ifc = ifc;
|
||||||
@@ -44,6 +44,7 @@ public class StatusPanel extends JComponent
|
|||||||
} else {
|
} else {
|
||||||
_psize = new Dimension(bgimg.getWidth(), bgimg.getHeight());
|
_psize = new Dimension(bgimg.getWidth(), bgimg.getHeight());
|
||||||
}
|
}
|
||||||
|
_barimg = barimg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,10 +134,18 @@ public class StatusPanel extends JComponent
|
|||||||
_newplab = null;
|
_newplab = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx.setColor(_ifc.progressBar);
|
if (_barimg != null) {
|
||||||
gfx.fillRect(_ifc.progress.x, _ifc.progress.y,
|
gfx.setClip(_ifc.progress.x, _ifc.progress.y,
|
||||||
_progress * _ifc.progress.width / 100,
|
_progress * _ifc.progress.width / 100,
|
||||||
_ifc.progress.height);
|
_ifc.progress.height);
|
||||||
|
gfx.drawImage(_barimg, _ifc.progress.x, _ifc.progress.y, null);
|
||||||
|
gfx.setClip(null);
|
||||||
|
} else {
|
||||||
|
gfx.setColor(_ifc.progressBar);
|
||||||
|
gfx.fillRect(_ifc.progress.x, _ifc.progress.y,
|
||||||
|
_progress * _ifc.progress.width / 100,
|
||||||
|
_ifc.progress.height);
|
||||||
|
}
|
||||||
|
|
||||||
if (_plabel != null) {
|
if (_plabel != null) {
|
||||||
int xmarg = (_ifc.progress.width - _plabel.getSize().width)/2;
|
int xmarg = (_ifc.progress.width - _plabel.getSize().width)/2;
|
||||||
@@ -228,7 +237,7 @@ public class StatusPanel extends JComponent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BufferedImage _bgimg;
|
protected BufferedImage _bgimg, _barimg;
|
||||||
protected Dimension _psize;
|
protected Dimension _psize;
|
||||||
|
|
||||||
protected ResourceBundle _msgs;
|
protected ResourceBundle _msgs;
|
||||||
|
|||||||
Reference in New Issue
Block a user