001/**
002 * 
003 */
004package plugins.kernel.roi.descriptor.property;
005
006import icy.roi.ROI;
007import icy.roi.ROIDescriptor;
008import icy.roi.ROIEvent;
009import icy.roi.ROIEvent.ROIEventType;
010import icy.sequence.Sequence;
011import icy.util.StringUtil;
012
013import java.awt.Image;
014
015/**
016 * Icon descriptor class (see {@link ROIDescriptor}).<br>
017 * Return the ROI icon a 20 pixels side icon
018 * 
019 * @author Stephane
020 */
021public class ROIIconDescriptor extends ROIDescriptor
022{
023    public static final String ID = "Icon";
024
025    public ROIIconDescriptor()
026    {
027        super(ID, "Icon", Image.class);
028    }
029
030    @Override
031    public String getDescription()
032    {
033        return "Icon";
034    }
035
036    @Override
037    public boolean needRecompute(ROIEvent change)
038    {
039        return (change.getType() == ROIEventType.PROPERTY_CHANGED)
040                && (StringUtil.equals(change.getPropertyName(), ROI.PROPERTY_ICON));
041    }
042
043    @Override
044    public Object compute(ROI roi, Sequence sequence) throws UnsupportedOperationException
045    {
046        return getIcon(roi);
047    }
048
049    /**
050     * Returns ROI icon
051     */
052    public static Image getIcon(ROI roi)
053    {
054        if (roi == null)
055            return null;
056
057        // return ImageUtil.getColorImageFromAlphaImage(roi.getIcon(), ColorUtil.mix(Color.gray, roi.getColor()));
058        return roi.getIcon();
059    }
060}