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:edu.upf.bioevo.manhattanPlotter.QQPlot.java

void drawPlot() {
    int dotRadius;
    int xIncrement = (IMAGE_WIDTH - (xMargin * 2)) / (int) (maxExpectedLogValue + 1);
    int yIncrement = (IMAGE_HEIGHT - (yMargin * 2)) / (int) (maxObservedLogValue + 1);
    Graphics g = image.getGraphics();

    // Cleans image
    g.setColor(Color.WHITE);//from   w  w w  .j  a  va 2  s .c om
    g.fillRect(0, 0, image.getWidth(), image.getHeight());

    // Draws axis lines
    g.setColor(Color.black);
    g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, IMAGE_WIDTH - xMargin, IMAGE_HEIGHT - yMargin);
    g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, xMargin, yMargin);

    // Draws confidence interval
    if (ic95Option) {
        g.setColor(Color.lightGray);
        for (int i = 0; i < upperCI.length - 1; i++) {
            int[] xPoints = { xMargin + (int) (orderedLog10ExpectedValues[i] * xIncrement),
                    xMargin + (int) (orderedLog10ExpectedValues[i] * xIncrement),
                    xMargin + (int) (orderedLog10ExpectedValues[i + 1] * xIncrement),
                    xMargin + (int) (orderedLog10ExpectedValues[i + 1] * xIncrement) };
            int[] yPoints = { IMAGE_HEIGHT - (yMargin + ((int) (upperCI[i] * yIncrement))),
                    IMAGE_HEIGHT - (yMargin + ((int) (lowerCI[i] * yIncrement))),
                    IMAGE_HEIGHT - (yMargin + ((int) (lowerCI[i + 1] * yIncrement))),
                    IMAGE_HEIGHT - (yMargin + ((int) (upperCI[i + 1] * yIncrement))) };

            g.fillPolygon(xPoints, yPoints, 4);
        }
    }

    // Draws dots
    dotRadius = 4;
    g.setColor(Color.black);
    for (int i = 0; i < orderedLog10ObservedValues.length; i++) {
        int xPosition = xMargin + ((int) (orderedLog10ExpectedValues[i] * xIncrement));
        int yPosition = IMAGE_HEIGHT - (yMargin + ((int) (orderedLog10ObservedValues[i] * yIncrement)));
        g.fillOval(xPosition - dotRadius, yPosition - dotRadius, dotRadius * 2, dotRadius * 2);
    }

    // --draw y axis scale
    // ----Calculates interval between labels in y axis
    int yInterval = 1;
    int verticalMaxValue = (int) maxObservedLogValue + 1;

    if (verticalMaxValue > 20) {
        yInterval = 5;
    }
    if (verticalMaxValue > 100) {
        yInterval = 50;
    }
    if (verticalMaxValue > 1000) {
        yInterval = verticalMaxValue;
    }

    g.setColor(Color.BLACK);
    for (int i = 0; i <= verticalMaxValue; i = i + yInterval) {
        int yPos = IMAGE_HEIGHT
                - (yMargin + (int) (((float) i / verticalMaxValue) * (IMAGE_HEIGHT - 2 * yMargin)));
        g.fillRect(45, yPos, 15, 3);
        g.setFont(new Font("courier", 1, 30));
        String value = String.valueOf(i);
        if (value.length() == 1) {
            value = " " + value;
        }
        g.drawString(value, 5, yPos + 10);
    }

    // --draw x axis scale
    // ----Calculates interval between labels in x axis
    int xInterval = 1;
    int horizontalMaxValue = (int) maxExpectedLogValue + 1;

    if (horizontalMaxValue > 20) {
        xInterval = 5;
    }
    if (horizontalMaxValue > 100) {
        xInterval = 50;
    }
    if (horizontalMaxValue > 1000) {
        xInterval = verticalMaxValue;
    }

    g.setColor(Color.BLACK);
    for (int i = 0; i <= horizontalMaxValue; i = i + xInterval) {
        int xPos = (xMargin + (int) (((float) i / horizontalMaxValue) * (IMAGE_WIDTH - 2 * xMargin)));
        g.fillRect(xPos, IMAGE_HEIGHT - yMargin, 3, 15);
        g.setFont(new Font("courier", 1, 30));
        String value = String.valueOf(i);
        if (value.length() == 1) {
            value = " " + value;
        }
        g.drawString(value, xPos - 15, IMAGE_HEIGHT - yMargin + 45);
    }

    // Draws identity line
    g.setColor(Color.RED);
    int endLineValue = horizontalMaxValue < verticalMaxValue ? horizontalMaxValue : verticalMaxValue;
    g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, xMargin + ((int) (endLineValue * xIncrement)),
            IMAGE_HEIGHT - (yMargin + ((int) (endLineValue * yIncrement))));

    // -- title
    g.setColor(Color.blue);
    g.setFont(new Font("arial", 1, 35));
    g.drawString(label, IMAGE_WIDTH / 7, 40);
}

From source file:BoxLayoutVerticalGlueTest.java

public void paintChildren(Graphics g) {
    super.paintChildren(g);
    Dimension size = getSize();//from   ww  w  .  ja  va 2s .c  o m
    LayoutManager manager = getLayout();
    if ((manager != null) && (manager instanceof BoxLayout)) {
        BoxLayout layout = (BoxLayout) manager;
        boolean vertical = true;
        if (vertical) {
            int axis = (int) (layout.getLayoutAlignmentX(this) * size.width);
            g.fillRect(axis - 1, 0, 3, size.height);
        } else {
            int axis = (int) (layout.getLayoutAlignmentY(this) * size.height);
            g.fillRect(0, axis - 1, size.width, 3);
        }
    }
}

From source file:DesktopManagerDemo.java

public void paintEventSquare(Graphics g, int value, int currwidth, int currheight, int cellwidth,
        int cellheight, Color color) {
    if (value != 0) {
        g.setColor(color);//from w  w  w.  j  a va 2  s .c o  m
        g.fillRect(currwidth, currheight, cellwidth, cellheight);
        g.setColor(Color.green);
        g.drawString("" + value, currwidth + 5, currheight + 14);
    }
    g.setColor(Color.black);
    g.drawRect(currwidth, currheight, cellwidth, cellheight);
}

From source file:io.github.karols.hocr4j.PageRenderer.java

/**
 * Renders this page on a blank image.//w  w  w. ja  v a 2  s.c  om
 * The image is filled with the background color.
 *
 * @param page page to render
 * @return rendered image
 */
@Nonnull
public BufferedImage renderOnBlank(@Nonnull Page page) {
    Bounds pageBounds = page.getBounds().scale(scale);
    BufferedImage img = new BufferedImage(pageBounds.getRight(), pageBounds.getBottom(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics g = img.getGraphics();
    g.setColor(backgroundColor);
    g.fillRect(0, 0, img.getWidth(), img.getHeight());
    renderOnTop(page, img);
    return img;
}

From source file:nl.b3p.kaartenbalie.core.server.b3pLayering.ConfigLayer.java

protected void drawEdgedBox(Graphics g2d, int x, int y, int w, int h) {
    g2d.setColor(KBConfiguration.OHD_borderBoxBackground);
    g2d.fillRect(x, y, w, h);
    g2d.setColor(KBConfiguration.OHD_borderBoxTopLeft);
    g2d.drawLine(x, y, x + w, y); //Top
    g2d.drawLine(x, y + h, x, y); //Left
    g2d.setColor(KBConfiguration.OHD_borderBoxBottomRight);
    g2d.drawLine(x + w, y + h, x, y + h); //Bottom
    g2d.drawLine(x + w, y, x + w, y + h); //Right

}

From source file:edu.ku.brc.af.prefs.GenericPrefsPanel.java

public void paint(Graphics g) {
    super.paint(g);

    if (shadeColor != null) {
        Dimension size = getSize();
        g.setColor(shadeColor);/*from   w  ww . j  a v  a 2  s  .c  o  m*/
        g.fillRect(0, 0, size.width, size.height);
    }
}

From source file:Bouncer.java

protected void render() {
    Graphics g = getGraphics();/*from  w  w w . ja v  a  2  s. c  o  m*/
    if (g != null) {
        Dimension d = getSize();
        if (checkImage(d)) {
            Graphics imageGraphics = image.getGraphics();

            imageGraphics.setColor(getBackground());
            imageGraphics.fillRect(0, 0, d.width, d.height);
            imageGraphics.setColor(getForeground());

            paint(imageGraphics);

            g.drawImage(image, 0, 0, null);

            imageGraphics.dispose();
        }
        g.dispose();
    }
}

From source file:ArrowIcon.java

protected void paintArrowBevel(Graphics g, Color base, int x, int y) {
    int len = size;
    int xx = x;/*from  w  w  w.  ja  v  a2  s . co m*/
    int yy = y;
    Color c2 = deriveColorHSB(base, 0f, 0f, (-DB) * (size / 2));
    while (len >= 2) {
        c2 = deriveColorHSB(c2, 0f, 0f, DB);
        g.setColor(c2);
        g.fillRect(xx, yy, 1, 1);
        g.fillRect(xx + len - 1, yy, 1, 1);
        len -= 2;
        xx++;
        yy++;
    }

}

From source file:ColorSwatch.java

/**
 * Paints this Icon into the provided graphics context.
 *//*  w  ww .ja va  2 s  .co  m*/
public void paintIcon(Component c, Graphics g, int x, int y) {
    if (ourSwatchIsVoid)
        return;

    Color oldColor = g.getColor();

    if (ourSwatchIsMultiColor) {
        g.setColor(Color.white);
        g.fillRect(x, y, ourSwatchSize, ourSwatchSize);
        g.setColor(ourBorderColor);
        for (int i = 0; i < ourSwatchSize; i += 2) {
            g.drawLine(x + i, y, x + i, y + ourSwatchSize);
        }
    }

    else if (ourSwatchColor != null) {
        g.setColor(ourSwatchColor);
        g.fillRect(x, y, ourSwatchSize, ourSwatchSize);
    }

    else {
        g.setColor(Color.white);
        g.fillRect(x, y, ourSwatchSize, ourSwatchSize);
        g.setColor(ourBorderColor);
        g.drawLine(x, y, x + ourSwatchSize, y + ourSwatchSize);
        g.drawLine(x, y + ourSwatchSize, x + ourSwatchSize, y);
    }

    if (ourBorderPainted) {
        g.setColor(ourBorderColor);
        g.drawRect(x, y, ourSwatchSize, ourSwatchSize);
    }

    g.setColor(oldColor);
}

From source file:test.mandelbrot.MandelbrotApp.java

@Override
public void paint(Graphics g) {
    if (done) {/*from  ww  w.  j  a v a  2 s. co  m*/
        g.drawImage(offscreen, 0, 0, this);
        this.setTitle("Done");
    } else {
        g.drawImage(offscreen, 0, 0, this);
        g.setColor(Color.white);
        g.drawRect(WIDTH / 4, 10, WIDTH / 2, 5);
        g.fillRect(WIDTH / 4, 11, (progress * (WIDTH / 2)) / HEIGHT, 4);
    }
}