Java Code Examples for java.awt.Graphics#fillRect()

The following examples show how to use java.awt.Graphics#fillRect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AcceleratedScaleTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 8 votes vote down vote up
private static void initVI(GraphicsConfiguration gc) {
    int res;
    if (destVI == null) {
        res = VolatileImage.IMAGE_INCOMPATIBLE;
    } else {
        res = destVI.validate(gc);
    }
    if (res == VolatileImage.IMAGE_INCOMPATIBLE) {
        if (destVI != null) destVI.flush();
        destVI = gc.createCompatibleVolatileImage(IMAGE_SIZE, IMAGE_SIZE);
        destVI.validate(gc);
        res = VolatileImage.IMAGE_RESTORED;
    }
    if (res == VolatileImage.IMAGE_RESTORED) {
        Graphics vig = destVI.getGraphics();
        vig.setColor(Color.red);
        vig.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
        vig.dispose();
    }
}
 
Example 2
Source File: DetailsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void paintVerticalLines(Graphics g) {
    int height = getHeight();
    int viewHeight = view.getHeight();
    if (viewHeight >= height) return;

    g.setColor(background);
    g.fillRect(0, viewHeight, getWidth(), getHeight() - viewHeight);

    int cellX = 0;
    int cellWidth;
    TableColumnModel model = view.getColumnModel();
    int columnCount = model.getColumnCount();
    
    g.setColor(DetailsTable.DEFAULT_GRID_COLOR);
    for (int i = 0; i < columnCount; i++) {
        cellWidth = model.getColumn(i).getWidth();
        cellX += cellWidth;
        g.drawLine(cellX - 1, viewHeight, cellX - 1, height);
    }
}
 
Example 3
Source File: ImageTests.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void modifyTest(TestEnvironment env) {
    int size = env.getIntValue(sizeList);
    Image src = tsit.getImage(env, size, size);
    Graphics g = src.getGraphics();
    if (hasGraphics2D) {
        ((Graphics2D) g).setComposite(AlphaComposite.Src);
    }
    if (size == 1) {
        g.setColor(colorsets[transparency][4]);
        g.fillRect(0, 0, 1, 1);
    } else {
        int mid = size/2;
        g.setColor(colorsets[transparency][0]);
        g.fillRect(0, 0, mid, mid);
        g.setColor(colorsets[transparency][1]);
        g.fillRect(mid, 0, size-mid, mid);
        g.setColor(colorsets[transparency][2]);
        g.fillRect(0, mid, mid, size-mid);
        g.setColor(colorsets[transparency][3]);
        g.fillRect(mid, mid, size-mid, size-mid);
    }
    g.dispose();
    env.setSrcImage(src);
}
 
Example 4
Source File: ImageTests.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    ImageOpTests.Context ictx = (ImageOpTests.Context)ctx;
    RasterOp op = ictx.rasterOp;
    Raster src = ictx.rasSrc;
    WritableRaster dst = ictx.rasDst;
    if (ictx.touchSrc) {
        Graphics gSrc = ictx.bufSrc.getGraphics();
        do {
            gSrc.fillRect(0, 0, 1, 1);
            op.filter(src, dst);
        } while (--numReps > 0);
    } else {
        do {
            op.filter(src, dst);
        } while (--numReps > 0);
    }
}
 
Example 5
Source File: RleEncodingTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void encodeRLE4Test() throws IOException {
    // create 4bpp image
    byte[] r = new byte[16];
    r[0] = (byte)0xff;
    byte[] g = new byte[16];
    g[1] = (byte)0xff;
    byte[] b = new byte[16];
    b[2] = (byte)0xff;
    IndexColorModel icm = new IndexColorModel(4, 16, r, g, b);

    BufferedImage bimg = new BufferedImage(100, 100,
                                           BufferedImage.TYPE_BYTE_BINARY,
                                           icm);

    Graphics gr = bimg.getGraphics();
    gr.setColor(Color.green);
    gr.fillRect(0, 0, 100, 100);

    doTest(bimg, "BI_RLE4", ImageWriteParam.MODE_EXPLICIT);
}
 
Example 6
Source File: ImageGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public ImageGenerator(int _width, int _height, Color bgColor)
{
      width = _width;
      height = _height;
      bi = new BufferedImage(
          width,
          height,
          BufferedImage.TYPE_INT_ARGB);
      Graphics gr = bi.getGraphics();
      if(null==bgColor){
          bgColor = Color.WHITE;
      }
      gr.setColor(bgColor);
      gr.fillRect(0, 0, width, height);
      paint(gr);
      gr.dispose();
}
 
Example 7
Source File: ImageDetailProvider.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static void drawChecker(Graphics g, int x, int y, int width, int height) {
    g.setColor(CHECKER_BG);
    g.fillRect(x, y, width, height);
    g.setColor(CHECKER_FG);
    for (int i = 0; i < width; i += CHECKER_SIZE) {
        for (int j = 0; j < height; j += CHECKER_SIZE) {
            if ((i / CHECKER_SIZE + j / CHECKER_SIZE) % 2 == 0) {
                g.fillRect(x + i, y + j, Math.min(CHECKER_SIZE, width - i), Math.min(CHECKER_SIZE, height - j));
            }
        }
    }
}
 
Example 8
Source File: GifTransparencyTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected BufferedImage createTestImage() {
    BufferedImage img = new BufferedImage(200, 200,
                                          BufferedImage.TYPE_INT_ARGB);
    Graphics g = img.createGraphics();
    g.setColor(Color.cyan);
    g.fillRect(0, 0, 200, 200);

    g.setColor(Color.red);
    g.fillRect(50, 50, 100, 100);
    g.dispose();

    return img;
}
 
Example 9
Source File: MultiResolutionSplashTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void generateImage(String name, Color color, int scale) throws Exception {
    File file = new File(name);
    if (file.exists()) {
        return;
    }
    BufferedImage image = new BufferedImage(scale * IMAGE_WIDTH, scale * IMAGE_HEIGHT,
            BufferedImage.TYPE_INT_RGB);
    Graphics g = image.getGraphics();
    g.setColor(color);
    g.fillRect(0, 0, scale * IMAGE_WIDTH, scale * IMAGE_HEIGHT);
    ImageIO.write(image, "png", file);
}
 
Example 10
Source File: PaintNativeOnUpdate.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void update(final Graphics g) {
    if (fullUpdate) {
        //full paint
        g.setColor(Color.GREEN);
        g.fillRect(0, 0, getWidth(), getHeight());
        fullUpdate = false;
    } else {
        // Do nothing
        // incremental paint
    }
}
 
Example 11
Source File: NonOpaqueDestLCDAATest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void render(Graphics g, int w, int h) {
    initImages(w, h);

    g.setColor(new Color(0xAD, 0xD8, 0xE6));
    g.fillRect(0, 0, w, h);

    Graphics2D g2d = (Graphics2D) g.create();
    for (Image im : images) {
        g2d.drawImage(im, 0, 0, null);
        g2d.translate(0, im.getHeight(null));
    }
}
 
Example 12
Source File: RenderTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    int size = rctx.size;
    int x = rctx.initX;
    int y = rctx.initY;
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    if (rctx.animate) {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.fillRect(x, y, size, size);
            if ((x -= 3) < 0) x += rctx.maxX;
            if ((y -= 1) < 0) y += rctx.maxY;
        } while (--numReps > 0);
    } else {
        do {
            if (rCArray != null) {
                g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
            }
            g.fillRect(x, y, size, size);
        } while (--numReps > 0);
    }
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 13
Source File: AltTabCrashTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void validateSprite() {
    int result =
        ((VolatileImage)image).validate(getGraphicsConfiguration());
    if (result == VolatileImage.IMAGE_INCOMPATIBLE) {
        image = createSprite();
        result = VolatileImage.IMAGE_RESTORED;
    }
    if (result == VolatileImage.IMAGE_RESTORED) {
        Graphics g = image.getGraphics();
        g.setColor(color);
        g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
    }
}
 
Example 14
Source File: BufferStrategyExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void render() {
    ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
    ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
    BufferCapabilities bufCap =
        new BufferCapabilities(imgFrontBufCap,
            imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
    try {

        createBufferStrategy(2, bufCap);
    } catch (AWTException ex) {
        createBufferStrategy(2);
    }

    BufferStrategy bs = getBufferStrategy();
    do {
        Graphics g =  bs.getDrawGraphics();
        g.setColor(Color.green);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(Color.red);
        g.drawString("Rendering test", 20, 20);

        g.drawImage(bi, 50, 50, null);

        g.dispose();
        bs.show();
    } while (bs.contentsLost()||bs.contentsRestored());
}
 
Example 15
Source File: DecoratedTreeUI.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * This is copied from BasicTreeUI.java. The only modifications are:
 * <ul>
 * <li>The background color is painted across the entire width of the tree.</li>
 * <li>Because of the above requirement: the expand control is redundantly
 * painted on top of that rectangle for visibility.</li>
 * <li>We never inform the CellRenderer whether focus is present. (That
 * argument is left false, because we don't have access to private fields
 * the original logic wanted.)</li>
 * </ul>
 */
@Override
protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets,
		Rectangle bounds, TreePath path, int row, boolean isExpanded,
		boolean hasBeenExpanded, boolean isLeaf) {
	// Don't paint the renderer if editing this row.
	if (editingComponent != null && editingRow == row)
		return;

	// this is in BasicTreeUI, but getLeadSelectionRow() is private.
	/*
	 * int leadIndex;
	 * 
	 * if(tree.hasFocus()) { leadIndex = getLeadSelectionRow(); } else
	 * leadIndex = -1;
	 */

	Component component;

	component = currentCellRenderer.getTreeCellRendererComponent(tree,
			path.getLastPathComponent(), tree.isRowSelected(row),
			isExpanded, isLeaf, row, false);

	if (component.isOpaque()) {
		Color bkgnd = component.getBackground();
		g.setColor(bkgnd);
		g.fillRect(0, bounds.y, tree.getWidth(), bounds.height);

		if (shouldPaintExpandControl(path, row, isExpanded,
				hasBeenExpanded, isLeaf)) {
			paintExpandControl(g, bounds, insets, bounds, path, row,
					isExpanded, hasBeenExpanded, isLeaf);
		}
	}

	rendererPane.paintComponent(g, component, tree, bounds.x, bounds.y,
			bounds.width, bounds.height, true);
}
 
Example 16
Source File: WorkerTask.java    From openstego with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    g.setColor(new Color(0.5f, 0.5f, 0.5f, 0.5f));
    g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
 
Example 17
Source File: RSLContextInvalidationTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    GraphicsEnvironment ge =
        GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);
    vi.validate(gc);
    VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100);
    vi1.validate(gc);

    if (!(vi instanceof DestSurfaceProvider)) {
        System.out.println("Test considered PASSED: no HW acceleration");
        return;
    }

    DestSurfaceProvider p = (DestSurfaceProvider)vi;
    Surface s = p.getDestSurface();
    if (!(s instanceof AccelSurface)) {
        System.out.println("Test considered PASSED: no HW acceleration");
        return;
    }
    AccelSurface dst = (AccelSurface)s;

    Graphics g = vi.createGraphics();
    g.drawImage(vi1, 95, 95, null);
    g.setColor(Color.red);
    g.fillRect(0, 0, 100, 100);
    g.setColor(Color.black);
    g.fillRect(0, 0, 100, 100);
    // after this the validated context color is black

    RenderQueue rq = dst.getContext().getRenderQueue();
    rq.lock();
    try {
        dst.getContext().saveState();
        dst.getContext().restoreState();
    } finally {
        rq.unlock();
    }

    // this will cause ResetPaint (it will set color to extended EA=ff,
    // which is ffffffff==Color.white)
    g.drawImage(vi1, 95, 95, null);

    // now try filling with black again, but it will come up as white
    // because this fill rect won't validate the color properly
    g.setColor(Color.black);
    g.fillRect(0, 0, 100, 100);

    BufferedImage bi = vi.getSnapshot();
    if (bi.getRGB(50, 50) != Color.black.getRGB()) {
        throw new RuntimeException("Test FAILED: found color="+
            Integer.toHexString(bi.getRGB(50, 50))+" instead of "+
            Integer.toHexString(Color.black.getRGB()));
    }

    System.out.println("Test PASSED.");
}
 
Example 18
Source File: MotifBorders.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Paints the border for the specified component with the
 * specified position and size.
 * @param c the component for which this border is being painted
 * @param g the paint graphics
 * @param x the x position of the painted border
 * @param y the y position of the painted border
 * @param width the width of the painted border
 * @param height the height of the painted border
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if (!(c instanceof JPopupMenu)) {
        return;
    }

    Font origFont = g.getFont();
    Color origColor = g.getColor();
    JPopupMenu popup = (JPopupMenu)c;

    String title = popup.getLabel();
    if (title == null) {
        return;
    }

    g.setFont(font);

    FontMetrics fm = SwingUtilities2.getFontMetrics(popup, g, font);
    int         fontHeight = fm.getHeight();
    int         descent = fm.getDescent();
    int         ascent = fm.getAscent();
    Point       textLoc = new Point();
    int         stringWidth = SwingUtilities2.stringWidth(popup, fm,
                                                          title);

    textLoc.y = y + ascent + TEXT_SPACING;
    textLoc.x = x + ((width - stringWidth) / 2);

    g.setColor(background);
    g.fillRect(textLoc.x - TEXT_SPACING, textLoc.y - (fontHeight-descent),
               stringWidth + (2 * TEXT_SPACING), fontHeight - descent);
    g.setColor(foreground);
    SwingUtilities2.drawString(popup, g, title, textLoc.x, textLoc.y);

    MotifGraphicsUtils.drawGroove(g, x, textLoc.y + TEXT_SPACING,
                                  width, GROOVE_HEIGHT,
                                  shadowColor, highlightColor);

    g.setFont(origFont);
    g.setColor(origColor);
}
 
Example 19
Source File: ColorLabel.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private void drawColorBox(Graphics g, int x, int y, int w, int h) {
    g.setColor(getColor());
    g.fillRect(x, y, w, h);
    g.setColor(getColorBoxLineColor());
    g.drawRect(x, y, w, h);
}
 
Example 20
Source File: DefaultTreeCellRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
  * Paints the value.  The background is filled based on selected.
  */
public void paint(Graphics g) {
    Color bColor;

    if (isDropCell) {
        bColor = DefaultLookup.getColor(this, ui, "Tree.dropCellBackground");
        if (bColor == null) {
            bColor = getBackgroundSelectionColor();
        }
    } else if (selected) {
        bColor = getBackgroundSelectionColor();
    } else {
        bColor = getBackgroundNonSelectionColor();
        if (bColor == null) {
            bColor = getBackground();
        }
    }

    int imageOffset = -1;
    if (bColor != null && fillBackground) {
        imageOffset = getLabelStart();
        g.setColor(bColor);
        if(getComponentOrientation().isLeftToRight()) {
            g.fillRect(imageOffset, 0, getWidth() - imageOffset,
                       getHeight());
        } else {
            g.fillRect(0, 0, getWidth() - imageOffset,
                       getHeight());
        }
    }

    if (hasFocus) {
        if (drawsFocusBorderAroundIcon) {
            imageOffset = 0;
        }
        else if (imageOffset == -1) {
            imageOffset = getLabelStart();
        }
        if(getComponentOrientation().isLeftToRight()) {
            paintFocus(g, imageOffset, 0, getWidth() - imageOffset,
                       getHeight(), bColor);
        } else {
            paintFocus(g, 0, 0, getWidth() - imageOffset, getHeight(), bColor);
        }
    }
    super.paint(g);
}