# Class GrayFilter

java.lang.Object
java.awt.image.ImageFilter
java.awt.image.RGBImageFilter
javax.swing.GrayFilter

All Implemented Interfaces:
  `ImageConsumer, Cloneable`

public class GrayFilter extends RGBImageFilter
An image filter that "disables" an image by turning it into a grayscale image, and brightening the pixels in the image. Used by buttons to create an image for a disabled button.

Since:
  1.2

- ## Field Summary

  ### Fields declared in class RGBImageFilter

  `canFilterIndexColorModel, newmodel, origmodel`
  Modifier and Type
  Field
  Description
  `protected boolean`
  `canFilterIndexColorModel`
  This boolean indicates whether or not it is acceptable to apply the color filtering of the filterRGB method to the color table entries of an IndexColorModel object in lieu of pixel by pixel filtering.
  `protected ColorModel`
  `newmodel`
  The `ColorModel` with which to replace `origmodel` when the user calls `substituteColorModel`.
  `protected ColorModel`
  `origmodel`
  The `ColorModel` to be replaced by `newmodel` when the user calls `substituteColorModel`.

  ### Fields declared in class ImageFilter

  `consumer`
  Modifier and Type
  Field
  Description
  `protected ImageConsumer`
  `consumer`
  The consumer of the particular image data stream for which this instance of the ImageFilter is filtering data.

  ### Fields declared in interface ImageConsumer

  `COMPLETESCANLINES, IMAGEABORTED, IMAGEERROR, RANDOMPIXELORDER, SINGLEFRAME, SINGLEFRAMEDONE, SINGLEPASS, STATICIMAGEDONE, TOPDOWNLEFTRIGHT`
  Modifier and Type
  Field
  Description
  `static final int`
  `COMPLETESCANLINES`
  The pixels will be delivered in (multiples of) complete scanlines at a time.
  `static final int`
  `IMAGEABORTED`
  The image creation process was deliberately aborted.
  `static final int`
  `IMAGEERROR`
  An error was encountered while producing the image.
  `static final int`
  `RANDOMPIXELORDER`
  The pixels will be delivered in a random order.
  `static final int`
  `SINGLEFRAME`
  The image contain a single static image.
  `static final int`
  `SINGLEFRAMEDONE`
  One frame of the image is complete but there are more frames to be delivered.
  `static final int`
  `SINGLEPASS`
  The pixels will be delivered in a single pass.
  `static final int`
  `STATICIMAGEDONE`
  The image is complete and there are no more pixels or frames to be delivered.
  `static final int`
  `TOPDOWNLEFTRIGHT`
  The pixels will be delivered in top-down, left-to-right order.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GrayFilter(boolean b, int p)`
  Constructs a GrayFilter object that filters a color image to a grayscale image.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Image`
  `createDisabledImage(Image i)`
  Creates a disabled image
  `int`
  `filterRGB(int x, int y, int rgb)`
  Overrides `RGBImageFilter.filterRGB`.

  ### Methods declared in class RGBImageFilter

  `filterIndexColorModel, filterRGBPixels, setColorModel, setPixels, setPixels, substituteColorModel`
  Modifier and Type
  Method
  Description
  `IndexColorModel`
  `filterIndexColorModel(IndexColorModel icm)`
  Filters an IndexColorModel object by running each entry in its color tables through the filterRGB function that RGBImageFilter subclasses must provide.
  `void`
  `filterRGBPixels(int x, int y, int w, int h, int[] pixels, int off, int scansize)`
  Filters a buffer of pixels in the default RGB ColorModel by passing them one by one through the filterRGB method.
  `void`
  `setColorModel(ColorModel model)`
  If the ColorModel is an IndexColorModel and the subclass has set the canFilterIndexColorModel flag to true, we substitute a filtered version of the color model here and wherever that original ColorModel object appears in the setPixels methods.
  `void`
  `setPixels(int x, int y, int w, int h, ColorModel model, byte[] pixels, int off, int scansize)`
  If the ColorModel object is the same one that has already been converted, then simply passes the pixels through with the converted ColorModel.
  `void`
  `setPixels(int x, int y, int w, int h, ColorModel model, int[] pixels, int off, int scansize)`
  If the ColorModel object is the same one that has already been converted, then simply passes the pixels through with the converted ColorModel, otherwise converts the buffer of integer pixels to the default RGB ColorModel and passes the converted buffer to the filterRGBPixels method to be converted one by one.
  `void`
  `substituteColorModel(ColorModel oldcm, ColorModel newcm)`
  Registers two ColorModel objects for substitution.

  ### Methods declared in class ImageFilter

  `clone, getFilterInstance, imageComplete, resendTopDownLeftRight, setDimensions, setHints, setProperties`
  Modifier and Type
  Method
  Description
  `Object`
  `clone()`
  Clones this object.
  `ImageFilter`
  `getFilterInstance(ImageConsumer ic)`
  Returns a unique instance of an ImageFilter object which will actually perform the filtering for the specified ImageConsumer.
  `void`
  `imageComplete(int status)`
  Filters the information provided in the imageComplete method of the ImageConsumer interface.
  `void`
  `resendTopDownLeftRight(ImageProducer ip)`
  Responds to a request for a TopDownLeftRight (TDLR) ordered resend of the pixel data from an `ImageConsumer`.
  `void`
  `setDimensions(int width, int height)`
  Filters the information provided in the setDimensions method of the ImageConsumer interface.
  `void`
  `setHints(int hints)`
  Filters the information provided in the setHints method of the ImageConsumer interface.
  `void`
  `setProperties(Hashtable<?,?> props)`
  Passes the properties from the source object along after adding a property indicating the stream of filters it has been run through.

  ### Methods declared in class Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `protected void`
  `finalize()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Finalization is deprecated and subject to removal in a future release.
  `final Class<?>`
  `getClass()`
  Returns the runtime class of this `Object`.
  `int`
  `hashCode()`
  Returns a hash code value for this object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `String`
  `toString()`
  Returns a string representation of the object.
  `final void`
  `wait()`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
  `final void`
  `wait(long timeoutMillis)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
  `final void`
  `wait(long timeoutMillis, int nanos)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

- ## Constructor Details

  - ### GrayFilter

    public GrayFilter(boolean b, int p)
    Constructs a GrayFilter object that filters a color image to a grayscale image. Used by buttons to create disabled ("grayed out") button images.
    Parameters:
      `b` - a boolean -- true if the pixels should be brightened
      `p` - an int in the range 0..100 that determines the percentage of gray, where 100 is the darkest gray, and 0 is the lightest

- ## Method Details

  - ### createDisabledImage

    public static Image createDisabledImage(Image i)
    Creates a disabled image
    Parameters:
      `i` - an `Image` to be created as disabled
    Returns:
      the new grayscale image created from `i`

  - ### filterRGB

    public int filterRGB(int x, int y, int rgb)
    Overrides `RGBImageFilter.filterRGB`.
    Specified by:
      `filterRGB` in class `RGBImageFilter`
    Parameters:
      `x` - the X coordinate of the pixel
      `y` - the Y coordinate of the pixel
      `rgb` - the integer pixel representation in the default RGB color model
    Returns:
      a filtered pixel in the default RGB color model.
    See Also:
      - `ColorModel.getRGBdefault()`
      - `RGBImageFilter.filterRGBPixels(int, int, int, int, int[], int, int)`