Example usage for java.awt AlphaComposite SRC_OVER

List of usage examples for java.awt AlphaComposite SRC_OVER

Introduction

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

Prototype

int SRC_OVER

To view the source code for java.awt AlphaComposite SRC_OVER.

Click Source Link

Document

The source is composited over the destination (Porter-Duff Source Over Destination rule).

Usage

From source file:edu.ku.brc.ui.GradiantButton.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int w = this.getWidth();
    int h = this.getHeight();

    drawButtonBody(g2, w, h, getForeground());

    if (pressed) {
        g2.translate(1, 1);/* w ww  .  j  a  va 2s  . c o m*/
    }

    String text = getText();
    if (isNotEmpty(text)) {
        drawText(g2, w, h, getText());
    }

    Icon roIcon = getRolloverIcon();
    Icon paintedIcon = isHover && roIcon != null ? roIcon : icon;
    if (paintedIcon != null) {
        //Graphics2D g2 = (Graphics2D) g.create();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, iconAlpha));
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        paintedIcon.paintIcon(this, g2, (w - icon.getIconWidth()) / 2, (h - icon.getIconHeight()) / 2);
    }
}

From source file:painting.IconDisplayer.java

protected void paintComponent(Graphics g) {
    if (isOpaque()) { //paint background
        g.setColor(getBackground());/*from   www  .ja va  2 s .  c  om*/
        g.fillRect(0, 0, getWidth(), getHeight());
    }

    if (icon != null) {
        //Draw the icon over and over, right aligned.
        Insets insets = getInsets();
        int iconWidth = icon.getIconWidth();
        int iconX = getWidth() - insets.right - iconWidth;
        int iconY = insets.top;
        boolean faded = false;

        //Copy the Graphics object, which is actually
        //a Graphics2D object.  Cast it so we can
        //set alpha composite.
        Graphics2D g2d = (Graphics2D) g.create();

        //Draw the icons, starting from the right.
        //After the first one, the rest are faded.
        //We won't bother painting icons that are clipped.
        g.getClipBounds(clipRect);
        while (iconX >= insets.left) {
            iconRect.setBounds(iconX, iconY, iconWidth, icon.getIconHeight());
            if (iconRect.intersects(clipRect)) {
                icon.paintIcon(this, g2d, iconX, iconY);
            }
            iconX -= (iconWidth + pad);
            if (!faded) {
                g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
                faded = true;
            }
        }

        g2d.dispose(); //clean up
    }
}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void paintEllipse2D(Graphics2D g2d, double x, double y, double width, double height, Color linecoler,
        int thickness, Color fillColor, float alpha) throws Exception {

    g2d.setStroke(new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    int[] rules = new int[8];

    //all possible Compositing Rules:
    rules[0] = AlphaComposite.SRC_OVER;
    rules[1] = AlphaComposite.DST_OVER;
    rules[2] = AlphaComposite.CLEAR;
    rules[3] = AlphaComposite.SRC;
    rules[4] = AlphaComposite.SRC_IN;
    rules[5] = AlphaComposite.DST_IN;
    rules[6] = AlphaComposite.SRC_OUT;
    rules[7] = AlphaComposite.DST_OUT;

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha));

    //int x, int y, int width, int height

    if (linecoler != null) {
        g2d.setPaint(linecoler);/*from  w ww.ja v a  2s.c  o m*/
        g2d.draw(new Ellipse2D.Double(x, y, width, height));
    }

    if (fillColor != null) {
        g2d.setPaint(fillColor);
        g2d.fill(new Ellipse2D.Double(x, y, width, height));
    }

}

From source file:de.dakror.villagedefense.game.entity.Entity.java

public void drawEntity(Graphics2D g) {
    if (alpha == 0)
        return;/*from   w w  w . j av  a2  s.c om*/

    drawBump(g, false);
    Composite c = g.getComposite();
    if (this instanceof Struct)
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
    draw(g);
    g.setComposite(c);

    if (isHungry()) {
        g.drawImage(Game.getImage("icon/hunger.png"), (int) x,
                (int) (y - Tile.SIZE - Math.cos(tick / 10f) * Tile.SIZE / 4), 32, 32, Game.w);
    } else if (this instanceof Struct && !((Struct) this).isWorking()) {
        g.drawImage(Game.getImage("icon/sleep.png"), (int) (x + width * 0.75f),
                (int) (y - Tile.SIZE - Math.cos(tick / 10f) * Tile.SIZE / 4), 32, 32, Game.w);
    }

    drawBump(g, true);
}

From source file:forge.view.arcane.util.OutlinedLabel.java

/** {@inheritDoc} */
@Override//from  www  .j  a v  a  2 s .  c  o  m
public final void paint(final Graphics g) {
    if (getText().length() == 0) {
        return;
    }

    Dimension size = getSize();
    //
    //        if( size.width < 50 ) {
    //            g.setColor(Color.cyan);
    //            g.drawRect(0, 0, size.width-1, size.height-1);
    //        }

    Graphics2D g2d = (Graphics2D) g;

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    int textX = outlineSize, textY = 0;
    int wrapWidth = Math.max(0, wrap ? size.width - outlineSize * 2 : Integer.MAX_VALUE);

    final String text = getText();
    AttributedString attributedString = new AttributedString(text);
    if (!StringUtils.isEmpty(text)) {
        attributedString.addAttribute(TextAttribute.FONT, getFont());
    }
    AttributedCharacterIterator charIterator = attributedString.getIterator();
    FontRenderContext fontContext = g2d.getFontRenderContext();

    LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator,
            BreakIterator.getWordInstance(Locale.ENGLISH), fontContext);
    int lineCount = 0;
    while (measurer.getPosition() < charIterator.getEndIndex()) {
        measurer.nextLayout(wrapWidth);
        lineCount++;
        if (lineCount > 2) {
            break;
        }
    }
    charIterator.first();
    // Use char wrap if word wrap would cause more than two lines of text.
    if (lineCount > 2) {
        measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH),
                fontContext);
    } else {
        measurer.setPosition(0);
    }
    while (measurer.getPosition() < charIterator.getEndIndex()) {
        TextLayout textLayout = measurer.nextLayout(wrapWidth);
        float ascent = textLayout.getAscent();
        textY += ascent; // Move down to baseline.

        g2d.setColor(outlineColor);
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));

        textLayout.draw(g2d, textX + outlineSize, textY - outlineSize);
        textLayout.draw(g2d, textX + outlineSize, textY + outlineSize);
        textLayout.draw(g2d, textX - outlineSize, textY - outlineSize);
        textLayout.draw(g2d, textX - outlineSize, textY + outlineSize);

        g2d.setColor(getForeground());
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
        textLayout.draw(g2d, textX, textY);

        // Move down to top of next line.
        textY += textLayout.getDescent() + textLayout.getLeading();
    }
}

From source file:IconDisplayer.java

protected void paintComponent(Graphics g) {
    if (isOpaque()) { //paint background
        g.setColor(getBackground());/*from  ww  w  .j ava  2 s. c  o  m*/
        g.fillRect(0, 0, getWidth(), getHeight());
    }

    if (icon != null) {
        //Draw the icon over and over, right aligned.
        Insets insets = getInsets();
        int iconWidth = icon.getIconWidth();
        int iconX = getWidth() - insets.right - iconWidth;
        int iconY = insets.top;
        boolean faded = false;

        //Copy the Graphics object, which is actually
        //a Graphics2D object. Cast it so we can
        //set alpha composite.
        Graphics2D g2d = (Graphics2D) g.create();

        //Draw the icons, starting from the right.
        //After the first one, the rest are faded.
        //We won't bother painting icons that are clipped.
        g.getClipBounds(clipRect);
        while (iconX >= insets.left) {
            iconRect.setBounds(iconX, iconY, iconWidth, icon.getIconHeight());
            if (iconRect.intersects(clipRect)) {
                icon.paintIcon(this, g2d, iconX, iconY);
            }
            iconX -= (iconWidth + pad);
            if (!faded) {
                g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
                faded = true;
            }
        }

        g2d.dispose(); //clean up
    }
}

From source file:org.tsho.dmc2.core.chart.CowebRenderer.java

private void animateCowebPlot(Graphics2D g2, Rectangle2D dataArea) {

    Graphics2D g2bisec = (Graphics2D) g2.create();
    g2bisec.setColor(Color.blue);

    Stroke stroke = new BasicStroke(3f);
    Stroke origStroke = g2.getStroke();
    Color color = Color.BLACK;
    g2blink = (Graphics2D) g2.create();
    g2blink.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

    g2blink.setXORMode(color);/*w  ww  . jav a2s.c o  m*/
    g2blink.setStroke(stroke);

    if (plot.isAlpha()) {
        g2bisec.setComposite(AlphaComposite.SrcOver);
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getForegroundAlpha()));
    }

    /* transients */
    stepper.setInitialValue(initialValue);
    stepper.initialize();

    state = STATE_TRANSIENTS;

    for (int index = 0; index < transients; index++) {

        stepper.step();

        if (stopped) {
            state = STATE_STOPPED;
            return;
        }
    }

    state = STATE_RUNNING;

    Range xDataRange = plot.getDataRange(domainAxis);
    int transX, transY, transX1, transY1;

    transX = (int) this.domainAxis.valueToJava2D(xDataRange.getLowerBound(), dataArea, RectangleEdge.BOTTOM);
    transY = (int) this.rangeAxis.valueToJava2D(xDataRange.getLowerBound(), dataArea, RectangleEdge.LEFT);
    transX1 = (int) this.domainAxis.valueToJava2D(xDataRange.getUpperBound(), dataArea, RectangleEdge.BOTTOM);
    transY1 = (int) this.rangeAxis.valueToJava2D(xDataRange.getUpperBound(), dataArea, RectangleEdge.LEFT);

    g2bisec.drawLine(transX, transY, transX1, transY1);

    //renderer.reset();

    recurseCoweb(g2, dataArea);
}

From source file:net.sf.maltcms.chromaui.project.spi.nodes.DescriptorNode.java

@Override
public Image getIcon(int type) {
    Image descrImage = DescriptorFactory.getImage(getBean());
    int w = descrImage.getWidth(null);
    int h = descrImage.getHeight(null);
    if (getBean() instanceof IColorizableDescriptor) {
        IColorizableDescriptor colorDescr = (IColorizableDescriptor) getBean();
        Color c = colorDescr.getColor();
        if (c != null) {
            BufferedImage bi = new BufferedImage(w / 10, h / 10, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = bi.createGraphics();

            g2.setColor(colorDescr.getColor());
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.9f));
            g2.fillRect(0, 0, bi.getWidth(), bi.getHeight());
            descrImage = ImageUtilities.mergeImages(bi, descrImage, w - bi.getWidth(), h - bi.getHeight());
        }//from w w  w  . j av  a  2  s. com
    }
    return descrImage;
}

From source file:WeatherWizard.java

void setupImages(int min, int max, BufferedImage i0, BufferedImage i1) {
    float alpha = (max - temperature) / (float) (max - min);
    alpha0 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
    alpha1 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1 - alpha);
    img0 = i0;/*from  w  w w  .jav a2s.c  o m*/
    img1 = i1;

}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void paintRect2D(Graphics2D g2d, double x, double y, double width, double height, Color linecoler,
        int thickness, Color fillColor, float alpha) throws Exception {

    g2d.setStroke(new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

    int[] rules = new int[8];

    //all possible Compositing Rules:
    rules[0] = AlphaComposite.SRC_OVER;
    rules[1] = AlphaComposite.DST_OVER;
    rules[2] = AlphaComposite.CLEAR;
    rules[3] = AlphaComposite.SRC;
    rules[4] = AlphaComposite.SRC_IN;
    rules[5] = AlphaComposite.DST_IN;
    rules[6] = AlphaComposite.SRC_OUT;
    rules[7] = AlphaComposite.DST_OUT;

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha));

    //int x, int y, int width, int height

    if (linecoler != null) {
        g2d.setPaint(linecoler);//from  w  w w. j a  va 2 s  .c  om
        g2d.draw(new Rectangle2D.Double(x, y, width, height));
    }

    if (fillColor != null) {
        g2d.setPaint(fillColor);
        g2d.fill(new Rectangle2D.Double(x, y, width, height));
    }

}