Search in sources :

Example 11 with AlphaComposite

use of java.awt.AlphaComposite in project omegat by omegat-org.

the class TransparentHighlightPainter method paint.

protected void paint(Graphics g, Rectangle rect, JTextComponent c) {
    Graphics2D g2d = (Graphics2D) g;
    Composite originalComposite = g2d.getComposite();
    g2d.setComposite(alphaComposite);
    g2d.setPaint(color);
    g2d.fill(rect);
    g2d.setComposite(originalComposite);
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) Graphics2D(java.awt.Graphics2D)

Example 12 with AlphaComposite

use of java.awt.AlphaComposite in project litiengine by gurkenlabs.

the class MapRenderer method renderImageLayer.

protected static void renderImageLayer(Graphics2D g, IImageLayer layer, final IMap map, Rectangle2D viewport, float opacity) {
    Spritesheet sprite = Resources.spritesheets().get(layer.getImage().getSource());
    BufferedImage img;
    if (sprite == null) {
        img = Resources.images().get(layer.getImage().getAbsoluteSourcePath());
    } else {
        img = sprite.getImage();
    }
    if (img == null) {
        return;
    }
    final Composite oldComp = g.getComposite();
    final AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
    g.setComposite(ac);
    final double viewportOffsetX = layer.getOffset().x - viewport.getX();
    final double viewportOffsetY = layer.getOffset().y - viewport.getY();
    ImageRenderer.render(g, img, viewportOffsetX, viewportOffsetY);
    g.setComposite(oldComp);
    final LayerRenderEvent event = new LayerRenderEvent(g, map, layer);
    for (LayerRenderedListener listener : layerRenderedListeners) {
        listener.rendered(event);
    }
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) BufferedImage(java.awt.image.BufferedImage)

Example 13 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 14 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 15 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)

Aggregations

AlphaComposite (java.awt.AlphaComposite)37 Composite (java.awt.Composite)15 Graphics2D (java.awt.Graphics2D)13 Paint (java.awt.Paint)9 BufferedImage (java.awt.image.BufferedImage)7 GradientPaint (java.awt.GradientPaint)5 LinearGradientPaint (java.awt.LinearGradientPaint)4 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