001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.image.colorspace;
020
021import icy.common.CollapsibleEvent;
022
023/**
024 * @author stephane
025 */
026public class IcyColorSpaceEvent implements CollapsibleEvent
027{
028    @Deprecated
029    public enum IcyColorSpaceEventType
030    {
031        CHANGED
032    }
033
034    private final IcyColorSpace colorSpace;
035    private int component;
036
037    public IcyColorSpaceEvent(IcyColorSpace colorSpace, int component)
038    {
039        super();
040
041        this.colorSpace = colorSpace;
042        this.component = component;
043    }
044
045    /**
046     * @return the colorSpace
047     */
048    public IcyColorSpace getColorSpace()
049    {
050        return colorSpace;
051    }
052
053    /**
054     * @return the type
055     */
056    public IcyColorSpaceEventType getType()
057    {
058        return IcyColorSpaceEventType.CHANGED;
059    }
060
061    /**
062     * @return the component
063     */
064    public int getComponent()
065    {
066        return component;
067    }
068
069    @Override
070    public boolean collapse(CollapsibleEvent event)
071    {
072        if (equals(event))
073        {
074            final IcyColorSpaceEvent e = (IcyColorSpaceEvent) event;
075
076            // set all component
077            if (e.getComponent() != component)
078                component = -1;
079
080            return true;
081        }
082
083        return false;
084    }
085
086    @Override
087    public int hashCode()
088    {
089        return colorSpace.hashCode();
090    }
091
092    @Override
093    public boolean equals(Object obj)
094    {
095        if (obj instanceof IcyColorSpaceEvent)
096        {
097            final IcyColorSpaceEvent e = (IcyColorSpaceEvent) obj;
098
099            return (colorSpace == e.getColorSpace());
100        }
101
102        return super.equals(obj);
103    }
104}