public void draw(Graphics2D g2d) { g2d.setStroke(new BasicStroke((float) 1.5)); g2d.draw(curve); g2d.setStroke(new BasicStroke()); }
/** * Sets the radius of the pen to the given size. * * @param r the radius of the pen * @throws IllegalArgumentException if r is negative */ public void setPenRadius(double r) { if (r < 0) throw new IllegalArgumentException("pen radius must be positive"); penRadius = r * DEFAULT_SIZE; BasicStroke stroke = new BasicStroke((float) penRadius, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); // BasicStroke stroke = new BasicStroke((float) penRadius); offscreen.setStroke(stroke); }
private void renderPoly(Graphics2D graphics, Color color, Polygon polygon) { if (polygon != null) { graphics.setColor(color); graphics.setStroke(new BasicStroke(2)); graphics.draw(polygon); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20)); graphics.fill(polygon); } } }
g.setColor(Color.white); g.fillRect(chartX, chartY, chartWidth, chartHeight); g.setColor(Color.black); g.drawRect(chartX, chartY, chartWidth, chartHeight); int x = (int)(yAxisWidth + chartWidth * percent); if (i != 0 && i != xSplit) { g.setColor(Color.lightGray); g.drawLine(x, chartY + 1, x, chartY + chartHeight); g.setColor(Color.black); g.setColor(Color.blue); g.setStroke(new BasicStroke(isExpanded ? 3 : 2)); int lastX = -1, lastY = -1; for (Point point : points) {
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setColor(getRandColor(210, 250)); g.fillRect(0, 0, WIDTH, HEIGHT); for(int i = 0; i < 20; i++){ color = getRandColor(120, 200); g.setColor(color); String rand = String.valueOf(charArray[random.nextInt(charArray.length)]); g.drawString(rand, random.nextInt(WIDTH), random.nextInt(HEIGHT)); g.setColor(color); g.setColor(color); BasicStroke bs = new BasicStroke(3); g.setStroke(bs); g.draw(curve);
antialiasSetting = RenderingHints.VALUE_ANTIALIAS_ON; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasSetting); g2.setColor(Color.white); g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND)); new BasicStroke( strokeWeight, new BasicStroke( strokeWeight, BasicStroke.CAP_BUTT, g2.setColor(shape.getFillColor()); g2.fill(path); g2.setStroke(dashStroke); g2.draw(path); g2.fill(path); new BasicStroke( 1, BasicStroke.CAP_ROUND,
public static BufferedImage drawOval(BufferedImage image, int x, int y, int w, int h, Color borderColor, int borderWidth, float[] dash, float dashPhase) { BufferedImage output = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); //BufferedImage output = UIUtil.createImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); boolean invert = borderColor == null; if (invert) { // invert final int rgb = image.getRGB(x + w / 2, y + h / 2); borderColor = Color.getColor("", ~(rgb & 0xFFFFFF)); } g2.drawImage(image, 0, 0, null); //UIUtil.drawImage(g2, image, 0, 0, null); if (dash != null) { g2.setStroke(new BasicStroke(borderWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, borderWidth, dash, dashPhase)); } else { g2.setStroke(new BasicStroke(borderWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, borderWidth)); } g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); if (invert) { //g2.setXORMode(Color.WHITE); } g2.setColor(borderColor); g2.drawOval(x, y, w, h); g2.dispose(); return output; }
g2.setRenderingHint(KEY_ANTIALIASING, isAntialiasingEnabled() ? VALUE_ANTIALIAS_ON : VALUE_ANTIALIAS_OFF); g2.setBackground(Color.BLACK); g2.fillRect(0, 0, getWidth(), getHeight()); int cy = (getHeight() - 40) / 2; g2.setStroke(new BasicStroke(2)); g2.setColor(Color.LIGHT_GRAY); g2.fillRoundRect(cx, cy, 70, 40, 10, 10); g2.setColor(Color.WHITE); g2.fillOval(cx + 5, cy + 5, 30, 30); g2.setColor(Color.LIGHT_GRAY); g2.fillOval(cx + 10, cy + 10, 20, 20); g2.setColor(Color.WHITE); g2.setColor(Color.DARK_GRAY); g2.setStroke(new BasicStroke(3)); g2.drawLine(0, 0, getWidth(), getHeight()); g2.drawLine(0, getHeight(), getWidth(), 0); g2.setRenderingHint(KEY_ANTIALIASING, antialiasing);
private void drawImage( SwingUniversalImage img, int locationX, int locationY, int imageSize ) { if ( isDrawingPixelatedImages() && img.isBitmap() ) { BufferedImage bi = new BufferedImage( imageSize, imageSize, BufferedImage.TYPE_INT_ARGB ); Graphics2D g2 = (Graphics2D) bi.getGraphics(); g2.setColor( Color.WHITE ); g2.fillRect( 0, 0, imageSize, imageSize ); g2.drawImage( img.getAsBitmapForSize( imageSize, imageSize ), 0, 0, observer ); g2.dispose(); for ( int x = 0; x < bi.getWidth( observer ); x++ ) { for ( int y = 0; y < bi.getHeight( observer ); y++ ) { int rgb = bi.getRGB( x, y ); gc.setColor( new Color( rgb ) ); gc.setStroke( new BasicStroke( 1.0f ) ); gc.drawLine( locationX + xOffset + x, locationY + yOffset + y, locationX + xOffset + x, locationY + yOffset + y ); } } } else { gc.setBackground( Color.white ); gc.clearRect( locationX, locationY, imageSize, imageSize ); img.drawToGraphics( gc, locationX, locationY, imageSize, imageSize ); } }
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setColor(shadowColorA); graphics.fillRoundRect( graphics.setColor(getBackground()); graphics.fillRoundRect(0, 0, width - shadowGap, height - shadowGap, arcs.width, arcs.height); graphics.setColor(getForeground()); graphics.setStroke(new BasicStroke(strokeSize)); graphics.drawRoundRect(0, 0, width - shadowGap, height - shadowGap, arcs.width, arcs.height); graphics.setStroke(new BasicStroke());
public static void renderPolygon(Graphics2D graphics, Polygon poly, Color color) { graphics.setColor(color); final Stroke originalStroke = graphics.getStroke(); graphics.setStroke(new BasicStroke(2)); graphics.drawPolygon(poly); graphics.setColor(new Color(0, 0, 0, 50)); graphics.fillPolygon(poly); graphics.setStroke(originalStroke); }
public static BufferedImage addBorder(BufferedImage image, Color borderColor, int borderWidth, int cornerRadius) { int w = image.getWidth() + borderWidth * 2; int h = image.getHeight() + borderWidth * 2; BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); //BufferedImage output = UIUtil.createImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); g2.setColor(borderColor); g2.drawImage(image, borderWidth, borderWidth, image.getWidth(), image.getHeight(), null); //UIUtil.drawImage(g2, image, 0, 0, null); g2.setStroke(new BasicStroke(borderWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, borderWidth)); g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); int width = w - borderWidth - 1; int height = h - borderWidth - 1; int halfBorder = borderWidth / 2; if (cornerRadius > 0) { int adjustedRadius = cornerRadius + borderWidth; g2.drawRoundRect(halfBorder, halfBorder, width, height, adjustedRadius, adjustedRadius); } else { g2.drawRect(halfBorder, halfBorder, width, height); } g2.dispose(); //output.setRGB(3, 3, 123); return output; }
for (BufferedImage icon : icons) graphics.setStroke(new BasicStroke(2)); graphics.setColor(COLOR_ICON_BACKGROUND); graphics.fillOval( point.getX() - totalWidth / 2 + currentPosX - bgPadding, icon.getHeight() + bgPadding * 2); graphics.setColor(COLOR_ICON_BORDER); graphics.drawOval( point.getX() - totalWidth / 2 + currentPosX - bgPadding, null); graphics.setColor(COLOR_ICON_BORDER_FILL); Arc2D.Double arc = new Arc2D.Double( point.getX() - totalWidth / 2 + currentPosX - bgPadding, gorilla.getAttacksUntilSwitch()) / DemonicGorilla.ATTACKS_PER_SWITCH, Arc2D.OPEN); graphics.draw(arc);
/** * Icon for point data in the provided color * * <p>XXX: Suggest point( SLD style ) at a later time. * * @param color * @param fill * @return ImageDescriptor */ public static BufferedImage point(final Color color, final Color fill) { BufferedImage bi = new BufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_DEPTH); Graphics2D gc = (Graphics2D) bi.getGraphics(); gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Stroke stroke = new BasicStroke(1); gc.setStroke(stroke); Color c = color; Color f = fill; if (c == null) c = Color.BLACK; if (f == null) f = Color.LIGHT_GRAY; gc.setColor(f); gc.fillRect(8, 7, 5, 5); gc.setColor(c); gc.drawRect(8, 7, 5, 5); return bi; }
@Override public void paintComponent(Graphics g){ Dimension d = new Dimension(textBox.width + triangle.width, textBox.height); Dimension originalSize = canonicalSize; Dimension actualSize = getActualSize(); float scalex = 1f * actualSize.width / originalSize.width; float scaley = 1f * actualSize.height / originalSize.height; ((Graphics2D) g).scale(scalex, scaley); super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setFont(font); g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); g2d.setColor(colorFront); g2d.fill(flagShape); // draw outline Stroke pen = new BasicStroke(1.0F); g2d.setStroke(pen); g2d.setColor(colorFrame); g2d.draw(flagShape); g2d.setColor(colorText); g2d.drawString(text, textBox.x + PADDING_X, textBox.y + textBox.height - fm.getDescent() - PADDING_Y); } }
java.awt.Graphics2D g2 = (java.awt.Graphics2D) g.create(); g2.setStroke(new java.awt.BasicStroke(3)); // thickness of 3.0f g2.setColor(Color.blue); g2.drawRect(10,10,50,100); // for example
public void drawDivider( Graphics g, DockStation station, Rectangle bounds ) { color.setId( "paint.divider" ); color.setBackup( Color.DARK_GRAY ); color.connect( station.getController() ); g.setColor( color.value() ); Graphics2D g2 = (Graphics2D)g; Stroke old = g2.getStroke(); g2.setStroke( new BasicStroke( 3f )); g2.fillRect( bounds.x, bounds.y, bounds.width, bounds.height ); g2.setStroke( old ); color.connect( null ); }
final double t = tickProgress * Math.PI; // Convert to 0 - pi graphics.setColor(ColorUtil.colorLerp(START_COLOR, END_COLOR, Math.sin(t))); graphics.setStroke(new BasicStroke(2)); graphics.drawOval(orbInnerX, orbInnerY, orbInnerSize, orbInnerSize);
public void plotDirectedEdge(Graphics2D g2, double lat, double lon, double lat2, double lon2, float width) { g2.setStroke(new BasicStroke(width)); int startLon = (int) getX(lon); int startLat = (int) getY(lat); int destLon = (int) getX(lon2); int destLat = (int) getY(lat2); g2.drawLine(startLon, startLat, destLon, destLat); // only for deep zoom show direction if (scaleX < 0.0001) { g2.setStroke(new BasicStroke(3)); Path2D.Float path = new Path2D.Float(); path.moveTo(destLon, destLat); path.lineTo(destLon + 6, destLat - 2); path.lineTo(destLon + 6, destLat + 2); path.lineTo(destLon, destLat); AffineTransform at = new AffineTransform(); double angle = Math.atan2(lat2 - lat, lon2 - lon); at.rotate(-angle + Math.PI, destLon, destLat); path.transform(at); g2.draw(path); } }
public void drawInteractiveComponents(Grouping group, Graphics g, Point pageOrigin, float zoomLevel){ drawMathObject(group, g, pageOrigin, zoomLevel); for (MathObject mathObj : group.getObjects()){ g.setColor(Color.BLUE); ((Graphics2D)g).setStroke(new BasicStroke(2)); Graphics2D g2d = (Graphics2D)g; g2d.drawPolygon(pageGui.getGUIForObj(mathObj).getCollisionAndSelectionPolygon(mathObj, pageOrigin, zoomLevel)); ((Graphics2D)g).setStroke(new BasicStroke(1)); } } }