@Override protected void paintWidget() { Graphics2D g = getGraphics(); g.setStroke(Util.STROKE_2); g.setFont(getFont()); Rectangle bounds = getBounds(); String text = Util.node(this).toString(); if (text.length() == 0) { g.setColor((Color) getBackground()); g.fillOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1); g.setColor(getForeground()); g.drawOval(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1); } else { g.setColor((Color) getBackground()); int arc = (bounds.height - 1); g.fillRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc); g.setColor(getForeground()); g.drawString( text, bounds.x + (bounds.height - 1) / 2, bounds.y + bounds.height - vborder - 1 - g.getFontMetrics().getMaxDescent()); g.drawRoundRect(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1, arc, arc); } }
@Override @SuppressWarnings({"PointlessArithmeticExpression"}) protected Rectangle calculateClientArea() { String text = Util.node(this).toString(); int w, h; if (text.length() == 0) w = h = 2 * radius; else { JLabel label = new JLabel(text); label.setFont(getFont()); Dimension dim = label.getPreferredSize(); w = dim.width + dim.height; h = dim.height + 2 * vborder; } return new Rectangle(-w / 2, -h / 2, w + 1, h + 1); }