Search in sources :

Example 1 with AlphaComposite

use of java.awt.AlphaComposite in project EnrichmentMapApp by BaderLab.

the class AbstractChartLayer method draw.

@Override
public void draw(final Graphics2D g, final Shape shape, final CyNetworkView networkView, final View<? extends CyIdentifiable> view) {
    // Give JFreeChart a larger area to draw into, so the proportions of the chart elements looks better
    final double scale = 2.0;
    Rectangle2D newBounds = new Rectangle2D.Double(bounds.getX() * scale, bounds.getY() * scale, bounds.getWidth() * scale, bounds.getHeight() * scale);
    // Of course, we also have to ask Graphics2D to apply the inverse transformation
    final double invScale = 1.0 / scale;
    final AffineTransform at = new AffineTransform();
    at.scale(invScale, invScale);
    g.transform(at);
    // Check to see if we have a current alpha composite
    Composite comp = g.getComposite();
    if (comp instanceof AlphaComposite) {
        float alpha = ((AlphaComposite) comp).getAlpha();
        JFreeChart fc = getChart();
        Plot plot = fc.getPlot();
        plot.setForegroundAlpha(alpha);
        fc.draw(g, newBounds);
    } else {
        getChart().draw(g, newBounds);
    }
    // Make sure Graphics2D is "back to normal" before returning
    try {
        at.invert();
    } catch (NoninvertibleTransformException e) {
        e.printStackTrace();
    }
    g.transform(at);
}
Also used : NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Plot(org.jfree.chart.plot.Plot) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) JFreeChart(org.jfree.chart.JFreeChart)

Example 2 with AlphaComposite

use of java.awt.AlphaComposite in project archi by archimatetool.

the class GraphicsToGraphics2DAdaptor method setAlpha.

@Override
public void setAlpha(int alpha) {
    swtGraphics.setAlpha(alpha);
    currentState.alpha = alpha;
    Composite composite = getGraphics2D().getComposite();
    if (composite instanceof AlphaComposite) {
        AlphaComposite newComposite = AlphaComposite.getInstance(((AlphaComposite) composite).getRule(), (float) alpha / (float) 255);
        getGraphics2D().setComposite(newComposite);
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite)

Example 3 with AlphaComposite

use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.

the class BufferedMaskBlit method MaskBlit.

@Override
public void MaskBlit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int srcx, int srcy, int dstx, int dsty, int width, int height, byte[] mask, int maskoff, int maskscan) {
    if (width <= 0 || height <= 0) {
        return;
    }
    if (mask == null) {
        // no mask involved; delegate to regular blit loop
        if (blitop == null) {
            blitop = Blit.getFromCache(src.getSurfaceType(), CompositeType.AnyAlpha, this.getDestType());
        }
        blitop.Blit(src, dst, comp, clip, srcx, srcy, dstx, dsty, width, height);
        return;
    }
    AlphaComposite acomp = (AlphaComposite) comp;
    if (acomp.getRule() != AlphaComposite.SRC_OVER) {
        comp = AlphaComposite.SrcOver;
    }
    rq.lock();
    try {
        validateContext(dst, comp, clip);
        RenderBuffer buf = rq.getBuffer();
        int totalBytesRequired = 20 + (width * height * 4);
        /*
             * REMIND: we should fix this so that it works with tiles that
             *         are larger than the entire buffer, but the native
             *         OGL/D3DMaskBlit isn't even prepared for tiles larger
             *         than 32x32 pixels, so there's no urgency here...
             */
        rq.ensureCapacity(totalBytesRequired);
        // enqueue parameters and tile pixels
        int newpos = enqueueTile(buf.getAddress(), buf.position(), src, src.getNativeOps(), srcTypeVal, mask, mask.length, maskoff, maskscan, srcx, srcy, dstx, dsty, width, height);
        buf.position(newpos);
    } finally {
        rq.unlock();
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite)

Example 4 with AlphaComposite

use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.

the class BufferedMaskFill method MaskFill.

@Override
public void MaskFill(SunGraphics2D sg2d, SurfaceData sData, Composite comp, final int x, final int y, final int w, final int h, final byte[] mask, final int maskoff, final int maskscan) {
    AlphaComposite acomp = (AlphaComposite) comp;
    if (acomp.getRule() != AlphaComposite.SRC_OVER) {
        comp = AlphaComposite.SrcOver;
    }
    rq.lock();
    try {
        validateContext(sg2d, comp, BufferedContext.USE_MASK);
        // we adjust the mask length so that the mask ends on a
        // 4-byte boundary
        int maskBytesRequired;
        if (mask != null) {
            // we adjust the mask length so that the mask ends on a
            // 4-byte boundary
            maskBytesRequired = (mask.length + 3) & (~3);
        } else {
            // mask not needed
            maskBytesRequired = 0;
        }
        int totalBytesRequired = 32 + maskBytesRequired;
        RenderBuffer buf = rq.getBuffer();
        if (totalBytesRequired <= buf.capacity()) {
            if (totalBytesRequired > buf.remaining()) {
                // process the queue first and then enqueue the mask
                rq.flushNow();
            }
            buf.putInt(MASK_FILL);
            // enqueue parameters
            buf.putInt(x).putInt(y).putInt(w).putInt(h);
            buf.putInt(maskoff);
            buf.putInt(maskscan);
            buf.putInt(maskBytesRequired);
            if (mask != null) {
                // enqueue the mask
                int padding = maskBytesRequired - mask.length;
                buf.put(mask);
                if (padding != 0) {
                    buf.position(buf.position() + padding);
                }
            }
        } else {
            // queue is too small to accommodate entire mask; perform
            // the operation directly on the queue flushing thread
            rq.flushAndInvokeNow(new Runnable() {

                public void run() {
                    maskFill(x, y, w, h, maskoff, maskscan, mask.length, mask);
                }
            });
        }
    } finally {
        rq.unlock();
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite)

Example 5 with AlphaComposite

use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.

the class BufferedContext method setComposite.

private void setComposite(Composite comp, int flags) {
    // assert rq.lock.isHeldByCurrentThread();
    if (comp instanceof AlphaComposite) {
        AlphaComposite ac = (AlphaComposite) comp;
        rq.ensureCapacity(16);
        buf.putInt(SET_ALPHA_COMPOSITE);
        buf.putInt(ac.getRule());
        buf.putFloat(ac.getAlpha());
        buf.putInt(flags);
    } else if (comp instanceof XORComposite) {
        int xorPixel = ((XORComposite) comp).getXorPixel();
        rq.ensureCapacity(8);
        buf.putInt(SET_XOR_COMPOSITE);
        buf.putInt(xorPixel);
    } else {
        throw new InternalError("not yet implemented");
    }
}
Also used : XORComposite(sun.java2d.loops.XORComposite) AlphaComposite(java.awt.AlphaComposite)

Aggregations

AlphaComposite (java.awt.AlphaComposite)33 Graphics2D (java.awt.Graphics2D)12 Composite (java.awt.Composite)11 Paint (java.awt.Paint)7 BufferedImage (java.awt.image.BufferedImage)6 GradientPaint (java.awt.GradientPaint)4 LinearGradientPaint (java.awt.LinearGradientPaint)3 Point (java.awt.Point)3 AffineTransform (java.awt.geom.AffineTransform)3 Image (java.awt.Image)2 RadialGradientPaint (java.awt.RadialGradientPaint)2 TexturePaint (java.awt.TexturePaint)2 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)2 Rectangle2D (java.awt.geom.Rectangle2D)2 JFreeChart (org.jfree.chart.JFreeChart)2 Plot (org.jfree.chart.plot.Plot)2 XORComposite (sun.java2d.loops.XORComposite)2 PixelToParallelogramConverter (sun.java2d.pipe.PixelToParallelogramConverter)2 TextPipe (sun.java2d.pipe.TextPipe)2 BaseCloseable (com.revolsys.io.BaseCloseable)1