return new Dimensions(preferredWidth, preferredHeight);
}
public void paint(Graphics2D graphics) {
PushButton pushButton = (PushButton)getComponent();
int width = getWidth();
int height = getHeight();
Color backgroundColor = null;
Color bevelColor = null;
Color borderColor = null;
if (!toolbar
|| highlighted) {
if (pushButton.isEnabled()) {
backgroundColor = this.backgroundColor;
bevelColor = (pressed
|| pushButton.isSelected()) ? pressedBevelColor : this.bevelColor;
borderColor = this.borderColor;
} else {
backgroundColor = disabledBackgroundColor;
bevelColor = disabledBevelColor;
borderColor = disabledBorderColor;
}
}
// Paint the background
if (backgroundColor != null
&& bevelColor != null) {
graphics.setPaint(new GradientPaint(width / 2, 0, bevelColor,
width / 2, height / 2, backgroundColor));
graphics.fillRect(0, 0, width, height);
}
// Paint the border
if (borderColor != null) {
graphics.setPaint(borderColor);
GraphicsUtilities.drawRect(graphics, 0, 0, width, height);
}
// Paint the content
Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
dataRenderer.render(pushButton.getButtonData(), pushButton, highlighted);
dataRenderer.setSize(Math.max(width - (padding.left + padding.right + 2), 0),
Math.max(getHeight() - (padding.top + padding.bottom + 2), 0));
Graphics2D contentGraphics = (Graphics2D)graphics.create();
contentGraphics.translate(padding.left + 1, padding.top + 1);
contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
dataRenderer.paint(contentGraphics);
contentGraphics.dispose();
// Paint the focus state
if (pushButton.isFocused()) {
BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND, 1.0f, new float[] {0.0f, 2.0f}, 0.0f);
graphics.setStroke(dashStroke);
graphics.setColor(this.borderColor);