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.lut;
020
021import icy.common.CollapsibleEvent;
022
023/**
024 * @author stephane
025 */
026public class LUTEvent implements CollapsibleEvent
027{
028    public enum LUTEventType
029    {
030        SCALER_CHANGED, COLORMAP_CHANGED
031    }
032
033    private final LUT lut;
034    private final LUTEventType type;
035    private int component;
036
037    /**
038     * @param lut
039     * @param component
040     */
041    public LUTEvent(LUT lut, int component, LUTEventType type)
042    {
043        super();
044
045        this.lut = lut;
046        this.component = component;
047        this.type = type;
048    }
049
050    /**
051     * @return the lut
052     */
053    public LUT getLut()
054    {
055        return lut;
056    }
057
058    /**
059     * @return the component
060     */
061    public int getComponent()
062    {
063        return component;
064    }
065
066    /**
067     * @return the {@link LUTEventType}
068     */
069    public LUTEventType getType()
070    {
071        return type;
072    }
073
074    @Override
075    public boolean collapse(CollapsibleEvent event)
076    {
077        if (equals(event))
078        {
079            final LUTEvent e = (LUTEvent) event;
080
081            // set all component
082            if (e.getComponent() != component)
083                component = -1;
084
085            return true;
086        }
087
088        return false;
089    }
090
091    @Override
092    public int hashCode()
093    {
094        return lut.hashCode() ^ type.hashCode();
095    }
096
097    @Override
098    public boolean equals(Object obj)
099    {
100        if (obj instanceof LUTEvent)
101        {
102            final LUTEvent e = (LUTEvent) obj;
103
104            return (lut == e.getLut()) && (type == e.getType());
105        }
106
107        return super.equals(obj);
108    }
109}