/**
 * GmailAssistant 1.1 (2008-03-16)
 * Copyright 2008 Zach Scrivena
 * zachscrivena@gmail.com
 * http://gmailassistant.sourceforge.net/
 *
 * Notifier for multiple Gmail accounts.
 *
 * TERMS AND CONDITIONS:
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package gmailassistant;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;


/**
 * Custom table cell renderer for the table of accounts.
 */
class AccountsTableCellRenderer
        extends JLabel
        implements TableCellRenderer
{
    /** foreground color */
    private final Color FOREGROUND;

    /** background color */
    private final Color BACKGROUND;

    /** foreground color for selected cells */
    private final Color SELECTION_FOREGROUND;

    /** background color for selected cells */
    private final Color SELECTION_BACKGROUND;

    /** Account object corresponding to the currently rendered cell */
    private Account ac;


    /**
    * Constructor.
    *
    * @param foreground
    *      foreground color
    * @param background
    *      background color
    * @param selectionForeground
    *      foreground color for selected cells
    * @param selectionBackground
    *      background color for selected cells
    */
    AccountsTableCellRenderer(
            final Color foreground,
            final Color background,
            final Color selectionForeground,
            final Color selectionBackground)
    {
        super();
        this.FOREGROUND = foreground;
        this.BACKGROUND = background;
        this.SELECTION_FOREGROUND = selectionForeground;
        this.SELECTION_BACKGROUND = selectionBackground;
    }


    /**
    * Return the tooltip text for this label.
    */
    @Override
    public String getToolTipText()
    {
        return this.ac.getAccountToolTipText();
    }


    /**
    * Return the JProgressBar component used for drawing the cell.
    */
    @Override
    public Component getTableCellRendererComponent(
            final JTable table,
            final Object val,
            final boolean isSelected,
            final boolean hasFocus,
            final int row,
            final int col)
    {
        final TableCellContent c = (TableCellContent) val;
        this.ac = c.ac;

        setText(c.text);
        setHorizontalAlignment(c.align);

        if (isSelected)
        {
            setForeground(this.SELECTION_FOREGROUND);
            setBackground(this.SELECTION_BACKGROUND);
            setOpaque(true);
        }
        else
        {
            setForeground(this.FOREGROUND);
            setBackground(this.BACKGROUND);
            setOpaque(false);
        }

        return this;
    }
}