textHeight += textBounds.getHeight();
}
@Override
public void paint(Graphics2D graphics) {
Label label = (Label)this.getComponent();
int width = getWidth();
int height = getHeight();
// Draw the background
if (backgroundColor != null) {
graphics.setPaint(backgroundColor);
graphics.fillRect(0, 0, width, height);
}
// Draw the text
if (glyphVectors != null && glyphVectors.getLength() > 0) {
graphics.setFont(font);
if (label.isEnabled()) {
graphics.setPaint(color);
} else {
graphics.setPaint(disabledColor);
}
FontRenderContext fontRenderContext = Platform.getFontRenderContext();
LineMetrics lm = font.getLineMetrics("", fontRenderContext);
float ascent = lm.getAscent();
float lineHeight = lm.getHeight();
float y = 0;
switch (verticalAlignment) {
case TOP: {
y = padding.top;
break;
}
case BOTTOM: {
y = height - (textHeight + padding.bottom);
break;
}
case CENTER: {
y = (height - textHeight) / 2;
break;
}
default: {
break;
}
}
for (int i = 0, n = glyphVectors.getLength(); i < n; i++) {
GlyphVector glyphVector = glyphVectors.get(i);
Rectangle2D textBounds = glyphVector.getLogicalBounds();
float lineWidth = (float)textBounds.getWidth();
float x = 0;
switch (horizontalAlignment) {
case LEFT: {
x = padding.left;
break;
}
case RIGHT: {
x = width - (lineWidth + padding.right);
break;
}
case CENTER: {
x = (width - lineWidth) / 2;
break;
}
default: {
break;
}
}
if (graphics instanceof PrintGraphics) {
// Work-around for printing problem in applets
String text = label.getText();
if (text != null && text.length() > 0) {
graphics.drawString(text, x, y + ascent);
}
}
else {