Align JButton height with combobox/textfield in Darcula

This commit is contained in:
Kirill Kirichenko
2018-01-26 13:03:37 +03:00
parent 7e332c161c
commit 728d3dca61
3 changed files with 25 additions and 29 deletions
@@ -157,7 +157,7 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder {
}
else if (myComponent instanceof JButton) {
top = isWin10 ? 2 : 4;
left = isWin10 ? 2 : isMacDefault ? 5 : 6;
left = isWin10 ? 2 : isMacDefault ? 5 : 4;
bottom = 0;
}
@@ -26,6 +26,7 @@ import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.UIResource;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Path2D;
import java.awt.geom.RoundRectangle2D;
@@ -46,7 +47,6 @@ public class DarculaButtonPainter implements Border, UIResource {
if (DarculaButtonUI.isSquare(c)) {
Rectangle r = new Rectangle(width, height);
//JBInsets.removeFrom(r, JBUI.insets(1));
g2.translate(r.x, r.y);
Path2D border = new Path2D.Float(Path2D.WIND_EVEN_ODD);
@@ -72,26 +72,23 @@ public class DarculaButtonPainter implements Border, UIResource {
DarculaUIUtil.paintFocusBorder(g2, width - off * 2, diam + off * 2, diam / 2.0f + 2.0f * off , true);
}
else {
g2.translate(off, off);
DarculaUIUtil.paintFocusBorder(g2, width - off * 2, height - off * 2, DarculaUIUtil.arc(), true);
DarculaUIUtil.paintFocusBorder(g2, width, height, DarculaUIUtil.arc(), true);
}
}
else {
Insets ins = getBorderInsets(c);
int yOff = (ins.top + ins.bottom) / 4;
int offset = JBUI.scale(getOffset());
int w = c.getWidth();
int h = c.getHeight();
g2.setPaint(getBorderColor());
if (UIUtil.isHelpButton((JComponent)c)) {
g2.drawOval((w - diam) / 2, (h - diam) / 2, diam, diam);
}
else {
g2.translate(x, y);
int r = JBUI.scale(5);
g2.drawRoundRect(offset, yOff, width - 2 * offset, height - 2 * yOff, r, r);
g2.translate(-x, -y);
g2.draw(new Ellipse2D.Float((width - diam) / 2, (height - diam) / 2, diam, diam));
} else {
float lw = DarculaUIUtil.lw(g2);
float bw = DarculaUIUtil.bw();
float arc = DarculaUIUtil.arc();
Path2D border = new Path2D.Float(Path2D.WIND_EVEN_ODD);
border.append(new RoundRectangle2D.Float(bw, bw, width - bw * 2, height - bw * 2, arc, arc), false);
border.append(new RoundRectangle2D.Float(bw + lw, bw + lw, width - (bw + lw) * 2, height - (bw + lw) * 2, arc - lw, arc - lw), false);
g2.fill(border);
}
}
}
@@ -112,7 +109,7 @@ public class DarculaButtonPainter implements Border, UIResource {
if (DarculaButtonUI.isSquare(c)) {
return JBUI.insets(3).asUIResource();
}
return JBUI.insets(8, 16, 8, 14).asUIResource();
return JBUI.insets(4, 14).asUIResource();
}
protected int getOffset() {
@@ -37,6 +37,7 @@ import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.RoundRectangle2D;
/**
@@ -76,11 +77,13 @@ public class DarculaButtonUI extends BasicButtonUI {
int h = c.getHeight();
if (UIUtil.isHelpButton(c)) {
g.setPaint(UIUtil.getGradientPaint(0, 0, getButtonColor1(), 0, h, getButtonColor2()));
int off = JBUI.scale(22);
int x = (w - off) / 2;
int y = (h - off) / 2;
g.fillOval(x, y, off, off);
int diam = JBUI.scale(22);
int x = (w - diam) / 2;
int y = (h - diam) / 2;
g.fill(new Ellipse2D.Float(x, y, diam, diam));
AllIcons.Actions.Help.paintIcon(c, g, x + JBUI.scale(3), y + JBUI.scale(3));
return false;
} else {
Graphics2D g2 = (Graphics2D)g.create();
@@ -89,16 +92,15 @@ public class DarculaButtonUI extends BasicButtonUI {
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
MacUIUtil.USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE);
float arc = isSquare(c) ? JBUI.scale(2.0f) : DarculaUIUtil.arc();
float bw = DarculaUIUtil.bw();
if (c.isEnabled()) {
if (isSquare(c)) {
Rectangle r = new Rectangle(w, h);
//JBInsets.removeFrom(r, JBUI.insets(1));
g2.translate(r.x, r.y);
g2.setPaint(UIUtil.getGradientPaint(r.x, r.y, getButtonColor1(), r.x + r.width,
r.y + r.height, getButtonColor2()));
float arc = JBUI.scale(2.0f);
float bw = DarculaUIUtil.bw();
g2.fill(new RoundRectangle2D.Float(bw, bw, r.width - bw * 2, r.height - bw * 2, arc, arc));
}
else {
@@ -106,10 +108,7 @@ public class DarculaButtonUI extends BasicButtonUI {
UIUtil.getGradientPaint(0, 0, getSelectedButtonColor1(), 0, h, getSelectedButtonColor2()) :
UIUtil.getGradientPaint(0, 0, getButtonColor1(), 0, h, getButtonColor2()));
Insets ins = c.getInsets();
int yOff = (ins.top + ins.bottom) / 4;
int rad = JBUI.scale(5);
g2.fillRoundRect(JBUI.scale(4), yOff, w - 2 * JBUI.scale(4), h - 2 * yOff, rad, rad);
g2.fill(new RoundRectangle2D.Float(bw, bw, w - bw * 2, h - bw * 2, arc, arc));
}
}
} finally {