1 7 8 package java.awt.image; 9 10 import java.awt.Image ; 11 import java.awt.image.ImageFilter ; 12 import java.awt.image.ImageConsumer ; 13 import java.awt.image.ImageProducer ; 14 import java.util.Hashtable ; 15 import java.awt.image.ColorModel ; 16 17 37 public class FilteredImageSource implements ImageProducer { 38 ImageProducer src; 39 ImageFilter filter; 40 41 49 public FilteredImageSource(ImageProducer orig, ImageFilter imgf) { 50 src = orig; 51 filter = imgf; 52 } 53 54 private Hashtable proxies; 55 56 78 public synchronized void addConsumer(ImageConsumer ic) { 79 if (proxies == null) { 80 proxies = new Hashtable (); 81 } 82 if (!proxies.containsKey(ic)) { 83 ImageFilter imgf = filter.getFilterInstance(ic); 84 proxies.put(ic, imgf); 85 src.addConsumer(imgf); 86 } 87 } 88 89 104 public synchronized boolean isConsumer(ImageConsumer ic) { 105 return (proxies != null && proxies.containsKey(ic)); 106 } 107 108 121 public synchronized void removeConsumer(ImageConsumer ic) { 122 if (proxies != null) { 123 ImageFilter imgf = (ImageFilter ) proxies.get(ic); 124 if (imgf != null) { 125 src.removeConsumer(imgf); 126 proxies.remove(ic); 127 if (proxies.isEmpty()) { 128 proxies = null; 129 } 130 } 131 } 132 } 133 134 157 public void startProduction(ImageConsumer ic) { 158 if (proxies == null) { 159 proxies = new Hashtable (); 160 } 161 ImageFilter imgf = (ImageFilter ) proxies.get(ic); 162 if (imgf == null) { 163 imgf = filter.getFilterInstance(ic); 164 proxies.put(ic, imgf); 165 } 166 src.startProduction(imgf); 167 } 168 169 184 public void requestTopDownLeftRightResend(ImageConsumer ic) { 185 if (proxies != null) { 186 ImageFilter imgf = (ImageFilter ) proxies.get(ic); 187 if (imgf != null) { 188 imgf.resendTopDownLeftRight(src); 189 } 190 } 191 } 192 } 193 | Popular Tags |