Java Code Examples for java.awt.geom.RoundRectangle2D#Float

The following examples show how to use java.awt.geom.RoundRectangle2D#Float . 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: Toastr.java    From training with MIT License 6 votes vote down vote up
public void paint(Graphics g) {
	super.paint(g); 
	 Graphics2D g2d = (Graphics2D) g;

        Color oldColor = g2d.getColor();
        g2d.setColor(GlobalSettings.TOASTR_FONT_COLOR);

        int x = 0, y = 0, width = getWidth(), height = getHeight();
        int radius = 20;
        int thickness = 2;
        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, radius, radius);

        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
}
 
Example 2
Source File: SxButton.java    From SikuliNG with MIT License 6 votes vote down vote up
@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 3
Source File: BasicThumbnail.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * If a background color was provided: this paints that background. This
 * method is not capable of painting the scaled image, though.
 * 
 */
public void paint(Graphics2D g, int x, int y, int width, int height) {
	if (color != null) {
		g.setColor(color);
		g.setRenderingHints(Thumbnail.qualityHints);
		if (curvature == 0) {
			g.fillRect(x, y, width, height);
		} else {
			RoundRectangle2D r = new RoundRectangle2D.Float(x, y,
					width, height, curvature, curvature);
			g.fill(r);
		}
	}
}
 
Example 4
Source File: ZxingHelper.java    From seezoon-framework-all with Apache License 2.0 5 votes vote down vote up
/**
 * 插入LOGO
 * 
 * @param source
 *            二维码图片
 * @param imgPath
 *            LOGO图片地址
 * @param needCompress
 *            是否压缩
 * @throws Exception
 */
private void insertLogo(BufferedImage source, InputStream logo, boolean needCompress) throws Exception {
	Image src = ImageIO.read(logo);
	int width = src.getWidth(null);
	int height = src.getHeight(null);
	if (needCompress) { // 压缩LOGO
		if (width > logoSize) {
			width = logoSize;
		}
		if (height > logoSize) {
			height = logoSize;
		}
		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 = (imageSize - width) / 2;
	int y = (imageSize - 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 5
Source File: RoundRectBorder.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
@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);
	g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

	RoundRectangle2D rect = new RoundRectangle2D.Float(borderWidth / 2, borderWidth / 2, width - borderWidth,
			height - borderWidth, arc, arc);
	g2.setStroke(new BasicStroke(this.borderWidth));
	g2.setColor(this.borderColor);
	g2.draw(rect);
	g2.dispose();
}
 
Example 6
Source File: SxCallout.java    From SikuliX1 with MIT License 5 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2d = (Graphics2D) g;
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
          RenderingHints.VALUE_ANTIALIAS_ON);
  RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, getWidth(), getHeight(), 15, 15);
  g2d.fill(roundedRectangle);
}
 
Example 7
Source File: LineBorder.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 8
Source File: RoundedPanel.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
public RoundedPanel(LayoutManager layout, int cornerRadius) {
    super(layout);
    this.cornerRadius = cornerRadius;
    this.roundBounds = new RoundRectangle2D.Float(0,0,0,0,
            cornerRadius, cornerRadius);
    this.contentAreaFilled = true;
    setOpaque(false);
}
 
Example 9
Source File: QrCodeUtil.java    From SpringBoot-Home with Apache License 2.0 5 votes vote down vote up
/**
 * 插入LOGO
 *
 * @param imgPath      二维码图片
 * @param imgPath      LOGO图片地址
 * @param needCompress 是否压缩
 * @throws Exception
 */
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);
    // 压缩logo
    if (needCompress) {
        if (width > QrCodeConfiguration.logoWidth) {
            width = QrCodeConfiguration.logoWidth;
        }
        if (height > QrCodeConfiguration.logoHeight) {
            height = QrCodeConfiguration.logoHeight;
        }
        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 = (QrCodeConfiguration.width - width) / 2;
    int y = (QrCodeConfiguration.height - 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 10
Source File: LineBorder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 11
Source File: LineBorder.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 12
Source File: LineBorder.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * 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 13
Source File: Rect.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private void readObject(final ObjectInputStream in) throws IOException {
	x = in.readFloat();
	y = in.readFloat();
	width = in.readFloat();
	height = in.readFloat();
	rx = in.readFloat();
	ry = in.readFloat();

	if (rx == 0f && ry == 0f) {
		rect = new Rectangle2D.Float(x, y, width, height);
	} else {
		rect = new RoundRectangle2D.Float(x, y, width, height, rx * 2, ry * 2);
	}
}
 
Example 14
Source File: FluxIniFim.java    From brModelo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Shape getRegiao() {
    if (Regiao == null) {
        Regiao = new RoundRectangle2D.Float(getLeft(), getTop(), getWidth(), getHeight(), getWidth() / 3, getHeight());
    }
    return Regiao;
}
 
Example 15
Source File: QRCodeUtil.java    From bicycleSharingServer with MIT License 5 votes vote down vote up
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 16
Source File: EstadoAtividade.java    From brModelo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Shape getRegiao() {
    if (Regiao == null) {
        Regiao = new RoundRectangle2D.Float(getLeft(), getTop(), getWidth(), getHeight(), getWidth()/3, getHeight());
    }
    return Regiao;
}
 
Example 17
Source File: FlatProgressBarUI.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
@Override
public void paint( Graphics g, JComponent c ) {
	Insets insets = progressBar.getInsets();
	int x = insets.left;
	int y = insets.top;
	int width = progressBar.getWidth() - (insets.right + insets.left);
	int height = progressBar.getHeight() - (insets.top + insets.bottom);

	if( width <= 0 || height <= 0 )
		return;

	boolean horizontal = (progressBar.getOrientation() == JProgressBar.HORIZONTAL);
	int arc = clientPropertyBoolean( c, PROGRESS_BAR_SQUARE, false )
		? 0
		: Math.min( UIScale.scale( this.arc ), horizontal ? height : width );

	FlatUIUtils.setRenderingHints( (Graphics2D) g );

	// paint track
	RoundRectangle2D.Float trackShape = new RoundRectangle2D.Float( x, y, width, height, arc, arc );
	g.setColor( progressBar.getBackground() );
	((Graphics2D)g).fill( trackShape );

	// paint progress
	if( progressBar.isIndeterminate() ) {
		boxRect = getBox( boxRect );
		if( boxRect != null ) {
			g.setColor( progressBar.getForeground() );
			((Graphics2D)g).fill( new RoundRectangle2D.Float( boxRect.x, boxRect.y,
				boxRect.width, boxRect.height, arc, arc ) );
		}

		if( progressBar.isStringPainted() )
			paintString( g, x, y, width, height, 0, insets );
	} else {
		int amountFull = getAmountFull( insets, width, height );

		RoundRectangle2D.Float progressShape = horizontal
			? new RoundRectangle2D.Float( c.getComponentOrientation().isLeftToRight() ? x : x + (width - amountFull),
				y, amountFull, height, arc, arc )
			: new RoundRectangle2D.Float( x, y + (height - amountFull), width, amountFull, arc, arc );

		g.setColor( progressBar.getForeground() );
		if( amountFull < (horizontal ? height : width) ) {
			// special painting for low amounts to avoid painting outside of track
			Area area = new Area( trackShape );
			area.intersect( new Area( progressShape ) );
			((Graphics2D)g).fill( area );
		} else
			((Graphics2D)g).fill( progressShape );

		if( progressBar.isStringPainted() )
			paintString( g, x, y, width, height, amountFull, insets );
	}
}
 
Example 18
Source File: MovingParticleFeeder.java    From energy2d with GNU Lesser General Public License v3.0 4 votes vote down vote up
MovingParticleFeeder(RoundRectangle2D.Float rectangle) {
	this.rectangle = rectangle;
}
 
Example 19
Source File: DarkCheckBoxUI.java    From darklaf with MIT License 4 votes vote down vote up
@Override
protected RectangularShape calculateHitArea() {
    return new RoundRectangle2D.Float(Math.max(iconRect.x, 0), Math.max(iconRect.y, 0),
                                      iconRect.width, iconRect.height, arcSize, arcSize);
}
 
Example 20
Source File: AbstractSwitchButtonIcon.java    From pumpernickel with MIT License 4 votes vote down vote up
protected void doPaintIcon(JComponent c, Graphics2D g, int x, int y) {
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	int w = getIconWidth() - 2 * focusOffset;
	int h = getIconHeight() - 2 * focusOffset;
	g.translate(focusOffset, focusOffset);
	RoundRectangle2D r = new RoundRectangle2D.Float(x, y + h / 2
			- trackHeight / 2, w, trackHeight, trackHeight, trackHeight);
	boolean isSelected = isSelected(c);
	boolean isArmed = isArmed(c);
	double selectedState = AnimationManager.setTargetProperty(c,
			PROPERTY_SELECTED_STATE, isSelected ? 1 : 0, .1f);
	double armedState = AnimationManager.setTargetProperty(c,
			PROPERTY_ARMED_STATE, isArmed ? 1 : 0, .1f);

	ButtonTheme colors = unselectedColors.tween(selectedColors,
			selectedState);
	Color handleColor = AnimationManager.tween(colors.handleFill,
			colors.handleFillArmed, armedState);

	Shape handle = new Ellipse2D.Float(x + handlePadding, y + h / 2
			- handleWidth / 2, handleWidth, handleWidth);

	double dx = selectedState
			* (r.getWidth() - handleWidth - 2 * handlePadding);
	AffineTransform tx = AffineTransform.getTranslateInstance(dx, 0);
	handle = tx.createTransformedShape(handle);

	g.setStroke(new BasicStroke(strokeWidth));

	if (c.isFocusOwner()) {
		Area area = new Area();
		area.add(new Area(flatten(r)));
		area.add(new Area(flatten(handle)));
		Graphics2D g2 = (Graphics2D) g.create();
		g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
				RenderingHints.VALUE_STROKE_PURE);
		PlafPaintUtils.paintFocus(g2, area, focusOffset);
		g2.dispose();
	}

	Color trackFillTop = AnimationManager.tween(colors.backgroundTop,
			colors.backgroundTopArmed, armedState);
	Color trackFillBottom = AnimationManager.tween(colors.backgroundBottom,
			colors.backgroundBottomArmed, armedState);
	g.setPaint(new GradientPaint(x, y, trackFillTop, x, y + h,
			trackFillBottom));
	g.fill(r);

	Paint trackOutlinePaint = new GradientPaint(x, y,
			colors.trackOutlineTop, x, y + h, colors.trackOutlineBottom);
	g.setPaint(trackOutlinePaint);
	g.draw(r);

	g.setPaint(handleColor);
	g.fill(handle);

	Paint handleOutlinePaint = new GradientPaint(x, y,
			colors.handleOutlineTop, x, y + h, colors.handleOutlineBottom);
	g.setPaint(handleOutlinePaint);
	g.draw(handle);

	g.dispose();
}