Example usage for java.awt Graphics fillRect

List of usage examples for java.awt Graphics fillRect

Introduction

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

Prototype

public abstract void fillRect(int x, int y, int width, int height);

Source Link

Document

Fills the specified rectangle.

Usage

From source file:net.rptools.tokentool.ui.TokenCompositionPanel.java

@Override
protected void paintComponent(Graphics g) {

    Dimension size = getSize();/*from w  ww.java2 s  .c  o m*/
    g.setColor(Color.black);
    g.fillRect(0, 0, size.width, size.height);

    int messageY = 15;
    int messageX = 5;

    // BASE
    if (AppState.compositionProperties.isBase()) {
        paintOverlay(g, size);
    }

    // TOKEN
    if (tokenImage != null) {
        int width = (int) (tokenImage.getWidth() * tokenScale);
        int height = (int) (tokenImage.getHeight() * tokenScale);
        g.drawImage(tokenImage, tokenOffsetX, tokenOffsetY, width, height, this);
    } else {
        g.setColor(Color.white);
        g.drawString("Drag an image onto this pane", messageX, messageY);
        messageY += 15;
    }

    if (!AppState.compositionProperties.isBase()) {
        paintOverlay(g, size);
    }
}

From source file:uk.co.modularaudio.mads.base.scopen.ui.display.ScopeWaveDisplay.java

@Override
public void paint(final Graphics g) {
    //      log.debug("paint");
    g.setColor(ScopeNColours.BACKGROUND_COLOR);
    g.fillRect(0, 0, width, height);

    g.setColor(ScopeNColours.SCOPE_BODY);

    g.translate(0, yOffset);//from ww  w. j  ava 2  s .co  m

    paintGridLines(g);

    paintData(g);

    g.translate(0, -yOffset);
}

From source file:AncestorTree.java

public void paint(Graphics g) {
    Color bColor = getBackground();
    Icon icon = getIcon();//from www. java 2s.  com

    g.setColor(bColor);
    int offset = 0;
    if (icon != null && getText() != null)
        offset = (icon.getIconWidth() + getIconTextGap());
    g.fillRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1);

    if (m_selected) {
        g.setColor(m_borderSelectionColor);
        g.drawRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1);
    }

    super.paint(g);
}

From source file:util.ui.PictureAreaIcon.java

public void paintIcon(final Component c, Graphics g, int x, int y) {
    if (mScaledIcon == null) {
        return;//w ww .  j a  v a2s .c om
    }

    y += 2;

    Color color = g.getColor();

    if (!colorsInEqualRange(c.getBackground(), c.getForeground()) && !mProgram.isExpired()) {
        g.setColor(c.getBackground());
        g.fillRect(x, y, getIconWidth(), getIconHeight() - 2);
    }

    g.setColor(color);
    g.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 3);

    y += 3;
    x += 3;

    if (mIsGrayFilter && !mIsExpired && mProgram.isExpired()) {
        ImageFilter filter = new GrayFilter(true, 60);
        mScaledIcon
                .setImage(c.createImage(new FilteredImageSource(mScaledIcon.getImage().getSource(), filter)));
        mIsExpired = true;
    }

    if (c.getForeground().getAlpha() != 255) {
        ImageFilter filter = new RGBImageFilter() {
            public int filterRGB(int x, int y, int rgb) {
                if ((rgb & 0xff000000) != 0) {
                    return (rgb & 0xffffff) | (c.getForeground().getAlpha() << 24);
                }
                return rgb;
            }
        };

        mScaledIcon
                .setImage(c.createImage(new FilteredImageSource(mScaledIcon.getImage().getSource(), filter)));
    }

    mScaledIcon.paintIcon(c, g, x, y);

    /*
    if(!mProgram.isExpired()) {
      g.setColor(color);
    } else {
      g.setColor(color);
    }
    */
    mCopyrightText.paintIcon(null, g, x, y + mScaledIcon.getIconHeight());
    if (mDescriptionLines > 0 && mDescriptionText != null) {
        mDescriptionText.paintIcon(null, g, x,
                y + mScaledIcon.getIconHeight() + mCopyrightText.getIconHeight() + 1);
    }
    g.setColor(color);
}

From source file:TextBouncer.java

protected void render() {
    Graphics g = getGraphics();/*ww w .  j  a v  a2 s.c om*/
    if (g != null) {
        Dimension d = getSize();
        if (checkImage(d)) {
            Graphics imageGraphics = image.getGraphics();
            // Clear the image background.
            imageGraphics.setColor(getBackground());
            imageGraphics.fillRect(0, 0, d.width, d.height);
            imageGraphics.setColor(getForeground());
            // Draw this component offscreen.
            paint(imageGraphics);
            // Now put the offscreen image on the screen.
            g.drawImage(image, 0, 0, null);
            // Clean up.
            imageGraphics.dispose();
        }
        g.dispose();
    }
}

From source file:org.b3log.symphony.service.AvatarQueryService.java

/**
 * Creates a avatar image with the specified hash string and size.
 *
 * <p>//from  w ww. j  av a 2 s. c o m
 * Refers to: https://github.com/superhj1987/awesome-identicon
 * </p>
 *
 * @param hash the specified hash string
 * @param size the specified size
 * @return buffered image
 */
public BufferedImage createAvatar(final String hash, final int size) {
    final boolean[][] array = new boolean[6][5];

    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 5; j++) {
            array[i][j] = false;
        }
    }

    for (int i = 0; i < hash.length(); i += 2) {
        final int s = i / 2;

        final boolean v = Math.random() > 0.5;
        if (s % 3 == 0) {
            array[s / 3][0] = v;
            array[s / 3][4] = v;
        } else if (s % 3 == 1) {
            array[s / 3][1] = v;
            array[s / 3][3] = v;
        } else {
            array[s / 3][2] = v;
        }
    }

    final int ratio = Math.round(size / 5);

    final BufferedImage ret = new BufferedImage(ratio * 5, ratio * 5, BufferedImage.TYPE_3BYTE_BGR);
    final Graphics graphics = ret.getGraphics();

    graphics.setColor(new Color(Integer.parseInt(String.valueOf(hash.charAt(0)), 16) * 16,
            Integer.parseInt(String.valueOf(hash.charAt(1)), 16) * 16,
            Integer.parseInt(String.valueOf(hash.charAt(2)), 16) * 16));
    graphics.fillRect(0, 0, ret.getWidth(), ret.getHeight());

    graphics.setColor(new Color(Integer.parseInt(String.valueOf(hash.charAt(hash.length() - 1)), 16) * 16,
            Integer.parseInt(String.valueOf(hash.charAt(hash.length() - 2)), 16) * 16,
            Integer.parseInt(String.valueOf(hash.charAt(hash.length() - 3)), 16) * 16));
    for (int i = 0; i < 6; i++) {
        for (int j = 0; j < 5; j++) {
            if (array[i][j]) {
                graphics.fillRect(j * ratio, i * ratio, ratio, ratio);
            }
        }
    }

    return ret;
}

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);//  ww  w.  j a  v a  2 s  .  c o  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:org.deegree.ogcwebservices.wms.dataaccess.ID2PInterpolation.java

private void writeErrorMessage() {
    Graphics g = image.getGraphics();
    g.setColor(Color.WHITE);/*from w ww .  j  av  a2 s  . co  m*/
    g.fillRect(0, 0, getMap.getWidth(), getMap.getHeight());
    g.setColor(Color.RED);
    g.drawString("not enough values for interpolation available", 10, 50);
    g.dispose();
}

From source file:VASSAL.counters.Labeler.java

public static void drawLabel(Graphics g, String text, int x, int y, Font f, int hAlign, int vAlign,
        Color fgColor, Color bgColor, Color borderColor) {
    g.setFont(f);/*w  w w  .  j a v  a2s  .  co m*/
    final int width = g.getFontMetrics().stringWidth(text + "  ");
    final int height = g.getFontMetrics().getHeight();
    int x0 = x;
    int y0 = y;
    switch (hAlign) {
    case CENTER:
        x0 = x - width / 2;
        break;
    case LEFT:
        x0 = x - width;
        break;
    }
    switch (vAlign) {
    case CENTER:
        y0 = y - height / 2;
        break;
    case BOTTOM:
        y0 = y - height;
        break;
    }
    if (bgColor != null) {
        g.setColor(bgColor);
        g.fillRect(x0, y0, width, height);
    }
    if (borderColor != null) {
        g.setColor(borderColor);
        g.drawRect(x0, y0, width, height);
    }
    g.setColor(fgColor);
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.drawString(" " + text + " ", x0, y0 + g.getFontMetrics().getHeight() - g.getFontMetrics().getDescent());
}

From source file:AccessibleScrollDemo.java

public void paintComponent(Graphics g) {
    Rectangle drawHere = g.getClipBounds();

    // Fill clipping area with dirty brown/orange.
    g.setColor(new Color(230, 163, 4));
    g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height);

    // Do the ruler labels in a small font that's black.
    g.setFont(new Font("SansSerif", Font.PLAIN, 10));
    g.setColor(Color.black);/*  w w w.j  a  v a 2s . c  om*/

    // Some vars we need.
    int end = 0;
    int start = 0;
    int tickLength = 0;
    String text = null;

    // Use clipping bounds to calculate first tick
    // and last tick location.
    if (orientation == HORIZONTAL) {
        start = (drawHere.x / increment) * increment;
        end = (((drawHere.x + drawHere.width) / increment) + 1) * increment;
    } else {
        start = (drawHere.y / increment) * increment;
        end = (((drawHere.y + drawHere.height) / increment) + 1) * increment;
    }

    // Make a special case of 0 to display the number
    // within the rule and draw a units label.
    if (start == 0) {
        text = Integer.toString(0) + (isMetric ? " cm" : " in");
        tickLength = 10;
        if (orientation == HORIZONTAL) {
            g.drawLine(0, SIZE - 1, 0, SIZE - tickLength - 1);
            g.drawString(text, 2, 21);
        } else {
            g.drawLine(SIZE - 1, 0, SIZE - tickLength - 1, 0);
            g.drawString(text, 9, 10);
        }
        text = null;
        start = increment;
    }

    // ticks and labels
    for (int i = start; i < end; i += increment) {
        if (i % units == 0) {
            tickLength = 10;
            text = Integer.toString(i / units);
        } else {
            tickLength = 7;
            text = null;
        }

        if (tickLength != 0) {
            if (orientation == HORIZONTAL) {
                g.drawLine(i, SIZE - 1, i, SIZE - tickLength - 1);
                if (text != null)
                    g.drawString(text, i - 3, 21);
            } else {
                g.drawLine(SIZE - 1, i, SIZE - tickLength - 1, i);
                if (text != null)
                    g.drawString(text, 9, i + 3);
            }
        }
    }
}