001/**
002 * 
003 */
004package icy.gui.component.renderer;
005
006import icy.gui.component.ColorIcon;
007import icy.resource.ResourceUtil;
008
009import java.awt.Color;
010import java.awt.Image;
011
012import org.pushingpixels.substance.api.renderers.SubstanceDefaultTableCellRenderer.IconRenderer;
013
014/**
015 * @author Stephane
016 */
017public class ImageTableCellRenderer extends IconRenderer
018{
019    /**
020     * 
021     */
022    private static final long serialVersionUID = -6330780301500309146L;
023
024    final int size;
025
026    public ImageTableCellRenderer(int size)
027    {
028        super();
029
030        this.size = size;
031        setIconTextGap(0);
032    }
033
034    public ImageTableCellRenderer()
035    {
036        this(-1);
037    }
038
039    @Override
040    public void setValue(Object value)
041    {
042        if (value instanceof Image)
043            setIcon(ResourceUtil.getImageIcon((Image) value, size));
044        else if (value instanceof Color)
045            setIcon(new ColorIcon((Color) value, size, size));
046        else
047            super.setValue(value);
048    }
049}