List of usage examples for java.awt Graphics2D fillRoundRect
public abstract void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight);
From source file:com.zacwolf.commons.email.Email.java
public static BufferedImage makeRoundedFooter(int width, int cornerRadius, Color bgcolor, Color border) throws Exception { int height = (cornerRadius * 2) + 10; BufferedImage output = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); g2.setComposite(AlphaComposite.Src); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(bgcolor);/*w w w.j a va 2s. c o m*/ g2.fillRoundRect(0, 0, width, height - 1, cornerRadius, cornerRadius); g2.setComposite(AlphaComposite.SrcOver); if (border != null) { g2.setColor(border); g2.drawRoundRect(0, 0, width - 1, height - 2, cornerRadius, cornerRadius); } g2.dispose(); Rectangle clip = createClip(output, new Dimension(width, cornerRadius), 0, height - cornerRadius - 1); return output.getSubimage(clip.x, clip.y, clip.width, clip.height); }
From source file:edu.kit.dama.ui.components.TextImage.java
/** * Get the bytes of the final image./* w w w . j av a 2 s. com*/ * * @return The byte array containing the bytes of the resulting image. * * @throws IOException if creating the image fails. */ public byte[] getBytes() throws IOException { Image transparentImage = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource( new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB).getSource(), new RGBImageFilter() { @Override public final int filterRGB(int x, int y, int rgb) { return (rgb << 8) & 0xFF000000; } })); //create the actual image and overlay it by the transparent background BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = outputImage.createGraphics(); g2d.drawImage(transparentImage, 0, 0, null); //draw the remaining stuff g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.setColor(color); g2d.fillRoundRect(0, 0, size, size, 20, 20); g2d.setColor(new Color(Math.round((float) color.getRed() * .9f), Math.round((float) color.getGreen() * .9f), Math.round((float) color.getBlue() * .9f))); g2d.drawRoundRect(0, 0, size - 1, size - 1, 20, 20); Font font = new Font("Dialog", Font.BOLD, size - 4); g2d.setFont(font); g2d.setColor(Color.WHITE); String s = text.toUpperCase().substring(0, 1); FontMetrics fm = g2d.getFontMetrics(); float x = ((float) size - (float) fm.stringWidth(s)) / 2f; float y = ((float) fm.getAscent() + (float) ((float) size - ((float) fm.getAscent() + (float) fm.getDescent())) / 2f) - 1f; g2d.drawString(s, x, y); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ImageIO.write(outputImage, "png", bout); g2d.dispose(); return bout.toByteArray(); }
From source file:Main.java
@Override protected void paintThumb(Graphics g, JComponent c, Rectangle r) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Color color = null;// w w w. j a va2 s. c om JScrollBar sb = (JScrollBar) c; if (!sb.isEnabled() || r.width > r.height) { return; } else if (isDragging) { color = Color.DARK_GRAY; } else if (isThumbRollover()) { color = Color.LIGHT_GRAY; } else { color = Color.GRAY; } g2.setPaint(color); g2.fillRoundRect(r.x, r.y, r.width, r.height, 10, 10); g2.setPaint(Color.WHITE); g2.drawRoundRect(r.x, r.y, r.width, r.height, 10, 10); g2.dispose(); }
From source file:com.celements.photo.image.GenerateThumbnail.java
private void drawBackground(String copyright, int width, int height, int bottomSpace, int rightSpace, int vSpacing, int hSpacing, int rounding, int stringHeight, FontMetrics metrics, Graphics2D g2d) { g2d.setColor(new Color(0, 0, 0)); AlphaComposite transprency = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f); g2d.setComposite(transprency);/*w w w . jav a 2 s . c o m*/ g2d.fillRoundRect(width - metrics.stringWidth(copyright) - rightSpace - 2 * hSpacing, height - stringHeight - bottomSpace - 2 * vSpacing, metrics.stringWidth(copyright) + 2 * hSpacing, stringHeight + 2 * vSpacing, rounding, rounding); }
From source file:net.java.sip.communicator.impl.osdependent.jdic.SystrayServiceJdicImpl.java
private BufferedImage createOverlayImage(String text) { int size = 16; BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //background/*ww w. j ava 2 s . c o m*/ g.setPaint(new Color(0, 0, 0, 102)); g.fillRoundRect(0, 0, size, size, size, size); //filling int mainRadius = 14; g.setPaint(new Color(255, 98, 89)); g.fillRoundRect(size / 2 - mainRadius / 2, size / 2 - mainRadius / 2, mainRadius, mainRadius, size, size); //text Font font = g.getFont(); g.setFont(new Font(font.getName(), Font.BOLD, 9)); FontMetrics fontMetrics = g.getFontMetrics(); int textWidth = fontMetrics.stringWidth(text); g.setColor(Color.white); g.drawString(text, size / 2 - textWidth / 2, size / 2 - fontMetrics.getHeight() / 2 + fontMetrics.getAscent()); return image; }
From source file:org.jas.gui.ImagePanel.java
@Override protected void paintComponent(Graphics g) { if (portrait == null) { super.paintComponent(g); return;/*from ww w . ja va 2s .c o m*/ } try { // Create a translucent intermediate image in which we can perform the soft clipping GraphicsConfiguration gc = ((Graphics2D) g).getDeviceConfiguration(); BufferedImage intermediateBufferedImage = gc.createCompatibleImage(getWidth(), getHeight(), Transparency.TRANSLUCENT); Graphics2D bufferGraphics = intermediateBufferedImage.createGraphics(); // Clear the image so all pixels have zero alpha bufferGraphics.setComposite(AlphaComposite.Clear); bufferGraphics.fillRect(0, 0, getWidth(), getHeight()); // Render our clip shape into the image. Shape on where to paint bufferGraphics.setComposite(AlphaComposite.Src); bufferGraphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); bufferGraphics.setColor(Color.WHITE); bufferGraphics.fillRoundRect(0, 0, getWidth(), getHeight(), (int) (getWidth() * arcWidth), (int) (getHeight() * arcHeight)); // SrcAtop uses the alpha value as a coverage value for each pixel stored in the // destination shape. For the areas outside our clip shape, the destination // alpha will be zero, so nothing is rendered in those areas. For // the areas inside our clip shape, the destination alpha will be fully // opaque. bufferGraphics.setComposite(AlphaComposite.SrcAtop); bufferGraphics.drawImage(portrait, 0, 0, getWidth(), getHeight(), null); bufferGraphics.dispose(); // Copy our intermediate image to the screen g.drawImage(intermediateBufferedImage, 0, 0, null); } catch (Exception e) { log.warn("Error: Creating Renderings", e); } }
From source file:org.squidy.designer.zoom.impl.DataTypeShape.java
@Override protected void paintShapeZoomedIn(PPaintContext paintContext) { Graphics2D g = paintContext.getGraphics(); paintContext.pushTransform(translation); PBounds bounds = getBoundsReference(); // Rectangle rectBounds = roundedRectangleShape.getBounds(); int x = (int) bounds.x - 3; int y = (int) bounds.y - 3; int width = (int) bounds.width + 6; int height = (int) bounds.height; g.setColor(Color.WHITE);/*from w ww. ja v a 2 s .c om*/ g.fillRoundRect(x - 40, y, width + 80, height, 825, 825); g.setStroke(STROKE_SHAPE); g.setColor(Color.BLACK); g.drawRoundRect(x - 40, y, width + 80, height, 825, 825); paintContext.popTransform(translation); // 1st vertical g.drawLine(1000, 100, 1000, 220); // 1st horizontal g.drawLine(230, 220, 1780, 220); // 2nd (left) vertical g.drawLine(230, 220, 230, 700); // 2nd (left-middle) vertical g.drawLine(740, 220, 740, 960); // 2d (right-middle) vertical g.drawLine(1260, 220, 1260, 700); // 2nd (right) vertical g.drawLine(1780, 220, 1780, 700); }
From source file:edu.ku.brc.ui.dnd.SimpleGlassPane.java
/** * @param g2/*w w w. j ava 2s. co m*/ * @param x * @param y * @param w * @param h * @param arcW * @param arcH */ private void drawBGContainer(final Graphics2D g2, final boolean doFill, final int x, final int y, final int w, final int h, final int arcW, final int arcH) { Stroke cacheStroke = g2.getStroke(); g2.setStroke(UIHelper.getStdLineStroke()); if (UIHelper.isWindows()) { if (doFill) { //g2.fillRect(x, y, w, h); // Make ugly for Windows g2.fillRoundRect(x, y, w, h, 4, 4); } else { //g2.drawRect(x, y, w, h); // Make ugly for Windows g2.drawRoundRect(x, y, w, h, 4, 4); } } else { if (doFill) { g2.fillRoundRect(x, y, w, h, arcW, arcH); } else { g2.drawRoundRect(x, y, w, h, arcW, arcH); } } g2.setStroke(cacheStroke); }
From source file:org.squidy.designer.zoom.NavigationShape.java
@Override protected void paintShapeZoomedIn(PPaintContext paintContext) { super.paintShapeZoomedIn(paintContext); Graphics2D g = (Graphics2D) paintContext.getGraphics(); if (showNavigation) {// && !isHierarchicalZoomInProgress()) { PBounds bounds = getBoundsReference(); int x = (int) bounds.getX(); int y = (int) bounds.getY(); int width = (int) bounds.getWidth(); int height = (int) bounds.getHeight(); g.setColor(Constants.Color.COLOR_SHAPE_BACKGROUND); if (isRenderPrimitiveRect()) g.fillRect(x, y, width, 60); else {/*from ww w . j av a 2 s .com*/ g.clearRect(x, y, width, 60); g.fillRoundRect(x, y, width, 60, 25, 25); } g.setColor(Constants.Color.COLOR_SHAPE_BORDER); if (isRenderPrimitiveRect()) g.drawRect(x, y, width, 60); else g.drawRoundRect(x, y, width, 60, 25, 25); g.setFont(fontBreadcrumb); if (titleBounds == null) { FontMetrics fm = g.getFontMetrics(); titleBounds = new Rectangle2D.Double(bounds.getX() + 455 + titleGap, bounds.getY() + 25 - fm.getHeight(), FontUtils.getWidthOfText(fm, getTitle()) + 10, fm.getHeight() + 5); } // Font font = internalFont.deriveFont(3.2f); for (int i = 0; i < 3; i++) { if (isRenderPrimitiveRect()) g.fillRect((int) (bounds.getX() + 430), (int) bounds.getY() + i * 15 + 10, 5, 10); else g.fillOval((int) (bounds.getX() + 430), (int) bounds.getY() + i * 15 + 10, 5, 10); } if (!ShapeUtils.isApparent(titleInputWrapper)) { g.drawString(getTitle(), (int) (bounds.getX() + 460 + titleGap), (int) (bounds.getY() + 25)); } if (croppedBreadcrumb == null) { croppedBreadcrumb = FontUtils.createCroppedLabelIfNecessary(g.getFontMetrics(), getBreadcrumb(), (int) bounds.getWidth() * 10 - 450); } g.drawString(croppedBreadcrumb, (int) (bounds.getX() + 460), (int) (bounds.getY() + 50)); } }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java
private void updateLegend() { int width = DEFAULT_LEGEND_WIDTH; int height = DEFAULT_LEGENT_HEIGHT; legend = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); Graphics2D g = (Graphics2D) legend.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setPaint(UI.colorBlack2);/* w w w .j av a 2 s. com*/ g.fillRoundRect(0, 0, width, height - 12, 5, 5); g.setColor(barColorBelow); int boxNum = 10; g.setStroke(UI.stroke1_5); double value; for (int i = 0; i < boxNum; i++) { value = _minValue + (_maxValue - _minValue) / boxNum * i; if (value > disectBound) { g.setColor(barColorNormal); } int h = (height - 12) / boxNum * i; g.drawLine(i * width / boxNum, height - 12 - h, (i + 1) * width / boxNum, height - 12 - h); } g.setColor(Color.BLACK); g.setFont(UI.fontMono.deriveFont(10f)); DecimalFormat format = new DecimalFormat("#.##"); g.drawString(format.format(_minValue), 2, 23); g.setColor(Color.BLACK); String maxString = format.format(_maxValue); int swidth = g.getFontMetrics().stringWidth(maxString); g.drawString(maxString, width - 2 - swidth, 23); g.dispose(); }