Java Code Examples for java.awt.geom.RoundRectangle2D#Double
The following examples show how to use
java.awt.geom.RoundRectangle2D#Double .
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: 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 2
Source File: ProcessDiagramCanvas.java From maven-framework-project with MIT License | 6 votes |
protected void drawTask(String name, int x, int y, int width, int height, boolean thickBorder) { Paint originalPaint = g.getPaint(); g.setPaint(TASK_COLOR); // shape RoundRectangle2D rect = new RoundRectangle2D.Double(x, y, width, height, 20, 20); g.fill(rect); g.setPaint(originalPaint); if (thickBorder) { Stroke originalStroke = g.getStroke(); g.setStroke(THICK_TASK_BORDER_STROKE); g.draw(rect); g.setStroke(originalStroke); } else { g.draw(rect); } // text if (name != null) { String text = fitTextToWidth(name, width); int textX = x + ((width - fontMetrics.stringWidth(text)) / 2); int textY = y + ((height - fontMetrics.getHeight()) / 2) + fontMetrics.getHeight(); g.drawString(text, textX, textY); } }
Example 3
Source File: MorphingDemo.java From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License | 6 votes |
private Morphing2D createMorph() { Shape sourceShape = new RoundRectangle2D.Double(2.0, 2.0, getWidth() - 4.0, getHeight() - 4.0, 12.0, 12.0); GeneralPath.Double destinationShape = new GeneralPath.Double(); destinationShape.moveTo(2.0, getHeight() / 2.0); destinationShape.lineTo(22.0, 0.0); destinationShape.lineTo(22.0, 5.0); destinationShape.lineTo(getWidth() - 2.0, 5.0); destinationShape.lineTo(getWidth() - 2.0, getHeight() - 5.0); destinationShape.lineTo(22.0, getHeight() - 5.0); destinationShape.lineTo(22.0, getHeight()); destinationShape.closePath(); return new Morphing2D(sourceShape, destinationShape); }
Example 4
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 5
Source File: Table.java From ramus with GNU General Public License v3.0 | 5 votes |
@Override public void paint(Graphics2D g, Bounds bounds, Diagram diagram) { double minWidth = getMinWidth(); double minHeight = getMinHeight(); label.setSize((int) minWidth - 18, 20); RoundRectangle2D rect = new RoundRectangle2D.Double(0, 3, minWidth, minHeight - 3, 15, 15); g.draw(rect); g.translate(6, 0); label.paint(g); g.translate(-6, 0); }
Example 6
Source File: CustomProcessDiagramGenerator.java From lemon with Apache License 2.0 | 5 votes |
/** * 绘制子流程 */ protected static void drawSubProcess(int x, int y, int width, int height, Graphics2D graphics) { RoundRectangle2D rect = new RoundRectangle2D.Double(x + 1, y + 1, width - 2, height - 2, OFFSET_SUBPROCESS, OFFSET_SUBPROCESS); graphics.draw(rect); }
Example 7
Source File: DefaultProcessDiagramCanvas.java From flowable-engine with Apache License 2.0 | 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 8
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
protected DraggableImageMouseListener(ImageIcon ii) { super(); image = ii.getImage(); int width = ii.getIconWidth(); int height = ii.getIconHeight(); imageSz = new Dimension(width, height); border = new RoundRectangle2D.Double(0d, 0d, width, height, 10d, 10d); polaroid = new Rectangle2D.Double(-2d, -2d, width + 4d, height + 20d); setCirclesLocation(centerPt); }
Example 9
Source File: WebStepProgress.java From weblaf with GNU General Public License v3.0 | 5 votes |
/** * Creates and returns step fill shape. * * @param step step index * @return newly created step fill shape */ protected Shape getStepFillShape ( final int step ) { final Point center = getStepCenter ( step ); if ( stepControlFillRound * 2 >= stepControlFillWidth ) { return new Ellipse2D.Double ( center.x - stepControlFillWidth / 2, center.y - stepControlFillWidth / 2, stepControlFillWidth, stepControlFillWidth ); } else { return new RoundRectangle2D.Double ( center.x - stepControlFillWidth / 2, center.y - stepControlFillWidth / 2, stepControlFillWidth, stepControlFillWidth, stepControlFillRound * 2, stepControlFillRound * 2 ); } }
Example 10
Source File: DropShadowBorder.java From darklaf with MIT License | 4 votes |
@SuppressWarnings("SuspiciousNameCombination") private BufferedImage[] getImages() { // first, check to see if an image for this size has already been rendered // if so, use the cache. Else, draw and save BufferedImage[] images = CACHE.get(getBorderHash(shadowSize, shadowOpacity, shadowColor)); if (images == null) { images = new BufferedImage[Position.count()]; /* * To draw a drop shadow, I have to: * 1) Create a rounded rectangle * 2) Create a BufferedImage to draw the rounded rect in * 3) Translate the graphics for the image, so that the rectangle * is centered in the drawn space. The border around the rectangle * needs to be shadowWidth wide, so that there is space for the * shadow to be drawn. * 4) Draw the rounded rect as shadowColor, with an opacity of shadowOpacity * 5) Create the BLUR_KERNEL * 6) Blur the image * 7) copy off the corners, sides, etc into images to be used for * drawing the Border */ int rectWidth = cornerSize + 1; RoundRectangle2D rect = new RoundRectangle2D.Double(0, 0, rectWidth, rectWidth, cornerSize, cornerSize); int imageWidth = rectWidth + shadowSize * 2; BufferedImage image = ImageUtil.createCompatibleTranslucentImage(imageWidth, imageWidth); Graphics2D buffer = (Graphics2D) image.getGraphics(); try (Disposable d = buffer::dispose) { buffer.setPaint(new Color(shadowColor.getRed(), shadowColor.getGreen(), shadowColor.getBlue(), (int) (shadowOpacity * 255))); buffer.translate(shadowSize, shadowSize); buffer.fill(rect); } float blurry = 1.0f / (float) (shadowSize * shadowSize); float[] blurKernel = new float[shadowSize * shadowSize]; Arrays.fill(blurKernel, blurry); ConvolveOp blur = new ConvolveOp(new Kernel(shadowSize, shadowSize, blurKernel)); BufferedImage targetImage = ImageUtil.createCompatibleTranslucentImage(imageWidth, imageWidth); ((Graphics2D) targetImage.getGraphics()).drawImage(image, blur, -(shadowSize / 2), -(shadowSize / 2)); int x = 1; int y = 1; int w = shadowSize; int h = shadowSize; images[Position.TOP_LEFT.ordinal()] = getSubImage(targetImage, x, y, w, h); x = 1; y = h; w = shadowSize; h = 1; images[Position.LEFT.ordinal()] = getSubImage(targetImage, x, y, w, h); x = 1; y = rectWidth; w = shadowSize; h = shadowSize; images[Position.BOTTOM_LEFT.ordinal()] = getSubImage(targetImage, x, y, w, h); x = cornerSize + 1; y = rectWidth; w = 1; h = shadowSize; images[Position.BOTTOM.ordinal()] = getSubImage(targetImage, x, y, w, h); x = rectWidth; y = x; w = shadowSize; h = shadowSize; images[Position.BOTTOM_RIGHT.ordinal()] = getSubImage(targetImage, x, y, w, h); x = rectWidth; y = cornerSize + 1; w = shadowSize; h = 1; images[Position.RIGHT.ordinal()] = getSubImage(targetImage, x, y, w, h); x = rectWidth; y = 1; w = shadowSize; h = shadowSize; images[Position.TOP_RIGHT.ordinal()] = getSubImage(targetImage, x, y, w, h); x = shadowSize; y = 1; w = 1; h = shadowSize; images[Position.TOP.ordinal()] = getSubImage(targetImage, x, y, w, h); image.flush(); CACHE.put(getBorderHash(shadowSize, shadowOpacity, shadowColor), images); } return images; }
Example 11
Source File: PdfGraphics2D.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see Graphics#fillRoundRect(int, int, int, int, int, int) */ public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { RoundRectangle2D rect = new RoundRectangle2D.Double(x,y,width,height,arcWidth, arcHeight); fill(rect); }
Example 12
Source File: TextBubbleBorder.java From bither-desktop-java with Apache License 2.0 | 4 votes |
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { // Work out the lowest inside line of the bubble int bottomLineY = height - thickness - pointerSize - 1; // Draw the rounded bubble border with a few tweaks for text fields and areas RoundRectangle2D.Double bubble = new RoundRectangle2D.Double( strokePad + 2, strokePad + 2, width - thickness - strokePad - 3, bottomLineY - 2, radii, radii); Area area = new Area(bubble); // Should the "speech pointer" polygon be included? if (pointerSize > 0) { Polygon pointer = new Polygon(); int pointerPad = 4; // Place on left if (pointerLeft) { // Left point pointer.addPoint(strokePad + radii + pointerPad, bottomLineY); // Right point pointer.addPoint(strokePad + radii + pointerPad + pointerSize, bottomLineY); // Bottom point pointer.addPoint(strokePad + radii + pointerPad + (pointerSize / 2), height - strokePad); } else { // Left point pointer.addPoint(width - (strokePad + radii + pointerPad), bottomLineY); // Right point pointer.addPoint(width - (strokePad + radii + pointerPad + pointerSize), bottomLineY); // Bottom point pointer.addPoint(width - (strokePad + radii + pointerPad + (pointerSize / 2)), height - strokePad); } area.add(new Area(pointer)); } // Get the 2D graphics context Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(hints); // Paint the background color of the parent everywhere // outside the clip of the text bubble Component parent = c.getParent(); if (parent != null) { Color bg = parent.getBackground(); Rectangle rect = new Rectangle(0, 0, width, height); Area borderRegion = new Area(rect); borderRegion.subtract(area); g2.setClip(borderRegion); g2.setColor(bg); g2.fillRect(0, 0, width, height); g2.setClip(null); } // Set the border color g2.setColor(color); g2.setStroke(stroke); g2.draw(area); }
Example 13
Source File: PdfGraphics2D.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see Graphics#drawRoundRect(int, int, int, int, int, int) */ public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { RoundRectangle2D rect = new RoundRectangle2D.Double(x,y,width,height,arcWidth, arcHeight); draw(rect); }
Example 14
Source File: MacIntelliJTextFieldUI.java From consulo with Apache License 2.0 | 4 votes |
protected void paintSearchField(Graphics2D g, JTextComponent c, Rectangle r) { 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); g2.translate(r.x, r.y); int arc = JBUI.scale(6); double lw = UIUtil.isRetina(g2) ? 0.5 : 1.0; Shape outerShape = new RoundRectangle2D.Double(JBUI.scale(3), JBUI.scale(3), r.width - JBUI.scale(6), r.height - JBUI.scale(6), arc, arc); g2.setColor(c.getBackground()); g2.fill(outerShape); Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD); path.append(outerShape, false); path.append(new RoundRectangle2D.Double(JBUI.scale(3) + lw, JBUI.scale(3) + lw, r.width - JBUI.scale(6) - lw*2, r.height - JBUI.scale(6) - lw*2, arc-lw, arc-lw), false); g2.setColor(Gray.xBC); g2.fill(path); if (c.hasFocus() && c.getClientProperty("JTextField.Search.noBorderRing") != Boolean.TRUE) { DarculaUIUtilPart.paintFocusBorder(g2, r.width, r.height, arc, true); } g2.translate(-r.x, -r.y); boolean withHistoryPopup = isSearchFieldWithHistoryPopup(c); Icon label = getSearchIcon(c); boolean isEmpty = !hasText(); Point point = getSearchIconCoord(); if (isEmpty && !c.hasFocus() && !withHistoryPopup) { label.paintIcon(c, g2, point.x, point.y); } else { Graphics ig = g2.create(0, 0, c.getWidth(), c.getHeight()); Area area = new Area(new Rectangle2D.Double(point.x, point.y, isEmpty ? label.getIconWidth() : 16, label.getIconHeight())); area.intersect(new Area(ig.getClip())); ig.setClip(area); label.paintIcon(c, ig, point.x, point.y); ig.dispose(); } if (!isEmpty) { Point ic = getClearIconCoord(); MacIntelliJIconCache.getIcon("searchFieldClear").paintIcon(c, g2, ic.x, ic.y); } AbstractAction newLineAction = getNewLineAction(c); if (newLineAction != null) { Icon newLineIcon = (Icon)newLineAction.getValue(Action.SMALL_ICON); if (newLineIcon != null) { newLineIcon.paintIcon(c, g2, getAddNewLineIconCoord().x, r.y); } } } finally { g2.dispose(); } }
Example 15
Source File: Stage0Base.java From radiance with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); Shape clip = g2d.getClip(); g2d.setStroke(new BasicStroke(1.0f)); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int radius = 16; Shape contour = new RoundRectangle2D.Double(0, 0, getWidth() - 1, getHeight() - 1, radius, radius); Shape innerContour = new RoundRectangle2D.Double(1, 1, getWidth() - 3, getHeight() - 3, radius - 1, radius - 1); g2d.setComposite(AlphaComposite.SrcOver.derive(1.0f - (float) Math.pow( 1.0f - alpha, 3.0))); // top part g2d.clipRect(0, 0, getWidth(), TITLE_HEIGHT); g2d.setPaint(new LinearGradientPaint(0, 0, 0, TITLE_HEIGHT, new float[] { 0.0f, 0.49999f, 0.5f, 1.0f }, new Color[] { new Color(119, 152, 251), new Color(80, 127, 250), new Color(48, 109, 250), new Color(10, 97, 250) })); g2d.fill(contour); g2d.setPaint(new GradientPaint(0, 0, new Color(151, 179, 253), 0, TITLE_HEIGHT, new Color(19, 92, 233))); g2d.draw(innerContour); g2d.setColor(new Color(11, 61, 200)); g2d.draw(contour); g2d.setClip(clip); if (this.searchString != null) { g2d.setFont(NeonCortex.getDefaultFontPolicy().getFontSet().getControlFont() .deriveFont(14.0f).deriveFont(Font.BOLD)); NeonCortex.installDesktopHints(g2d, g2d.getFont()); int fa = g2d.getFontMetrics().getAscent(); int x = (getWidth() - g2d.getFontMetrics().stringWidth(this.searchString)) / 2; int y = (TITLE_HEIGHT + fa) / 2; g2d.setColor(new Color(31, 60, 114)); g2d.drawString(this.searchString, x, y + 1); g2d.setColor(new Color(255, 255, 255)); g2d.drawString(this.searchString, x, y); } // bottom part g2d.setComposite(AlphaComposite.SrcOver.derive(this.alpha)); g2d.clipRect(0, TITLE_HEIGHT, getWidth(), getHeight() - TITLE_HEIGHT + 1); g2d.setColor(new Color(0, 0, 0)); g2d.fill(contour); g2d.setPaint(new GradientPaint(0, TITLE_HEIGHT, new Color(57, 56, 57), 0, getHeight() - TITLE_HEIGHT, new Color(50, 48, 50))); g2d.draw(innerContour); g2d.setPaint(new GradientPaint(0, TITLE_HEIGHT, new Color(13, 11, 15), 0, getHeight() - TITLE_HEIGHT, new Color(15, 8, 13))); g2d.draw(contour); // separator g2d.setClip(clip); g2d.setColor(new Color(12, 11, 12)); g2d.drawLine(1, TITLE_HEIGHT, getWidth() - 2, TITLE_HEIGHT); g2d.dispose(); }
Example 16
Source File: ImageUtil.java From oim-fx with MIT License | 4 votes |
public static BufferedImage getRoundedCornerBufferedImage(int rx, int ry, Image image) { Shape shape = new RoundRectangle2D.Double(0, 0, image.getWidth(null), image.getHeight(null), rx, ry); BufferedImage cutImage = getRoundedCornerBufferedImage(shape, image); return cutImage; }
Example 17
Source File: AppIcon.java From consulo with Apache License 2.0 | 4 votes |
@Override public boolean _setProgress(IdeFrame frame, Object processId, AppIconScheme.Progress scheme, double value, boolean isOk) { assertIsDispatchThread(); if (getAppImage() == null) return false; myCurrentProcessId = processId; if (myLastValue > value) return true; if (Math.abs(myLastValue - value) < 0.02d) return true; try { double progressHeight = (myAppImage.getHeight() * 0.13); double xInset = (myAppImage.getWidth() * 0.05); double yInset = (myAppImage.getHeight() * 0.15); final double width = myAppImage.getWidth() - xInset * 2; final double y = myAppImage.getHeight() - progressHeight - yInset; Area borderArea = new Area(new RoundRectangle2D.Double(xInset - 1, y - 1, width + 2, progressHeight + 2, (progressHeight + 2), (progressHeight + 2))); Area backgroundArea = new Area(new Rectangle2D.Double(xInset, y, width, progressHeight)); backgroundArea.intersect(borderArea); Area progressArea = new Area(new Rectangle2D.Double(xInset + 1, y + 1, (width - 2) * value, progressHeight - 1)); progressArea.intersect(borderArea); AppImage appImg = createAppImage(); appImg.myG2d.setColor(PROGRESS_BACKGROUND_COLOR); appImg.myG2d.fill(backgroundArea); final Color color = isOk ? scheme.getOkColor() : scheme.getErrorColor(); appImg.myG2d.setColor(color); appImg.myG2d.fill(progressArea); appImg.myG2d.setColor(PROGRESS_OUTLINE_COLOR); appImg.myG2d.draw(backgroundArea); appImg.myG2d.draw(borderArea); setDockIcon(appImg.myImg); myLastValue = value; } catch (Exception e) { LOG.error(e); } finally { myCurrentProcessId = null; } return true; }
Example 18
Source File: FXGraphics2D.java From ECG-Viewer with GNU General Public License v2.0 | 3 votes |
/** * Sets the attributes of the reusable {@link RoundRectangle2D} object that * is used by the {@link #drawRoundRect(int, int, int, int, int, int)} and * {@link #fillRoundRect(int, int, int, int, int, int)} methods. * * @param x the x-coordinate. * @param y the y-coordinate. * @param width the width. * @param height the height. * @param arcWidth the arc width. * @param arcHeight the arc height. */ private void setRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { if (this.roundRect == null) { this.roundRect = new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight); } else { this.roundRect.setRoundRect(x, y, width, height, arcWidth, arcHeight); } }
Example 19
Source File: SVGGraphics2D.java From jfreesvg with GNU General Public License v3.0 | 3 votes |
/** * Sets the attributes of the reusable {@link RoundRectangle2D} object that * is used by the {@link #drawRoundRect(int, int, int, int, int, int)} and * {@link #fillRoundRect(int, int, int, int, int, int)} methods. * * @param x the x-coordinate. * @param y the y-coordinate. * @param width the width. * @param height the height. * @param arcWidth the arc width. * @param arcHeight the arc height. */ private void setRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { if (this.roundRect == null) { this.roundRect = new RoundRectangle2D.Double(x, y, width, height, arcWidth, arcHeight); } else { this.roundRect.setRoundRect(x, y, width, height, arcWidth, arcHeight); } }
Example 20
Source File: AbstractGraphics2D.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 2 votes |
/** * Fills the specified rounded corner rectangle with the current color. The left and right edges of the rectangle are * at <code>x</code> and <code>x + width - 1</code>, respectively. The top and bottom edges of the * rectangle are at <code>y</code> and <code>y + height - 1</code>. * * @param x * the <i>x</i> coordinate of the rectangle to be filled. * @param y * the <i>y</i> coordinate of the rectangle to be filled. * @param width * the width of the rectangle to be filled. * @param height * the height of the rectangle to be filled. * @param arcWidth * the horizontal diameter of the arc at the four corners. * @param arcHeight * the vertical diameter of the arc at the four corners. * @see java.awt.Graphics#drawRoundRect */ public void fillRoundRect( final int x, final int y, final int width, final int height, final int arcWidth, final int arcHeight ) { final RoundRectangle2D rect = new RoundRectangle2D.Double( x, y, width, height, arcWidth, arcHeight ); fill( rect ); }