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
013/**
014 * Opacity descriptor class (see {@link ROIDescriptor})
015 * 
016 * @author Stephane
017 */
018public class ROIOpacityDescriptor extends ROIDescriptor
019{
020    public static final String ID = "Opacity";
021
022    public ROIOpacityDescriptor()
023    {
024        super(ID, "Opacity", Float.class);
025    }
026
027    @Override
028    public String getDescription()
029    {
030        return "Opacity factor to display ROI content";
031    }
032
033    @Override
034    public boolean needRecompute(ROIEvent change)
035    {
036        return (change.getType() == ROIEventType.PROPERTY_CHANGED)
037                && (StringUtil.equals(change.getPropertyName(), ROI.PROPERTY_OPACITY));
038    }
039
040
041    @Override
042    public Object compute(ROI roi, Sequence sequence) throws UnsupportedOperationException
043    {
044        return Float.valueOf(getOpacity(roi));
045    }
046
047    /**
048     * Returns ROI opacity
049     */
050    public static float getOpacity(ROI roi)
051    {
052        if (roi == null)
053            return 1f;
054
055        return roi.getOpacity();
056    }
057}