Java Code Examples for java.awt.Graphics2D.dispose()

The following are Jave code examples for showing how to use dispose() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VASSAL-src   File: FreeRotator.java   View Source Code Vote up 6 votes
public void draw(Graphics g, Map map) {
  if (drawGhost) {
    final Point p = map.componentCoordinates(getGhostPosition());

    final Graphics2D g2d = (Graphics2D) g.create();
    g2d.transform(
       AffineTransform.getRotateInstance(-PI_180 * tempAngle,
                                         p.x + centerX(),
                                         p.y + centerY()));
    g2d.setComposite(
       AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                         RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         RenderingHints.VALUE_ANTIALIAS_ON);
    piece.draw(g2d, p.x, p.y, map.getView(), map.getZoom());
    g2d.dispose();
  }
}
 
Example 2
Project: VISNode   File: JNodeContainer.java   View Source Code Vote up 6 votes
@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g.create();
    super.paintComponent(g2d);
    int gridSize = 10;
    int majorGridSize = 100;
    g2d.setColor(new Color(0x484848));
    for (int i = 0; i < Math.max(getWidth(), getHeight()); i += gridSize) {
        if (i < getWidth()) {
            g2d.drawLine(i, 0, i, getHeight());
        }
        if (i < getHeight()) {
            g2d.drawLine(0, i, getWidth(), i);
        }
    }
    g2d.setColor(new Color(0x585858));
    for (int i = 0; i < Math.max(getWidth(), getHeight()); i += majorGridSize) {
        if (i < getWidth()) {
            g2d.drawLine(i, 0, i, getHeight());
        }
        if (i < getHeight()) {
            g2d.drawLine(0, i, getWidth(), i);
        }
    }
    g2d.dispose();
}
 
Example 3
Project: openjdk-jdk10   File: ShortHistogramTest.java   View Source Code Vote up 6 votes
protected BufferedImage createTestImage(int numColors) {

        IndexColorModel icm = createTestICM(numColors);
        int w = numColors * 10;
        int h = 20;

        BufferedImage img = new BufferedImage(w, h,
                BufferedImage.TYPE_BYTE_INDEXED, icm);

        Graphics2D g = img.createGraphics();
        for (int i = 0; i < numColors; i++) {
            int rgb = icm.getRGB(i);
            //System.out.printf("pixel %d, rgb %x\n", i, rgb);
            g.setColor(new Color(rgb));
            g.fillRect(i * 10, 0, w - i * 10, h);
        }
        g.dispose();

       return img;
    }
 
Example 4
Project: omr-dataset-tools   File: SheetProcessor.java   View Source Code Vote up 6 votes
/**
 * Draw symbols boxes and None symbols locations on control image.
 *
 * @param controlPath target path for control image
 * @throws java.io.IOException in case of IO problem
 */
public void drawBoxes (Path controlPath)
        throws IOException
{
    BufferedImage ctrl = new BufferedImage(
            initialImg.getWidth(),
            initialImg.getHeight(),
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g = ctrl.createGraphics();
    g.drawImage(initialImg, null, null);

    drawSymbols(annotations.getSymbols(), g);

    g.dispose();
    Files.createDirectories(controlPath.getParent());
    ImageIO.write(ctrl, OUTPUT_IMAGES_FORMAT, controlPath.toFile());
}
 
Example 5
Project: hearthstone   File: Img.java   View Source Code Vote up 6 votes
/**
 * Redimensiona a imagem do caminho passado por parâmetro
 *
 * @param image imagem
 * @param razao proporção do redimensionamento
 * @return retorna a imagem redimensionada
 */
public static ImageIcon redimensionaImg(Image image, double razao) {
    double new_w, new_h;
    ImageIcon img = new ImageIcon(image);
    new_w = img.getIconWidth();
    new_h = img.getIconHeight();
    new_w *= razao;
    new_h *= razao;
    BufferedImage new_img = new BufferedImage((int) new_w, (int) new_h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = new_img.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g.drawImage(image, 0, 0, (int) new_w, (int) new_h, null);
    g.dispose();
    return new ImageIcon(new_img);
}
 
Example 6
Project: jdk8u-jdk   File: CGLGraphicsConfig.java   View Source Code Vote up 6 votes
@Override
public void flip(final LWComponentPeer<?, ?> peer, final Image backBuffer,
                 final int x1, final int y1, final int x2, final int y2,
                 final BufferCapabilities.FlipContents flipAction) {
    final Graphics g = peer.getGraphics();
    try {
        g.drawImage(backBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
    } finally {
        g.dispose();
    }
    if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
        final Graphics2D bg = (Graphics2D) backBuffer.getGraphics();
        try {
            bg.setBackground(peer.getBackground());
            bg.clearRect(0, 0, backBuffer.getWidth(null),
                         backBuffer.getHeight(null));
        } finally {
            bg.dispose();
        }
    }
}
 
Example 7
Project: XiaomiRobotVacuumProtocol   File: RRDraw.java   View Source Code Vote up 5 votes
public static BufferedImage flipHoriz(BufferedImage image) {
    BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D gg = newImage.createGraphics();
    gg.drawImage(image, image.getHeight(), 0, -image.getWidth(), image.getHeight(), null);
    gg.dispose();
    return newImage;
}
 
Example 8
Project: ramus   File: StartupPanel.java   View Source Code Vote up 5 votes
@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setColor(Color.WHITE);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f));
    g2.fillRect(0, 0, getWidth(), getHeight());
    g2.dispose();
}
 
Example 9
Project: rapidminer   File: RoundTitledBorder.java   View Source Code Vote up 5 votes
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
	Graphics2D g2d = (Graphics2D) g.create();
	g2d.setRenderingHints(ProcessDrawer.HI_QUALITY_HINTS);
	g2d.setStroke(new BasicStroke(2f));

	// clear edges, otherwise they will be in the color of the component background
	if (drawRoundFrame && !c.getBackground().equals(c.getParent().getBackground())) {
		Shape frame = new Rectangle2D.Float(x + 2, y + 2, width - 4, height - 4);
		g2d.setPaint(c.getParent().getBackground());
		g2d.draw(frame);
	}

	g2d.setPaint(paint);
	g2d.setFont(new Font("Dialog", Font.BOLD, 21));

	if (drawRoundFrame) {
		Shape roundFrame = new RoundRectangle2D.Float(x + 2, y + 2, width - 4, height - 4, 10, 10);
		g2d.draw(roundFrame);
	}

	if (number > 0) {
		Shape circle = new Ellipse2D.Float(20, 20, 34, 34);
		g2d.fill(circle);
		g2d.setPaint(Color.WHITE);
		g2d.drawString(String.valueOf(number), 29, 44);
	}

	if (key != null) {
		g2d.setPaint(paint);
		g2d.drawString(key, 60, 44);
	}

	g2d.dispose();
}
 
Example 10
Project: jdk8u-jdk   File: Test8004859.java   View Source Code Vote up 5 votes
public static void main(final String[] args)
        throws NoninvertibleTransformException {
    final BufferedImage bi = new BufferedImage(300, 300,
                                               BufferedImage.TYPE_INT_RGB);
    final Graphics2D g = (Graphics2D) bi.getGraphics();
    test(g);
    g.translate(2.0, 2.0);
    test(g);
    g.translate(-4.0, -4.0);
    test(g);
    g.scale(2.0, 2.0);
    test(g);
    g.scale(-4.0, -4.0);
    test(g);
    g.rotate(Math.toRadians(90));
    test(g);
    g.rotate(Math.toRadians(90));
    test(g);
    g.rotate(Math.toRadians(90));
    test(g);
    g.rotate(Math.toRadians(90));
    test(g);
    g.dispose();
    if (!status) {
        throw new RuntimeException("Test failed");
    }
}
 
Example 11
Project: openjdk-jdk10   File: ConcurrentReadingTest.java   View Source Code Vote up 5 votes
private static void createTestFile() {
    int w = 1280;
    int h = 1024;

    BufferedImage img = new
        BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    Color[] colors = { Color.red, Color.green, Color.blue };
    float[] dist = {0.0f, 0.5f, 1.0f };
    Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);

    RadialGradientPaint p =
        new RadialGradientPaint(center, 0.5f * w, dist, colors);
    g.setPaint(p);
    g.fillRect(0, 0, w, h);
    g.dispose();

    try {
        System.out.println("Create test image " + file.getAbsolutePath());
        boolean b = ImageIO.write(img, "JPEG", file);
        if (!b) {
            throw new RuntimeException("Failed to create test image.");
        }
    } catch (IOException e) {
        throw new RuntimeException("Test failed", e);
    }
}
 
Example 12
Project: incubator-netbeans   File: MenuEditLayer.java   View Source Code Vote up 5 votes
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setColor(Color.BLACK);
    /* Using the assistant now instead of text ontop of the glasspane.
     * josh: I need to delete all of the previous code related to the showMenubarWarning boolean
    if(showMenubarWarning) {
        g2.drawString("You cannot add a menu component to a form without a menubar.", 5, getHeight()-30);
    }*/
    g2.dispose();
}
 
Example 13
Project: openjdk-jdk10   File: ButtonGradientTest.java   View Source Code Vote up 5 votes
private static Color getGradientColor(int w, int h, Color c1, Color c2) {
    GradientPaint gradient = new GradientPaint(0, 0, c1, 0, h, c2,
            true);
    BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    g.setPaint(gradient);
    g.fillRect(0, 0, w, h);
    g.dispose();
    return new Color(img.getRGB(w / 2, h / 2));
}
 
Example 14
Project: jdk8u-jdk   File: IncorrectClipXorModeSurface2Surface.java   View Source Code Vote up 5 votes
private static BufferedImage getSourceGold(GraphicsConfiguration gc,
                                           int size) {
    final BufferedImage bi = gc.createCompatibleImage(size, size);
    Graphics2D g2d = bi.createGraphics();
    g2d.setColor(Color.RED);
    g2d.fillRect(0, 0, size, size);
    g2d.dispose();
    return bi;
}
 
Example 15
Project: jdk8u-jdk   File: MisplacedBorder.java   View Source Code Vote up 5 votes
/**
 * Draws standard JMenuBar.
 */
private BufferedImage step1(final JMenuBar menubar) {
    final BufferedImage bi1 = new BufferedImage(W, H, TYPE_INT_ARGB_PRE);
    final Graphics2D g2d = bi1.createGraphics();
    g2d.scale(2, 2);
    g2d.setColor(Color.RED);
    g2d.fillRect(0, 0, W, H);
    menubar.paintAll(g2d);
    g2d.dispose();
    return bi1;
}
 
Example 16
Project: QN-ACTR-Release   File: EnlargePlotDistGraph.java   View Source Code Vote up 5 votes
BufferedImage convertType(BufferedImage src, int targetType) {
	if (src.getType() == targetType) {
		return src;
	}
	BufferedImage tgt = new BufferedImage(src.getWidth(), src.getHeight(), targetType);
	Graphics2D g = tgt.createGraphics();
	g.drawRenderedImage(src, null);
	g.dispose();
	return tgt;
}
 
Example 17
Project: DicomViewer   File: AbstractSliderComponentForTimeSlider.java   View Source Code Vote up 5 votes
/** dessine un cursseur dont le centre en X est centerX, et le centre en Y est centerY */
public static void drawCursor(final Graphics2D g, final Color fillColor, final Color drawColor, final int centerX, final int centerY) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setColor(fillColor);
    g2.fillRoundRect(centerX - CURSOR_W / 2, centerY - CURSOR_H / 2, CURSOR_W, CURSOR_H, ARC_SIZE, ARC_SIZE);

    g2.setColor(drawColor);
    g2.drawRoundRect(centerX - CURSOR_W / 2, centerY - CURSOR_H / 2, CURSOR_W, CURSOR_H, ARC_SIZE, ARC_SIZE);
    g2.dispose();
}
 
Example 18
Project: hearthstone   File: Img.java   View Source Code Vote up 5 votes
/**
 * Redimensiona a imagem do caminho passado por parâmetro
 *
 * @param image imagem
 * @param new_w nova largura
 * @param new_h nova altura
 * @return retorna a imagem redimensionada
 */
public static ImageIcon redimensionaImg(Image image, int new_w, int new_h) {
    BufferedImage new_img = new BufferedImage(new_w, new_h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = new_img.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    g.drawImage(image, 0, 0, new_w, new_h, null);
    g.dispose();
    return new ImageIcon(new_img);
}
 
Example 19
Project: rapidminer   File: ProcessDrawer.java   View Source Code Vote up 5 votes
/**
 * Draws operator backgrounds and then calls all registered {@link ProcessDrawDecorator}s for
 * the annotations render phase.
 *
 * @param process
 *            the process to draw the operator backgrounds for
 * @param g2
 *            the graphics context to draw upon
 * @param printing
 *            if {@code true} we are printing instead of drawing to the screen
 */
public void drawOperatorBackgrounds(final ExecutionUnit process, final Graphics2D g2, final boolean printing) {
	Graphics2D gBG = (Graphics2D) g2.create();
	// draw background of operators
	for (Operator op : process.getOperators()) {
		Rectangle2D frame = model.getOperatorRect(op);
		if (frame == null) {
			continue;
		}

		// only draw background if operator is visisble
		Rectangle2D opBounds = new Rectangle2D.Double(frame.getX() - 10, frame.getY(), frame.getWidth() + 20,
				frame.getHeight());
		if (g2.getClipBounds() != null && !g2.getClipBounds().intersects(opBounds)) {
			continue;
		}

		renderOperatorBackground(op, gBG);
	}

	// draw connections background for all operators
	for (Operator operator : process.getOperators()) {
		renderConnectionsBackground(operator.getInputPorts(), operator.getOutputPorts(), gBG);
	}

	// draw connections background for process
	renderConnectionsBackground(process.getInnerSinks(), process.getInnerSources(), gBG);
	gBG.dispose();

	// let decorators draw
	drawPhaseDecorators(process, g2, RenderPhase.OPERATOR_BACKGROUND, printing);
}
 
Example 20
Project: lemon   File: CustomProcessDiagramGenerator.java   View Source Code Vote up 3 votes
/**
 * 标记历史节点
 * 
 * @param image
 *            原始图片
 * @param x
 *            左上角节点坐在X位置
 * @param y
 *            左上角节点坐在Y位置
 * @param width
 *            宽
 * @param height
 *            高
 * @param activityType
 *            节点类型
 */
private static void signHistoryNode(BufferedImage image, int x, int y,
        int width, int height, String activityType) {
    Color nodeColor = HISTORY_COLOR;
    Graphics2D graphics = image.createGraphics();

    try {
        drawNodeBorder(x, y, width, height, graphics, nodeColor,
                activityType);
    } finally {
        graphics.dispose();
    }
}