下面列出了java.awt.Graphics2D#drawRoundRect ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
if(color == null) {
return;
}
Graphics2D g2 = (Graphics2D)g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(deriveColorAlpha(color, 40));
g2.drawRoundRect(x, y + 2, width - 1, height - 3, cornerRadius, cornerRadius);
g2.setColor(deriveColorAlpha(color, 90));
g2.drawRoundRect(x, y + 1, width - 1, height - 2, cornerRadius, cornerRadius);
g2.setColor(deriveColorAlpha(color, 255));
g2.drawRoundRect(x, y, width - 1, height - 1, cornerRadius, cornerRadius);
g2.dispose();
}
/**
* Over-painting component, so it can have different colors.
*/
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(bkgColor);
// draw the button rounded opaque
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // for high quality
g2d.fillRoundRect(0, 0, getWidth(), getHeight(), 7, 7);
// draw the border
g2d.setColor(bkgColor.darker().darker());
g2d.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, 7, 7);
super.paintComponent(g);
}
@Override
public void draw(Graphics2D g2) {
if (enabled) {
if (pressed) {
g2.setColor(new Color(this.backgroundPressed));
} else
if (hover) {
g2.setColor(new Color(this.backgroundHover));
} else {
g2.setColor(new Color(this.background));
}
} else {
g2.setColor(Color.GRAY);
}
g2.fillRect(0, 0, width, height);
g2.setColor(Color.BLACK);
g2.drawRoundRect(1, 1, width - 3, height - 3, 3, 3);
tr.paintTo(g2, marginWidth, marginHeight, size, color, text);
}
@Override
protected void paintBox(final Graphics2D gfx, final double x, final double y,
final double width1, final double height2) {
// final Graph2D g = (Graph2D) this.getEdge().getGraph();
final int roundedX = (int) (x - (m_width / 2));
final int roundedY = (int) (y - (m_height / 2));
final BasicStroke oldStroke = (BasicStroke) gfx.getStroke();
gfx.setStroke(new BasicStroke(oldStroke.getLineWidth()));
gfx.setColor(m_backGroundColor);
gfx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.80f));
gfx.fillRoundRect(roundedX, roundedY, m_roundedWidth, m_roundedHeight, 5, 5);
gfx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.95f));
gfx.setColor(borderColor);
gfx.drawRoundRect(roundedX, roundedY, m_roundedWidth, m_roundedHeight, SHADOW_SIZE, SHADOW_SIZE);
gfx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.00f));
gfx.setStroke(oldStroke);
}
/**
* Highlights the line.
*
* @param gfx The graphics context where the highlighting is drawn.
* @param x The x position where the highlighting begins.
* @param y The y position where the highlighting begins.
* @param width The width of the highlighting area.
* @param height The height of the highlighting area.
* @param color The color of the highlighting area.
*/
private void drawHighlighting(final Graphics2D gfx, final double x, final double y,
final double width, final double height, final Color color) {
gfx.setColor(color);
final int roundedX = (int) Math.round(x);
final int roundedY = (int) Math.round(y);
final int roundedHeight = (int) Math.round(height);
final int roundedWidth = (int) Math.round(width);
gfx.setComposite(DEFAULT_COMPOSITE);
// Draw the inner part of the highlighting area
gfx.fillRoundRect(roundedX, roundedY, roundedWidth, roundedHeight, 10, 10);
// Draw the border of the highlighting area
gfx.setColor(color.darker());
gfx.setStroke(DEFAULT_BORDER_STROKE);
gfx.drawRoundRect(roundedX, roundedY, roundedWidth, roundedHeight, 10, 10);
// Reset the setting changes
gfx.setComposite(NORMAL_COMPOSITE);
gfx.setStroke(NORMAL_STROKE);
}
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);
Color color = Utilities.deriveColorHSB(c.getBackground(), 0, 0, -.3f);
g2.setColor(Utilities.deriveColorAlpha(color, 40));
g2.drawRoundRect(x, y + 2, width - 1, height - 3, cornerRadius, cornerRadius);
g2.setColor(Utilities.deriveColorAlpha(color, 90));
g2.drawRoundRect(x, y + 1, width - 1, height - 2, cornerRadius, cornerRadius);
g2.setColor(Utilities.deriveColorAlpha(color, 255));
g2.drawRoundRect(x, y, width - 1, height - 1, cornerRadius, cornerRadius);
g2.dispose();
}
private void drawSelectedRoundBorder(Graphics g, Color aColor) {
final Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(DEFAULT_BORDER_STROKE);
g2d.setColor(aColor);
g2d.drawRoundRect(1, 1, getWidth()-3, getHeight()-3, 16, 16);
}
@Override
protected void paintBase(Graphics2D g) {
if (endOFF) {
return;
}
setArea(null);
Rectangle r = this.getBounds();
g.setColor(Color.GRAY);
g.drawRoundRect(0, 0, r.width - 1, r.height - 1, 10, 10);
g.setColor(Color.lightGray);
g.drawRoundRect(5, 5, r.height - 10, r.height - 10, 4,4);
int met = (r.height - 11) / 2;
g.setColor(Color.black);
g.drawLine(7, 6 + met, r.height - 7, 6 + met);
if ('+' == getEstado()) {
g.drawLine(6 + met, 7, 6 + met, r.height - 7);
}
g.setColor(Color.BLACK);
Rectangle bkp = g.getClipBounds();
g.clipRect(0, 0, r.width - 1, r.height);
if (isSelecionado()) {
g.setFont(new Font(this.getFont().getFontName(), Font.BOLD, getFont().getSize()));
g.drawRoundRect(0, 0, r.width - 1, r.height - 1, 10, 10);
}
int tmp = (r.width - g.getFontMetrics().stringWidth(getTexto())) / 2;
g.drawString(getTexto(), tmp, (int) (r.height * 0.72));
g.setClip(bkp);
}
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.translate(x, y);
g2.setColor(Colors.SPINNER_BORDER);
g2.drawRoundRect(x, y, w - 1, h - 1, RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
g2.translate(-x, -y);
}
public static Image[] getColorIcons(Model model){
Stroke outlineStroke = new BasicStroke(2.0f);
Stroke holeStroke = new BasicStroke(2.0f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,19.0f,new float[]{3.0f,1.0f},0.0f);
Color holeColor = new Color(213, 246, 255);
Color holeStrokeColor = new Color(0,102,128);
Image[] icons = new Image[16];
for(int i = 0; i < 16; i++){
BufferedImage icon = new BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB);
icons[i] = icon;
Graphics2D g2d = (Graphics2D)icon.getGraphics();
g2d.setFont(Resources.SMALL_FONT);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if(i == 0){
g2d.setStroke(holeStroke);
g2d.setColor(holeColor);
g2d.fillRoundRect(4, 4, 24, 24, 8, 8);
g2d.setColor(holeStrokeColor);
g2d.drawRoundRect(4, 4, 24, 24, 8, 8);
Rectangle2D bounds = g2d.getFontMetrics().getStringBounds("Hole", g2d);
g2d.drawString("Hole",16-(int)bounds.getCenterX(),16-(int)bounds.getCenterY());
} else {
g2d.setStroke(outlineStroke);
Color c = new Color(model.getColor(i));
g2d.setColor(c);
g2d.fillRoundRect(4, 4, 24, 24, 8, 8);
g2d.setPaint(new GradientPaint(new Point(0,4),c.brighter(),new Point(0,32+4), c.darker()));
g2d.drawRoundRect(4, 4, 24, 24, 8, 8);
}
}
return icons;
}
protected void drawSelection(Graphics2D g) {
// Vertically centered
double y = getVisibleLocalBottom() - (getVisibleLocalHeight() - heightOfLabel) / 2;
Stroke stroke = g.getStroke();
g.setStroke(UI.SELECTED_STROKE);
g.setColor(UI.getHighlightColor());
g.drawRoundRect((int)getVisibleLocalLeft(), (int)(y - heightOfLabel), (int)widthOfLabel + UI.PADDING_WITHIN_EVENTS * 2, (int)heightOfLabel, UI.getRoundedness(), UI.getRoundedness());
g.setStroke(stroke);
}
@Override
public void paintComponent(final Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
int x = 0;
int y = 0;
int width = (int) getSize().getWidth();
int height = (int) getSize().getHeight();
// draw background depending special roles and hovering
g2.setPaint(AttributeGuiTools.getColorForAttributeRole(mapAttributeRoleName(),
hovered ? ColorScope.HOVER : ColorScope.BACKGROUND));
g2.fillRoundRect(x, y, width, height, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
// draw background depending special roles and hovering
g2.setPaint(AttributeGuiTools.getColorForAttributeRole(mapAttributeRoleName(), ColorScope.BORDER));
if (hovered) {
g2.setStroke(new BasicStroke(1.0f));
} else {
g2.setStroke(new BasicStroke(0.5f));
}
g2.drawRoundRect(x, y, width - 1, height - 1, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
// let Swing draw its components
super.paintComponent(g2);
}
@Override
public void paintComponent(Graphics g) {
Graphics2D g2D = (Graphics2D) g;
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // 反锯齿平滑绘制
// 通过对并发消息链表遍历绘制全部消息气泡、消息发出者头像
if (messageConcurrentLinkedQueue != null) {
Iterator<Message> iterator = messageConcurrentLinkedQueue.iterator();
while (iterator.hasNext()) {
Message message = iterator.next();
Point point = message.getMessagePaintLeftTop();
if (point != null) {
// 绘制消息发出者头像
if (senderHeadImageConcurrentHashMap != null) {
Image image = senderHeadImageConcurrentHashMap.get(message.getSenderHeadImageID());
if (image != null) {
if (message.isSelfSender()) {
g2D.drawImage(image, this.getWidth() - image.getWidth(null) - 9, point.y - 25, null);
} else {
// 消息发出者是别人,则头像靠左显示
g2D.drawImage(image, 9, point.y - 25, null);
}
}
}
// 绘制额消息气泡左边小箭头
int xPoints[] = new int[3];
int yPoints[] = new int[3];
if (message.isSelfSender()) {
// 绘制自己消息圆角消息气泡矩形
g2D.setColor(selfMessageColor);
g2D.fillRoundRect(point.x - 7, point.y - 7, message.getMessagePaintWidth() + 14, message.getMessagePaintHeight() + 14, 10, 10);
// 绘制圆角消息气泡边框
g2D.setColor(selfMessageBorderColor);
g2D.drawRoundRect(point.x - 7, point.y - 7, message.getMessagePaintWidth() + 14, message.getMessagePaintHeight() + 14, 10, 10);
// 消息发出者是自己,则头像靠右显示
xPoints[0] = (point.x - 7) + (message.getMessagePaintWidth() + 14);
yPoints[0] = point.y;
xPoints[1] = xPoints[0] + 7;
yPoints[1] = point.y;
xPoints[2] = xPoints[0];
yPoints[2] = point.y + 7;
g2D.setColor(selfMessageColor);
g2D.fillPolygon(xPoints, yPoints, 3);
g2D.setColor(selfMessageBorderColor);
g2D.drawPolyline(xPoints, yPoints, 3);
g2D.setColor(selfMessageColor);
g2D.drawLine(xPoints[0], yPoints[0] + 1, xPoints[2], yPoints[2] - 1);
} else {
// 绘制别人消息圆角消息气泡矩形
// 绘制圆角消息气泡矩形
g2D.setColor(otherMessageColor);
g2D.fillRoundRect(point.x - 7, point.y - 7, message.getMessagePaintWidth() + 14, message.getMessagePaintHeight() + 14, 10, 10);
// 绘制圆角消息气泡边框
g2D.setColor(otherMessageBorderColor);
g2D.drawRoundRect(point.x - 7, point.y - 7, message.getMessagePaintWidth() + 14, message.getMessagePaintHeight() + 14, 10, 10);
// 消息发出者是别人,则头像靠左显示
xPoints[0] = point.x - 7;
yPoints[0] = point.y;
xPoints[1] = xPoints[0] - 7;
yPoints[1] = point.y;
xPoints[2] = xPoints[0];
yPoints[2] = point.y + 7;
g2D.setColor(otherMessageColor);
g2D.fillPolygon(xPoints, yPoints, 3);
g2D.setColor(otherMessageBorderColor);
g2D.drawPolyline(xPoints, yPoints, 3);
g2D.setColor(otherMessageColor);
g2D.drawLine(xPoints[0], yPoints[0] + 1, xPoints[2], yPoints[2] - 1);
}
}
} // while
}
super.paintComponent(g); // 执行默认组件绘制(消息文本、图片以及段落显示等内容)
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D g2 = (Graphics2D)g;
g2.setPaint(fillColor);
// NOTE: fillRoundRect seems to have poor performance on Linux
// g2.fillRoundRect(x + halfBorderStrokeWidth, y + halfBorderStrokeWidth,
// width - borderStrokeWidth, height - borderStrokeWidth,
// arcRadius * 2, arcRadius * 2);
int arcRadius2 = arcRadius * 2;
int arcRadius2p1 = arcRadius2 + 1;
g2.fillArc(x, y, arcRadius2, arcRadius2, 90, 90);
g2.fillArc(x + width - arcRadius2p1, y, arcRadius2, arcRadius2, 0, 90);
g2.fillArc(x, y + height - arcRadius2p1, arcRadius2, arcRadius2, 180, 90);
g2.fillArc(x + width - arcRadius2p1, y + height - arcRadius2p1, arcRadius2, arcRadius2, 270, 90);
g2.fillRect(x + arcRadius, y, width - arcRadius2p1, height);
g2.fillRect(x, y + arcRadius, arcRadius, height - arcRadius2p1);
g2.fillRect(x + width - arcRadius - 1, y + arcRadius, arcRadius, height - arcRadius2p1);
Object aa = null;
Object sc = null;
if (!forceSpeed) {
aa = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
sc = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
}
g2.setStroke(borderStroke);
g2.setPaint(lineColor);
g2.drawRoundRect(x + halfBorderStrokeWidth, y + halfBorderStrokeWidth,
width - borderStrokeWidth, height - borderStrokeWidth,
arcRadius * 2, arcRadius * 2);
if (!forceSpeed) {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aa);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, sc);
}
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D g2 = (Graphics2D)g;
g2.setPaint(fillColor);
// NOTE: fillRoundRect seems to have poor performance on Linux
// g2.fillRoundRect(x + halfBorderStrokeWidth, y + halfBorderStrokeWidth,
// width - borderStrokeWidth, height - borderStrokeWidth,
// arcRadius * 2, arcRadius * 2);
int arcRadius2 = arcRadius * 2;
int arcRadius2p1 = arcRadius2 + 1;
g2.fillArc(x, y, arcRadius2, arcRadius2, 90, 90);
g2.fillArc(x + width - arcRadius2p1, y, arcRadius2, arcRadius2, 0, 90);
g2.fillArc(x, y + height - arcRadius2p1, arcRadius2, arcRadius2, 180, 90);
g2.fillArc(x + width - arcRadius2p1, y + height - arcRadius2p1, arcRadius2, arcRadius2, 270, 90);
g2.fillRect(x + arcRadius, y, width - arcRadius2p1, height);
g2.fillRect(x, y + arcRadius, arcRadius, height - arcRadius2p1);
g2.fillRect(x + width - arcRadius - 1, y + arcRadius, arcRadius, height - arcRadius2p1);
Object aa = null;
Object sc = null;
if (!forceSpeed) {
aa = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
sc = g2.getRenderingHint(RenderingHints.KEY_STROKE_CONTROL);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
}
g2.setStroke(borderStroke);
g2.setPaint(lineColor);
g2.drawRoundRect(x + halfBorderStrokeWidth, y + halfBorderStrokeWidth,
width - borderStrokeWidth, height - borderStrokeWidth,
arcRadius * 2, arcRadius * 2);
if (!forceSpeed) {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, aa);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, sc);
}
}
@Override
protected void paintDeterminate(Graphics g, JComponent c) {
boolean compressed = Boolean.parseBoolean(String.valueOf(progressBar
.getClientProperty(RapidLookTools.PROPERTY_PROGRESSBAR_COMPRESSED)));
int y = 0;
int x = 0;
int w;
int h;
if (compressed) {
x = (int) (c.getWidth() * 0.67);
w = (int) (c.getWidth() * 0.33);
y = 3;
h = c.getHeight() - 6;
} else {
w = c.getWidth();
h = c.getHeight() / 2;
}
int amountFull = getAmountFull(progressBar.getInsets(), w, h);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (c.isOpaque()) {
if (c.getParent() != null) {
g2.setColor(c.getParent().getBackground());
} else {
g2.setColor(c.getBackground());
}
g2.fillRect(x, y, c.getWidth(), c.getHeight());
}
g2.setColor(Colors.PROGRESSBAR_BACKGROUND);
g2.fillRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
g2.setColor(Colors.PROGRESSBAR_BORDER);
g2.drawRoundRect(x + 1, y + 1, w - 2, h - 2, RapidLookAndFeel.CORNER_DEFAULT_RADIUS,
RapidLookAndFeel.CORNER_DEFAULT_RADIUS);
Paint gp = new GradientPaint(x, y + 3, Colors.PROGRESSBAR_DETERMINATE_FOREGROUND_GRADIENT_START, x, h - 5,
Colors.PROGRESSBAR_DETERMINATE_FOREGROUND_GRADIENT_END);
g2.setPaint(gp);
g2.fillRoundRect(x + 3, y + 3, amountFull - 5, h - 5, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);
drawString(g2, w, h, compressed);
}
@Override
protected void paintBase(Graphics2D g) {
Rectangle r = this.getBounds();
int esq = (int) (r.width * Criador.getDivisor());
setArea(new Rectangle(esq -2, 0, 4, r.height - 1));
//int dir = r.width - esq;
if (!isSelecionado()) {
g.setColor(Color.GRAY);
g.drawRoundRect(0, 0, r.width - 1, r.height - 1, 10, 10);
g.drawLine(esq, 0, esq, r.height - 1);
g.setColor(Color.BLACK);
getCorParaTexto(g);
Rectangle bkp = g.getClipBounds();
g.clipRect(0, 0, esq - 1, r.height);
g.drawString(getTexto(), (Criador.espaco * 2) + 1, (int) (r.height * 0.72));
g.setClip(bkp);
int re = esq + r.height -5;
g.setColor(CanEdit() ? Color.BLACK : Color.LIGHT_GRAY);
g.fillRect(esq + 4, 4, r.height - 9, r.height - 9);
try {
Color c = util.Utilidades.StringToColor(getTransValor());//new Color(Integer.parseInt(getTransValor()));
g.setColor(c);
} catch (Exception e) {
}
Color tmpc = g.getColor();
String bonito = Integer.toString(tmpc.getRed()) + ", " + Integer.toString(tmpc.getGreen()) + ", " +Integer.toString(tmpc.getBlue())+ ", " +Integer.toString(tmpc.getAlpha());
if (CanEdit()) {
g.fillRect(esq + 5, 5, r.height - 10, r.height -10);
}
// g.setColor(CanEdit() ? Color.BLACK : Color.LIGHT_GRAY);
// g.drawRect(tmp + 4, 4, r.height - 9, r.height -9);
g.clipRect(re, 0, esq - 1, r.height);
getCorParaTexto(g);
g.drawString(bonito, re + (Criador.espaco * 2) + 1, (int) (r.height * 0.72));
g.setClip(bkp);
} else {
super.paintBase(g);
}
}
@Override
public void paintComponent(Graphics g) {
final int buttonWidth = 20;
boolean enabled = this.isEnabled();
// turn on anti-alias mode
Graphics2D antiAlias = (Graphics2D) g;
antiAlias.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (enabled) {
antiAlias.setColor(Color.white);
} else {
antiAlias.setColor(Color.decode("#e0e0e4"));
}
antiAlias.fillRoundRect(1, 1, getWidth(), getHeight() - 2, 5, 5);
// draw text
if (enabled) {
antiAlias.setColor(Color.black);
} else {
antiAlias.setColor(Color.decode("#909090"));
}
Object selectedItem = getSelectedItem();
String text = selectedItem == null ? "" : selectedItem.toString();
// display default text if appropriate
if (text.isBlank() && this.getSelectedIndex() == 0) {
text = defaultText;
antiAlias.setColor(Color.decode("#909090"));
}
if (!text.isEmpty()) { // 0 length text makes bounding box explode
FontMetrics fm = antiAlias.getFontMetrics(getFont());
Rectangle2D rec = fm.getStringBounds(text, antiAlias);
int stringW = (int) Math.round(rec.getWidth());
int stringH = (int) Math.round(rec.getHeight());
antiAlias.drawChars(text.toCharArray(), 0, text.length(), ((getWidth() - buttonWidth)/2)
- (stringW/2), (getHeight() - 9)/2 + stringH/2);
}
if (enabled) {
antiAlias.setColor(PGTUtil.COLOR_ENABLED_BG);
} else {
antiAlias.setColor(Color.decode("#d0d0d0"));
}
antiAlias.fillRect(getWidth() - buttonWidth, 1, buttonWidth, getHeight() - 1);
// draw outline
if ((mouseOver || this.hasFocus()) && enabled) {
antiAlias.setColor(Color.black);
} else
{
antiAlias.setColor(Color.lightGray);
}
antiAlias.drawRoundRect(1, 1, getWidth() - 2, getHeight() - 2, 5, 5);
}
@Override
public void paintTrack(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
// make sure slider has same background as container
if (slider.getParent() != null) {
g2.setColor(slider.getParent().getBackground());
g2.fillRect(0, 0, slider.getWidth(), slider.getHeight());
}
if (this.slider.getOrientation() == SwingConstants.HORIZONTAL) {
int trackTop = (int) this.trackRect.getY() + 2;
int w = this.slider.getWidth();
int length = w - 6;
// draw background bar
if (this.slider.isEnabled()) {
g2.setColor(Colors.SLIDER_TRACK_BACKGROUND);
} else {
g2.setColor(Colors.SLIDER_TRACK_BACKGROUND_DISABLED);
}
g2.fillRoundRect(3, trackTop + 1, length, 5, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);
// draw fill bar
g2.setColor(Colors.SLIDER_TRACK_FOREGROUND);
g2.fill(new Rectangle2D.Double(4, trackTop + 2, this.thumbRect.x + 2, 3));
// draw border
g2.setColor(Colors.SLIDER_TRACK_BORDER);
g2.drawRoundRect(2, trackTop, length, 6, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);
} else {
int trackLeft = (int) this.trackRect.getX() + 2;
int h = this.slider.getHeight();
int height = h - 6;
// draw background bar
if (this.slider.isEnabled()) {
g2.setColor(Colors.SLIDER_TRACK_BACKGROUND);
} else {
g2.setColor(Colors.SLIDER_TRACK_BACKGROUND_DISABLED);
}
g2.fillRoundRect(trackLeft + 1, 3, 5, height, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);
// draw fill bar
g2.setColor(Colors.SLIDER_TRACK_FOREGROUND);
g2.fill(new Rectangle2D.Double(trackLeft + 2, this.thumbRect.y - 2, 3, h - this.thumbRect.y - 4));
// draw border
g2.setColor(Colors.SLIDER_TRACK_BORDER);
g2.drawRoundRect(trackLeft, 2, 6, height, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);
}
}
public void paint(Graphics2D g) {
g.drawRoundRect(getX(), getY(), getWidth(), getHeight(), getCornerX(), getCornerY());
}