Example usage for java.awt AlphaComposite getAlpha

List of usage examples for java.awt AlphaComposite getAlpha

Introduction

In this page you can find the example usage for java.awt AlphaComposite getAlpha.

Prototype

public float getAlpha() 

Source Link

Document

Returns the alpha value of this AlphaComposite .

Usage

From source file:Main.java

public static double getAlpha(Color color, Composite composite) {
    int trans = color.getTransparency();
    if ((trans == Color.TRANSLUCENT || trans == Color.BITMASK)) {
        return color.getAlpha() / 255d;
    }/*  ww w.  j  ava  2  s  .  c om*/
    if (composite instanceof AlphaComposite) {
        AlphaComposite ac = (AlphaComposite) composite;
        return ac.getAlpha();
    }
    return 1d;
}

From source file:SWTGraphics2D.java

/**
 * Sets the current composite.  This implementation currently supports
 * only the {@link AlphaComposite} class.
 *
 * @param comp  the composite./*  w  w w .jav  a 2s .co m*/
 */
public void setComposite(Composite comp) {
    this.composite = comp;
    if (comp instanceof AlphaComposite) {
        AlphaComposite acomp = (AlphaComposite) comp;
        int alpha = (int) (acomp.getAlpha() * 0xFF);
        this.gc.setAlpha(alpha);
    } else {
        System.out.println("warning, can only handle alpha composite at the moment.");
    }
}

From source file:org.jfree.experimental.swt.SWTGraphics2D.java

/**
 * Sets the current composite.  This implementation currently supports
 * only the {@link AlphaComposite} class.
 *
 * @param comp  the composite (<code>null</code> not permitted).
 *//*w  w  w . j a  v  a  2  s.co m*/
public void setComposite(Composite comp) {
    if (comp == null) {
        throw new IllegalArgumentException("Null 'comp' argument.");
    }
    this.composite = comp;
    if (comp instanceof AlphaComposite) {
        AlphaComposite acomp = (AlphaComposite) comp;
        int alpha = (int) (acomp.getAlpha() * 0xFF);
        this.gc.setAlpha(alpha);
    }
}

From source file:SWTGraphics2D.java

/**
 * Sets the current color for this graphics context.
 *
 * @param color  the color.//from   www  .  ja  va  2s.c om
 *
 * @see #getColor()
 */
public void setColor(Color color) {
    org.eclipse.swt.graphics.Color swtColor = getSwtColorFromPool(color);
    this.gc.setForeground(swtColor);
    // handle transparency and compositing.
    if (this.composite instanceof AlphaComposite) {
        AlphaComposite acomp = (AlphaComposite) this.composite;
        switch (acomp.getRule()) {
        case AlphaComposite.SRC_OVER:
            this.gc.setAlpha((int) (color.getAlpha() * acomp.getAlpha()));
            break;
        default:
            this.gc.setAlpha(color.getAlpha());
            break;
        }
    }
}

From source file:org.jfree.experimental.swt.SWTGraphics2D.java

/**
 * Sets the current color for this graphics context.
 *
 * @param color  the color (<code>null</code> permitted but ignored).
 *
 * @see #getColor()/*from   w  w  w. j av a  2 s .com*/
 */
public void setColor(Color color) {
    if (color == null) {
        return;
    }
    org.eclipse.swt.graphics.Color swtColor = getSwtColorFromPool(color);
    this.gc.setForeground(swtColor);
    // handle transparency and compositing.
    if (this.composite instanceof AlphaComposite) {
        AlphaComposite acomp = (AlphaComposite) this.composite;
        switch (acomp.getRule()) {
        case AlphaComposite.SRC_OVER:
            this.gc.setAlpha((int) (color.getAlpha() * acomp.getAlpha()));
            break;
        default:
            this.gc.setAlpha(color.getAlpha());
            break;
        }
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

/**
 * Method contributed by Alexej Suchov// w  w  w  . ja va 2 s  . co  m
 *
 * @see Graphics2D#setComposite(Composite)
 */
@Override
public void setComposite(final Composite comp) {

    if (comp instanceof AlphaComposite) {

        final AlphaComposite composite = (AlphaComposite) comp;

        if (composite.getRule() == 3) {

            alpha = composite.getAlpha();
            this.composite = composite;

            if (realPaint != null && (realPaint instanceof Color)) {

                final Color c = (Color) realPaint;
                paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (c.getAlpha() * alpha));
            }
            return;
        }
    }

    this.composite = comp;
    alpha = 1.0F;

}