package kiyut.sketsa.modules.symbollibrary;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import kiyut.sketsa.api.symbollibrary.Symbol;

/**
 * Symbol Renderer for the Container TopComponent
 * @author Kiyut
 */
public class SymbolRenderer extends JLabel implements ListCellRenderer {
    
    /** Creates a new instance of SymbolRenderer */
    public SymbolRenderer() {
        setOpaque(true);
        setHorizontalAlignment(CENTER);
        setVerticalAlignment(CENTER);
    }
    
    /** {@inheritDoc} */
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }
        
        //Set the icon and text.  If icon was null, say so.
        Symbol symbol = (Symbol)list.getModel().getElementAt(index);
        setIcon(symbol.getIcon());
        setToolTipText(symbol.getTooltipText());
        return this;
    }
}
