Java Code Examples for java.awt.AlphaComposite#getAlpha()

The following examples show how to use java.awt.AlphaComposite#getAlpha() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PeekMetrics.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Record information about drawing done
 * with the supplied <code>Composite</code>.
 */
private void checkAlpha(Composite composite) {

    if (composite instanceof AlphaComposite) {
        AlphaComposite alphaComposite = (AlphaComposite) composite;
        float alpha = alphaComposite.getAlpha();
        int rule = alphaComposite.getRule();

        if (alpha != 1.0
                || (rule != AlphaComposite.SRC
                    && rule != AlphaComposite.SRC_OVER)) {

            mHasCompositing = true;
        }

    } else {
        mHasCompositing = true;
    }

}
 
Example 2
Source File: PeekMetrics.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Record information about drawing done
 * with the supplied {@code Composite}.
 */
private void checkAlpha(Composite composite) {

    if (composite instanceof AlphaComposite) {
        AlphaComposite alphaComposite = (AlphaComposite) composite;
        float alpha = alphaComposite.getAlpha();
        int rule = alphaComposite.getRule();

        if (alpha != 1.0
                || (rule != AlphaComposite.SRC
                    && rule != AlphaComposite.SRC_OVER)) {

            mHasCompositing = true;
        }

    } else {
        mHasCompositing = true;
    }

}
 
Example 3
Source File: PeekMetrics.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Record information about drawing done
 * with the supplied <code>Composite</code>.
 */
private void checkAlpha(Composite composite) {

    if (composite instanceof AlphaComposite) {
        AlphaComposite alphaComposite = (AlphaComposite) composite;
        float alpha = alphaComposite.getAlpha();
        int rule = alphaComposite.getRule();

        if (alpha != 1.0
                || (rule != AlphaComposite.SRC
                    && rule != AlphaComposite.SRC_OVER)) {

            mHasCompositing = true;
        }

    } else {
        mHasCompositing = true;
    }

}
 
Example 4
Source File: PdfGraphics2D.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
* Method contributed by Alexej Suchov
   * @see Graphics2D#setComposite(Composite)
   */
  public void setComposite(Composite comp) {
      
if (comp instanceof AlphaComposite) {

	AlphaComposite composite = (AlphaComposite) comp;

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

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

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

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

this.composite = comp;
alpha = 1.0F;

  }
 
Example 5
Source File: PeekMetrics.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Record information about drawing done
 * with the supplied {@code Composite}.
 */
private void checkAlpha(Composite composite) {

    if (composite instanceof AlphaComposite) {
        AlphaComposite alphaComposite = (AlphaComposite) composite;
        float alpha = alphaComposite.getAlpha();
        int rule = alphaComposite.getRule();

        if (alpha != 1.0
                || (rule != AlphaComposite.SRC
                    && rule != AlphaComposite.SRC_OVER)) {

            mHasCompositing = true;
        }

    } else {
        mHasCompositing = true;
    }

}
 
Example 6
Source File: PeekMetrics.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Record information about drawing done
 * with the supplied <code>Composite</code>.
 */
private void checkAlpha(Composite composite) {

    if (composite instanceof AlphaComposite) {
        AlphaComposite alphaComposite = (AlphaComposite) composite;
        float alpha = alphaComposite.getAlpha();
        int rule = alphaComposite.getRule();

        if (alpha != 1.0
                || (rule != AlphaComposite.SRC
                    && rule != AlphaComposite.SRC_OVER)) {

            mHasCompositing = true;
        }

    } else {
        mHasCompositing = true;
    }

}
 
Example 7
Source File: PeekMetrics.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Record information about drawing done
 * with the supplied <code>Composite</code>.
 */
private void checkAlpha(Composite composite) {

    if (composite instanceof AlphaComposite) {
        AlphaComposite alphaComposite = (AlphaComposite) composite;
        float alpha = alphaComposite.getAlpha();
        int rule = alphaComposite.getRule();

        if (alpha != 1.0
                || (rule != AlphaComposite.SRC
                    && rule != AlphaComposite.SRC_OVER)) {

            mHasCompositing = true;
        }

    } else {
        mHasCompositing = true;
    }

}
 
Example 8
Source File: PdfGraphics2D.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Method contributed by Alexej Suchov
 * 
 * @see Graphics2D#setComposite(Composite)
 */
@Override
public void setComposite(Composite comp) {

	if (comp instanceof AlphaComposite) {

		AlphaComposite composite = (AlphaComposite) comp;

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

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

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

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

	composite = comp;
	alpha = 1.0F;

}
 
Example 9
Source File: PeekMetrics.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Record information about drawing done
 * with the supplied <code>Composite</code>.
 */
private void checkAlpha(Composite composite) {

    if (composite instanceof AlphaComposite) {
        AlphaComposite alphaComposite = (AlphaComposite) composite;
        float alpha = alphaComposite.getAlpha();
        int rule = alphaComposite.getRule();

        if (alpha != 1.0
                || (rule != AlphaComposite.SRC
                    && rule != AlphaComposite.SRC_OVER)) {

            mHasCompositing = true;
        }

    } else {
        mHasCompositing = true;
    }

}
 
Example 10
Source File: SWTGraphics2D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the current composite.  This implementation currently supports
 * only the {@link AlphaComposite} class.
 *
 * @param comp  the composite.
 */
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.");
    }
}
 
Example 11
Source File: CompositeType.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a CompositeType object for the specified AlphaComposite
 * rule.
 */
public static CompositeType forAlphaComposite(AlphaComposite ac) {
    switch (ac.getRule()) {
    case AlphaComposite.CLEAR:
        return Clear;
    case AlphaComposite.SRC:
        if (ac.getAlpha() >= 1.0f) {
            return SrcNoEa;
        } else {
            return Src;
        }
    case AlphaComposite.DST:
        return Dst;
    case AlphaComposite.SRC_OVER:
        if (ac.getAlpha() >= 1.0f) {
            return SrcOverNoEa;
        } else {
            return SrcOver;
        }
    case AlphaComposite.DST_OVER:
        return DstOver;
    case AlphaComposite.SRC_IN:
        return SrcIn;
    case AlphaComposite.DST_IN:
        return DstIn;
    case AlphaComposite.SRC_OUT:
        return SrcOut;
    case AlphaComposite.DST_OUT:
        return DstOut;
    case AlphaComposite.SRC_ATOP:
        return SrcAtop;
    case AlphaComposite.DST_ATOP:
        return DstAtop;
    case AlphaComposite.XOR:
        return AlphaXor;
    default:
        throw new InternalError("Unrecognized alpha rule");
    }
}
 
Example 12
Source File: SWTGraphics2D.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the current composite.  This implementation currently supports
 * only the {@link AlphaComposite} class.
 *
 * @param comp  the composite (<code>null</code> not permitted).
 */
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);
    }
}
 
Example 13
Source File: CompositeType.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a CompositeType object for the specified AlphaComposite
 * rule.
 */
public static CompositeType forAlphaComposite(AlphaComposite ac) {
    switch (ac.getRule()) {
    case AlphaComposite.CLEAR:
        return Clear;
    case AlphaComposite.SRC:
        if (ac.getAlpha() >= 1.0f) {
            return SrcNoEa;
        } else {
            return Src;
        }
    case AlphaComposite.DST:
        return Dst;
    case AlphaComposite.SRC_OVER:
        if (ac.getAlpha() >= 1.0f) {
            return SrcOverNoEa;
        } else {
            return SrcOver;
        }
    case AlphaComposite.DST_OVER:
        return DstOver;
    case AlphaComposite.SRC_IN:
        return SrcIn;
    case AlphaComposite.DST_IN:
        return DstIn;
    case AlphaComposite.SRC_OUT:
        return SrcOut;
    case AlphaComposite.DST_OUT:
        return DstOut;
    case AlphaComposite.SRC_ATOP:
        return SrcAtop;
    case AlphaComposite.DST_ATOP:
        return DstAtop;
    case AlphaComposite.XOR:
        return AlphaXor;
    default:
        throw new InternalError("Unrecognized alpha rule");
    }
}
 
Example 14
Source File: CompositeType.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a CompositeType object for the specified AlphaComposite
 * rule.
 */
public static CompositeType forAlphaComposite(AlphaComposite ac) {
    switch (ac.getRule()) {
    case AlphaComposite.CLEAR:
        return Clear;
    case AlphaComposite.SRC:
        if (ac.getAlpha() >= 1.0f) {
            return SrcNoEa;
        } else {
            return Src;
        }
    case AlphaComposite.DST:
        return Dst;
    case AlphaComposite.SRC_OVER:
        if (ac.getAlpha() >= 1.0f) {
            return SrcOverNoEa;
        } else {
            return SrcOver;
        }
    case AlphaComposite.DST_OVER:
        return DstOver;
    case AlphaComposite.SRC_IN:
        return SrcIn;
    case AlphaComposite.DST_IN:
        return DstIn;
    case AlphaComposite.SRC_OUT:
        return SrcOut;
    case AlphaComposite.DST_OUT:
        return DstOut;
    case AlphaComposite.SRC_ATOP:
        return SrcAtop;
    case AlphaComposite.DST_ATOP:
        return DstAtop;
    case AlphaComposite.XOR:
        return AlphaXor;
    default:
        throw new InternalError("Unrecognized alpha rule");
    }
}
 
Example 15
Source File: CompositeType.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a CompositeType object for the specified AlphaComposite
 * rule.
 */
public static CompositeType forAlphaComposite(AlphaComposite ac) {
    switch (ac.getRule()) {
    case AlphaComposite.CLEAR:
        return Clear;
    case AlphaComposite.SRC:
        if (ac.getAlpha() >= 1.0f) {
            return SrcNoEa;
        } else {
            return Src;
        }
    case AlphaComposite.DST:
        return Dst;
    case AlphaComposite.SRC_OVER:
        if (ac.getAlpha() >= 1.0f) {
            return SrcOverNoEa;
        } else {
            return SrcOver;
        }
    case AlphaComposite.DST_OVER:
        return DstOver;
    case AlphaComposite.SRC_IN:
        return SrcIn;
    case AlphaComposite.DST_IN:
        return DstIn;
    case AlphaComposite.SRC_OUT:
        return SrcOut;
    case AlphaComposite.DST_OUT:
        return DstOut;
    case AlphaComposite.SRC_ATOP:
        return SrcAtop;
    case AlphaComposite.DST_ATOP:
        return DstAtop;
    case AlphaComposite.XOR:
        return AlphaXor;
    default:
        throw new InternalError("Unrecognized alpha rule");
    }
}
 
Example 16
Source File: CompositeType.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a CompositeType object for the specified AlphaComposite
 * rule.
 */
public static CompositeType forAlphaComposite(AlphaComposite ac) {
    switch (ac.getRule()) {
    case AlphaComposite.CLEAR:
        return Clear;
    case AlphaComposite.SRC:
        if (ac.getAlpha() >= 1.0f) {
            return SrcNoEa;
        } else {
            return Src;
        }
    case AlphaComposite.DST:
        return Dst;
    case AlphaComposite.SRC_OVER:
        if (ac.getAlpha() >= 1.0f) {
            return SrcOverNoEa;
        } else {
            return SrcOver;
        }
    case AlphaComposite.DST_OVER:
        return DstOver;
    case AlphaComposite.SRC_IN:
        return SrcIn;
    case AlphaComposite.DST_IN:
        return DstIn;
    case AlphaComposite.SRC_OUT:
        return SrcOut;
    case AlphaComposite.DST_OUT:
        return DstOut;
    case AlphaComposite.SRC_ATOP:
        return SrcAtop;
    case AlphaComposite.DST_ATOP:
        return DstAtop;
    case AlphaComposite.XOR:
        return AlphaXor;
    default:
        throw new InternalError("Unrecognized alpha rule");
    }
}
 
Example 17
Source File: OGLSurfaceData.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private boolean canHandleComposite(Composite c) {
    if (c instanceof AlphaComposite) {
        AlphaComposite ac = (AlphaComposite)c;

        return ac.getRule() == AlphaComposite.SRC_OVER && ac.getAlpha() >= 1f;
    }
    return false;
}
 
Example 18
Source File: CompositeType.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a CompositeType object for the specified AlphaComposite
 * rule.
 */
public static CompositeType forAlphaComposite(AlphaComposite ac) {
    switch (ac.getRule()) {
    case AlphaComposite.CLEAR:
        return Clear;
    case AlphaComposite.SRC:
        if (ac.getAlpha() >= 1.0f) {
            return SrcNoEa;
        } else {
            return Src;
        }
    case AlphaComposite.DST:
        return Dst;
    case AlphaComposite.SRC_OVER:
        if (ac.getAlpha() >= 1.0f) {
            return SrcOverNoEa;
        } else {
            return SrcOver;
        }
    case AlphaComposite.DST_OVER:
        return DstOver;
    case AlphaComposite.SRC_IN:
        return SrcIn;
    case AlphaComposite.DST_IN:
        return DstIn;
    case AlphaComposite.SRC_OUT:
        return SrcOut;
    case AlphaComposite.DST_OUT:
        return DstOut;
    case AlphaComposite.SRC_ATOP:
        return SrcAtop;
    case AlphaComposite.DST_ATOP:
        return DstAtop;
    case AlphaComposite.XOR:
        return AlphaXor;
    default:
        throw new InternalError("Unrecognized alpha rule");
    }
}
 
Example 19
Source File: SWTGraphics2D.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the current composite.  This implementation currently supports
 * only the {@link AlphaComposite} class.
 *
 * @param comp  the composite (<code>null</code> not permitted).
 */
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);
    }
}
 
Example 20
Source File: AbstractGraphics2D.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Sets the <code>Composite</code> for the <code>Graphics2D</code> context. The <code>Composite</code> is used in all
 * drawing methods such as <code>drawImage</code>, <code>drawString</code>, <code>draw</code>, and <code>fill</code>.
 * It specifies how new pixels are to be combined with the existing pixels on the graphics device during the rendering
 * process.
 * <p>
 * If this <code>Graphics2D</code> context is drawing to a <code>Component</code> on the display screen and the
 * <code>Composite</code> is a custom object rather than an instance of the <code>AlphaComposite</code> class, and if
 * there is a security manager, its <code>checkPermission</code> method is called with an
 * <code>AWTPermission("readDisplayPixels")</code> permission.
 *
 * @param comp
 *          the <code>Composite</code> object to be used for rendering
 * @throws SecurityException
 *           if a custom <code>Composite</code> object is being used to render to the screen and a security manager is
 *           set and its <code>checkPermission</code> method does not allow the operation.
 * @see java.awt.Graphics#setXORMode
 * @see java.awt.Graphics#setPaintMode
 * @see #getComposite
 * @see java.awt.AlphaComposite
 * @see SecurityManager#checkPermission
 * @see java.awt.AWTPermission
 */
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) ( (float) c.getAlpha() * alpha ) );
      }
      return;
    }
  }

  this.composite = comp;
  alpha = 1.0F;
}