FileDocCategorySizeDatePackage
AlphaComposite.javaAPI DocAndroid 1.5 API11138Wed May 06 22:41:54 BST 2009java.awt

AlphaComposite

public final class AlphaComposite extends Object implements Composite
The AlphaComposite class defines a basic alpha compositing rules for combining source and destination colors to achieve blending and transparency effects with graphics and images.
since
Android 1.0

Fields Summary
public static final int
CLEAR
The Constant CLEAR indicates that both the color and the alpha of the destination are cleared (Porter-Duff Clear rule).
public static final int
SRC
The Constant SRC indicates that the source is copied to the destination (Porter-Duff Source rule).
public static final int
DST
The Constant DST indicates that the destination is left untouched (Porter-Duff Destination rule).
public static final int
SRC_OVER
The Constant SRC_OVER indicates that the source is composited over the destination (Porter-Duff Source Over Destination rule).
public static final int
DST_OVER
The Constant DST_OVER indicates that The destination is composited over the source and the result replaces the destination (Porter-Duff Destination Over Source rule).
public static final int
SRC_IN
The Constant SRC_IN indicates that the part of the source lying inside of the destination replaces the destination (Porter-Duff Source In Destination rule).
public static final int
DST_IN
The Constant DST_IN indicates that the part of the destination lying inside of the source replaces the destination (Porter-Duff Destination In Source rule).
public static final int
SRC_OUT
The Constant SRC_OUT indicates that the part of the source lying outside of the destination replaces the destination (Porter-Duff Source Held Out By Destination rule).
public static final int
DST_OUT
The Constant DST_OUT indicates that the part of the destination lying outside of the source replaces the destination (Porter-Duff Destination Held Out By Source rule).
public static final int
SRC_ATOP
The Constant SRC_ATOP indicates that the part of the source lying inside of the destination is composited onto the destination (Porter-Duff Source Atop Destination rule).
public static final int
DST_ATOP
The Constant DST_ATOP indicates that the part of the destination lying inside of the source is composited over the source and replaces the destination (Porter-Duff Destination Atop Source rule).
public static final int
XOR
The Constant XOR indicates that the part of the source that lies outside of the destination is combined with the part of the destination that lies outside of the source (Porter-Duff Source Xor Destination rule).
public static final AlphaComposite
Clear
AlphaComposite object with the opaque CLEAR rule and an alpha of 1.0f.
public static final AlphaComposite
Src
AlphaComposite object with the opaque SRC rule and an alpha of 1.0f.
public static final AlphaComposite
Dst
AlphaComposite object with the opaque DST rule and an alpha of 1.0f.
public static final AlphaComposite
SrcOver
AlphaComposite object with the opaque SRC_OVER rule and an alpha of 1.0f.
public static final AlphaComposite
DstOver
AlphaComposite object with the opaque DST_OVER rule and an alpha of 1.0f.
public static final AlphaComposite
SrcIn
AlphaComposite object with the opaque SRC_IN rule and an alpha of 1.0f.
public static final AlphaComposite
DstIn
AlphaComposite object with the opaque DST_IN rule and an alpha of 1.0f.
public static final AlphaComposite
SrcOut
AlphaComposite object with the opaque SRC_OUT rule and an alpha of 1.0f.
public static final AlphaComposite
DstOut
AlphaComposite object with the opaque DST_OUT rule and an alpha of 1.0f.
public static final AlphaComposite
SrcAtop
AlphaComposite object with the opaque SRC_ATOP rule and an alpha of 1.0f.
public static final AlphaComposite
DstAtop
AlphaComposite object with the opaque DST_ATOP rule and an alpha of 1.0f.
public static final AlphaComposite
Xor
AlphaComposite object with the opaque XOR rule and an alpha of 1.0f.
private int
rule
The rule.
private float
alpha
The alpha.
Constructors Summary
private AlphaComposite(int rule, float alpha)
Instantiates a new alpha composite. Creates a context for the compositing operation. The context contains state that is used in performing the compositing operation.

param
rule the rule.
param
alpha the alpha.


                                                                
         
        if (rule < CLEAR || rule > XOR) {
            // awt.11D=Unknown rule
            throw new IllegalArgumentException(Messages.getString("awt.11D")); //$NON-NLS-1$
        }
        if (alpha < 0.0f || alpha > 1.0f) {
            // awt.11E=Wrong alpha value
            throw new IllegalArgumentException(Messages.getString("awt.11E")); //$NON-NLS-1$
        }

        this.rule = rule;
        this.alpha = alpha;
    
private AlphaComposite(int rule)
Instantiates a new alpha composite.

param
rule the rule.

        this(rule, 1.0f);
    
Methods Summary
public java.awt.CompositeContextcreateContext(java.awt.image.ColorModel srcColorModel, java.awt.image.ColorModel dstColorModel, java.awt.RenderingHints hints)
Creates a CompositeContext object with the specified source ColorModel, destination ColorModel and RenderingHints parameters for a composing operation.

param
srcColorModel the source's ColorModel.
param
dstColorModel the destination's ColorModel.
param
hints the RenderingHints object.
return
the CompositeContext object.
see
java.awt.Composite#createContext(java.awt.image.ColorModel, java.awt.image.ColorModel, java.awt.RenderingHints)

        return new ICompositeContext(this, srcColorModel, dstColorModel);
    
public booleanequals(java.lang.Object obj)
Compares the AlphaComposite object with the specified object.

param
obj the Object to be compared.
return
true, if the AlphaComposite object is equal to the specified object.

        if (!(obj instanceof AlphaComposite)) {
            return false;
        }
        AlphaComposite other = (AlphaComposite)obj;
        return (this.rule == other.getRule() && this.alpha == other.getAlpha());
    
public floatgetAlpha()
Gets the alpha value of this AlphaComposite object; returns 1.0 if this AlphaComposite object doesn't have alpha value.

return
the alpha value of this AlphaComposite object or 1.0 if this AlphaComposite object doesn't have alpha value.

        return alpha;
    
public static java.awt.AlphaCompositegetInstance(int rule, float alpha)
Gets the AlphaComposite instance with the specified rule and alpha value.

param
rule the compositing rule.
param
alpha the alpha value.
return
the AlphaComposite instance.

        if (alpha == 1.0f) {
            return getInstance(rule);
        }
        return new AlphaComposite(rule, alpha);
    
public static java.awt.AlphaCompositegetInstance(int rule)
Gets the AlphaComposite instance with the specified rule.

param
rule the compositing rule.
return
the AlphaComposite instance.

        switch (rule) {
            case CLEAR:
                return Clear;
            case SRC:
                return Src;
            case DST:
                return Dst;
            case SRC_OVER:
                return SrcOver;
            case DST_OVER:
                return DstOver;
            case SRC_IN:
                return SrcIn;
            case DST_IN:
                return DstIn;
            case SRC_OUT:
                return SrcOut;
            case DST_OUT:
                return DstOut;
            case SRC_ATOP:
                return SrcAtop;
            case DST_ATOP:
                return DstAtop;
            case XOR:
                return Xor;
            default:
                // awt.11D=Unknown rule
                throw new IllegalArgumentException(Messages.getString("awt.11D")); //$NON-NLS-1$
        }
    
public intgetRule()
Gets the compositing rule of this AlphaComposite object.

return
the compositing rule of this AlphaComposite object.

        return rule;
    
public inthashCode()
Returns the hash code of the AlphaComposite object.

return
the hash code of the AlphaComposite object.

        int hash = Float.floatToIntBits(alpha);
        int tmp = hash >>> 24;
        hash <<= 8;
        hash |= tmp;
        hash ^= rule;
        return hash;