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.colormodel; 020 021import icy.common.CollapsibleEvent; 022 023/** 024 * @author stephane 025 */ 026public class IcyColorModelEvent implements CollapsibleEvent 027{ 028 public enum IcyColorModelEventType 029 { 030 SCALER_CHANGED, COLORMAP_CHANGED 031 } 032 033 private final IcyColorModel colorModel; 034 private final IcyColorModelEventType type; 035 private int component; 036 037 /** 038 * @param colorModel 039 * @param type 040 */ 041 public IcyColorModelEvent(IcyColorModel colorModel, IcyColorModelEventType type, int component) 042 { 043 super(); 044 045 this.colorModel = colorModel; 046 this.type = type; 047 this.component = component; 048 } 049 050 /** 051 * @return the colorModel 052 */ 053 public IcyColorModel getColorModel() 054 { 055 return colorModel; 056 } 057 058 /** 059 * @return the type 060 */ 061 public IcyColorModelEventType getType() 062 { 063 return type; 064 } 065 066 /** 067 * @return the component 068 */ 069 public int getComponent() 070 { 071 return component; 072 } 073 074 @Override 075 public boolean collapse(CollapsibleEvent event) 076 { 077 if (equals(event)) 078 { 079 final IcyColorModelEvent e = (IcyColorModelEvent) 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 colorModel.hashCode() ^ type.hashCode(); 095 } 096 097 @Override 098 public boolean equals(Object obj) 099 { 100 if (obj instanceof IcyColorModelEvent) 101 { 102 final IcyColorModelEvent e = (IcyColorModelEvent) obj; 103 104 return (colorModel == e.getColorModel()) && (type == e.getType()); 105 } 106 107 return super.equals(obj); 108 } 109}