Example usage for java.awt Graphics2D getClipBounds

List of usage examples for java.awt Graphics2D getClipBounds

Introduction

In this page you can find the example usage for java.awt Graphics2D getClipBounds.

Prototype

public Rectangle getClipBounds(Rectangle r) 

Source Link

Document

Returns the bounding rectangle of the current clipping area.

Usage

From source file:uk.co.modularaudio.service.bufferedimageallocation.impl.debugwindow.imagebrowser.RawImageCanvas.java

@Override
public void paint(final Graphics rawG) {
    final Graphics2D g = (Graphics2D) rawG;
    g.getClipBounds(clipBounds);

    if (curBufferedImage != null) {
        g.setComposite(opaqueComposite);
        g.setColor(Color.DARK_GRAY);
        g.fillRect(0, 0, width, height);
        g.drawImage(curBufferedImage, 0, 0, null);

        // Draw the free blocks over the top
        // We draw 50 transparent fill then outline with full yellow
        g.setColor(DARK_BLUE);/*w w  w .j av  a  2  s.co m*/
        g.setComposite(ninetyPercentAlphaComposite);
        //         g.setComposite( fiftyPercentAlphaComposite );
        //         g.setComposite( tenPercentAlphaComposite );
        for (final Rectangle freeBlockRectangle : freeBlockRectangles) {
            g.fillRect(freeBlockRectangle.x, freeBlockRectangle.y, freeBlockRectangle.width,
                    freeBlockRectangle.height);
        }

        g.setColor(Color.yellow);
        g.setComposite(opaqueComposite);
        for (final Rectangle freeBlockRectangle : freeBlockRectangles) {
            g.drawRect(freeBlockRectangle.x, freeBlockRectangle.y, freeBlockRectangle.width,
                    freeBlockRectangle.height);
        }

        g.setComposite(opaqueComposite);
        g.setColor(Color.RED);
        for (final Rectangle usedBlockRectangle : usedBlockRectangles) {
            g.drawRect(usedBlockRectangle.x, usedBlockRectangle.y, usedBlockRectangle.width,
                    usedBlockRectangle.height);
        }
    } else {
        g.setColor(Color.gray);
        g.fillRect(0, 0, width, height);
    }
}