Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jdesktop.swingx.graphics
Class BlendComposite

    java.lang.Object
      org.jdesktop.swingx.graphics.BlendComposite

All Implemented Interfaces:
  java.awt.Composite

    public final class BlendComposite

extends java.lang.Object
implements java.awt.Composite

A blend composite defines the rule according to which a drawing primitive (known as the source) is mixed with existing graphics (know as the destination.)

`BlendComposite` is an implementation of the `Composite` interface and must therefore be set as a state on a `Graphics2D` surface.

Please refer to `Graphics2D.setComposite(java.awt.Composite)` for more information on how to use this class with a graphics surface.

## Blending Modes

This class offers a certain number of blending modes, or compositing rules. These rules are inspired from graphics editing software packages, like Adobe Photoshop or The GIMP.

Given the wide variety of implemented blending modes and the difficulty to describe them with words, please refer to those tools to visually see the result of these blending modes.

## Opacity

Each blending mode has an associated opacity, defined as a float value between 0.0 and 1.0. Changing the opacity controls the force with which the compositing operation is applied. For instance, a composite with an opacity of 0.0 will not draw the source onto the destination. With an opacity of 1.0, the source will be fully drawn onto the destination, according to the selected blending mode rule.

The opacity, or alpha value, is used by the composite instance to mutiply the alpha value of each pixel of the source when being composited over the destination.

## Creating a Blend Composite

Blend composites can be created in various manners:

- Use one of the pre-defined instance. Example: `BlendComposite.Average`.
- Derive one of the pre-defined instances by calling `derive(float)` or `derive(BlendingMode)`. Deriving allows you to change either the opacity or the blending mode. Example: `BlendComposite.Average.derive(0.5f)`.
- Use a factory method: `getInstance(BlendingMode)` or `getInstance(BlendingMode, float)`.

## Implementation Caveat

TThe blending mode SoftLight has not been implemented yet.

Author:
  Romain Guy
See Also:
  `BlendComposite.BlendingMode`, `Graphics2D`, `Composite`, `AlphaComposite`

Nested Class Summary
`static class` | `BlendComposite.BlendingMode` A blending mode defines the compositing rule of a `BlendComposite`.

Field Summary
`static BlendComposite` | `Add`
`static BlendComposite` | `Average`
`static BlendComposite` | `Blue`
`static BlendComposite` | `Color`
`static BlendComposite` | `ColorBurn`
`static BlendComposite` | `ColorDodge`
`static BlendComposite` | `Darken`
`static BlendComposite` | `Difference`
`static BlendComposite` | `Exclusion`
`static BlendComposite` | `Freeze`
`static BlendComposite` | `Glow`
`static BlendComposite` | `Green`
`static BlendComposite` | `HardLight`
`static BlendComposite` | `Heat`
`static BlendComposite` | `Hue`
`static BlendComposite` | `InverseColorBurn`
`static BlendComposite` | `InverseColorDodge`
`static BlendComposite` | `Lighten`
`static BlendComposite` | `Luminosity`
`static BlendComposite` | `Multiply`
`static BlendComposite` | `Negation`
`static BlendComposite` | `Overlay`
`static BlendComposite` | `Red`
`static BlendComposite` | `Reflect`
`static BlendComposite` | `Saturation`
`static BlendComposite` | `Screen`
`static BlendComposite` | `SoftBurn`
`static BlendComposite` | `SoftDodge`
`static BlendComposite` | `SoftLight`
`static BlendComposite` | `Stamp`
`static BlendComposite` | `Subtract`

Method Summary
`java.awt.CompositeContext` | `createContext(java.awt.image.ColorModel srcColorModel, java.awt.image.ColorModel dstColorModel, java.awt.RenderingHints hints)`
`BlendComposite` | `derive(BlendComposite.BlendingMode mode)` Returns a `BlendComposite` object that uses the specified blending mode and this object's alpha value.
`BlendComposite` | `derive(float alpha)` Returns a `BlendComposite` object that uses the specified opacity, or alpha, and this object's blending mode.
`boolean` | `equals(java.lang.Object obj)`
`float` | `getAlpha()` Returns the opacity of this composite.
`static BlendComposite` | `getInstance(BlendComposite.BlendingMode mode)` Creates a new composite based on the blending mode passed as a parameter.
`static BlendComposite` | `getInstance(BlendComposite.BlendingMode mode, float alpha)` Creates a new composite based on the blending mode and opacity passed as parameters.
`BlendComposite.BlendingMode` | `getMode()` Returns the blending mode of this composite.
`int` | `hashCode()`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### Average

    public static final BlendComposite Average

### Multiply

    public static final BlendComposite Multiply

### Screen

    public static final BlendComposite Screen

### Darken

    public static final BlendComposite Darken

### Lighten

    public static final BlendComposite Lighten

### Overlay

    public static final BlendComposite Overlay

### HardLight

    public static final BlendComposite HardLight

### SoftLight

    public static final BlendComposite SoftLight

### Difference

    public static final BlendComposite Difference

### Negation

    public static final BlendComposite Negation

### Exclusion

    public static final BlendComposite Exclusion

### ColorDodge

    public static final BlendComposite ColorDodge

### InverseColorDodge

    public static final BlendComposite InverseColorDodge

### SoftDodge

    public static final BlendComposite SoftDodge

### ColorBurn

    public static final BlendComposite ColorBurn

### InverseColorBurn

    public static final BlendComposite InverseColorBurn

### SoftBurn

    public static final BlendComposite SoftBurn

### Reflect

    public static final BlendComposite Reflect

### Glow

    public static final BlendComposite Glow

### Freeze

    public static final BlendComposite Freeze

### Heat

    public static final BlendComposite Heat

### Add

    public static final BlendComposite Add

### Subtract

    public static final BlendComposite Subtract

### Stamp

    public static final BlendComposite Stamp

### Red

    public static final BlendComposite Red

### Green

    public static final BlendComposite Green

### Blue

    public static final BlendComposite Blue

### Hue

    public static final BlendComposite Hue

### Saturation

    public static final BlendComposite Saturation

### Color

    public static final BlendComposite Color

### Luminosity

    public static final BlendComposite Luminosity

Method Detail

### getInstance

    public static BlendComposite getInstance(BlendComposite.BlendingMode mode)

  Creates a new composite based on the blending mode passed as a parameter. A default opacity of 1.0 is applied.

  Parameters:
    `mode` - the blending mode defining the compositing rule
  Returns:
    a new `BlendComposite` based on the selected blending mode, with an opacity of 1.0

### getInstance

    public static BlendComposite getInstance(BlendComposite.BlendingMode mode,
                                             float alpha)

  Creates a new composite based on the blending mode and opacity passed as parameters. The opacity must be a value between 0.0 and 1.0.

  Parameters:
    `mode` - the blending mode defining the compositing rule
    `alpha` - the constant alpha to be multiplied with the alpha of the source. `alpha` must be a floating point between 0.0 and 1.0.
  Returns:
    a new `BlendComposite` based on the selected blending mode and opacity
  Throws:
    `java.lang.IllegalArgumentException` - if the opacity is less than 0.0 or greater than 1.0

### derive

    public BlendComposite derive(BlendComposite.BlendingMode mode)

  Returns a `BlendComposite` object that uses the specified blending mode and this object's alpha value. If the newly specified blending mode is the same as this object's, this object is returned.

  Parameters:
    `mode` - the blending mode defining the compositing rule
  Returns:
    a `BlendComposite` object derived from this object, that uses the specified blending mode

### derive

    public BlendComposite derive(float alpha)

  Returns a `BlendComposite` object that uses the specified opacity, or alpha, and this object's blending mode. If the newly specified opacity is the same as this object's, this object is returned.

  Parameters:
    `alpha` - the constant alpha to be multiplied with the alpha of the source. `alpha` must be a floating point between 0.0 and 1.0.
  Returns:
    a `BlendComposite` object derived from this object, that uses the specified blending mode
  Throws:
    `java.lang.IllegalArgumentException` - if the opacity is less than 0.0 or greater than 1.0

### getAlpha

    public float getAlpha()

  Returns the opacity of this composite. If no opacity has been defined, 1.0 is returned.

  Returns:
    the alpha value, or opacity, of this object

### getMode

    public BlendComposite.BlendingMode getMode()

  Returns the blending mode of this composite.

  Returns:
    the blending mode used by this object

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `java.lang.Object`

### equals

    public boolean equals(java.lang.Object obj)

  Overrides:
    `equals` in class `java.lang.Object`

### createContext

    public java.awt.CompositeContext createContext(java.awt.image.ColorModel srcColorModel,
                                                   java.awt.image.ColorModel dstColorModel,
                                                   java.awt.RenderingHints hints)

  Specified by:
    `createContext` in interface `java.awt.Composite`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2010. All Rights Reserved.