/**
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 *
 * Copyright (C)
 * <a href="http://www.inab.org">Spanish National Institute of Bioinformatics (INB)</a>
 * <a href="http://www.bsc.es">Barcelona Supercomputing Center (BSC)</a>
 * <a href="http://inb.bsc.es">Computational Node 6</a>
 */

package org.inb.biomoby.central.gui.renderer;

import java.awt.Color;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.TableCellRenderer;

/**
 * A simple abstract TableCellRenderer based on JLabel
 *
 * @author Dmitry Repchevsky
 */

public class AbstractTableCellRenderer extends AbstractCellRenderer implements TableCellRenderer
{
    public AbstractTableCellRenderer getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    {
        Color foreground, background;
        if (isSelected)
        {
            foreground = UIManager.getLookAndFeel().getDefaults().getColor("Table.selectionForeground");

            if (foreground == null)
            {
                foreground = Color.WHITE;
            }

            background = UIManager.getLookAndFeel().getDefaults().getColor("Table.selectionBackground");

            if (background == null)
            {
                background = Color.BLUE;
            }
        }
        else
        {
            foreground = table.getForeground();
            background = table.getBackground();
        }

        setForeground(foreground);
        setBackground(background);

        return this;
    }
}
