Java Code Examples for java.awt.Graphics#drawRoundRect()

The following examples show how to use java.awt.Graphics#drawRoundRect() . 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: BEUtils.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
/**
	 * 绘制虚线框(本方法适用于对4个边的可选绘制情况下,可能会有4舍5入的小误差
	 * ,除了要可选绘制4个边外,一般不推荐使用).
	 *
	 * @param g the g
	 * @param x the x
	 * @param y the y
	 * @param width the width
	 * @param height the height
	 * @param arcWidth the arc width
	 * @param arcHeight the arc height
	 * @param separator_solid 虚线段实线长度
	 * @param separator_space 虚线段空白长度
	 * add by js,2009-08-30
	 */
    public static void drawDashedRect(Graphics g,int x,int y,int width,int height
    		,int arcWidth, int arcHeight, int separator_solid, int separator_space) 
    {
//    	drawDashedRect(g,x,y,width,height,step,true,true,true,true);
    	BEUtils.setAntiAliasing((Graphics2D)g, true);
    	
    	//虚线样式
		Stroke oldStroke = ((Graphics2D)g).getStroke();
		Stroke sroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
				BasicStroke.JOIN_BEVEL, 0, new float[]{separator_solid, separator_space}, 0);//实线,空白
		((Graphics2D)g).setStroke(sroke);
		
		g.drawRoundRect(x, y
				, width-1, height-1 //* 一个很诡异的问题:使用BasicStroke实现虚线绘制后,似乎绘制的距形
									//* 要比普通方法绘制实线距形往下偏移一个坐标,此处-1是为了修正这个问题,这难道是java的bug?
									//* 难怪当初打印工具开发时也遇到了莫名其妙偏移一个像素的现象,具体有待进一步研究!
				, arcWidth, arcHeight);
		
		((Graphics2D)g).setStroke(oldStroke);
		BEUtils.setAntiAliasing((Graphics2D)g, false);
    }
 
Example 2
Source File: TabWidget.java    From DroidUIBuilder with Apache License 2.0 6 votes vote down vote up
public void paint(Graphics g)
	{
		// 绘制背景
		super.paintBackground(g);
		
		if (tab == null)
		{
			g.setColor(Color.white);
			g.fillRoundRect(getX(), getY(), getWidth(), getHeight(), 8, 8);

			g.setColor(Color.black);
			g.drawRoundRect(getX(), getY(), getWidth(), getHeight(), 8, 8);
		}
		else
		{
			tab.draw((Graphics2D)g, getX(), getY(), getWidth(), getHeight());
//			img.paint(g, getX(), getY(), getWidth(), getHeight());
			g.setColor(Color.black);
			final String showName = "Tab Widget";
			g.drawString(showName, getX() + (getWidth() - Utils.getStrPixWidth(g.getFont(), showName))/2
					, getY() + Utils.getFontCenterY(g.getFont(), getHeight()));
		}
	}
 
Example 3
Source File: ExpressionValueCellEditor.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Draws indicator in case the expression text overflows on the y axis.
 *
 * @param g
 *            the graphics context to draw upon
 * @param maxX
 *            maximal width
 */
private void drawOverflowIndicator(final Graphics g, int maxX) {

	int width = 25;
	int height = 10;
	int xOffset = 10;
	int stepSize = width / 5;
	int dotSize = 3;
	int x = maxX - width - xOffset;
	int y = button.getSize().height - height;
	g.setColor(LIGHTER_GRAY);

	g.fillRect(x, y, width, width);

	g.setColor(Color.GRAY);
	g.drawRoundRect(x, y, width, width, 5, 5);

	g.setColor(Color.BLACK);
	g.fillOval(x + stepSize, y + 4, dotSize, dotSize);
	g.fillOval(x + stepSize * 2, y + 4, dotSize, dotSize);
	g.fillOval(x + stepSize * 3, y + 4, dotSize, dotSize);

	g.dispose();
}
 
Example 4
Source File: NotGate.java    From Logisim with GNU General Public License v3.0 6 votes vote down vote up
private void paintRectangularBase(Graphics g, InstancePainter painter) {
	GraphicsUtil.switchToWidth(g, 2);
	if (painter.getAttributeValue(ATTR_SIZE) == SIZE_NARROW) {
		if (AppPreferences.FILL_COMPONENT_BACKGROUND.getBoolean()) {
			g.setColor(Color.WHITE);
			g.fillRoundRect(-20, -9, 14, 18, 5, 5);
			g.fillOval(-6, -3, 6, 6);
			g.setColor(Color.BLACK);
		}
		g.drawRoundRect(-20, -9, 14, 18, 5, 5);
		GraphicsUtil.drawCenteredText(g, RECT_LABEL, -13, -2);
		g.drawOval(-6, -3, 6, 6);
	} else {
		if (AppPreferences.FILL_COMPONENT_BACKGROUND.getBoolean()) {
			g.setColor(Color.WHITE);
			g.fillRoundRect(-30, -9, 20, 18, 10, 10);
			g.fillOval(-10, -5, 9, 9);
			g.setColor(Color.BLACK);
		}
		g.drawRoundRect(-30, -9, 20, 18, 10, 10);
		GraphicsUtil.drawCenteredText(g, RECT_LABEL, -20, -2);
		g.drawOval(-10, -5, 9, 9);
	}
	GraphicsUtil.switchToWidth(g, 1);
}
 
Example 5
Source File: DipSwitch.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paintGhost(InstancePainter painter) {
	Bounds bds = painter.getBounds();
	Graphics g = painter.getGraphics();
	GraphicsUtil.switchToWidth(g, 2);
	g.drawRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(), 10, 10);
}
 
Example 6
Source File: IconPackagerButtonBarUI.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
public void paint(Graphics g, JComponent c) {
  AbstractButton button = (AbstractButton)c;

  if (button.getModel().isSelected()) {
    Color oldColor = g.getColor();
    g.setColor(selectedBackground);
    g.fillRoundRect(0, 0, c.getWidth() - 1, c.getHeight() - 1, 5, 5);

    g.setColor(selectedBorder);
    g.drawRoundRect(0, 0, c.getWidth() - 1, c.getHeight() - 1, 5, 5);

    g.setColor(oldColor);
  }

  // this is a tweak to get the View with the color we expect it to be. We
  // change directly the color of the button
  if (c.getClientProperty(BasicHTML.propertyKey) != null) {
    ButtonModel model = button.getModel();
    if (model.isEnabled()) {
      if (model.isSelected()) {
        button.setForeground(selectedForeground);
      } else {
        button.setForeground(unselectedForeground);
      }
    } else {
      button.setForeground(unselectedForeground.darker());
    }
  }

  super.paint(g, c);
}
 
Example 7
Source File: Symbol.java    From energy2d with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void paintIcon(Component c, Graphics g, int x, int y) {
	xSymbol = x + offsetX;
	ySymbol = y + offsetY;
	Graphics2D g2 = (Graphics2D) g;
	g2.setColor(color);
	if (paintBorder) {
		g.drawRoundRect(xSymbol, ySymbol, wSymbol, hSymbol, 10, 10);
	}
	g2.setStroke(stroke);
}
 
Example 8
Source File: BERoundBorder.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
	{
		Color oldColor = g.getColor();

		BEUtils.setAntiAliasing((Graphics2D)g, true);
//		((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
//				RenderingHints.VALUE_ANTIALIAS_ON);
		Component cp=c.getParent();
		if(cp!=null)
		{
			//** 因java的textField边框默认是直角的,为了在LNF级别使加上圆连框后自然些,就得给这原始的直角先做隐藏处理(不要看见它)
			//				Color parentBackground=c.getParent().getBackground();
			//				g.setColor(parentBackground);
			//				g.drawRect(x, y, width-1, height-1);
		}

		//据thickness画出边框(当前是圆角的)
		g.setColor(lineColor);
		int i;
		for(i = 0; i < thickness; i++)  
		{
			g.drawRoundRect(x+i, y+i, width-i-i-1, height-i-i-1,this.arcWidth,this.arcWidth);
			if(thickness>1)
				g.setColor(BEUtils.getColor(g.getColor(), 70, 70, 70,-50));
		}

		g.setColor(oldColor);
//		((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
//				RenderingHints.VALUE_ANTIALIAS_OFF);
		BEUtils.setAntiAliasing((Graphics2D)g, false);
	}
 
Example 9
Source File: Button.java    From DroidUIBuilder with Apache License 2.0 5 votes vote down vote up
@Override
	public void paint(Graphics g)
	{
		// 绘制背景
		super.paintBackground(g);
		
		// 处于可见状态才填充内容
		if(this.isVisible())
		{
			if (img_base == null)
			{
				g.setColor(Color.white);
				g.fillRoundRect(getX(), getY(), getWidth(), getHeight(), 8, 8);

				g.setColor(Color.black);
				g.drawRoundRect(getX(), getY(), getWidth(), getHeight(), 8, 8);
			}
			else
			{
//				img_base.paint(g, getX(), getY(), getWidth(), getHeight());
				img_base.draw((Graphics2D)g, getX(), getY(), getWidth(), getHeight());
				g.setColor(Color.black);
			}
		}
		
		g.setFont(f);
		// int w = g.getFontMetrics(f).stringWidth(text.getStringValue());
		g.setColor(textColor.getColorValue());

		drawText(g, 0, getHeight() / 2 + fontSize / 2 - 2, CENTER);
		// g.drawString(text.getStringValue(), getX()+getWidth()/2-w/2,
		// getY()+fontSize+2);
	}
 
Example 10
Source File: Joystick.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paintInstance(InstancePainter painter) {
	Bounds bds = painter.getBounds();
	int x = bds.getX() + 30;
	int y = bds.getY() + 15;

	Graphics g = painter.getGraphics();
	painter.drawRoundBounds(Color.WHITE);
	g.drawRoundRect(x - 27, y - 12, 24, 24, 5, 5);
	drawBall(g, x - 15, y, painter.getAttributeValue(Io.ATTR_COLOR), painter.shouldDrawColor());
	painter.drawPorts();
}
 
Example 11
Source File: Joystick.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paintGhost(InstancePainter painter) {
	Bounds bds = painter.getBounds();
	int x = bds.getX();
	int y = bds.getY();
	Graphics g = painter.getGraphics();
	GraphicsUtil.switchToWidth(g, 2);
	g.drawRoundRect(x, y, 30, 30, 8, 8);
}
 
Example 12
Source File: DigitalOscilloscope.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paintGhost(InstancePainter painter) {
	Bounds bds = painter.getBounds();
	Graphics g = painter.getGraphics();
	GraphicsUtil.switchToWidth(g, 2);
	g.drawRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(), border, border);
}
 
Example 13
Source File: TMAbstractEdge.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * @param g -
 *               The graphic context for the drawing operation.
 * @param string -
 *               The String to be rendered.
 * @param x -
 *               The x coordinate where the String should be positioned.
 * @param y -
 *               The y coordinate where the String should be positioned. NOTE: The text is <b>centered </b> over the given coordinates.
 */
protected void paintToolTipText(Graphics g, String string, int x, int y) {

  g.setFont(this.getFont());
  FontMetrics fontMetrics = g.getFontMetrics();

  int a = fontMetrics.getAscent();
  int h = a + fontMetrics.getDescent();
  int w = fontMetrics.stringWidth(string);

  int xPosition = x - (w / 2);
  int yPosition = y - (h / 2);

  // Draw the background

  Color c = this.getColor();
  g.setColor(c);

  int r = h / 2;
  int vPad = h / 8;
  int hPad = h / 4;

  g.fillRoundRect(xPosition - hPad, yPosition - vPad, w + (2 * hPad), h
      + (2 * vPad), r, r);

  //Draw a defined edge to the popup
  g.setColor(TMTopicNode.textColourForBackground(c));
  g.drawRoundRect(xPosition - hPad, yPosition - vPad, w + (2 * hPad), h
      + (2 * vPad), r, r);

  // Draw the text
  g.drawString(string, xPosition, yPosition + a);
}
 
Example 14
Source File: Probe.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paintGhost(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	Bounds bds = painter.getOffsetBounds();
	int x = bds.getX();
	int y = bds.getY();
	if (bds.getWidth() <= 20) {
		g.drawOval(x, y, bds.getWidth(), bds.getHeight());
	} else {
		g.drawRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(), 10, 10);
	}
}
 
Example 15
Source File: RPCScrollPane.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
protected synchronized void paintComponent(Graphics g) {
	super.paintComponent(g);
	if (_gradation == null) {
		_gradation = Gradation.getInstance(_colorStart, _colorEnd, getWidth(), getHeight(), _alpha);
	}
	_gradation.drawHeight(g, 0, 0);
	g.setColor(LColor.white.brighter());
	g.drawRoundRect(0, 0, getWidth(), getHeight(), 0, 0);
	g.drawRoundRect(0, 0, getWidth() - 2, getHeight() - 2, 0, 0);
}
 
Example 16
Source File: RoundRectangle.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void draw(Graphics g, int x, int y, int w, int h) {
	int diam = 2 * radius;
	if (setForFill(g))
		g.fillRoundRect(x, y, w, h, diam, diam);
	if (setForStroke(g))
		g.drawRoundRect(x, y, w, h, diam, diam);
}
 
Example 17
Source File: EditView.java    From DroidUIBuilder with Apache License 2.0 4 votes vote down vote up
@Override
	public void paint(Graphics g)
	{
		// 绘制背景
		super.paintBackground(g);
		
		// 处于可见状态才填充内容
		if(this.isVisible())
		{
			if (img_base == null)
			{
				g.setColor(Color.white);
				g.fillRoundRect(getX(), getY(), getWidth(), getHeight(), 8, 8);
				g.setColor(Color.darkGray);
				g.drawRoundRect(getX(), getY(), getWidth(), getHeight(), 8, 8);
			}
			else
			{
				img_base.draw((Graphics2D)g, getX(), getY(), getWidth(), getHeight());
//				img.paint(g, getX(), getY(), getWidth(), getHeight());
				g.setColor(Color.darkGray);
			}
		}
		
		g.setFont(f);
		String s;
		if (password.getBooleanValue())
		{
			s = "";
			for (int i = 0; i < text.getStringValue().length(); i++)
				s = s + '\245';
		}
		else
			s = text.getStringValue();
		g.setColor(textColor.getColorValue());
		// g.drawString(s, getX()+pad_x/2, getY()+fontSize+pad_y/2-1);
		this.drawText(g, 0, (fontSize + getHeight()) / 2 - 2);
//		g.setColor(Color.black);
		
		// 绘制一个fucos状态下的光标样式,仅用于装饰哦
		g.setColor(Color.gray);
		g.fillRect(getX() + pad_x / 2 - 4, getY() + (getHeight() - fontSize)
				/ 2 - 2, 1, fontSize + 4);
	}
 
Example 18
Source File: RoundedBorder.java    From WorldGrower with GNU General Public License v3.0 4 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
	g.drawRoundRect(x, y, width - 1, height - 1, radius, radius);
}
 
Example 19
Source File: GlossyTaskPaneGroupUI.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
protected void paintTitleBackground(JTaskPaneGroup group, Graphics g) {
  if (group.isSpecial()) {
    g.setColor(specialTitleBackground);
    g.fillRoundRect(
      0,
      0,
      group.getWidth(),
      ROUND_HEIGHT * 2,
      ROUND_HEIGHT,
      ROUND_HEIGHT);
    g.fillRect(
      0,
      ROUND_HEIGHT,
      group.getWidth(),
      TITLE_HEIGHT - ROUND_HEIGHT);
  } else {
    Paint oldPaint = ((Graphics2D)g).getPaint();
    GradientPaint gradient =
      new GradientPaint(
        0f,
        0f, //group.getWidth() / 2,
        titleBackgroundGradientStart,
        0f, //group.getWidth(),
        TITLE_HEIGHT,
        titleBackgroundGradientEnd);
            
    ((Graphics2D)g).setRenderingHint(
      RenderingHints.KEY_COLOR_RENDERING,
      RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    ((Graphics2D)g).setRenderingHint(
      RenderingHints.KEY_INTERPOLATION,
      RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    ((Graphics2D)g).setRenderingHint(
      RenderingHints.KEY_RENDERING,
      RenderingHints.VALUE_RENDER_QUALITY);
    ((Graphics2D)g).setPaint(gradient);
    
    g.fillRoundRect(
      0,
      0,
      group.getWidth(),
      ROUND_HEIGHT * 2,
      ROUND_HEIGHT,
      ROUND_HEIGHT);
    g.fillRect(
      0,
      ROUND_HEIGHT,
      group.getWidth(),
      TITLE_HEIGHT - ROUND_HEIGHT);
    ((Graphics2D)g).setPaint(oldPaint);
  }
  
  Rectangle oldRect = g.getClipBounds();
  g.setClip(0, 0, group.getWidth(), TITLE_HEIGHT);
  g.setColor(borderColor);
  g.drawRoundRect(
    0,
    0,
    group.getWidth() - 1,
    TITLE_HEIGHT + ROUND_HEIGHT,
    ROUND_HEIGHT,
    ROUND_HEIGHT);
  g.drawLine(0, TITLE_HEIGHT - 1, group.getWidth(), TITLE_HEIGHT - 1);
  g.setClip(oldRect);      
}
 
Example 20
Source File: WhylineScrollPane.java    From whyline with MIT License 3 votes vote down vote up
protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds ) {

			((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
			((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	    	g.setColor(UI.getControlCenterColor());
	    	g.fillRoundRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height, UI.getRoundedness(), UI.getRoundedness());

	    	g.setColor(UI.getControlFrontColor());
	    	g.drawRoundRect(trackBounds.x, trackBounds.y, trackBounds.width - 1, trackBounds.height - 1, UI.getRoundedness(), UI.getRoundedness());
	    	
	    }