Search in sources :

Example 16 with AlphaComposite

use of java.awt.AlphaComposite in project sirix by sirixdb.

the class ProgressGlassPane method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    // enables anti-aliasing
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // gets the current clipping area
    Rectangle clip = g.getClipBounds();
    // sets a 65% translucent composite
    AlphaComposite alpha = AlphaComposite.SrcOver.derive(0.65f);
    Composite composite = g2.getComposite();
    g2.setComposite(alpha);
    // fills the background
    g2.setColor(getBackground());
    g2.fillRect(clip.x, clip.y, clip.width, clip.height);
    // centers the progress bar on screen
    FontMetrics metrics = g.getFontMetrics();
    int x = (getWidth() - BAR_WIDTH) / 2;
    int y = (getHeight() - BAR_HEIGHT - metrics.getDescent()) / 2;
    // draws the text
    g2.setColor(TEXT_COLOR);
    g2.drawString(message, x, y);
    // goes to the position of the progress bar
    y += metrics.getDescent();
    // computes the size of the progress indicator
    int w = (int) (BAR_WIDTH * ((float) progress / 100.0f));
    int h = BAR_HEIGHT;
    // draws the content of the progress bar
    Paint paint = g2.getPaint();
    // bar's background
    Paint gradient = new GradientPaint(x, y, GRADIENT_COLOR1, x, y + h, GRADIENT_COLOR2);
    g2.setPaint(gradient);
    g2.fillRect(x, y, BAR_WIDTH, BAR_HEIGHT);
    // actual progress
    gradient = new LinearGradientPaint(x, y, x, y + h, GRADIENT_FRACTIONS, GRADIENT_COLORS);
    g2.setPaint(gradient);
    g2.fillRect(x, y, w, h);
    g2.setPaint(paint);
    // draws the progress bar border
    g2.drawRect(x, y, BAR_WIDTH, BAR_HEIGHT);
    g2.setComposite(composite);
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint) LinearGradientPaint(java.awt.LinearGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) LinearGradientPaint(java.awt.LinearGradientPaint) LinearGradientPaint(java.awt.LinearGradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 17 with AlphaComposite

use of java.awt.AlphaComposite in project pivot by apache.

the class ImageViewSkin method paint.

@Override
public void paint(Graphics2D graphics) {
    ImageView imageView = (ImageView) getComponent();
    Image image = imageView.getImage();
    int width = getWidth();
    int height = getHeight();
    if (backgroundColor != null) {
        graphics.setPaint(backgroundColor);
        graphics.fillRect(0, 0, width, height);
    }
    if (image != null) {
        Graphics2D imageGraphics = (Graphics2D) graphics.create();
        imageGraphics.translate(imageX, imageY);
        imageGraphics.scale(scaleX, scaleY);
        // Apply an alpha composite if the opacity value is less than
        // the current alpha
        float alpha = 1.0f;
        Composite composite = imageGraphics.getComposite();
        if (composite instanceof AlphaComposite) {
            AlphaComposite alphaComposite = (AlphaComposite) composite;
            alpha = alphaComposite.getAlpha();
        }
        if (opacity < alpha) {
            imageGraphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
        }
        image.paint(imageGraphics);
        imageGraphics.dispose();
    }
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) ImageView(org.apache.pivot.wtk.ImageView) Image(org.apache.pivot.wtk.media.Image) Graphics2D(java.awt.Graphics2D)

Example 18 with AlphaComposite

use of java.awt.AlphaComposite in project com.revolsys.open by revolsys.

the class GeoreferencedImageLayerRenderer method renderAlpha.

public static void renderAlpha(final Viewport2D viewport, final Graphics2D graphics, final GeoreferencedImage image, final boolean useTransform, final double alpha, Object interpolationMethod) {
    final Composite composite = graphics.getComposite();
    try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, false)) {
        AlphaComposite alphaComposite = AlphaComposite.SrcOver;
        if (alpha < 1) {
            alphaComposite = alphaComposite.derive((float) alpha);
        }
        graphics.setComposite(alphaComposite);
        render(viewport, graphics, image, useTransform, interpolationMethod);
    } finally {
        graphics.setComposite(composite);
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite)

Example 19 with AlphaComposite

use of java.awt.AlphaComposite in project ultimate-java by pantinor.

the class ImageTransparency method createTransparentImage.

public static BufferedImage createTransparentImage(int width, int height) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f);
    Graphics2D g2d = (Graphics2D) image.getGraphics();
    g2d.setComposite(composite);
    g2d.setColor(new Color(0, 0, 0, 0));
    g2d.fillRect(0, 0, width, height);
    return image;
}
Also used : AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 20 with AlphaComposite

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

the class GraphicsTests method initContext.

public void initContext(TestEnvironment env, Context ctx) {
    ctx.graphics = env.getGraphics();
    int w = env.getWidth();
    int h = env.getHeight();
    ctx.size = env.getIntValue(sizeList);
    ctx.outdim = getOutputSize(ctx.size, ctx.size);
    ctx.pixscale = 1.0;
    if (hasGraphics2D) {
        Graphics2D g2d = (Graphics2D) ctx.graphics;
        AlphaComposite ac = (AlphaComposite) env.getModifier(compRules);
        if (env.isEnabled(doExtraAlpha)) {
            ac = AlphaComposite.getInstance(ac.getRule(), 0.125f);
        }
        g2d.setComposite(ac);
        if (env.isEnabled(doXor)) {
            g2d.setXORMode(Color.white);
        }
        if (env.isEnabled(doClipping)) {
            Polygon p = new Polygon();
            p.addPoint(0, 0);
            p.addPoint(w, 0);
            p.addPoint(0, h);
            p.addPoint(w, h);
            p.addPoint(0, 0);
            g2d.clip(p);
        }
        Transform tx = (Transform) env.getModifier(transforms);
        Dimension envdim = new Dimension(w, h);
        tx.init(g2d, ctx, envdim);
        w = envdim.width;
        h = envdim.height;
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, env.getModifier(renderHint));
    }
    switch(env.getIntValue(animList)) {
        case 0:
            ctx.animate = false;
            ctx.maxX = 3;
            ctx.maxY = 1;
            ctx.orgX = (w - ctx.outdim.width) / 2;
            ctx.orgY = (h - ctx.outdim.height) / 2;
            break;
        case 1:
            ctx.animate = true;
            ctx.maxX = Math.max(Math.min(32, w - ctx.outdim.width), 3);
            ctx.maxY = 1;
            ctx.orgX = (w - ctx.outdim.width - ctx.maxX) / 2;
            ctx.orgY = (h - ctx.outdim.height) / 2;
            break;
        case 2:
            ctx.animate = true;
            ctx.maxX = (w - ctx.outdim.width) + 1;
            ctx.maxY = (h - ctx.outdim.height) + 1;
            ctx.maxX = adjustWidth(ctx.maxX, ctx.maxY);
            ctx.maxX = Math.max(ctx.maxX, 3);
            ctx.maxY = Math.max(ctx.maxY, 1);
            // ctx.orgX = ctx.orgY = 0;
            break;
    }
    ctx.initX = ctx.maxX / 2;
    ctx.initY = ctx.maxY / 2;
}
Also used : AlphaComposite(java.awt.AlphaComposite) Dimension(java.awt.Dimension) Polygon(java.awt.Polygon) AffineTransform(java.awt.geom.AffineTransform) Graphics2D(java.awt.Graphics2D)

Aggregations

AlphaComposite (java.awt.AlphaComposite)35 Composite (java.awt.Composite)13 Graphics2D (java.awt.Graphics2D)13 Paint (java.awt.Paint)8 BufferedImage (java.awt.image.BufferedImage)7 GradientPaint (java.awt.GradientPaint)5 LinearGradientPaint (java.awt.LinearGradientPaint)3 Point (java.awt.Point)3 AffineTransform (java.awt.geom.AffineTransform)3 Rectangle2D (java.awt.geom.Rectangle2D)3 Spritesheet (de.gurkenlabs.litiengine.graphics.Spritesheet)2 Image (java.awt.Image)2 RadialGradientPaint (java.awt.RadialGradientPaint)2 TexturePaint (java.awt.TexturePaint)2 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)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