}
}
protected void paintText(SeaGlassContext context, Graphics g, String title) {
if (progressBar.isStringPainted()) {
SynthStyle style = context.getStyle();
Font font = style.getFont(context);
FontMetrics fm = SwingUtilities2.getFontMetrics(progressBar, g, font);
int strLength = style.getGraphicsUtils(context).computeStringWidth(context, font, fm, title);
Rectangle bounds = progressBar.getBounds();
if (rotateText && progressBar.getOrientation() == JProgressBar.VERTICAL) {
Graphics2D g2 = (Graphics2D) g;
// Calculate the position for the text.
Point textPos;
AffineTransform rotation;
if (progressBar.getComponentOrientation().isLeftToRight()) {
rotation = AffineTransform.getRotateInstance(-Math.PI / 2);
textPos = new Point((bounds.width + fm.getAscent() - fm.getDescent()) / 2, (bounds.height + strLength) / 2);
} else {
rotation = AffineTransform.getRotateInstance(Math.PI / 2);
textPos = new Point((bounds.width - fm.getAscent() + fm.getDescent()) / 2, (bounds.height - strLength) / 2);
}
// Progress bar isn't wide enough for the font. Don't paint it.
if (textPos.x < 0) {
return;
}
// Paint the text.
font = font.deriveFont(rotation);
g2.setFont(font);
g2.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
style.getGraphicsUtils(context).paintText(context, g, title, textPos.x, textPos.y, -1);
} else {
// Calculate the bounds for the text.
// Rossi: Move text down by one pixel: Looks better but is a hack that may not look good for other font sizes / fonts
Rectangle textRect = new Rectangle((bounds.width / 2) - (strLength / 2),
(bounds.height - (fm.getAscent() + fm.getDescent())) / 2+1, 0, 0);
// Progress bar isn't tall enough for the font. Don't paint it.
if (textRect.y < 0) {
return;
}
// Paint the text.
g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND));
g.setFont(font);
style.getGraphicsUtils(context).paintText(context, g, title, textRect.x, textRect.y, -1);
}
}
}