48 * instance of the ImageFilter is filtering data. It is not 49 * initialized during the constructor, but rather during the 50 * getFilterInstance() method call when the FilteredImageSource 51 * is creating a unique instance of this object for a particular 52 * image data stream. 53 * @see #getFilterInstance 54 * @see ImageConsumer 55 */ 56 protected ImageConsumer consumer; 57 58 /** 59 * Returns a unique instance of an ImageFilter object which will 60 * actually perform the filtering for the specified ImageConsumer. 61 * The default implementation just clones this object. 62 * <p> 63 * Note: This method is intended to be called by the ImageProducer 64 * of the Image whose pixels are being filtered. Developers using 65 * this class to filter pixels from an image should avoid calling 66 * this method directly since that operation could interfere 67 * with the filtering operation. 68 * @param ic the specified <code>ImageConsumer</code> 69 * @return an <code>ImageFilter</code> used to perform the 70 * filtering for the specified <code>ImageConsumer</code>. 71 */ 72 public ImageFilter getFilterInstance(ImageConsumer ic) { 73 ImageFilter instance = (ImageFilter) clone(); 74 instance.consumer = ic; 75 return instance; 76 } 77 78 /** 79 * Filters the information provided in the setDimensions method 80 * of the ImageConsumer interface. 81 * <p> 82 * Note: This method is intended to be called by the ImageProducer 83 * of the Image whose pixels are being filtered. Developers using 84 * this class to filter pixels from an image should avoid calling 85 * this method directly since that operation could interfere 86 * with the filtering operation. 87 * @see ImageConsumer#setDimensions 88 */ 89 public void setDimensions(int width, int height) { 90 consumer.setDimensions(width, height); 91 } 92 93 /** 94 * Passes the properties from the source object along after adding a 95 * property indicating the stream of filters it has been run through. 96 * <p> 97 * Note: This method is intended to be called by the ImageProducer 98 * of the Image whose pixels are being filtered. Developers using 99 * this class to filter pixels from an image should avoid calling 100 * this method directly since that operation could interfere 101 * with the filtering operation. 102 * 103 * @param props the properties from the source object 104 * @exception NullPointerException if <code>props</code> is null 105 */ 106 public void setProperties(Hashtable<?,?> props) { 107 @SuppressWarnings("unchecked") 108 Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone(); 109 Object o = p.get("filters"); 110 if (o == null) { 111 p.put("filters", toString()); 112 } else if (o instanceof String) { 113 p.put("filters", ((String) o)+toString()); 114 } 115 consumer.setProperties(p); 116 } 117 118 /** 119 * Filter the information provided in the setColorModel method 120 * of the ImageConsumer interface. 121 * <p> 122 * Note: This method is intended to be called by the ImageProducer 123 * of the Image whose pixels are being filtered. Developers using 124 * this class to filter pixels from an image should avoid calling 179 consumer.setPixels(x, y, w, h, model, pixels, off, scansize); 180 } 181 182 /** 183 * Filters the information provided in the imageComplete method of 184 * the ImageConsumer interface. 185 * <p> 186 * Note: This method is intended to be called by the ImageProducer 187 * of the Image whose pixels are being filtered. Developers using 188 * this class to filter pixels from an image should avoid calling 189 * this method directly since that operation could interfere 190 * with the filtering operation. 191 * @see ImageConsumer#imageComplete 192 */ 193 public void imageComplete(int status) { 194 consumer.imageComplete(status); 195 } 196 197 /** 198 * Responds to a request for a TopDownLeftRight (TDLR) ordered resend 199 * of the pixel data from an <code>ImageConsumer</code>. 200 * When an <code>ImageConsumer</code> being fed 201 * by an instance of this <code>ImageFilter</code> 202 * requests a resend of the data in TDLR order, 203 * the <code>FilteredImageSource</code> 204 * invokes this method of the <code>ImageFilter</code>. 205 * 206 * <p> 207 * 208 * An <code>ImageFilter</code> subclass might override this method or not, 209 * depending on if and how it can send data in TDLR order. 210 * Three possibilities exist: 211 * 212 * <ul> 213 * <li> 214 * Do not override this method. 215 * This makes the subclass use the default implementation, 216 * which is to 217 * forward the request 218 * to the indicated <code>ImageProducer</code> 219 * using this filter as the requesting <code>ImageConsumer</code>. 220 * This behavior 221 * is appropriate if the filter can determine 222 * that it will forward the pixels 223 * in TDLR order if its upstream producer object 224 * sends them in TDLR order. 225 * 226 * <li> 227 * Override the method to simply send the data. 228 * This is appropriate if the filter can handle the request itself — 229 * for example, 230 * if the generated pixels have been saved in some sort of buffer. 231 * 232 * <li> 233 * Override the method to do nothing. 234 * This is appropriate 235 * if the filter cannot produce filtered data in TDLR order. 236 * </ul> 237 * 238 * @see ImageProducer#requestTopDownLeftRightResend 239 * @param ip the ImageProducer that is feeding this instance of 240 * the filter - also the ImageProducer that the request should be 241 * forwarded to if necessary 242 * @exception NullPointerException if <code>ip</code> is null 243 */ 244 public void resendTopDownLeftRight(ImageProducer ip) { 245 ip.requestTopDownLeftRightResend(this); 246 } 247 248 /** 249 * Clones this object. 250 */ 251 public Object clone() { 252 try { 253 return super.clone(); 254 } catch (CloneNotSupportedException e) { 255 // this shouldn't happen, since we are Cloneable 256 throw new InternalError(e); 257 } 258 } 259 } | 48 * instance of the ImageFilter is filtering data. It is not 49 * initialized during the constructor, but rather during the 50 * getFilterInstance() method call when the FilteredImageSource 51 * is creating a unique instance of this object for a particular 52 * image data stream. 53 * @see #getFilterInstance 54 * @see ImageConsumer 55 */ 56 protected ImageConsumer consumer; 57 58 /** 59 * Returns a unique instance of an ImageFilter object which will 60 * actually perform the filtering for the specified ImageConsumer. 61 * The default implementation just clones this object. 62 * <p> 63 * Note: This method is intended to be called by the ImageProducer 64 * of the Image whose pixels are being filtered. Developers using 65 * this class to filter pixels from an image should avoid calling 66 * this method directly since that operation could interfere 67 * with the filtering operation. 68 * @param ic the specified {@code ImageConsumer} 69 * @return an {@code ImageFilter} used to perform the 70 * filtering for the specified {@code ImageConsumer}. 71 */ 72 public ImageFilter getFilterInstance(ImageConsumer ic) { 73 ImageFilter instance = (ImageFilter) clone(); 74 instance.consumer = ic; 75 return instance; 76 } 77 78 /** 79 * Filters the information provided in the setDimensions method 80 * of the ImageConsumer interface. 81 * <p> 82 * Note: This method is intended to be called by the ImageProducer 83 * of the Image whose pixels are being filtered. Developers using 84 * this class to filter pixels from an image should avoid calling 85 * this method directly since that operation could interfere 86 * with the filtering operation. 87 * @see ImageConsumer#setDimensions 88 */ 89 public void setDimensions(int width, int height) { 90 consumer.setDimensions(width, height); 91 } 92 93 /** 94 * Passes the properties from the source object along after adding a 95 * property indicating the stream of filters it has been run through. 96 * <p> 97 * Note: This method is intended to be called by the ImageProducer 98 * of the Image whose pixels are being filtered. Developers using 99 * this class to filter pixels from an image should avoid calling 100 * this method directly since that operation could interfere 101 * with the filtering operation. 102 * 103 * @param props the properties from the source object 104 * @exception NullPointerException if {@code props} is null 105 */ 106 public void setProperties(Hashtable<?,?> props) { 107 @SuppressWarnings("unchecked") 108 Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone(); 109 Object o = p.get("filters"); 110 if (o == null) { 111 p.put("filters", toString()); 112 } else if (o instanceof String) { 113 p.put("filters", ((String) o)+toString()); 114 } 115 consumer.setProperties(p); 116 } 117 118 /** 119 * Filter the information provided in the setColorModel method 120 * of the ImageConsumer interface. 121 * <p> 122 * Note: This method is intended to be called by the ImageProducer 123 * of the Image whose pixels are being filtered. Developers using 124 * this class to filter pixels from an image should avoid calling 179 consumer.setPixels(x, y, w, h, model, pixels, off, scansize); 180 } 181 182 /** 183 * Filters the information provided in the imageComplete method of 184 * the ImageConsumer interface. 185 * <p> 186 * Note: This method is intended to be called by the ImageProducer 187 * of the Image whose pixels are being filtered. Developers using 188 * this class to filter pixels from an image should avoid calling 189 * this method directly since that operation could interfere 190 * with the filtering operation. 191 * @see ImageConsumer#imageComplete 192 */ 193 public void imageComplete(int status) { 194 consumer.imageComplete(status); 195 } 196 197 /** 198 * Responds to a request for a TopDownLeftRight (TDLR) ordered resend 199 * of the pixel data from an {@code ImageConsumer}. 200 * When an {@code ImageConsumer} being fed 201 * by an instance of this {@code ImageFilter} 202 * requests a resend of the data in TDLR order, 203 * the {@code FilteredImageSource} 204 * invokes this method of the {@code ImageFilter}. 205 * 206 * <p> 207 * 208 * An {@code ImageFilter} subclass might override this method or not, 209 * depending on if and how it can send data in TDLR order. 210 * Three possibilities exist: 211 * 212 * <ul> 213 * <li> 214 * Do not override this method. 215 * This makes the subclass use the default implementation, 216 * which is to 217 * forward the request 218 * to the indicated {@code ImageProducer} 219 * using this filter as the requesting {@code ImageConsumer}. 220 * This behavior 221 * is appropriate if the filter can determine 222 * that it will forward the pixels 223 * in TDLR order if its upstream producer object 224 * sends them in TDLR order. 225 * 226 * <li> 227 * Override the method to simply send the data. 228 * This is appropriate if the filter can handle the request itself — 229 * for example, 230 * if the generated pixels have been saved in some sort of buffer. 231 * 232 * <li> 233 * Override the method to do nothing. 234 * This is appropriate 235 * if the filter cannot produce filtered data in TDLR order. 236 * </ul> 237 * 238 * @see ImageProducer#requestTopDownLeftRightResend 239 * @param ip the ImageProducer that is feeding this instance of 240 * the filter - also the ImageProducer that the request should be 241 * forwarded to if necessary 242 * @exception NullPointerException if {@code ip} is null 243 */ 244 public void resendTopDownLeftRight(ImageProducer ip) { 245 ip.requestTopDownLeftRightResend(this); 246 } 247 248 /** 249 * Clones this object. 250 */ 251 public Object clone() { 252 try { 253 return super.clone(); 254 } catch (CloneNotSupportedException e) { 255 // this shouldn't happen, since we are Cloneable 256 throw new InternalError(e); 257 } 258 } 259 } |