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.image.colormap.IcyColorMap; 022import icy.image.colorspace.IcyColorSpace; 023import icy.image.colorspace.IcyColorSpaceEvent; 024import icy.image.colorspace.IcyColorSpaceEvent.IcyColorSpaceEventType; 025import icy.image.colorspace.IcyColorSpaceListener; 026import icy.image.lut.LUT.LUTChannel; 027import icy.image.lut.LUTBandEvent.LUTBandEventType; 028import icy.math.Scaler; 029import icy.math.ScalerEvent; 030import icy.math.ScalerEvent.ScalerEventType; 031import icy.math.ScalerListener; 032 033import javax.swing.event.EventListenerList; 034 035/** 036 * @deprecated Use {@link LUTChannel} instead. 037 */ 038@Deprecated 039public class LUTBand implements ScalerListener, IcyColorSpaceListener 040{ 041 /** 042 * parent LUT 043 */ 044 private final LUT lut; 045 046 /** 047 * band index 048 */ 049 private final int component; 050 051 private boolean enabled; 052 053 /** 054 * cached 055 */ 056 private final Scaler scaler; 057 058 /** 059 * listeners 060 */ 061 private EventListenerList listeners; 062 063 public LUTBand(LUT lut, int component) 064 { 065 this.lut = lut; 066 this.component = component; 067 068 // add listener 069 getColorSpace().addListener(this); 070 071 // cached 072 scaler = lut.getScalers()[component]; 073 scaler.addListener(this); 074 075 // default 076 enabled = true; 077 078 listeners = new EventListenerList(); 079 } 080 081 @Override 082 protected void finalize() throws Throwable 083 { 084 // remove listener 085 getColorSpace().removeListener(this); 086 scaler.removeListener(this); 087 088 super.finalize(); 089 } 090 091 public LUT getLut() 092 { 093 return lut; 094 } 095 096 public IcyColorSpace getColorSpace() 097 { 098 return lut.getColorSpace(); 099 } 100 101 public IcyColorMap getColorMap() 102 { 103 return getColorSpace().getColorMap(component); 104 } 105 106 public void copyColorMap(IcyColorMap colorMap, boolean copyName, boolean copyAlpha) 107 { 108 getColorSpace().copyColormap(component, colorMap, copyName, copyAlpha); 109 } 110 111 public void copyColorMap(IcyColorMap colorMap) 112 { 113 copyColorMap(colorMap, true, true); 114 } 115 116 // private void adJustBounds() 117 // { 118 // // return default bounds ([0..255] / [-128..127]) for BYTE data type 119 // if ((!adjustByteToo) && (dataType.getJavaType() == DataType.BYTE)) 120 // return dataType.getDefaultBounds(); 121 // } 122 123 public Scaler getScaler() 124 { 125 return scaler; 126 } 127 128 public double getMin() 129 { 130 return scaler.getLeftIn(); 131 } 132 133 public void setMin(double value) 134 { 135 scaler.setLeftIn(value); 136 } 137 138 public double getMax() 139 { 140 return scaler.getRightIn(); 141 } 142 143 public void setMax(double value) 144 { 145 scaler.setRightIn(value); 146 } 147 148 public void setMinMax(double min, double max) 149 { 150 scaler.setLeftRightIn(min, max); 151 } 152 153 public double getMinBound() 154 { 155 return scaler.getAbsLeftIn(); 156 } 157 158 public double getMaxBound() 159 { 160 return scaler.getAbsRightIn(); 161 } 162 163 public void setMinBound(double value) 164 { 165 scaler.setAbsLeftIn(value); 166 } 167 168 public void setMaxBound(double value) 169 { 170 scaler.setAbsRightIn(value); 171 } 172 173 public boolean isEnabled() 174 { 175 return enabled; 176 } 177 178 public void setEnabled(boolean enabled) 179 { 180 this.enabled = enabled; 181 } 182 183 /** 184 * @return the component 185 */ 186 public int getComponent() 187 { 188 return component; 189 } 190 191 /** 192 * Add a listener 193 * 194 * @param listener 195 */ 196 public void addListener(LUTBandListener listener) 197 { 198 listeners.add(LUTBandListener.class, listener); 199 } 200 201 /** 202 * Remove a listener 203 * 204 * @param listener 205 */ 206 public void removeListener(LUTBandListener listener) 207 { 208 listeners.remove(LUTBandListener.class, listener); 209 } 210 211 /** 212 * fire event 213 */ 214 public void fireEvent(LUTBandEvent e) 215 { 216 for (LUTBandListener listener : listeners.getListeners(LUTBandListener.class)) 217 listener.lutBandChanged(e); 218 } 219 220 @Override 221 public void scalerChanged(ScalerEvent e) 222 { 223 if (e.getType() == ScalerEventType.CHANGED) 224 // notify LUTBand changed 225 fireEvent(new LUTBandEvent(this, LUTBandEventType.SCALER_CHANGED)); 226 } 227 228 @Override 229 public void colorSpaceChanged(IcyColorSpaceEvent e) 230 { 231 if ((e.getType() == IcyColorSpaceEventType.CHANGED) && (e.getComponent() == component)) 232 // notify LUTBand changed 233 fireEvent(new LUTBandEvent(this, LUTBandEventType.COLORMAP_CHANGED)); 234 } 235 236}