List of usage examples for java.awt Graphics2D drawRoundRect
public abstract void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight);
From source file:Main.java
public static void drawRoundBorder(Graphics g, Color c, int x, int y, int w, int h, int r) { Graphics2D g2D = (Graphics2D) g; Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.setColor(c);/*from w w w .j a v a 2 s . c o m*/ g2D.drawRoundRect(x, y, w - 1, h - 1, r, r); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); }
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);//www . j a va 2s.c om 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: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;//from www . j a v a 2s. co m 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:edu.kit.dama.ui.components.TextImage.java
/** * Get the bytes of the final image./* w ww . j a v 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:edu.ku.brc.ui.dnd.SimpleGlassPane.java
/** * @param g2//from w w w .j a v a 2 s .c om * @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.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private void drawInformationBox(Graphics2D g2, Activities activities, Rectangle2D rect, List<String> params, List<String> values, String totalParam, double totalValue, Color background_color, Color border_color) { final Font oldFont = g2.getFont(); final Font paramFont = oldFont; final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont); final Font valueFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() + 1); final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont); final Font dateFont = oldFont.deriveFont((float) oldFont.getSize() - 1); final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont); final int x = (int) rect.getX(); final int y = (int) rect.getY(); final int width = (int) rect.getWidth(); final int height = (int) rect.getHeight(); final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Composite oldComposite = g2.getComposite(); final Color oldColor = g2.getColor(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(border_color);/*from w w w . j a v a 2 s.c o m*/ g2.drawRoundRect(x - 1, y - 1, width + 1, height + 1, 15, 15); g2.setColor(background_color); g2.setComposite(Utils.makeComposite(0.75f)); g2.fillRoundRect(x, y, width, height, 15, 15); g2.setComposite(oldComposite); g2.setColor(oldColor); final Date date = activities.getDate().getTime(); final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, MMMM d, yyyy"); final String dateString = simpleDateFormat.format(date); final int padding = 5; int yy = y + padding + dateFontMetrics.getAscent(); g2.setFont(dateFont); g2.setColor(COLOR_BLUE); g2.drawString(dateString, ((width - dateFontMetrics.stringWidth(dateString)) >> 1) + x, yy); int index = 0; final int dateInfoHeightMargin = 5; final int infoTotalHeightMargin = 5; final int paramValueHeightMargin = 0; yy += dateFontMetrics.getDescent() + dateInfoHeightMargin + Math.max(paramFontMetrics.getAscent(), valueFontMetrics.getAscent()); for (String param : params) { final String value = values.get(index++); g2.setColor(Color.BLACK); g2.setFont(paramFont); g2.drawString(param + ":", padding + x, yy); g2.setFont(valueFont); g2.drawString(value, width - padding - valueFontMetrics.stringWidth(value) + x, yy); // Same as yy += valueFontMetrics.getDescent() + paramValueHeightMargin + valueFontMetrics.getAscent() yy += paramValueHeightMargin + Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight()); } if (values.size() > 1) { yy -= paramValueHeightMargin; yy += infoTotalHeightMargin; if (totalValue > 0.0) { g2.setColor(JStockOptions.DEFAULT_HIGHER_NUMERICAL_VALUE_FOREGROUND_COLOR); } else if (totalValue < 0.0) { g2.setColor(JStockOptions.DEFAULT_LOWER_NUMERICAL_VALUE_FOREGROUND_COLOR); } g2.setFont(paramFont); g2.drawString(totalParam + ":", padding + x, yy); g2.setFont(valueFont); final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace(); final String totalValueStr = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, totalValue); g2.drawString(totalValueStr, width - padding - valueFontMetrics.stringWidth(totalValueStr) + x, yy); } g2.setColor(oldColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias); g2.setFont(oldFont); }
From source file:edu.ku.brc.ui.UIRegistry.java
/** * Writes a string message into the BufferedImage on GlassPane and sets the main component's visibility to false and * shows the GlassPane./*from w ww.j a va 2s .co m*/ * @param msg the message * @param pointSize the Font point size for the message to be writen in */ public static GhostGlassPane writeGlassPaneMsg(final String msg, final int pointSize) { GhostGlassPane glassPane = getGlassPane(); if (glassPane != null) { glassPane.finishDnD(); } glassPane.setMaskingEvents(true); Component mainComp = get(MAINPANE); if (mainComp != null && glassPane != null) { JFrame frame = (JFrame) get(FRAME); frameRect = frame.getBounds(); int y = 0; JMenuBar menuBar = null; Dimension size = mainComp.getSize(); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { menuBar = frame.getJMenuBar(); size.height += menuBar.getSize().height; y += menuBar.getSize().height; } BufferedImage buffer = getGlassPaneBufferedImage(size.width, size.height); Graphics2D g2 = buffer.createGraphics(); if (menuBar != null) { menuBar.paint(g2); } g2.translate(0, y); mainComp.paint(g2); g2.translate(0, -y); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(new Color(255, 255, 255, 128)); g2.fillRect(0, 0, size.width, size.height); g2.setFont(new Font((new JLabel()).getFont().getName(), Font.BOLD, pointSize)); FontMetrics fm = g2.getFontMetrics(); int tw = fm.stringWidth(msg); int th = fm.getHeight(); int tx = (size.width - tw) / 2; int ty = (size.height - th) / 2; int expand = 20; int arc = expand * 2; g2.setColor(Color.WHITE); g2.fillRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc, arc); g2.setColor(Color.DARK_GRAY); g2.drawRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc, arc); g2.setColor(Color.BLACK); g2.drawString(msg, tx, ty); g2.dispose(); glassPane.setImage(buffer); glassPane.setPoint(new Point(0, 0), GhostGlassPane.ImagePaintMode.ABSOLUTE); glassPane.setOffset(new Point(0, 0)); glassPane.setVisible(true); mainComp.setVisible(false); //Using paintImmediately fixes problems with glass pane not showing, such as for workbench saves initialed //during workbench or app shutdown. Don't know if there is a better way to fix it. //glassPane.repaint(); glassPane.paintImmediately(glassPane.getBounds()); showingGlassPane = true; } return glassPane; }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private void drawBusyBox(Graphics2D g2, JXLayer<? extends V> layer) { final Font oldFont = g2.getFont(); final Font font = oldFont; final FontMetrics fontMetrics = g2.getFontMetrics(font); // Not sure why. Draw GIF image on JXLayer, will cause endless setDirty // being triggered by system. //final Image image = ((ImageIcon)Icons.BUSY).getImage(); //final int imgWidth = Icons.BUSY.getIconWidth(); //final int imgHeight = Icons.BUSY.getIconHeight(); //final int imgMessageWidthMargin = 5; final int imgWidth = 0; final int imgHeight = 0; final int imgMessageWidthMargin = 0; final String message = MessagesBundle.getString("info_message_retrieving_latest_stock_price"); final int maxWidth = imgWidth + imgMessageWidthMargin + fontMetrics.stringWidth(message); final int maxHeight = Math.max(imgHeight, fontMetrics.getHeight()); final int padding = 5; final int width = maxWidth + (padding << 1); final int height = maxHeight + (padding << 1); final int x = (int) this.drawArea.getX() + (((int) this.drawArea.getWidth() - width) >> 1); final int y = (int) this.drawArea.getY() + (((int) this.drawArea.getHeight() - height) >> 1); final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Composite oldComposite = g2.getComposite(); final Color oldColor = g2.getColor(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(COLOR_BORDER);// w w w. j a va 2 s . c o m g2.drawRoundRect(x - 1, y - 1, width + 1, height + 1, 15, 15); g2.setColor(COLOR_BACKGROUND); g2.setComposite(Utils.makeComposite(0.75f)); g2.fillRoundRect(x, y, width, height, 15, 15); g2.setComposite(oldComposite); g2.setColor(oldColor); //g2.drawImage(image, x + padding, y + ((height - imgHeight) >> 1), layer.getView()); g2.setFont(font); g2.setColor(COLOR_BLUE); int yy = y + ((height - fontMetrics.getHeight()) >> 1) + fontMetrics.getAscent(); g2.setFont(font); g2.setColor(COLOR_BLUE); g2.drawString(message, x + padding + imgWidth + imgMessageWidthMargin, yy); g2.setColor(oldColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias); g2.setFont(oldFont); }
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param g2d/*w w w . j a v a 2 s . c om*/ * @param color * @param x * @param y * @param w * @param h * @param arcSizeW * @param arcSizeH */ public static void drawRoundedRect(final Graphics2D g2d, final Color color, final int x, final int y, final int w, final int h, final int arcSizeW, final int arcSizeH) { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setStroke(UIHelper.getStdLineStroke()); g2d.setColor(color); g2d.drawRoundRect(x, y, w, h, arcSizeW, arcSizeH); }
From source file:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java
@Override public void paintComponent(final Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int x = 0;/* w w w . j av a2 s.co m*/ int y = 0; int width = (int) getSize().getWidth(); int height = (int) getSize().getHeight(); // draw background depending special roles and hovering if (getModel() != null && getModel().isSpecialAtt()) { if (Attributes.LABEL_NAME.equals(getModel().getSpecialAttName())) { // label special attributes have a distinct color g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.LABEL_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.LABEL_NAME, false, hovered))); } else if (Attributes.WEIGHT_NAME.equals(getModel().getSpecialAttName())) { // weight special attributes have another distinct color g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.WEIGHT_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.WEIGHT_NAME, false, hovered))); } else if (Attributes.PREDICTION_NAME.equals(getModel().getSpecialAttName())) { // prediction special attributes have another distinct color g2.setPaint(new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.PREDICTION_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.PREDICTION_NAME, false, hovered))); } else if (getModel().getSpecialAttName().startsWith(Attributes.CONFIDENCE_NAME + "_")) { // confidence special attributes have another distinct color g2.setPaint(new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.CONFIDENCE_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.CONFIDENCE_NAME, false, hovered))); } else if (Attributes.ID_NAME.equals(getModel().getSpecialAttName())) { // id special attributes have another distinct color g2.setPaint(new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.ID_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.ID_NAME, false, hovered))); } else { // other special attributes have another color g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(GENERIC_SPECIAL_NAME, true, hovered), x, height, getColorForSpecialAttribute(GENERIC_SPECIAL_NAME, false, hovered))); } } else { // regular attributes g2.setPaint( new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.ATTRIBUTE_NAME, true, hovered), x, height, getColorForSpecialAttribute(Attributes.ATTRIBUTE_NAME, false, hovered))); } g2.fillRoundRect(x, y, width, height, CORNER_ARC_WIDTH, CORNER_ARC_WIDTH); // draw border g2.setPaint(new GradientPaint(x, y, COLOR_BORDER_GRADIENT_FIRST, x, height, COLOR_BORDER_GRADIENT_SECOND)); if (hovered) { g2.setStroke(new BasicStroke(1.0f)); } else { g2.setStroke(new BasicStroke(0.5f)); } g2.drawRoundRect(x, y, width - 1, height - 1, CORNER_ARC_WIDTH, CORNER_ARC_WIDTH); // let Swing draw its components super.paintComponent(g2); }