Java Code Examples for java.awt.Graphics.create()

The following are Jave code examples for showing how to use create() of the java.awt.Graphics 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: Logisim   File: ComponentIcon.java   View Source Code Vote up 7 votes
@Override
public void paintIcon(java.awt.Component c, Graphics g, int x, int y) {
	// draw tool icon
	Graphics gIcon = g.create();
	ComponentDrawContext context = new ComponentDrawContext(c, null, null, g, gIcon);
	comp.getFactory().paintIcon(context, x, y, comp.getAttributeSet());
	gIcon.dispose();

	if (triangleState != TRIANGLE_NONE) {
		int[] xp;
		int[] yp;
		if (triangleState == TRIANGLE_CLOSED) {
			xp = new int[] { x + 13, x + 13, x + 17 };
			yp = new int[] { y + 11, y + 19, y + 15 };
		} else {
			xp = new int[] { x + 11, x + 19, x + 15 };
			yp = new int[] { y + 13, y + 13, y + 17 };
		}
		g.setColor(Color.LIGHT_GRAY);
		g.fillPolygon(xp, yp, 3);
		g.setColor(Color.DARK_GRAY);
		g.drawPolygon(xp, yp, 3);
	}
}
 
Example 2
Project: JDigitalSimulator   File: Simulation.java   View Source Code Vote up 6 votes
@Override public int print(Graphics default_graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
	List<Image> images = getPrintPages(pageFormat);
	if(pageIndex>=images.size())
		return NO_SUCH_PAGE;
	Graphics2D graphics = (Graphics2D)default_graphics.create();
	graphics.translate(pageFormat.getImageableX(),
			pageFormat.getImageableY());
	graphics.drawImage(images.get(pageIndex), 0, 0, null);
	Thread.yield(); //yield shortly, so that the image is painted
	return PAGE_EXISTS;
}
 
Example 3
Project: DicomViewer   File: ThicknessIcon.java   View Source Code Vote up 6 votes
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    int w = getIconWidth();
    int h = getIconHeight();

    GeneralPath path = new GeneralPath();
    path.moveTo(0, h / 2);
    double segment = w / 3d;
    path.curveTo(segment, -h * 0.3, 2 * segment, h * 1.3, w, h / 2);

    Graphics2D g2 = (Graphics2D) g.create();
    g2.translate(x, y);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    g2.setColor(c.getForeground());
    g2.setStroke(new BasicStroke(thickness));
    g2.draw(path);
    g2.dispose();
}
 
Example 4
Project: incubator-netbeans   File: GlassPane.java   View Source Code Vote up 6 votes
/**
 * Paints additional information about component constraints.
 * 
 * @param g graphics to use for painting.
 */
private void paintConstraints(Graphics g) {
    Point shift = fromComponentPane(new Point());
    Graphics gClip = g.create();
    Rectangle paneRect = fromComponentPane(new Rectangle(new Point(), componentPane.getSize()));
    gClip.clipRect(paneRect.x, paneRect.y, paneRect.width, paneRect.height);
    gClip.translate(shift.x, shift.y);
    for (Component comp : componentPane.getComponents()) {
        if (GridUtils.isPaddingComponent(comp)) {
            continue;
        }
        boolean selected = selection.contains(comp);
        gridInfo.paintConstraints(gClip, comp, selected);
    }
    gClip.dispose();
}
 
Example 5
Project: Logisim   File: Icons.java   View Source Code Vote up 6 votes
public static void paintRotated(Graphics g, int x, int y, Direction dir, Icon icon, Component dest) {
	if (!(g instanceof Graphics2D) || dir == Direction.EAST) {
		icon.paintIcon(dest, g, x, y);
		return;
	}

	Graphics2D g2 = (Graphics2D) g.create();
	double cx = x + icon.getIconWidth() / 2.0;
	double cy = y + icon.getIconHeight() / 2.0;
	if (dir == Direction.WEST) {
		g2.rotate(Math.PI, cx, cy);
	} else if (dir == Direction.NORTH) {
		g2.rotate(-Math.PI / 2.0, cx, cy);
	} else if (dir == Direction.SOUTH) {
		g2.rotate(Math.PI / 2.0, cx, cy);
	} else {
		g2.translate(-x, -y);
	}
	icon.paintIcon(dest, g2, x, y);
	g2.dispose();
}
 
Example 6
Project: Logisim   File: CircuitAppearance.java   View Source Code Vote up 6 votes
public void paintSubcircuit(Graphics g, Direction facing) {
	Direction defaultFacing = getFacing();
	double rotate = 0.0;
	if (facing != defaultFacing && g instanceof Graphics2D) {
		rotate = defaultFacing.toRadians() - facing.toRadians();
		((Graphics2D) g).rotate(rotate);
	}
	Location offset = findAnchorLocation();
	g.translate(-offset.getX(), -offset.getY());
	for (CanvasObject shape : getObjectsFromBottom()) {
		if (!(shape instanceof AppearanceElement)) {
			Graphics dup = g.create();
			shape.paint(dup, null);
			dup.dispose();
		}
	}
	g.translate(offset.getX(), offset.getY());
	if (rotate != 0.0) {
		((Graphics2D) g).rotate(-rotate);
	}
}
 
Example 7
Project: incubator-netbeans   File: CustomizableSideBar.java   View Source Code Vote up 6 votes
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    int thick = getThickness();
    if (!(g instanceof Graphics2D)) {
        return;
    }
    
    Graphics2D g2d = (Graphics2D)g.create();
    if (thick >= 1) {
        g2d.setColor(this.lineColor);
        int x2 = x + width - ((thick +1) / 2);
        g2d.drawLine(x2 - SIDEBAR_GAP_WIDTH, 
                0, x2 - SIDEBAR_GAP_WIDTH, y + height - 1);
    }
    g2d.setColor(textBkColor);
    int gap = width - SIDEBAR_GAP_WIDTH;
    g2d.drawRect(gap, 0, width - gap, height);
}
 
Example 8
Project: AgentWorkbench   File: MissingIcon.java   View Source Code Vote up 6 votes
public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2d = (Graphics2D) g.create();
    
    g2d.setColor(Color.WHITE);
    g2d.fillRect(x +1 ,y + 1,width -2 ,height -2);
    
    g2d.setColor(Color.BLACK);
    g2d.drawRect(x +1 ,y + 1,width -2 ,height -2);
    
    g2d.setColor(Color.RED);
    
    g2d.setStroke(stroke);
    g2d.drawLine(x +10, y + 10, x + width -10, y + height -10);
    g2d.drawLine(x +10, y + height -10, x + width -10, y + 10);
    
    g2d.dispose();
}
 
Example 9
Project: rapidminer   File: SimilarityKDistanceVisualization.java   View Source Code Vote up 5 votes
@Override
public void paintComponent(Graphics graphics) {
	super.paintComponent(graphics);

	int pixWidth = getWidth() - 2 * MARGIN;
	int pixHeight = getHeight() - 2 * MARGIN - this.updatePanelHeight - 50;
	Graphics2D translated = (Graphics2D) graphics.create();
	translated.translate(MARGIN, MARGIN);
	paintGraph(translated, pixWidth, pixHeight);

}
 
Example 10
Project: pdi   File: Quadrado.java   View Source Code Vote up 5 votes
public BufferedImage criaQuadrado(BufferedImage img, PosicoesDTO posicoes) {
	Graphics graphics = img.getGraphics();
	Graphics2D graphics2d = (Graphics2D) graphics.create();
	graphics2d.setStroke(new BasicStroke(4));
	graphics2d.setColor(Color.BLUE);

	int x1 = posicoes.getX1();
	int x2 = posicoes.getX2();
	int y1 = posicoes.getY1();
	int y2 = posicoes.getY2();

	graphics2d.drawPolygon(new int[] { x1, x1, x2, x2 }, new int[] { y1, y2, y2, y1 }, 4);
	graphics2d.dispose();
	return img;
}
 
Example 11
Project: school-game   File: MetalGradientButton.java   View Source Code Vote up 5 votes
@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D)g.create();
    g2.setPaint(new GradientPaint(new Point(0, 0), Color.WHITE, new Point(0, getHeight()), isEnabled() ? getBackground() : Color.LIGHT_GRAY));
    g2.fillRect(0, 0, getWidth(), getHeight());
    g2.dispose();

    super.paintComponent(g);
}
 
Example 12
Project: Cognizant-Intelligent-Test-Scripter   File: MenuScroller.java   View Source Code Vote up 5 votes
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    Dimension size = c.getSize();
    Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
    g2.setColor(Color.GRAY);
    g2.drawPolygon(xPoints, yPoints, 3);
    if (c.isEnabled()) {
        g2.setColor(Color.BLACK);
        g2.fillPolygon(xPoints, yPoints, 3);
    }
    g2.dispose();
}
 
Example 13
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 14
Project: Logisim   File: Drawing.java   View Source Code Vote up 5 votes
@Override
public void paint(Graphics g, Selection selection) {
	Set<CanvasObject> suppressed = selection.getDrawsSuppressed();
	for (CanvasObject shape : getObjectsFromBottom()) {
		Graphics dup = g.create();
		if (suppressed.contains(shape)) {
			selection.drawSuppressed(dup, shape);
		} else {
			shape.paint(dup, null);
		}
		dup.dispose();
	}
}
 
Example 15
Project: rapidminer   File: ComponentPrinter.java   View Source Code Vote up 5 votes
/**
 * 
 * @param g
 *            the graphics object
 * @param pageFormat
 *            the page format
 * @param width
 *            the downscaled width
 * @param height
 *            the downscaled height
 * @param pageIndex
 *            the page index that should be printed
 */
public int print(Graphics g, double x, double y, double width, double height, int pageIndex) {
	if (pageIndex >= components.length) {
		return NO_SUCH_PAGE;
	}

	String title = components[pageIndex].getExportName();
	if (title == null) {
		title = LicenseTools.translateProductName(ProductConstraintManager.INSTANCE.getActiveLicense());
	}
	Rectangle2D rect = TITLE_FONT.getStringBounds(title, ((Graphics2D) g).getFontRenderContext());
	g.setFont(TITLE_FONT);
	int stringX = (int) (x + width / 2 - rect.getWidth() / 2);
	int stringY = (int) (y - rect.getY());
	g.drawString(title, stringX, stringY);

	// remove string rect height from graphic pane
	height = height - rect.getHeight() * 2;

	Graphics2D translated = (Graphics2D) g.create((int) x, (int) (y + rect.getHeight() * 2), (int) width, (int) height);

	double widthFactor = width / components[pageIndex].getExportComponent().getWidth();
	double heightFactor = height / components[pageIndex].getExportComponent().getHeight();
	double scaleFactor = Math.min(widthFactor, heightFactor);
	translated.scale(scaleFactor, scaleFactor);
	components[pageIndex].getExportComponent().print(translated);
	translated.dispose();
	return PAGE_EXISTS;
}
 
Example 16
Project: incubator-netbeans   File: ConfigurationRenderer.java   View Source Code Vote up 5 votes
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Graphics gr = g.create();
    if (gr != null) {
        try {
            gr.translate(x, y);
            gr.setColor(fgColor);
            gr.drawLine(0, height - 1, width - 1, height - 1);
        } finally {
            gr.dispose();
        }
    }
}
 
Example 17
Project: openjdk-jdk10   File: MatteBorder.java   View Source Code Vote up 5 votes
private void paintEdge(Component c, Graphics g, int x, int y, int width, int height, int tileW, int tileH) {
    g = g.create(x, y, width, height);
    int sY = -(y % tileH);
    for (x = -(x % tileW); x < width; x += tileW) {
        for (y = sY; y < height; y += tileH) {
            this.tileIcon.paintIcon(c, g, x, y);
        }
    }
    g.dispose();
}
 
Example 18
Project: openjdk-jdk10   File: NonOpaqueDestLCDAATest.java   View Source Code Vote up 5 votes
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 19
Project: Logisim   File: Print.java   View Source Code Vote up 4 votes
@Override
public int print(Graphics base, PageFormat format, int pageIndex) {
	if (pageIndex >= circuits.size())
		return Printable.NO_SUCH_PAGE;

	Circuit circ = circuits.get(pageIndex);
	CircuitState circState = proj.getCircuitState(circ);
	Graphics g = base.create();
	Graphics2D g2 = g instanceof Graphics2D ? (Graphics2D) g : null;
	FontMetrics fm = g.getFontMetrics();
	String head = (header != null && !header.equals(""))
			? format(header, pageIndex + 1, circuits.size(), circ.getName())
			: null;
	int headHeight = (head == null ? 0 : fm.getHeight());

	// Compute image size
	double imWidth = format.getImageableWidth();
	double imHeight = format.getImageableHeight();

	// Correct coordinate system for page, including
	// translation and possible rotation.
	Bounds bds = circ.getBounds(g).expand(4);
	double scale = Math.min(imWidth / bds.getWidth(), (imHeight - headHeight) / bds.getHeight());
	if (g2 != null) {
		g2.translate(format.getImageableX(), format.getImageableY());
		if (rotateToFit && scale < 1.0 / 1.1) {
			double scale2 = Math.min(imHeight / bds.getWidth(), (imWidth - headHeight) / bds.getHeight());
			if (scale2 >= scale * 1.1) { // will rotate
				scale = scale2;
				if (imHeight > imWidth) { // portrait -> landscape
					g2.translate(0, imHeight);
					g2.rotate(-Math.PI / 2);
				} else { // landscape -> portrait
					g2.translate(imWidth, 0);
					g2.rotate(Math.PI / 2);
				}
				double t = imHeight;
				imHeight = imWidth;
				imWidth = t;
			}
		}
	}

	// Draw the header line if appropriate
	if (head != null) {
		g.drawString(head, (int) Math.round((imWidth - fm.stringWidth(head)) / 2), fm.getAscent());
		if (g2 != null) {
			imHeight -= headHeight;
			g2.translate(0, headHeight);
		}
	}

	// Now change coordinate system for circuit, including
	// translation and possible scaling
	if (g2 != null) {
		if (scale < 1.0) {
			g2.scale(scale, scale);
			imWidth /= scale;
			imHeight /= scale;
		}
		double dx = Math.max(0.0, (imWidth - bds.getWidth()) / 2);
		g2.translate(-bds.getX() + dx, -bds.getY());
	}

	// Ensure that the circuit is eligible to be drawn
	Rectangle clip = g.getClipBounds();
	clip.add(bds.getX(), bds.getY());
	clip.add(bds.getX() + bds.getWidth(), bds.getY() + bds.getHeight());
	g.setClip(clip);

	// And finally draw the circuit onto the page
	ComponentDrawContext context = new ComponentDrawContext(proj.getFrame().getCanvas(), circ, circState, base,
			g, printerView);
	Collection<Component> noComps = Collections.emptySet();
	circ.draw(context, noComps);
	g.dispose();
	return Printable.PAGE_EXISTS;
}
 
Example 20
Project: openjdk-jdk10   File: StrokeBorder.java   View Source Code Vote up 4 votes
/**
 * Paints the border for the specified component
 * with the specified position and size.
 * If the border was not specified with a {@link Paint} object,
 * the component's foreground color will be used to render the border.
 * If the component's foreground color is not available,
 * the default color of the {@link Graphics} object will be used.
 *
 * @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
 *
 * @throws NullPointerException if the specified {@code g} is {@code null}
 */
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    float size = this.stroke.getLineWidth();
    if (size > 0.0f) {
        g = g.create();
        if (g instanceof Graphics2D) {
            Graphics2D g2d = (Graphics2D) g;
            g2d.setStroke(this.stroke);
            g2d.setPaint(this.paint != null ? this.paint : c == null ? null : c.getForeground());
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                 RenderingHints.VALUE_ANTIALIAS_ON);
            g2d.draw(new Rectangle2D.Float(x + size / 2, y + size / 2, width - size, height - size));
        }
        g.dispose();
    }
}