java.awt.geom.RoundRectangle2D Java Examples
The following examples show how to use
java.awt.geom.RoundRectangle2D.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubtleScrollBarUI.java From pumpernickel with MIT License | 6 votes |
@Override protected void paintThumb(Graphics g0, JComponent c, Rectangle thumbBounds) { Graphics2D g = (Graphics2D) g0.create(); int alpha = 60; Number rollover = (Number) scrollbar .getClientProperty(PROPERTY_ACTIVE_NUMBER); if (rollover != null) { alpha += (int) (rollover.floatValue() * 60); } g.setColor(new Color(0, 0, 0, alpha)); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int k = thumbWidth; g.fill(new RoundRectangle2D.Float(thumbBounds.x + thumbBounds.width / 2 - thumbWidth / 2, thumbBounds.y, thumbWidth, thumbBounds.height, k, k)); g.dispose(); }
Example #2
Source File: MyLineBorder.java From training with MIT License | 6 votes |
/** * Paints the border for the specified component with the * specified position and size. * @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 */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { if ((this.thickness > 0) && (g instanceof Graphics2D)) { Graphics2D g2d = (Graphics2D) g; Color oldColor = g2d.getColor(); g2d.setColor(this.lineColor); RoundRectangle2D.Float outer = new RoundRectangle2D.Float(x, y, width, height, radius, radius); RoundRectangle2D.Float inner = new RoundRectangle2D.Float(x + thickness, y + thickness, width - thickness * 2, height - thickness * 2, 10, 10); Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD); path.append(outer, false); path.append(inner, false); g2d.fill(path); g2d.setColor(oldColor); } }
Example #3
Source File: FXGraphics2D.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Fills the specified shape with the current {@code paint}. There is * direct handling for {@code RoundRectangle2D}, * {@code Rectangle2D}, {@code Ellipse2D} and {@code Arc2D}. * All other shapes are mapped to a path outline and then filled. * * @param s the shape ({@code null} not permitted). * * @see #draw(java.awt.Shape) */ @Override public void fill(Shape s) { if (s instanceof RoundRectangle2D) { RoundRectangle2D rr = (RoundRectangle2D) s; this.gc.fillRoundRect(rr.getX(), rr.getY(), rr.getWidth(), rr.getHeight(), rr.getArcWidth(), rr.getArcHeight()); } else if (s instanceof Rectangle2D) { Rectangle2D r = (Rectangle2D) s; this.gc.fillRect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); } else if (s instanceof Ellipse2D) { Ellipse2D e = (Ellipse2D) s; this.gc.fillOval(e.getX(), e.getY(), e.getWidth(), e.getHeight()); } else if (s instanceof Arc2D) { Arc2D a = (Arc2D) s; this.gc.fillArc(a.getX(), a.getY(), a.getWidth(), a.getHeight(), a.getAngleStart(), a.getAngleExtent(), intToArcType(a.getArcType())); } else { shapeToPath(s); this.gc.fill(); } }
Example #4
Source File: MfCmdRoundRect.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
/** * Replays the command on the given WmfFile. * * @param file the meta file. */ public void replay( final WmfFile file ) { final Graphics2D graph = file.getGraphics2D(); final Rectangle rec = getScaledBounds(); final Dimension dim = getScaledRoundingDim(); final RoundRectangle2D shape = new RoundRectangle2D.Double(); shape.setRoundRect( rec.x, rec.y, rec.width, rec.height, dim.width, dim.height ); final MfDcState state = file.getCurrentState(); if ( state.getLogBrush().isVisible() ) { state.preparePaint(); graph.fill( shape ); state.postPaint(); } if ( state.getLogPen().isVisible() ) { state.prepareDraw(); graph.draw( shape ); state.postDraw(); } }
Example #5
Source File: DefaultProcessDiagramCanvas.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
public void drawExpandedSubProcess(String name, GraphicInfo graphicInfo, Boolean isTriggeredByEvent, double scaleFactor) { RoundRectangle2D rect = new RoundRectangle2D.Double(graphicInfo.getX(), graphicInfo.getY(), graphicInfo.getWidth(), graphicInfo.getHeight(), 8, 8); // Use different stroke (dashed) if (isTriggeredByEvent) { Stroke originalStroke = g.getStroke(); g.setStroke(EVENT_SUBPROCESS_STROKE); g.draw(rect); g.setStroke(originalStroke); } else { Paint originalPaint = g.getPaint(); g.setPaint(SUBPROCESS_BOX_COLOR); g.fill(rect); g.setPaint(SUBPROCESS_BORDER_COLOR); g.draw(rect); g.setPaint(originalPaint); } if (scaleFactor == 1.0 && name != null && !name.isEmpty()) { String text = fitTextToWidth(name, (int) graphicInfo.getWidth()); g.drawString(text, (int) graphicInfo.getX() + 10, (int) graphicInfo.getY() + 15); } }
Example #6
Source File: SxButton.java From SikuliX1 with MIT License | 6 votes |
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; Color cb = null; if (isMouseOver()) { cb = mouseOverColor; } else { cb = colorFront; } g2d.setColor(cb); RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, getActualWidth() - 1, getActualHeight() - 1, PADDING_X, PADDING_Y); g2d.fill(roundedRectangle); g2d.setColor(cb); g2d.draw(roundedRectangle); roundedRectangle = new RoundRectangle2D.Float(1, 1, getActualWidth() - 3, getActualHeight() - 3, PADDING_X, PADDING_Y); g2d.setColor(colorFrame); g2d.draw(roundedRectangle); label.paintComponents(g); }
Example #7
Source File: DarculaSpinnerUI.java From consulo with Apache License 2.0 | 6 votes |
@Override public void paint(Graphics g, JComponent c) { Graphics2D g2 = (Graphics2D)g.create(); Rectangle r = new Rectangle(c.getSize()); JBInsets.removeFrom(r, JBUI.insets(1)); try { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, MacUIUtil.USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE); g2.translate(r.x, r.y); float bw = BW.getFloat(); float arc = COMPONENT_ARC.getFloat(); g2.setColor(getBackground()); g2.fill(new RoundRectangle2D.Float(bw, bw, r.width - bw * 2, r.height - bw * 2, arc, arc)); } finally { g2.dispose(); } }
Example #8
Source File: AbstractTitledWidget.java From netbeans with Apache License 2.0 | 6 votes |
@org.netbeans.api.annotations.common.SuppressWarnings(" NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") protected final void paintWidget() { Rectangle bounds = getClientArea(); Graphics2D g = getGraphics(); Paint oldPaint = g.getPaint(); RoundRectangle2D rect = new RoundRectangle2D.Double(bounds.x + 0.75f, bounds.y+ 0.75f, bounds.width - 1.5f, bounds.height - 1.5f, radius, radius); if(isExpanded()) { int titleHeight = headerWidget.getBounds().height; Area titleArea = new Area(rect); titleArea.subtract(new Area(new Rectangle(bounds.x, bounds.y + titleHeight, bounds.width, bounds.height))); g.setPaint(getTitlePaint(titleArea.getBounds())); g.fill(titleArea); if(isOpaque()) { Area bodyArea = new Area(rect); bodyArea.subtract(titleArea); g.setPaint(getBackground()); g.fill(bodyArea); } } else { g.setPaint(getTitlePaint(bounds)); g.fill(rect); } g.setPaint(oldPaint); }
Example #9
Source File: ShapeLayout.java From Alice-LiveMan with GNU Affero General Public License v3.0 | 6 votes |
@Override public void paintLayout(Graphics2D g) throws Exception { RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(x, y, width, height, width * (radiusPercentW * 0.01f), height * (radiusPercentH * 0.01f)); if (mask) { g.setColor(new Color(0, 0, 0, 0)); g.setPaintMode(); g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR)); g.fill(roundedRectangle); } else { g.setColor(Color.decode(hexColor)); Composite oldComp = g.getComposite(); g.setPaintMode(); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); g.fill(roundedRectangle); g.setComposite(oldComp); } }
Example #10
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int r = ARC; int w = width - 1; int h = height - 1; Area round = new Area(new RoundRectangle2D.Double(x, y, w, h, r, r)); if (c instanceof JPopupMenu) { g2.setPaint(c.getBackground()); g2.fill(round); } else { Container parent = c.getParent(); if (Objects.nonNull(parent)) { g2.setPaint(parent.getBackground()); Area corner = new Area(new Rectangle2D.Double(x, y, width, height)); corner.subtract(round); g2.fill(corner); } } g2.setPaint(c.getForeground()); g2.draw(round); g2.dispose(); }
Example #11
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
@Override protected void paintComponent(Graphics g) { float x = 0f; float y = 0f; float w = getWidth(); float h = getHeight(); Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Shape area = new RoundRectangle2D.Float(x, y, w - 1f, h - 1f, R, R); Color ssc = TL; Color bgc = BR; ButtonModel m = getModel(); if (m.isPressed()) { ssc = SB; bgc = ST; } else if (m.isRollover()) { ssc = ST; bgc = SB; } g2.setPaint(new GradientPaint(x, y, ssc, x, y + h, bgc, true)); g2.fill(area); g2.setPaint(BR); g2.draw(area); g2.dispose(); super.paintComponent(g); }
Example #12
Source File: CompositeButtonPainter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Draws the component border. * * @param g * the graphics context */ public void paintBorder(Graphics g) { Shape borderShape; int radius = RapidLookAndFeel.CORNER_DEFAULT_RADIUS; switch (position) { case SwingConstants.LEFT: borderShape = new RoundRectangle2D.Double(0, 0, button.getWidth() + radius, button.getHeight() - 1, radius, radius); RapidLookTools.drawButtonBorder(button, g, borderShape); break; case SwingConstants.CENTER: borderShape = new Rectangle2D.Double(0, 0, button.getWidth() + radius, button.getHeight() - 1); RapidLookTools.drawButtonBorder(button, g, borderShape); break; default: borderShape = new RoundRectangle2D.Double(-radius, 0, button.getWidth() + radius - 1, button.getHeight() - 1, radius, radius); RapidLookTools.drawButtonBorder(button, g, borderShape); // special case, right button has a left border borderShape = new Line2D.Double(0, 0, 0, button.getHeight()); RapidLookTools.drawButtonBorder(button, g, borderShape); break; } }
Example #13
Source File: DefaultProcessDiagramCanvas.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected void drawTask(String name, GraphicInfo graphicInfo, boolean thickBorder) { Paint originalPaint = g.getPaint(); int x = (int) graphicInfo.getX(); int y = (int) graphicInfo.getY(); int width = (int) graphicInfo.getWidth(); int height = (int) graphicInfo.getHeight(); // Create a new gradient paint for every task box, gradient depends on x and y and is not relative g.setPaint(TASK_BOX_COLOR); int arcR = 6; if (thickBorder) arcR = 3; // shape RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width, height, arcR, arcR); g.fill(rect); g.setPaint(TASK_BORDER_COLOR); if (thickBorder) { Stroke originalStroke = g.getStroke(); g.setStroke(THICK_TASK_BORDER_STROKE); g.draw(rect); g.setStroke(originalStroke); } else { g.draw(rect); } g.setPaint(originalPaint); // text if (name != null && name.length() > 0) { int boxWidth = width - (2 * TEXT_PADDING); int boxHeight = height - 16 - ICON_PADDING - ICON_PADDING - MARKER_WIDTH - 2 - 2; int boxX = x + width/2 - boxWidth/2; int boxY = y + height/2 - boxHeight/2 + ICON_PADDING + ICON_PADDING - 2 - 2; drawMultilineCentredText(name, boxX, boxY, boxWidth, boxHeight); } }
Example #14
Source File: NotificationBalloonShadowBorderProvider.java From consulo with Apache License 2.0 | 5 votes |
@Override public void paintBorder(@Nonnull Rectangle bounds, @Nonnull Graphics2D g) { g.setColor(myFillColor); g.fill(new Rectangle2D.Double(bounds.x, bounds.y, bounds.width, bounds.height)); g.setColor(myBorderColor); g.draw(new RoundRectangle2D.Double(bounds.x + 0.5, bounds.y + 0.5, bounds.width - 1, bounds.height - 1, 3, 3)); }
Example #15
Source File: RoundRectangle2DObjectDescription.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates an object based on this description. * * @return The object. */ public Object createObject() { final RoundRectangle2D rect = new RoundRectangle2D.Float(); final float w = getFloatParameter( "width" ); final float h = getFloatParameter( "height" ); final float x = getFloatParameter( "x" ); final float y = getFloatParameter( "y" ); final float aw = getFloatParameter( "arcWidth" ); final float ah = getFloatParameter( "arcHeight" ); rect.setRoundRect( x, y, w, h, aw, ah ); return rect; }
Example #16
Source File: ButtonOverlayControl.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private ButtonDef(Action action, Dimension buttonDimension, int numCols, String toolTipText) { this.action = action; this.numCols = numCols; this.toolTipText = toolTipText; Image rawImage = iconToImage((Icon) this.action.getValue(Action.LARGE_ICON_KEY)); image = rawImage.getScaledInstance(buttonDimension.width, buttonDimension.height, Image.SCALE_SMOOTH); shape = new RoundRectangle2D.Double(); shape.arcwidth = 4; shape.archeight = 4; shape.setFrame(new Point(), buttonDimension); }
Example #17
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public void paint(Graphics2D g, JComponent c, int width, int height) { int a = selected ? OVERPAINT : 0; int r = 6; int x = 3; int y = 3; Graphics2D g2 = (Graphics2D) g.create(0, 0, width, height + a); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = width - x; int h = height + a; // Paint tab shadow if (selected) { g2.setPaint(new Color(0, 0, 0, 20)); RoundRectangle2D rrect = new RoundRectangle2D.Double(0d, 0d, w, h, r, r); for (int i = 0; i < x; i++) { rrect.setFrame(x - i, y - i, w + i + i, h); g2.fill(rrect); } } // Fill tab background g2.setColor(color); g2.fill(new RoundRectangle2D.Double(x, y, w - 1d, h + a, r, r)); if (selected) { // Draw a border g2.setStroke(new BasicStroke(STROKE_SIZE)); g2.setPaint(TABAREA_BORDER); g2.draw(new RoundRectangle2D.Double(x, y, w - 1d, h + a, r, r)); // Overpaint the overexposed area with the background color g2.setColor(TAB_TABAREA_MASK); g2.fill(new Rectangle2D.Double(0d, height + STROKE_SIZE, width, OVERPAINT)); } g2.dispose(); }
Example #18
Source File: LineBorder.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Paints the border for the specified component with the * specified position and size. * @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 */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { if ((this.thickness > 0) && (g instanceof Graphics2D)) { Graphics2D g2d = (Graphics2D) g; Color oldColor = g2d.getColor(); g2d.setColor(this.lineColor); Shape outer; Shape inner; int offs = this.thickness; int size = offs + offs; if (this.roundedCorners) { float arc = .2f * offs; outer = new RoundRectangle2D.Float(x, y, width, height, offs, offs); inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc); } else { outer = new Rectangle2D.Float(x, y, width, height); inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size); } Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD); path.append(outer, false); path.append(inner, false); g2d.fill(path); g2d.setColor(oldColor); } }
Example #19
Source File: DarculaSpinnerBorder.java From consulo with Apache License 2.0 | 5 votes |
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D)g.create(); Rectangle r = new Rectangle(x, y, width, height); JBInsets.removeFrom(r, JBUI.insets(1)); try { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, MacUIUtil.USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE); g2.translate(r.x, r.y); float lw = LW.getFloat(); float bw = BW.getFloat(); float arc = COMPONENT_ARC.getFloat(); Object op = ((JComponent)c).getClientProperty("JComponent.outline"); if (c.isEnabled() && op != null) { paintOutlineBorder(g2, r.width, r.height, arc, true, isFocused(c), Outline.valueOf(op.toString())); } else { if (isFocused(c)) { paintFocusBorder(g2, r.width, r.height, arc, true); } Path2D border = new Path2D.Float(Path2D.WIND_EVEN_ODD); border.append(new RoundRectangle2D.Float(bw, bw, r.width - bw * 2, r.height - bw * 2, arc, arc), false); arc = arc > lw ? arc - lw : 0.0f; border.append(new RoundRectangle2D.Float(bw + lw, bw + lw, r.width - (bw + lw) * 2, r.height - (bw + lw) * 2, arc, arc), false); g2.setColor(getOutlineColor(c.isEnabled(), isFocused(c))); g2.fill(border); } } finally { g2.dispose(); } }
Example #20
Source File: BufferedRenderPipe.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void drawRoundRect(SunGraphics2D sg2d, int x, int y, int width, int height, int arcWidth, int arcHeight) { draw(sg2d, new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight)); }
Example #21
Source File: LineBorder.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Paints the border for the specified component with the * specified position and size. * @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 */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { if ((this.thickness > 0) && (g instanceof Graphics2D)) { Graphics2D g2d = (Graphics2D) g; Color oldColor = g2d.getColor(); g2d.setColor(this.lineColor); Shape outer; Shape inner; int offs = this.thickness; int size = offs + offs; if (this.roundedCorners) { float arc = .2f * offs; outer = new RoundRectangle2D.Float(x, y, width, height, offs, offs); inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc); } else { outer = new Rectangle2D.Float(x, y, width, height); inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size); } Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD); path.append(outer, false); path.append(inner, false); g2d.fill(path); g2d.setColor(oldColor); } }
Example #22
Source File: DefaultMultiThumbSliderUI.java From pumpernickel with MIT License | 5 votes |
protected Shape getTrackOutline() { trackRect = calculateTrackRect(); float k = Math.max(10, FOCUS_PADDING) + 1; int z = 3; if (slider.getOrientation() == MultiThumbSlider.VERTICAL) { return new RoundRectangle2D.Float(trackRect.x, trackRect.y - z, trackRect.width, trackRect.height + 2 * z, k, k); } return new RoundRectangle2D.Float(trackRect.x - z, trackRect.y, trackRect.width + 2 * z, trackRect.height, k, k); }
Example #23
Source File: LoopPipe.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void fillRoundRect(SunGraphics2D sg2d, int x, int y, int width, int height, int arcWidth, int arcHeight) { sg2d.shapepipe.fill(sg2d, new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight)); }
Example #24
Source File: ProcessDiagramCanvas.java From maven-framework-project with MIT License | 5 votes |
public void drawHighLight(int x, int y, int width, int height) { Paint originalPaint = g.getPaint(); Stroke originalStroke = g.getStroke(); g.setPaint(HIGHLIGHT_COLOR); g.setStroke(THICK_TASK_BORDER_STROKE); RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width, height, 20, 20); g.draw(rect); g.setPaint(originalPaint); g.setStroke(originalStroke); }
Example #25
Source File: Compiler.java From appinventor-extensions with Apache License 2.0 | 5 votes |
private BufferedImage produceRoundedCornerIcon(BufferedImage icon) { int imageWidth = icon.getWidth(); // Ratio of icon size to png image size for roundRect icon is 0.93 double iconWidth = imageWidth * 0.93; // Round iconWidth value to even int for a centered png int intIconWidth = ((int)Math.round(iconWidth / 2) * 2); Image tmp = icon.getScaledInstance(intIconWidth, intIconWidth, Image.SCALE_SMOOTH); int marginWidth = ((imageWidth - intIconWidth) / 2); // Corner radius of roundedCornerIcon needs to be 1/12 of width according to Android material guidelines float cornerRadius = intIconWidth / 12; BufferedImage roundedCornerIcon = new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = roundedCornerIcon.createGraphics(); g2.setClip(new RoundRectangle2D.Float(marginWidth, marginWidth, intIconWidth, intIconWidth, cornerRadius, cornerRadius)); g2.drawImage(tmp, marginWidth, marginWidth, null); return roundedCornerIcon; }
Example #26
Source File: CreateNamePicture.java From Aooms with Apache License 2.0 | 5 votes |
/** * 图片做圆角处理 * * @param image * @param cornerRadius * @return */ public static BufferedImage makeRoundedCorner(BufferedImage image, int cornerRadius) { int w = image.getWidth(); int h = image.getHeight(); BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = output.createGraphics(); g2.setComposite(AlphaComposite.Src); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.WHITE); g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius)); g2.setComposite(AlphaComposite.SrcAtop); g2.drawImage(image, 0, 0, null); g2.dispose(); return output; }
Example #27
Source File: NinePatchUtils.java From weblaf with GNU General Public License v3.0 | 5 votes |
/** * Returns shade nine-patch icon. * * @param shadeWidth shade width * @param round corners round * @param shadeOpacity shade opacity * @return shade nine-patch icon */ @NotNull @Deprecated public static NinePatchIcon createShadeIcon ( final int shadeWidth, final int round, final float shadeOpacity ) { // Making round value into real rounding radius final int r = round * 2; // Calculating width for temporary image final int inner = Math.max ( shadeWidth, round ); final int w = shadeWidth * 2 + inner * 2; // Creating shade image final Shape shape = new RoundRectangle2D.Double ( shadeWidth, shadeWidth, w - shadeWidth * 2, w - shadeWidth * 2, r, r ); final BufferedImage shade = ImageUtils.createShadowImage ( w, w, shape, shadeWidth, shadeOpacity, true ); // Creating nine-patch icon based on shade image final NinePatchIcon ninePatchIcon = new NinePatchIcon ( shade, false ); ninePatchIcon.addHorizontalStretch ( 0, shadeWidth + inner, true ); ninePatchIcon.addHorizontalStretch ( shadeWidth + inner + 1, w - shadeWidth - inner - 1, false ); ninePatchIcon.addHorizontalStretch ( w - shadeWidth - inner, w, true ); ninePatchIcon.addVerticalStretch ( 0, shadeWidth + inner, true ); ninePatchIcon.addVerticalStretch ( shadeWidth + inner + 1, w - shadeWidth - inner - 1, false ); ninePatchIcon.addVerticalStretch ( w - shadeWidth - inner, w, true ); ninePatchIcon.setMargin ( shadeWidth ); return ninePatchIcon; }
Example #28
Source File: DarculaTextBorder.java From consulo with Apache License 2.0 | 5 votes |
public static void paintDarculaSearchArea(Graphics2D g, Rectangle r, JTextComponent c, boolean fillBackground) { Graphics2D g2 = (Graphics2D)g.create(); try { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, MacUIUtil.USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE); JBInsets.removeFrom(r, JBUI.insets(1)); g2.translate(r.x, r.y); float arc = COMPONENT_ARC.get(); float lw = LW.getFloat(); float bw = BW.getFloat(); Shape outerShape = new RoundRectangle2D.Float(bw, bw, r.width - bw * 2, r.height - bw * 2, arc, arc); if (fillBackground) { g2.setColor(c.getBackground()); g2.fill(outerShape); } if (c.getClientProperty("JTextField.Search.noBorderRing") != Boolean.TRUE) { if (c.hasFocus()) { paintFocusBorder(g2, r.width, r.height, arc, true); } Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD); path.append(outerShape, false); arc = arc > lw ? arc - lw : 0.0f; path.append(new RoundRectangle2D.Float(bw + lw, bw + lw, r.width - (bw + lw) * 2, r.height - (bw + lw) * 2, arc, arc), false); g2.setColor(DarculaUIUtil.getOutlineColor(c.isEnabled() && c.isEditable(), c.hasFocus())); g2.fill(path); } } finally { g2.dispose(); } }
Example #29
Source File: QRCodeUtil.java From bicycleSharingServer with MIT License | 5 votes |
private static void insertImage(BufferedImage source, String imgPath, boolean needCompress) throws Exception { File file = new File(imgPath); if (!file.exists()) { System.err.println(""+imgPath+" 该文件不存在!"); return; } Image src = ImageIO.read(new File(imgPath)); int width = src.getWidth(null); int height = src.getHeight(null); if (needCompress) { // 压缩LOGO if (width > WIDTH) { width = WIDTH; } if (height > HEIGHT) { height = HEIGHT; } Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH); BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = tag.getGraphics(); g.drawImage(image, 0, 0, null); // 绘制缩小后的图 g.dispose(); src = image; } // 插入LOGO Graphics2D graph = source.createGraphics(); int x = (QRCODE_SIZE - width) / 2; int y = (QRCODE_SIZE - height) / 2; graph.drawImage(src, x, y, width, height, null); Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6); graph.setStroke(new BasicStroke(3f)); graph.draw(shape); graph.dispose(); }
Example #30
Source File: BufferedRenderPipe.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public void drawRoundRect(SunGraphics2D sg2d, int x, int y, int width, int height, int arcWidth, int arcHeight) { draw(sg2d, new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight)); }