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.canvas;
020
021import icy.common.CollapsibleEvent;
022import icy.sequence.DimensionId;
023
024/**
025 * @author Stephane
026 */
027public class IcyCanvasEvent implements CollapsibleEvent
028{
029    public enum IcyCanvasEventType
030    {
031        POSITION_CHANGED, OFFSET_CHANGED, SCALE_CHANGED, ROTATION_CHANGED, MOUSE_IMAGE_POSITION_CHANGED, SYNC_CHANGED;
032    }
033
034    private IcyCanvas source;
035    private final IcyCanvasEventType type;
036    private final DimensionId dim;
037
038    public IcyCanvasEvent(IcyCanvas source, IcyCanvasEventType type, DimensionId dim)
039    {
040        this.source = source;
041        this.type = type;
042        this.dim = dim;
043    }
044
045    public IcyCanvasEvent(IcyCanvas source, IcyCanvasEventType type)
046    {
047        this(source, type, DimensionId.NULL);
048    }
049
050    /**
051     * @return the source
052     */
053    public IcyCanvas getSource()
054    {
055        return source;
056    }
057
058    /**
059     * @return the type
060     */
061    public IcyCanvasEventType getType()
062    {
063        return type;
064    }
065
066    /**
067     * @return the dimension
068     */
069    public DimensionId getDim()
070    {
071        return dim;
072    }
073
074    @Override
075    public boolean collapse(CollapsibleEvent event)
076    {
077        if (equals(event))
078        {
079            // nothing to change here
080            return true;
081        }
082
083        return false;
084    }
085
086    @Override
087    public int hashCode()
088    {
089        return source.hashCode() ^ type.hashCode() ^ dim.hashCode();
090    }
091
092    @Override
093    public boolean equals(Object obj)
094    {
095        if (obj instanceof IcyCanvasEvent)
096        {
097            final IcyCanvasEvent e = (IcyCanvasEvent) obj;
098
099            return (e.getSource() == source) && (e.getType() == type) && (e.getDim() == dim);
100        }
101
102        return super.equals(obj);
103    }
104}