Skip to content

Commit

Permalink
Fixed button content overlapping border. Fixes #148
Browse files Browse the repository at this point in the history
  • Loading branch information
weisJ committed Apr 23, 2020
1 parent f25006f commit c301049
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,36 +199,31 @@ protected void paintNeighbourFocus(final Graphics2D g2, final Component c,
boolean paintLeft = DarkUIUtil.hasFocus(left);
if (paintLeft) {
int h = height - Math.max(0, getShadowSize(left) - borderSize);
int arc = getFocusArc(left);
g2.translate(-2 * borderSize, 0);
PaintUtil.paintLineBorder(g2, -borderSize, borderSize, 3 * borderSize, h, arc);
PaintUtil.paintFocusBorder(g2, 3 * borderSize, h, arc, borderSize);
g2.translate(2 * borderSize, 0);
g2.translate(-3 * borderSize + 1, 0);
PaintUtil.paintFocusBorder(g2, 4 * borderSize, h, getFocusArc(left), borderSize);
g2.translate(-(-3 * borderSize + 1), 0);
}
JComponent right = ButtonConstants.getNeighbour(DarkButtonUI.KEY_RIGHT_NEIGHBOUR, c);
boolean paintRight = DarkUIUtil.hasFocus(right);
g2.setColor(focusBorderColor);
if (paintRight) {
int h = height - Math.max(0, getShadowSize(right) - borderSize);
g2.translate(width - borderSize, 0);
PaintUtil.paintFocusBorder(g2, 3 * borderSize, h, getFocusArc(right), borderSize);
g2.translate(borderSize - width, 0);
g2.translate(width - borderSize - 1, 0);
PaintUtil.paintFocusBorder(g2, 4 * borderSize, h, getFocusArc(right), borderSize);
g2.translate(-(width - borderSize - 1), 0);
}
JComponent top = ButtonConstants.getNeighbour(DarkButtonUI.KEY_TOP_NEIGHBOUR, c);
boolean paintTop = DarkUIUtil.hasFocus(top);
if (paintTop) {
g2.translate(0, -2 * borderSize);
PaintUtil.paintFocusBorder(g2, width, 3 * borderSize,
getFocusArc(top), borderSize);
g2.translate(0, 2 * borderSize);
g2.translate(0, -3 * borderSize + 1);
PaintUtil.paintFocusBorder(g2, width, 4 * borderSize, getFocusArc(top), borderSize);
g2.translate(0, -(-3 * borderSize + 1));
}
JComponent bottom = ButtonConstants.getNeighbour(DarkButtonUI.KEY_TOP_NEIGHBOUR, c);
boolean paintBottom = DarkUIUtil.hasFocus(bottom);
if (paintBottom) {
g2.translate(0, height - borderSize);
PaintUtil.paintFocusBorder(g2, width, 3 * borderSize,
getFocusArc(bottom), borderSize);
g2.translate(0, borderSize - height);
g2.translate(0, height - borderSize - 1);
PaintUtil.paintFocusBorder(g2, width, 4 * borderSize, getFocusArc(bottom), borderSize);
g2.translate(0, -(height - borderSize - 1));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,6 @@ protected void uninstallListeners(final AbstractButton b) {
ToggleButtonFocusNavigationActions.uninstallActions(b);
}

@Override
public void update(final Graphics g, final JComponent c) {
super.update(g, c);
boolean isDefaultButton = ButtonConstants.isDefaultButton(c) && !SystemInfo.isMac;
if (isDefaultButton && !c.getFont().isBold()) {
c.setFont(c.getFont().deriveFont(Font.BOLD));
} else if (!isDefaultButton && c.getFont().isBold()) {
c.setFont(c.getFont().deriveFont(Font.PLAIN));
}
}

@Override
public void paint(final Graphics g, final JComponent c) {
GraphicsContext config = new GraphicsContext(g);
Expand Down Expand Up @@ -391,14 +380,14 @@ protected String layout(final AbstractButton b, final JComponent c, final FontMe
}

AlignmentExt corner = DarkButtonBorder.getCornerFlag(c);
Insets insetMask = new Insets(borderSize, borderSize, borderSize, borderSize);
if (corner != null) {
Insets insetMask = new Insets(borderSize, borderSize, borderSize, borderSize);
insetMask = corner.maskInsetsInverted(insetMask, 0);
i.left -= insetMask.left;
i.right -= insetMask.right;
i.top -= insetMask.top;
i.bottom -= insetMask.bottom;
}
i.left -= insetMask.left;
i.right -= insetMask.right;
i.top -= insetMask.top;
i.bottom -= insetMask.bottom;

viewRect.x = i.left;
viewRect.y = i.top;
Expand Down

0 comments on commit c301049

Please sign in to comment.