Example usage for java.awt AlphaComposite CLEAR

List of usage examples for java.awt AlphaComposite CLEAR

Introduction

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

Prototype

int CLEAR

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

Click Source Link

Document

Both the color and the alpha of the destination are cleared (Porter-Duff Clear rule).

Usage

From source file:JDK6SplashTest.java

static void renderSplashFrame(Graphics2D g, int frame) {
    final String[] comps = { "foo", "bar", "baz" };
    g.setComposite(AlphaComposite.Clear);
    g.fillRect(130, 250, 280, 40);// www  . j  av  a2s .com
    g.setPaintMode();
    g.setColor(Color.BLACK);
    g.drawString("Loading " + comps[(frame / 5) % 3] + "...", 130, 260);
    g.fillRect(130, 270, (frame * 10) % 280, 20);
}

From source file:Main.java

/**
 * Clears the given area of the specified graphics object with the given
 * color or makes the region transparent.
 *//* w w  w  .j  a  v  a2s .c o m*/
public static void clearRect(Graphics2D g, Rectangle rect, Color background) {
    if (background != null) {
        g.setColor(background);
        g.fillRect(rect.x, rect.y, rect.width, rect.height);
    } else {
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
        g.fillRect(rect.x, rect.y, rect.width, rect.height);
        g.setComposite(AlphaComposite.SrcOver);
    }
}

From source file:MainClass.java

public void paint(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;

    RenderingHints rh = g2.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);/*from w  ww . ja v  a2 s .  c  om*/

    int x = 40, y = 40;

    g.setColor(Color.red);
    g.fillOval(x, y, 50, 50);

    Composite old = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR));

    g.setColor(Color.green);
    g.fillOval(x + 30, y + 30, 30, 30);

    g2.setComposite(old);

    g.setColor(Color.black);
    g.drawString("AlphaComposite.CLEAR", x, y + 80);

}

From source file:SplashDemo.java

static void renderSplashFrame(Graphics2D g, int frame) {
    final String[] comps = { "foo", "bar", "baz" };
    g.setComposite(AlphaComposite.Clear);
    g.fillRect(120, 140, 200, 40);/*from  ww  w.ja  va  2s  .c  o  m*/
    g.setPaintMode();
    g.setColor(Color.BLACK);
    g.drawString("Loading " + comps[(frame / 5) % 3] + "...", 120, 150);
}

From source file:Main.java

/**
 * Snapshots the specified JavaFX {@link Image} object and stores a
 * copy of its pixels into a {@link BufferedImage} object, creating
 * a new object if needed./*from   w w w  .j  a v a2  s  .  c  om*/
 * The method will only convert a JavaFX {@code Image} that is readable
 * as per the conditions on the
 * {@link Image#getPixelReader() Image.getPixelReader()}
 * method.
 * If the {@code Image} is not readable, as determined by its
 * {@code getPixelReader()} method, then this method will return null.
 * If the {@code Image} is a writable, or other dynamic image, then
 * the {@code BufferedImage} will only be set to the current state of
 * the pixels in the image as determined by its {@link PixelReader}.
 * Further changes to the pixels of the {@code Image} will not be
 * reflected in the returned {@code BufferedImage}.
 * <p>
 * The optional {@code BufferedImage} parameter may be reused to store
 * the copy of the pixels.
 * A new {@code BufferedImage} will be created if the supplied object
 * is null, is too small or of a type which the image pixels cannot
 * be easily converted into.
 * 
 * @param img the JavaFX {@code Image} to be converted
 * @param bimg an optional {@code BufferedImage} object that may be
 *        used to store the returned pixel data
 * @return a {@code BufferedImage} containing a snapshot of the JavaFX
 *         {@code Image}, or null if the {@code Image} is not readable.
 * @since JavaFX 2.2
 */
public static BufferedImage fromFXImage(Image img, BufferedImage bimg) {
    PixelReader pr = img.getPixelReader();
    if (pr == null) {
        return null;
    }
    int iw = (int) img.getWidth();
    int ih = (int) img.getHeight();
    int prefBimgType = getBestBufferedImageType(pr.getPixelFormat(), bimg);
    if (bimg != null) {
        int bw = bimg.getWidth();
        int bh = bimg.getHeight();
        if (bw < iw || bh < ih || bimg.getType() != prefBimgType) {
            bimg = null;
        } else if (iw < bw || ih < bh) {
            Graphics2D g2d = bimg.createGraphics();
            g2d.setComposite(AlphaComposite.Clear);
            g2d.fillRect(0, 0, bw, bh);
            g2d.dispose();
        }
    }
    if (bimg == null) {
        bimg = new BufferedImage(iw, ih, prefBimgType);
    }
    IntegerComponentRaster icr = (IntegerComponentRaster) bimg.getRaster();
    int offset = icr.getDataOffset(0);
    int scan = icr.getScanlineStride();
    int data[] = icr.getDataStorage();
    WritablePixelFormat<IntBuffer> pf = getAssociatedPixelFormat(bimg);
    pr.getPixels(0, 0, iw, ih, pf, data, offset, scan);
    return bimg;
}

From source file:HighlightedButton.java

/**
 * Creates a new instance of HighlightedButton
 *///  ww w . ja v  a  2 s  . c  o m
public HighlightedButton(String label) {
    super(label);

    // Get the Graphics for the image
    Graphics2D g2d = highlight.createGraphics();

    // Erase the image with a transparent background
    g2d.setComposite(AlphaComposite.Clear);
    g2d.fillRect(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE);
    g2d.setComposite(AlphaComposite.SrcOver);

    // Draw the highlight
    Point2D center = new Point2D.Float((float) HIGHLIGHT_SIZE / 2.0f, (float) HIGHLIGHT_SIZE / 2.0f);
    float radius = (float) HIGHLIGHT_SIZE / 2.0f;
    float[] dist = { 0.0f, .85f };
    Color[] colors = { Color.white, new Color(255, 255, 255, 0) };
    RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors);
    g2d.setPaint(paint);
    g2d.fillOval(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE);
    g2d.dispose();
}

From source file:Composite.java

public int getRule(int rule) {
    int alphaComp = 0;
    switch (rule) {
    case 0://w  w w  .  j a va 2 s  .com
        alphaComp = AlphaComposite.SRC;
        break;
    case 1:
        alphaComp = AlphaComposite.DST_IN;
        break;
    case 2:
        alphaComp = AlphaComposite.DST_OUT;
        break;
    case 3:
        alphaComp = AlphaComposite.DST_OVER;
        break;
    case 4:
        alphaComp = AlphaComposite.SRC_IN;
        break;
    case 5:
        alphaComp = AlphaComposite.SRC_OVER;
        break;
    case 6:
        alphaComp = AlphaComposite.SRC_OUT;
        break;
    case 7:
        alphaComp = AlphaComposite.CLEAR;
        break;
    }
    return alphaComp;
}

From source file:test.uk.co.modularaudio.util.audio.controlinterpolation.InterpolatorVisualiser.java

public void interpolateEvents(final TestEvent[] events) {
    int lastEventIndex = events[events.length - 1].getOffsetInSamples();
    final float[] vals = new float[lastEventIndex];

    final int numEvents = events.length;

    int curOutputOffset = 0;

    for (int i = 1; i < numEvents; ++i) {
        final int eventOffset = events[i].getOffsetInSamples();

        // Generate using the interpolator up to this event
        final int numForThisEvent = eventOffset - curOutputOffset;
        valueInterpolator.generateControlValues(vals, curOutputOffset, numForThisEvent);

        final float newValue = events[i].getEventValue();
        //         log.debug("Using newValue " + newValue );
        valueInterpolator.notifyOfNewValue(newValue);

        curOutputOffset += numForThisEvent;
    }//from ww w.ja  va  2 s.com

    if (curOutputOffset < lastEventIndex) {
        valueInterpolator.generateControlValues(vals, curOutputOffset,
                SwingControlInterpolatorAnalyser.VIS_WIDTH - curOutputOffset);
    }
    g2d.setComposite(AlphaComposite.Clear);
    g2d.setColor(Color.WHITE);
    g2d.fillRect(0, 0, SwingControlInterpolatorAnalyser.VIS_WIDTH + 1,
            SwingControlInterpolatorAnalyser.VIS_HEIGHT + 1);

    g2d.setComposite(AlphaComposite.SrcOver);
    // If we are the src signal,
    // draw some lines where we have events
    if (controlSrcVisualiser == null) {
        g2d.setColor(new Color(0.6f, 0.6f, 1.0f));
        for (int i = 1; i < numEvents; ++i) {
            final int eventOffset = events[i].getOffsetInSamples();
            final int eventPosInPixels = eventOffset / SwingControlInterpolatorAnalyser.VIS_SAMPLES_PER_PIXEL;

            g2d.drawLine(eventPosInPixels, 0, eventPosInPixels,
                    SwingControlInterpolatorAnalyser.VIS_HEIGHT + 1);
        }
    }

    if (controlSrcVisualiser == null) {
        g2d.setColor(Color.RED);
    } else {
        g2d.setColor(Color.BLACK);
    }

    int previousY = (int) (vals[0] * SwingControlInterpolatorAnalyser.VIS_HEIGHT);
    for (int i = 1; i < lastEventIndex; ++i) {
        final float val = vals[i];
        final float asYValue = val * SwingControlInterpolatorAnalyser.VIS_HEIGHT;
        final int asYInt = (int) asYValue;
        final int x1 = (i - 1) / SwingControlInterpolatorAnalyser.VIS_SAMPLES_PER_PIXEL;
        final int y1 = previousY;
        final int x2 = i / SwingControlInterpolatorAnalyser.VIS_SAMPLES_PER_PIXEL;
        final int y2 = asYInt;
        //         log.debug("Drawing line from " + x1 + ", " + y1 + " to " + x2 + ", " + y2 );
        g2d.drawLine(x1, SwingControlInterpolatorAnalyser.VIS_HEIGHT - y1, x2,
                SwingControlInterpolatorAnalyser.VIS_HEIGHT - y2);

        previousY = y2;
    }

    repaint();
}

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);//  w  w w  .j a v a2 s  .  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:org.broad.igv.hic.MainWindow.java

public void createCursors() {
    BufferedImage handImage = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);

    // Make backgroun transparent
    Graphics2D g = handImage.createGraphics();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
    Rectangle2D.Double rect = new Rectangle2D.Double(0, 0, 32, 32);
    g.fill(rect);/*w ww  .  j  a  v a 2  s. co  m*/

    // Draw hand image in middle
    g = handImage.createGraphics();
    g.drawImage(IconFactory.getInstance().getIcon(IconFactory.IconID.FIST).getImage(), 0, 0, null);
    MainWindow.fistCursor = getToolkit().createCustomCursor(handImage, new Point(8, 6), "Move");
}