imageUpdate(progressbar, ImageObserver.FRAMEBITS, 0, 0, 0, 0);
}
}
// draw everything onto an image before drawing to avoid flicker
Graphics og = offscreen.getGraphics();
FontMetrics fm = og.getFontMetrics();
// clear background color
og.setColor(bgColor);
og.fillRect(0, 0, offscreen.getWidth(null), offscreen.getHeight(null));
og.setColor(fgColor);
String message = getDescriptionForState();
// if we had a failure of some sort, notify the user
if (fatalError) {
String[] errorMessage = (certificateRefused) ? certificateRefusedMessage : genericErrorMessage;
for(int i=0; i<errorMessage.length; i++) {
if(errorMessage[i] != null) {
int messageX = (offscreen.getWidth(null) - fm.stringWidth(errorMessage[i])) / 2;
int messageY = (offscreen.getHeight(null) - (fm.getHeight() * errorMessage.length)) / 2;
og.drawString(errorMessage[i], messageX, messageY + i*fm.getHeight());
}
}
} else {
og.setColor(fgColor);
painting = true;
// get position at the middle of the offscreen buffer
int x = offscreen.getWidth(null)/2;
int y = offscreen.getHeight(null)/2;
// draw logo
if (logo != null) {
og.drawImage(logoBuffer, x-logo.getWidth(null)/2, y-logo.getHeight(null)/2, this);
}
// draw message
int messageX = (offscreen.getWidth(null) - fm.stringWidth(message)) / 2;
int messageY = y + 20;
if (logo != null) messageY += logo.getHeight(null)/2;
else if (progressbar != null) messageY += progressbar.getHeight(null)/2;
og.drawString(message, messageX, messageY);
// draw subtaskmessage, if any
if(subtaskMessage.length() > 0) {
messageX = (offscreen.getWidth(null) - fm.stringWidth(subtaskMessage)) / 2;
og.drawString(subtaskMessage, messageX, messageY+20);
}
// draw loading bar, clipping it depending on percentage done
if (progressbar != null) {
int barSize = (progressbar.getWidth(null) * percentage) / 100;
og.clipRect(x-progressbar.getWidth(null)/2, 0, barSize, offscreen.getHeight(null));
og.drawImage(progressbarBuffer, x-progressbar.getWidth(null)/2, y-progressbar.getHeight(null)/2, this);
}
painting = false;
}
og.dispose();
// finally draw it all centred
g.drawImage(offscreen, (getWidth() - offscreen.getWidth(null))/2, (getHeight() - offscreen.getHeight(null))/2, null);
}