package com.nullprogram.chess.gui;

import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Font;
import java.awt.Color;

import javax.swing.JPanel;

/**
 * Progress bar and status bar combined as one.
 */
public class StatusBar extends JPanel {

    /** Version for object serialization. */
    private static final long serialVersionUID = 1L;

    /** Maximum value of progress bar. */
    private int maximum = 1;

    /** Current value of progress bar. */
    private int value = 0;

    /** Status string to be displayed. */
    private String status;

    /** Panel's background color. */
    static final Color BACKGROUND = new Color(0xAA, 0xAA, 0xAA);

    /** Color of the progress bar. */
    static final Color BAR_COLOR = new Color(0x40, 0x00, 0xFF);

    /** Color of the status text. */
    static final Color STATUS_COLOR = new Color(0x00, 0x00, 0x00);

    /** Height of the progress bar. */
    static final int BAR_HEIGHT = 3;

    /** Vertical padding around the progress bar. */
    static final int BAR_PADDING_Y = 3;

    /** Horizontal padding around the progress bar. */
    static final int BAR_PADDING_X = 10;

    /**
     * Create a new status bar.
     */
    public StatusBar() {
        super();
        setBackground(BACKGROUND);
        setPreferredSize(null);
        setMinimumSize(null);
    }

    /** {@inheritDoc} */
    public final Dimension getPreferredSize() {
        Graphics g = getGraphics();
        if (g != null) {
            FontMetrics fm = g.getFontMetrics();
            int bar = BAR_PADDING_Y * 2 + BAR_HEIGHT;
            return new Dimension(0, fm.getAscent() + bar);
        }
        return null;
    }

    /** {@inheritDoc} */
    public final Dimension getMinimumSize() {
        return getPreferredSize();
    }

    /**
     * Return the maximum value of the progress bar.
     *
     * @return maximum value
     */
    public final int getMaximum() {
        return maximum;
    }

    /**
     * Set the maximum value of the progress bar.
     *
     * @param val new maximum value
     */
    public final void setMaximum(final int val) {
        maximum = Math.max(val, 1);
    }

    /**
     * Get the current value of the progress bar.
     *
     * @return current progress bar value
     */
    public final int getValue() {
        return value;
    }

    /**
     * Set the value of the progress bar.
     *
     * @param val the new value
     */
    public final void setValue(final int val) {
        value = Math.min(maximum, val);
        repaint();
    }

    /**
     * Set the status string of the status bar.
     *
     * @param message the new status string
     */
    public final void setStatus(final String message) {
        status = message;
        System.out.println(message);
        repaint();
    }

    /** {@inheritDoc} */
    public final void paintComponent(final Graphics g) {
        super.paintComponent(g);
        FontMetrics fm = g.getFontMetrics();
        int fh = fm.getAscent();

        /* Draw the progress bar. */
        g.setColor(BAR_COLOR);
        int barWidth = getWidth() - BAR_PADDING_X * 2;
        int progress = (barWidth * value) / maximum;
        g.fillRect(BAR_PADDING_X, fh + BAR_PADDING_Y,
                   progress, BAR_HEIGHT);

        /* Draw the string. */
        g.setColor(STATUS_COLOR);
        int width = fm.stringWidth(status);
        int height = fm.getHeight();
        Font f = fm.getFont();
        g.setFont(f.deriveFont(Font.BOLD));
        g.drawString(status, getWidth() / 2 - width / 2, height);
    }
}

@@ -51,24 +51,52 @@
 t.Graphics;%0A
+import java.awt.Graphics2D;%0A
 import java.
@@ -183,16 +183,48 @@
 t.Color;
+%0Aimport java.awt.RenderingHints;
 %0A%0Aimport
@@ -3011,16 +3011,182 @@
 ent(g);%0A
+        Graphics2D g2 = (Graphics2D) g;%0A        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,%0A                            RenderingHints.VALUE_ANTIALIAS_ON);%0A%0A
         

Switch to anti-aliasing on new StatusBar.