Example usage for java.awt Graphics getClipBounds

List of usage examples for java.awt Graphics getClipBounds

Introduction

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

Prototype

public Rectangle getClipBounds(Rectangle r) 

Source Link

Document

Returns the bounding rectangle of the current clipping area.

Usage

From source file:painting.IconDisplayer.java

protected void paintComponent(Graphics g) {
    if (isOpaque()) { //paint background
        g.setColor(getBackground());/*from   www .  ja v  a2 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:IconDisplayer.java

protected void paintComponent(Graphics g) {
    if (isOpaque()) { //paint background
        g.setColor(getBackground());/* w  w  w.j a  va  2s  .  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:uk.co.modularaudio.util.audio.gui.patternsequencer.PatternSequenceAmpGrid.java

@Override
public void paint(final Graphics g) {
    //      log.debug("Paint called");
    getBounds(curClipBounds);/* w  ww .jav a  2 s . co m*/
    //      log.debug( "Curclipbounds after get bounds are " + curClipBounds.toString() );
    g.getClipBounds(curClipBounds);
    g.setColor(backgroundColour);
    //      log.debug( "Curclipbounds after get clip bounds are " + curClipBounds.toString() );
    g.fillRect(curClipBounds.x, curClipBounds.y, curClipBounds.width, curClipBounds.height);
    // Work out our boundings values +/- the individual cell width so we paint the edge cases too
    minPointToPaint.x = curClipBounds.x - cellDimensions.width;
    minPointToPaint.y = curClipBounds.y - cellDimensions.height;
    maxPointToPaint.x = curClipBounds.x + curClipBounds.width + (cellDimensions.width);
    maxPointToPaint.y = curClipBounds.y + curClipBounds.height + (cellDimensions.height);
    final int startCol = (minPointToPaint.x < 0 ? 0 : (minPointToPaint.x / cellDimensions.width));
    final int endCol = (maxPointToPaint.x >= size.width ? numCols : (maxPointToPaint.x / cellDimensions.width));

    //      log.debug( "So for minpoint(" + minPointToPaint.toString() + ") and maxpoint(" + maxPointToPaint.toString() + ")");
    //      log.debug( "We get startCol(" + startCol + ") and endCol(" + endCol +")");

    paintGrid(g, startCol, endCol);
    paintCells(g, startCol, endCol);
}

From source file:uk.co.modularaudio.util.audio.gui.patternsequencer.PatternSequenceNoteGrid.java

@Override
public void paint(final Graphics g) {
    //      log.debug("Paint called");
    getBounds(curClipBounds);//from   w  w  w  . j  a  va 2s. c om
    //      log.debug( "Curclipbounds after get bounds are " + curClipBounds.toString() );
    g.getClipBounds(curClipBounds);
    g.setColor(backgroundColour);
    //      log.debug( "Curclipbounds after get clip bounds are " + curClipBounds.toString() );
    g.fillRect(curClipBounds.x, curClipBounds.y, curClipBounds.width, curClipBounds.height);
    // Work out our boundings values +/- the individual cell width so we paint the edge cases too
    minPointToPaint.x = curClipBounds.x - cellDimensions.width;
    minPointToPaint.y = curClipBounds.y - cellDimensions.height;
    maxPointToPaint.x = curClipBounds.x + curClipBounds.width + (cellDimensions.width);
    maxPointToPaint.y = curClipBounds.y + curClipBounds.height + (cellDimensions.height);
    final int startCol = (minPointToPaint.x < 0 ? 0 : (minPointToPaint.x / cellDimensions.width));
    final int endCol = (maxPointToPaint.x >= size.width ? numCols : (maxPointToPaint.x / cellDimensions.width));
    final int startRow = (minPointToPaint.y < 0 ? 0 : (minPointToPaint.y / cellDimensions.height));
    final int endRow = (maxPointToPaint.y >= size.height ? numMidiNotes
            : (maxPointToPaint.y / cellDimensions.height));
    //      log.debug( "So for minpoint(" + minPointToPaint.toString() + ") and maxpoint(" + maxPointToPaint.toString() + ")");
    //      log.debug( "We get startCol(" + startCol + ") and endCol(" + endCol +")");
    //      log.debug( "We get startRow(" + startRow + ") and endRow(" + endRow +")");

    paintGrid(g, startCol, endCol, startRow, endRow);
    paintCells(g, startCol, endCol, startRow, endRow);

    //      g.setColor( Color.RED );
    //      g.drawLine( lastPoint.x-2, lastPoint.y, lastPoint.x+2, lastPoint.y );
    //      g.drawLine( lastPoint.x, lastPoint.y-2, lastPoint.x, lastPoint.y+2 );
}