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

The following are Jave code examples for showing how to use drawRoundRect() of the java.awt.Graphics class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: rapidminer   File: ExpressionValueCellEditor.java   View Source Code Vote up 6 votes
/**
 * 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 2
Project: LivroJavaComoProgramar10Edicao   File: LinesRectsOvalsJPanel.java   View Source Code Vote up 6 votes
@Override
public void paintComponent(Graphics g)
{
   super.paintComponent(g); 
   this.setBackground(Color.WHITE);

   g.setColor(Color.RED);
   g.drawLine(5, 30, 380, 30);

   g.setColor(Color.BLUE);
   g.drawRect(5, 40, 90, 55);
   g.fillRect(100, 40, 90, 55);

   g.setColor(Color.BLACK);
   g.fillRoundRect(195, 40, 90, 55, 50, 50);
   g.drawRoundRect(290, 40, 90, 55, 20, 20);

   g.setColor(Color.GREEN);   
   g.draw3DRect(5, 100, 90, 55, true);
   g.fill3DRect(100, 100, 90, 55, false);

   g.setColor(Color.MAGENTA);
   g.drawOval(195, 100, 90, 55);
   g.fillOval(290, 100, 90, 55);
}
 
Example 3
Project: JavaGraph   File: StrokedLineBorder.java   View Source Code Vote up 6 votes
/**
 * Overrides the super method to set the stroke first.
 * @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
 */
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width,
        int height) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(this.stroke);

    Color oldColor = g.getColor();
    int i = this.thickness / 2;
    g.setColor(this.lineColor);
    if (!this.roundedCorners) {
        g.drawRect(x + i, y + i, width - i - i - 1, height - i - i - 1);
    } else {
        g.drawRoundRect(x + i, y + i, width - i - i - 1,
            height - i - i - 1, this.thickness, this.thickness);
    }
    g.setColor(oldColor);
}
 
Example 4
Project: Logisim   File: NotGate.java   View Source Code Vote up 6 votes
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
Project: ScreenCut   File: ScreenCut.java   View Source Code Vote up 5 votes
/**
 * 绘制圆形
 */
private void drawRoundRect(Point st, Point ed, Color c, Graphics g) {
    g.setColor(c);
    int w = Math.abs(st.x - ed.x);
    int h = Math.abs(st.y - ed.y);
    g.drawRoundRect(Math.min(st.x, ed.x), Math.min(st.y, ed.y), w, h, w, h);
}
 
Example 6
Project: rapidminer   File: ColorIcon.java   View Source Code Vote up 5 votes
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
	g.setColor(color);
	g.fillRoundRect(x, y, getIconWidth() - 1, getIconHeight(), 2, 2);
	g.setColor(borderColor);
	g.drawRoundRect(x, y, getIconWidth() - 1, getIconHeight(), 2, 2);
}
 
Example 7
Project: jmt   File: FastGraph.java   View Source Code Vote up 5 votes
/**
 * Draws the selected value
 * @param selectedValue the selected value to draw
 * @param g the graphics object
 * @param width the total chart width
 * @param height the total chart height
 * @param maxx the maximum X value (simulation time)
 * @param maxy the maximum Y value
 */
private void paintSelectedValue(MeasureValue selectedValue, Graphics g, int width, int height, double maxx, double maxy) {
	FontMetrics metric = g.getFontMetrics();
	String x_str = simulationTimeFormat.format(selectedValue.getSimTime());
	String m_str = formatNumber(selectedValue.getMeanValue());
	String i_str = formatNumber(selectedValue.getLastIntervalAvgValue());
	
	Dimension bounds = composeVerticalBounds(g, metric, POPUP_FULL_X_PREFIX + x_str, POPUP_FULL_X_PREFIX + m_str, POPUP_FULL_X_PREFIX + i_str);
	int selectedValueX = getX(selectedValue.getSimTime());
	int textX = (int)(selectedValueX - bounds.getWidth() / 2);
	// Fix value out of chart for label
	if (textX < 2) {
		textX = 2;
	} else if (textX + bounds.getWidth() + POPUP_MARGIN > width) {
		textX = width - (int)bounds.getWidth() - POPUP_MARGIN;
	}
	int textY = getY(maxy / 2) + (int)bounds.getHeight() / 2;
	
	g.setColor(COLOR_POPUP);
	g.drawLine(selectedValueX, getY(0), selectedValueX, getY(selectedValue.getLastIntervalAvgValue()));
	g.setColor(COLOR_POPUP_BG);
	g.fillRoundRect(textX - POPUP_MARGIN, textY - (int)bounds.getHeight(), (int)bounds.getWidth() + POPUP_MARGIN * 2, (int)bounds.getHeight() + POPUP_MARGIN, 4, 4);	
	g.setColor(COLOR_POPUP);
	g.drawRoundRect(textX - POPUP_MARGIN, textY - (int)bounds.getHeight(), (int)bounds.getWidth() + POPUP_MARGIN * 2, (int)bounds.getHeight() + POPUP_MARGIN, 4, 4);
	
	// Draw squares
	Rectangle2D prefixBounds = metric.getStringBounds(POPUP_X_PREFIX, g);
	g.setColor(COLOR_DRAW);
	g.fillRect(textX, textY - (int)prefixBounds.getHeight() - bounds.height / 3, (int)prefixBounds.getWidth(), (int)prefixBounds.getHeight());
	g.setColor(COLOR_LAST_INTERVAL);
	g.fillRect(textX, textY - (int)prefixBounds.getHeight(), (int)prefixBounds.getWidth(), (int)prefixBounds.getHeight());
	
	// Draws texts
	g.setColor(COLOR_AXIS);
	g.drawString(POPUP_FULL_X_PREFIX + x_str, textX, textY - bounds.height * 2 / 3);
	g.drawString(POPUP_MIDDLE + m_str, textX + (int)prefixBounds.getWidth(), textY - bounds.height / 3);
	g.drawString(POPUP_MIDDLE + i_str, textX + (int)prefixBounds.getWidth(), textY);
}
 
Example 8
Project: Logisim   File: Joystick.java   View Source Code Vote up 5 votes
@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 9
Project: Logisim   File: Joystick.java   View Source Code Vote up 5 votes
@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 10
Project: Equella   File: FlatterIcons.java   View Source Code Vote up 5 votes
@Override
public void paintIcon(Component c, Graphics g, int x, int y)
{
	setColor(c, g);
	g.drawRoundRect(x, y, width, height, 2, 2);
	g.fillRoundRect(x + 2, y + 2, width - 3, height - 3, 1, 1);
}
 
Example 11
Project: Logisim   File: AbstractComponentFactory.java   View Source Code Vote up 5 votes
@Override
public void drawGhost(ComponentDrawContext context, Color color, int x, int y, AttributeSet attrs) {
	Graphics g = context.getGraphics();
	Bounds bds = getOffsetBounds(attrs);
	g.setColor(color);
	GraphicsUtil.switchToWidth(g, 2);
	g.drawRoundRect(x + bds.getX(), y + bds.getY(), bds.getWidth(), bds.getHeight(), 10, 10);
}
 
Example 12
Project: enigma-vk   File: BoxHighlightPainter.java   View Source Code Vote up 5 votes
@Override
public void paint(Graphics g, int start, int end, Shape shape, JTextComponent text) {
	Rectangle bounds = getBounds(text, start, end);
	
	// fill the area
	if (m_fillColor != null) {
		g.setColor(m_fillColor);
		g.fillRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4);
	}
	
	// draw a box around the area
	g.setColor(m_borderColor);
	g.drawRoundRect(bounds.x, bounds.y, bounds.width, bounds.height, 4, 4);
}
 
Example 13
Project: Logisim   File: Tty.java   View Source Code Vote up 5 votes
@Override
public void paintGhost(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	GraphicsUtil.switchToWidth(g, 2);
	Bounds bds = painter.getBounds();
	g.drawRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(), 10, 10);
}
 
Example 14
Project: Tarski   File: mxInsertHandler.java   View Source Code Vote up 5 votes
/**
 * 
 */
public void paint(Graphics g) {
  if (first != null && current != null) {
    ((Graphics2D) g).setStroke(new BasicStroke(lineWidth));
    g.setColor(lineColor);
    Rectangle rect = current.getRectangle();

    if (rounded) {
      g.drawRoundRect(rect.x, rect.y, rect.width, rect.height, 8, 8);
    } else {
      g.drawRect(rect.x, rect.y, rect.width, rect.height);
    }
  }
}
 
Example 15
Project: Logisim   File: DigitalOscilloscope.java   View Source Code Vote up 5 votes
@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 16
Project: Logisim   File: Probe.java   View Source Code Vote up 5 votes
@Override
public void paintInstance(InstancePainter painter) {
	Value value = getValue(painter);

	Graphics g = painter.getGraphics();
	Bounds bds = painter.getBounds(); // intentionally with no graphics
										// object - we don't want label
										// included
	int x = bds.getX();
	int y = bds.getY();
	g.setColor(Color.WHITE);
	g.fillRect(x + 5, y + 5, bds.getWidth() - 10, bds.getHeight() - 10);
	g.setColor(Color.GRAY);
	if (value.getWidth() <= 1) {
		g.drawOval(x, y, bds.getWidth(), bds.getHeight());
	} else {
		g.drawRoundRect(x, y, bds.getWidth(), bds.getHeight(), 10, 10);
	}

	painter.drawLabel();

	if (!painter.getShowState()) {
		if (value.getWidth() > 0) {
			GraphicsUtil.drawCenteredText(g, "x" + value.getWidth(), bds.getX() + bds.getWidth() / 2,
					bds.getY() + bds.getHeight() / 2);
		}
	} else {
		paintValue(painter, value);
	}

	painter.drawPorts();
}
 
Example 17
Project: Logisim   File: DipSwitch.java   View Source Code Vote up 5 votes
@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 18
Project: VASSAL-src   File: ShapeItem.java   View Source Code Vote up 4 votes
public void draw(Graphics g, GamePieceImage defn) {

    ShapeItemInstance si = null;
    if (defn != null) {
      si = defn.getShapeInstance(getConfigureName());
    }
    if (si == null) {
      si = new ShapeItemInstance();
    }

    Color fg = si.getFgColor().getColor();
    Color bg = si.getBorderColor().getColor();

    Point origin = layout.getPosition(this);
    Rectangle r = new Rectangle(origin.x, origin.y, getWidth(), getHeight());

    if (isAntialias()) {
      ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    }
    else {
      ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
    }

    if (fg != null) {
      g.setColor(fg);
      if (shape.equals(RECT)) {
        g.fillRect(r.x, r.y, r.width, r.height);
      }
      else if (shape.equals(RRECT)) {
        g.fillRoundRect(r.x, r.y, r.width, r.height, bevel*2, bevel*2);
      }
      else if (shape.equals(OVAL)) {
        g.fillOval(r.x, r.y, r.width, r.height);
      }
    }

    if (bg != null) {
      g.setColor(bg);
      if (shape.equals(RECT)) {
        g.drawRect(r.x, r.y, r.width, r.height);
      }
      else if (shape.equals(RRECT)) {
        g.drawRoundRect(r.x, r.y, r.width, r.height, bevel*2, bevel*2);
      }
      else if (shape.equals(OVAL)) {
        g.drawOval(r.x, r.y, r.width, r.height);
      }
    }
  }
 
Example 19
Project: Equella   File: FlatterIcons.java   View Source Code Vote up 4 votes
@Override
public void paintIcon(Component c, Graphics g, int x, int y)
{
	setColor(c, g);
	g.drawRoundRect(x, y, width, height, 2, 2);
}
 
Example 20
Project: Logisim   File: RoundRectangleTool.java   View Source Code Vote up 4 votes
@Override
public void drawShape(Graphics g, int x, int y, int w, int h) {
	int r = 2 * attrs.getValue(DrawAttr.CORNER_RADIUS).intValue();
	g.drawRoundRect(x, y, w, h, r, r);
}