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:org.jfree.experimental.swt.SWTGraphics2D.java

/**
 * Sets the current color for this graphics context.
 *
 * @param color  the color (<code>null</code> permitted but ignored).
 *
 * @see #getColor()//from  w  w  w .j  a  v a2s. c  om
 */
public void setColor(Color color) {
    if (color == null) {
        return;
    }
    org.eclipse.swt.graphics.Color swtColor = getSwtColorFromPool(color);
    this.gc.setForeground(swtColor);
    // handle transparency and compositing.
    if (this.composite instanceof AlphaComposite) {
        AlphaComposite acomp = (AlphaComposite) this.composite;
        switch (acomp.getRule()) {
        case AlphaComposite.SRC_OVER:
            this.gc.setAlpha((int) (color.getAlpha() * acomp.getAlpha()));
            break;
        default:
            this.gc.setAlpha(color.getAlpha());
            break;
        }
    }
}

From source file:org.apache.pdfbox.pdmodel.graphics.PDGraphicsState.java

public Composite getStrokeJavaComposite() {

    return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alphaConstants);
}

From source file:org.apache.pdfbox.pdmodel.graphics.PDGraphicsState.java

public Composite getNonStrokeJavaComposite() {

    return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) nonStrokingAlphaConstants);
}

From source file:org.geomajas.plugin.rasterizing.layer.RasterDirectLayer.java

private BufferedImage makeOpaque(BufferedImage image) {
    if (image.getType() == BufferedImage.TYPE_CUSTOM) {
        log.warn("makeOpaque {} Unknown Image Type 0: ", getTitle());
        return image;
    }/*from  w ww. j  a  va 2 s .  co m*/
    BufferedImage opaqueCopy = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
    Graphics2D g1 = opaqueCopy.createGraphics();
    g1.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getOpacity()));
    g1.drawImage(image, null, 0, 0);
    g1.dispose();
    return opaqueCopy;
}

From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java

private void drawOutline(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel,
        boolean scale, float alpha) {
    if (entity != null) {
        //System.out.println("Drawing entity with bbox: "+entity.getBounds2D());
        Shape savedClip = g2.getClip();
        Rectangle2D dataArea = chartPanel.getScreenDataArea();
        Color c = g2.getColor();// www .j a  va2  s .  c om
        Composite comp = g2.getComposite();
        g2.clip(dataArea);
        g2.setColor(fill);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        JFreeChart chart = chartPanel.getChart();
        XYPlot plot = (XYPlot) chart.getPlot();
        ValueAxis xAxis = plot.getDomainAxis();
        ValueAxis yAxis = plot.getRangeAxis();
        RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
        RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
        Rectangle2D entityBounds = entity.getBounds2D();
        double viewX = xAxis.valueToJava2D(entityBounds.getCenterX(), dataArea, xAxisEdge);
        double viewY = yAxis.valueToJava2D(entityBounds.getCenterY(), dataArea, yAxisEdge);
        double viewW = xAxis.lengthToJava2D(entityBounds.getWidth(), dataArea, xAxisEdge);
        double viewH = yAxis.lengthToJava2D(entityBounds.getHeight(), dataArea, yAxisEdge);
        PlotOrientation orientation = plot.getOrientation();

        //transform model to origin (0,0) in model coordinates
        AffineTransform toOrigin = AffineTransform.getTranslateInstance(-entityBounds.getCenterX(),
                -entityBounds.getCenterY());
        //transform from origin (0,0) to model location
        AffineTransform toModelLocation = AffineTransform.getTranslateInstance(entityBounds.getCenterX(),
                entityBounds.getCenterY());
        //transform from model scale to view scale
        double scaleX = viewW / entityBounds.getWidth();
        double scaleY = viewH / entityBounds.getHeight();
        Logger.getLogger(getClass().getName()).log(Level.FINE, "Scale x: {0} Scale y: {1}",
                new Object[] { scaleX, scaleY });
        AffineTransform toViewScale = AffineTransform.getScaleInstance(scaleX, scaleY);
        AffineTransform toViewLocation = AffineTransform.getTranslateInstance(viewX, viewY);
        AffineTransform flipTransform = AffineTransform.getScaleInstance(1.0f, -1.0f);
        AffineTransform modelToView = new AffineTransform(toOrigin);
        modelToView.preConcatenate(flipTransform);
        modelToView.preConcatenate(toViewScale);
        modelToView.preConcatenate(toViewLocation);
        //
        //            if (orientation == PlotOrientation.HORIZONTAL) {
        //                entity = ShapeUtilities.createTranslatedShape(entity, viewY,
        //                        viewX);
        //            } else if (orientation == PlotOrientation.VERTICAL) {
        //                entity = ShapeUtilities.createTranslatedShape(entity, viewX,
        //                        viewY);
        //            }
        FlatteningPathIterator iter = new FlatteningPathIterator(modelToView.createTransformedShape(entity)
                .getPathIterator(AffineTransform.getTranslateInstance(0, 0)), 5);
        Path2D.Float path = new Path2D.Float();
        path.append(iter, false);

        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        g2.fill(path);
        if (stroke != null) {
            g2.setColor(stroke);
            g2.draw(path);
        }
        g2.setComposite(comp);
        g2.setColor(c);
        g2.setClip(savedClip);
    } else {
        Logger.getLogger(getClass().getName()).info("Entity is null!");
    }
}

From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java

/**
 * Draws the plot on a Java 2D graphics device (such as the screen
 * or a printer)./*from  w w w  .  j  a v  a 2  s.c o m*/
 * @param g2 The graphics device.
 * @param plotArea The area within which the plot should be drawn.
 */
@Override
public void draw(Graphics2D g2, Rectangle2D plotArea, Point2D anchor, PlotState state, PlotRenderingInfo info) {
    // adjust for insets...
    RectangleInsets insets = getInsets();
    if (insets != null) {
        plotArea.setRect(plotArea.getX() + insets.getLeft(), plotArea.getY() + insets.getTop(),
                plotArea.getWidth() - insets.getLeft() - insets.getRight(),
                plotArea.getHeight() - insets.getTop() - insets.getBottom());
    }

    if (info != null) {
        info.setPlotArea(plotArea);
        info.setDataArea(plotArea);
    }

    drawBackground(g2, plotArea);
    drawOutline(g2, plotArea);

    Shape savedClip = g2.getClip();
    g2.clip(plotArea);

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));

    if (this.dataset != null) {
        drawRadar(g2, plotArea, info, 0, this.dataset);
    } else {
        drawNoDataMessage(g2, plotArea);
    }

    g2.clip(savedClip);
    g2.setComposite(originalComposite);

    drawOutline(g2, plotArea);

}

From source file:com.celements.photo.image.GenerateThumbnail.java

private void drawWatermark(String watermark, Graphics2D g2d, int width, int height) {
    //TODO implement 'secure' watermark (i.e. check if this algorithm secure or can it be easily reversed?)
    g2d.setColor(new Color(255, 255, 150));
    AlphaComposite transprency = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.45f);
    g2d.setComposite(transprency);/*  w  w  w.jav a  2 s . c  o m*/

    FontMetrics metrics = calcWatermarkFontSize(watermark, width, g2d);
    g2d.setFont(calcWatermarkFontSize(watermark, width, g2d).getFont());

    // rotate around image center
    double angle = (Math.sin(height / (double) width));
    g2d.rotate(-angle, width / 2.0, height / 2.0);

    g2d.drawString(watermark, (width - metrics.stringWidth(watermark)) / 2,
            ((height - metrics.getHeight()) / 2) + metrics.getAscent());

    // undo rotation for correct copyright positioning
    g2d.rotate(angle, width / 2.0, height / 2.0);
}

From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java

private void drawEntity(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel,
        boolean scale, float alpha) {
    if (entity != null) {
        //System.out.println("Drawing entity with bbox: "+entity.getBounds2D());
        Shape savedClip = g2.getClip();
        Rectangle2D dataArea = chartPanel.getScreenDataArea();
        Color c = g2.getColor();//w w w  .  ja  va  2  s .com
        Composite comp = g2.getComposite();
        g2.clip(dataArea);
        g2.setColor(fill);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        AffineTransform originalTransform = g2.getTransform();
        Shape transformed = entity;
        FlatteningPathIterator iter = new FlatteningPathIterator(
                transformed.getPathIterator(new AffineTransform()), 1);
        Path2D.Float path = new Path2D.Float();
        path.append(iter, false);
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        g2.fill(path);
        if (stroke != null) {
            g2.setColor(stroke);
            g2.draw(path);
        }
        g2.setComposite(comp);
        g2.setColor(c);
        g2.setClip(savedClip);
    } else {
        Logger.getLogger(getClass().getName()).info("Entity is null!");
    }
}

From source file:userinterface.graph.PrismErrorRenderer.java

/**
 * Draws the visual representation for one data item.
 *
 * @param g2  the graphics output target.
 * @param state  the renderer state.//from www .  ja va2s .com
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index
 * @author Muhammad Omer Saeed.
 */

@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    if (!drawError) {
        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);
        return;
    }

    switch (currentMethod) {

    case PrismErrorRenderer.ERRORBARS:

        if (pass == 0 && dataset instanceof XYSeriesCollection && getItemVisible(series, item)) {

            synchronized (dataset) {

                XYSeriesCollection collection = (XYSeriesCollection) dataset;

                PlotOrientation orientation = plot.getOrientation();
                // draw the error bar for the y-interval
                XYSeries s = collection.getSeries(series);
                PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item);

                double y0 = it.getYValue() + it.getError();
                double y1 = it.getYValue() - it.getError();
                double x = collection.getXValue(series, item);

                RectangleEdge edge = plot.getRangeAxisEdge();
                double yy0 = rangeAxis.valueToJava2D(y0, dataArea, edge);
                double yy1 = rangeAxis.valueToJava2D(y1, dataArea, edge);
                double xx = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
                Line2D line;
                Line2D cap1;
                Line2D cap2;
                double adj = this.capLength / 2.0;
                if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(xx, yy0, xx, yy1);
                    cap1 = new Line2D.Double(xx - adj, yy0, xx + adj, yy0);
                    cap2 = new Line2D.Double(xx - adj, yy1, xx + adj, yy1);
                } else { // PlotOrientation.HORIZONTAL
                    line = new Line2D.Double(yy0, xx, yy1, xx);
                    cap1 = new Line2D.Double(yy0, xx - adj, yy0, xx + adj);
                    cap2 = new Line2D.Double(yy1, xx - adj, yy1, xx + adj);
                }

                g2.setPaint(getItemPaint(series, item));

                if (this.errorStroke != null) {
                    g2.setStroke(this.errorStroke);
                } else {
                    g2.setStroke(getItemStroke(series, item));
                }
                g2.draw(line);
                g2.draw(cap1);
                g2.draw(cap2);
            }

        }

        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);

        break;

    case PrismErrorRenderer.ERRORDEVIATION:

        synchronized (dataset) {
            // do nothing if item is not visible
            if (!getItemVisible(series, item)) {
                return;
            }

            // first pass draws the shading
            if (pass == 0) {

                XYSeriesCollection collection = (XYSeriesCollection) dataset;
                XYSeries s = collection.getSeries(series);
                PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item);

                State drState = (State) state;

                double x = collection.getXValue(series, item);
                double yLow = it.getYValue() - it.getError();
                double yHigh = it.getYValue() + it.getError();

                RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
                RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

                double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
                double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

                PlotOrientation orientation = plot.getOrientation();
                if (orientation == PlotOrientation.HORIZONTAL) {
                    drState.lowerCoordinates.add(new double[] { yyLow, xx });
                    drState.upperCoordinates.add(new double[] { yyHigh, xx });
                } else if (orientation == PlotOrientation.VERTICAL) {
                    drState.lowerCoordinates.add(new double[] { xx, yyLow });
                    drState.upperCoordinates.add(new double[] { xx, yyHigh });
                }

                if (item == (dataset.getItemCount(series) - 1)) {
                    // last item in series, draw the lot...
                    // set up the alpha-transparency...
                    Composite originalComposite = g2.getComposite();
                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) this.alpha));
                    g2.setPaint(getItemPaint(series, item));
                    GeneralPath area = new GeneralPath();
                    double[] coords = (double[]) drState.lowerCoordinates.get(0);
                    area.moveTo((float) coords[0], (float) coords[1]);
                    for (int i = 1; i < drState.lowerCoordinates.size(); i++) {
                        coords = (double[]) drState.lowerCoordinates.get(i);
                        area.lineTo((float) coords[0], (float) coords[1]);
                    }
                    int count = drState.upperCoordinates.size();
                    coords = (double[]) drState.upperCoordinates.get(count - 1);
                    area.lineTo((float) coords[0], (float) coords[1]);
                    for (int i = count - 2; i >= 0; i--) {
                        coords = (double[]) drState.upperCoordinates.get(i);
                        area.lineTo((float) coords[0], (float) coords[1]);
                    }
                    area.closePath();
                    g2.fill(area);
                    g2.setComposite(originalComposite);

                    drState.lowerCoordinates.clear();
                    drState.upperCoordinates.clear();
                }
            }
            if (isLinePass(pass)) {

                // the following code handles the line for the y-values...it's
                // all done by code in the super class
                if (item == 0) {
                    State s = (State) state;
                    s.seriesPath.reset();
                    s.setLastPointGood(false);
                }

                if (getItemLineVisible(series, item)) {
                    drawPrimaryLineAsPath(state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis,
                            dataArea);
                }
            }

            // second pass adds shapes where the items are ..
            else if (isItemPass(pass)) {

                // setup for collecting optional entity info...
                EntityCollection entities = null;
                if (info != null) {
                    entities = info.getOwner().getEntityCollection();
                }

                drawSecondaryPass(g2, plot, dataset, pass, series, item, domainAxis, dataArea, rangeAxis,
                        crosshairState, entities);
            }

        }

        break;
    default:
        return;
    }
}

From source file:net.sf.maltcms.common.charts.api.overlay.SelectionOverlay.java

private void drawEntity(Shape entity, Graphics2D g2, Color fill, ChartPanel chartPanel, boolean scale) {
    if (entity != null) {
        Shape savedClip = g2.getClip();
        Rectangle2D dataArea = chartPanel.getScreenDataArea();
        Color c = g2.getColor();/*from   www  . j  ava  2 s . c o  m*/
        Composite comp = g2.getComposite();
        g2.clip(dataArea);
        g2.setColor(fill);
        AffineTransform originalTransform = g2.getTransform();
        Shape transformed = entity;
        if (scale) {
            transformed = scaleAtOrigin(entity, hoverScaleX, hoverScaleY).createTransformedShape(entity);
        }
        transformed = getTranslateInstance(
                entity.getBounds2D().getCenterX() - transformed.getBounds2D().getCenterX(),
                entity.getBounds2D().getCenterY() - transformed.getBounds2D().getCenterY())
                        .createTransformedShape(transformed);
        g2.setComposite(getInstance(AlphaComposite.SRC_OVER, fillAlpha));
        g2.fill(transformed);
        g2.setColor(Color.DARK_GRAY);
        g2.draw(transformed);
        g2.setComposite(comp);
        g2.setColor(c);
        g2.setClip(savedClip);
    }
}