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