return new Dimensions(preferredWidth, preferredHeight);
}
public void paint(Graphics2D graphics) {
PushButton pushButton = (PushButton)getComponent();
Color borderColor = null;
Color gradientStartColor = null;
Color gradientEndColor = null;
if (pushButton.isEnabled()) {
if (pressed
|| pushButton.isSelected()) {
borderColor = pressedBorderColor;
gradientStartColor = pressedGradientStartColor;
gradientEndColor = pressedGradientEndColor;
} else {
if (highlighted) {
borderColor = highlightedBorderColor;
gradientStartColor = highlightedGradientStartColor;
gradientEndColor = highlightedGradientEndColor;
} else {
borderColor = this.borderColor;
gradientStartColor = this.gradientStartColor;
gradientEndColor = this.gradientEndColor;
}
}
}
else {
borderColor = disabledBorderColor;
gradientStartColor = disabledGradientStartColor;
gradientEndColor = disabledGradientEndColor;
}
int width = getWidth();
int height = getHeight();
Graphics2D contentGraphics = (Graphics2D)graphics.create();
// Paint the background
RoundRectangle2D buttonRectangle = new RoundRectangle2D.Double(0, 0,
width - 1, height - 1, cornerRadius, cornerRadius);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setPaint(new GradientPaint(width / 2, 0, gradientStartColor,
width / 2, height, gradientEndColor));
graphics.fill(buttonRectangle);
// Paint the border
graphics.setPaint(borderColor);
graphics.setStroke(new BasicStroke());
graphics.draw(buttonRectangle);
// Paint the content
Button.DataRenderer dataRenderer = pushButton.getDataRenderer();
dataRenderer.render(pushButton.getButtonData(), pushButton, false);
dataRenderer.setSize(Math.max(width - (padding.left + padding.right + 2), 0),
Math.max(getHeight() - (padding.top + padding.bottom + 2), 0));
contentGraphics.translate(padding.left + 1, padding.top + 1);
contentGraphics.clipRect(0, 0, dataRenderer.getWidth(), dataRenderer.getHeight());
dataRenderer.paint(contentGraphics);
// 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.setColor(highlightedGradientStartColor);
graphics.setStroke(dashStroke);