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.gui.viewer;
020
021import icy.sequence.DimensionId;
022
023/**
024 * @author stephane
025 */
026public class ViewerEvent
027{
028    public enum ViewerEventType
029    {
030        POSITION_CHANGED, CANVAS_CHANGED, LUT_CHANGED;
031    }
032
033    private final Viewer source;
034    private final ViewerEventType type;
035    private final DimensionId dim;
036
037    public ViewerEvent(Viewer source, ViewerEventType type, DimensionId dim)
038    {
039        this.source = source;
040        this.type = type;
041        this.dim = dim;
042    }
043
044    public ViewerEvent(Viewer source, ViewerEventType type)
045    {
046        this(source, type, DimensionId.NULL);
047    }
048
049    /**
050     * @return the source
051     */
052    public Viewer getSource()
053    {
054        return source;
055    }
056
057    /**
058     * @return the type
059     */
060    public ViewerEventType getType()
061    {
062        return type;
063    }
064
065    /**
066     * @return the dimension
067     */
068    public DimensionId getDim()
069    {
070        return dim;
071    }
072
073    @Override
074    public int hashCode()
075    {
076        return source.hashCode() ^ type.hashCode() ^ dim.hashCode();
077    }
078
079    @Override
080    public boolean equals(Object obj)
081    {
082        if (obj instanceof ViewerEvent)
083        {
084            final ViewerEvent e = (ViewerEvent) obj;
085
086            return (e.getSource() == source) && (e.getType() == type) && (e.getDim() == dim);
087        }
088
089        return super.equals(obj);
090    }
091}