src/share/classes/java/awt/image/FilteredImageSource.java

Print this page




  51  *
  52  * @author      Jim Graham
  53  */
  54 public class FilteredImageSource implements ImageProducer {
  55     ImageProducer src;
  56     ImageFilter filter;
  57 
  58     /**
  59      * Constructs an ImageProducer object from an existing ImageProducer
  60      * and a filter object.
  61      * @param orig the specified <code>ImageProducer</code>
  62      * @param imgf the specified <code>ImageFilter</code>
  63      * @see ImageFilter
  64      * @see java.awt.Component#createImage
  65      */
  66     public FilteredImageSource(ImageProducer orig, ImageFilter imgf) {
  67         src = orig;
  68         filter = imgf;
  69     }
  70 
  71     private Hashtable proxies;
  72 
  73     /**
  74      * Adds the specified <code>ImageConsumer</code>
  75      * to the list of consumers interested in data for the filtered image.
  76      * An instance of the original <code>ImageFilter</code>
  77      * is created
  78      * (using the filter's <code>getFilterInstance</code> method)
  79      * to manipulate the image data
  80      * for the specified <code>ImageConsumer</code>.
  81      * The newly created filter instance
  82      * is then passed to the <code>addConsumer</code> method
  83      * of the original <code>ImageProducer</code>.
  84      *
  85      * <p>
  86      * This method is public as a side effect
  87      * of this class implementing
  88      * the <code>ImageProducer</code> interface.
  89      * It should not be called from user code,
  90      * and its behavior if called from user code is unspecified.
  91      *
  92      * @param ic  the consumer for the filtered image
  93      * @see ImageConsumer
  94      */
  95     public synchronized void addConsumer(ImageConsumer ic) {
  96         if (proxies == null) {
  97             proxies = new Hashtable();
  98         }
  99         if (!proxies.containsKey(ic)) {
 100             ImageFilter imgf = filter.getFilterInstance(ic);
 101             proxies.put(ic, imgf);
 102             src.addConsumer(imgf);
 103         }
 104     }
 105 
 106     /**
 107      * Determines whether an ImageConsumer is on the list of consumers
 108      * currently interested in data for this image.
 109      *
 110      * <p>
 111      * This method is public as a side effect
 112      * of this class implementing
 113      * the <code>ImageProducer</code> interface.
 114      * It should not be called from user code,
 115      * and its behavior if called from user code is unspecified.
 116      *
 117      * @param ic the specified <code>ImageConsumer</code>


 156      * is created
 157      * (using the filter's <code>getFilterInstance</code> method)
 158      * to manipulate the image data
 159      * for the <code>ImageConsumer</code>.
 160      * The filter instance for the <code>ImageConsumer</code>
 161      * is then passed to the <code>startProduction</code> method
 162      * of the original <code>ImageProducer</code>.
 163      *
 164      * <p>
 165      * This method is public as a side effect
 166      * of this class implementing
 167      * the <code>ImageProducer</code> interface.
 168      * It should not be called from user code,
 169      * and its behavior if called from user code is unspecified.
 170      *
 171      * @param ic  the consumer for the filtered image
 172      * @see ImageConsumer
 173      */
 174     public void startProduction(ImageConsumer ic) {
 175         if (proxies == null) {
 176             proxies = new Hashtable();
 177         }
 178         ImageFilter imgf = (ImageFilter) proxies.get(ic);
 179         if (imgf == null) {
 180             imgf = filter.getFilterInstance(ic);
 181             proxies.put(ic, imgf);
 182         }
 183         src.startProduction(imgf);
 184     }
 185 
 186     /**
 187      * Requests that a given ImageConsumer have the image data delivered
 188      * one more time in top-down, left-right order.  The request is
 189      * handed to the ImageFilter for further processing, since the
 190      * ability to preserve the pixel ordering depends on the filter.
 191      *
 192      * <p>
 193      * This method is public as a side effect
 194      * of this class implementing
 195      * the <code>ImageProducer</code> interface.
 196      * It should not be called from user code,


  51  *
  52  * @author      Jim Graham
  53  */
  54 public class FilteredImageSource implements ImageProducer {
  55     ImageProducer src;
  56     ImageFilter filter;
  57 
  58     /**
  59      * Constructs an ImageProducer object from an existing ImageProducer
  60      * and a filter object.
  61      * @param orig the specified <code>ImageProducer</code>
  62      * @param imgf the specified <code>ImageFilter</code>
  63      * @see ImageFilter
  64      * @see java.awt.Component#createImage
  65      */
  66     public FilteredImageSource(ImageProducer orig, ImageFilter imgf) {
  67         src = orig;
  68         filter = imgf;
  69     }
  70 
  71     private Hashtable<ImageConsumer, ImageFilter> proxies;
  72 
  73     /**
  74      * Adds the specified <code>ImageConsumer</code>
  75      * to the list of consumers interested in data for the filtered image.
  76      * An instance of the original <code>ImageFilter</code>
  77      * is created
  78      * (using the filter's <code>getFilterInstance</code> method)
  79      * to manipulate the image data
  80      * for the specified <code>ImageConsumer</code>.
  81      * The newly created filter instance
  82      * is then passed to the <code>addConsumer</code> method
  83      * of the original <code>ImageProducer</code>.
  84      *
  85      * <p>
  86      * This method is public as a side effect
  87      * of this class implementing
  88      * the <code>ImageProducer</code> interface.
  89      * It should not be called from user code,
  90      * and its behavior if called from user code is unspecified.
  91      *
  92      * @param ic  the consumer for the filtered image
  93      * @see ImageConsumer
  94      */
  95     public synchronized void addConsumer(ImageConsumer ic) {
  96         if (proxies == null) {
  97             proxies = new Hashtable<>();
  98         }
  99         if (!proxies.containsKey(ic)) {
 100             ImageFilter imgf = filter.getFilterInstance(ic);
 101             proxies.put(ic, imgf);
 102             src.addConsumer(imgf);
 103         }
 104     }
 105 
 106     /**
 107      * Determines whether an ImageConsumer is on the list of consumers
 108      * currently interested in data for this image.
 109      *
 110      * <p>
 111      * This method is public as a side effect
 112      * of this class implementing
 113      * the <code>ImageProducer</code> interface.
 114      * It should not be called from user code,
 115      * and its behavior if called from user code is unspecified.
 116      *
 117      * @param ic the specified <code>ImageConsumer</code>


 156      * is created
 157      * (using the filter's <code>getFilterInstance</code> method)
 158      * to manipulate the image data
 159      * for the <code>ImageConsumer</code>.
 160      * The filter instance for the <code>ImageConsumer</code>
 161      * is then passed to the <code>startProduction</code> method
 162      * of the original <code>ImageProducer</code>.
 163      *
 164      * <p>
 165      * This method is public as a side effect
 166      * of this class implementing
 167      * the <code>ImageProducer</code> interface.
 168      * It should not be called from user code,
 169      * and its behavior if called from user code is unspecified.
 170      *
 171      * @param ic  the consumer for the filtered image
 172      * @see ImageConsumer
 173      */
 174     public void startProduction(ImageConsumer ic) {
 175         if (proxies == null) {
 176             proxies = new Hashtable<>();
 177         }
 178         ImageFilter imgf = (ImageFilter) proxies.get(ic);
 179         if (imgf == null) {
 180             imgf = filter.getFilterInstance(ic);
 181             proxies.put(ic, imgf);
 182         }
 183         src.startProduction(imgf);
 184     }
 185 
 186     /**
 187      * Requests that a given ImageConsumer have the image data delivered
 188      * one more time in top-down, left-right order.  The request is
 189      * handed to the ImageFilter for further processing, since the
 190      * ability to preserve the pixel ordering depends on the filter.
 191      *
 192      * <p>
 193      * This method is public as a side effect
 194      * of this class implementing
 195      * the <code>ImageProducer</code> interface.
 196      * It should not be called from user code,