Unify Darcula radiobutton and checkbox alignment

This commit is contained in:
Kirill Kirichenko
2017-11-20 15:14:00 +03:00
parent 20473245ac
commit d8660d2ca7
5 changed files with 24 additions and 23 deletions
@@ -120,6 +120,7 @@ ComboBox.disabledForeground=585858
ComboBox.squareButton=false
RadioButtonUI=com.intellij.ide.ui.laf.darcula.ui.DarculaRadioButtonUI
RadioButton.border=com.intellij.ide.ui.laf.darcula.ui.DarculaCheckBoxBorder
RadioButton.darcula.selectionEnabledColor=aaaaaa
RadioButton.darcula.selectionDisabledColor=606060
RadioButton.darcula.selectionEnabledShadowColor=1e1e1e
@@ -21,7 +21,6 @@ import com.intellij.util.ui.UIUtil;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.InsetsUIResource;
import javax.swing.plaf.UIResource;
import java.awt.*;
@@ -30,13 +29,12 @@ import java.awt.*;
*/
public class DarculaCheckBoxBorder implements Border, UIResource {
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {}
@Override
public Insets getBorderInsets(Component c) {
final int a = SystemInfo.isMac || UIUtil.getParentOfType(CellRendererPane.class, c) != null ? 0 : 2;
return JBUI.insets(a, a, a, a).asUIResource();
int a = SystemInfo.isMac || UIUtil.getParentOfType(CellRendererPane.class, c) != null ? 0 : 2;
return JBUI.insets(a).asUIResource();
}
@Override
@@ -47,23 +47,24 @@ public class DarculaCheckBoxUI extends MetalCheckBoxUI {
@Override
public synchronized void paint(Graphics g2d, JComponent c) {
Graphics2D g = (Graphics2D)g2d;
JCheckBox b = (JCheckBox) c;
final Dimension size = c.getSize();
final Font font = c.getFont();
g.setFont(font);
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, font);
Dimension size = c.getSize();
Rectangle viewRect = new Rectangle(size);
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
AbstractButton b = (AbstractButton) c;
Font f = c.getFont();
g.setFont(f);
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
JBInsets.removeFrom(viewRect, c.getInsets());
String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), getDefaultIcon(),
b.getVerticalAlignment(), b.getHorizontalAlignment(),
b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
viewRect, iconRect, textRect, b.getIconTextGap());
String text = SwingUtilities.layoutCompoundLabel(
c, fm, b.getText(), getDefaultIcon(),
b.getVerticalAlignment(), b.getHorizontalAlignment(),
b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
viewRect, iconRect, textRect, b.getIconTextGap());
//background
if (c.isOpaque()) {
@@ -75,7 +76,7 @@ public class DarculaCheckBoxUI extends MetalCheckBoxUI {
drawText(c, g, b, fm, textRect, text);
}
protected void drawCheckIcon(JComponent c, Graphics2D g, JCheckBox b, Rectangle iconRect, boolean selected, boolean enabled) {
protected void drawCheckIcon(JComponent c, Graphics2D g, AbstractButton b, Rectangle iconRect, boolean selected, boolean enabled) {
if (selected && b.getSelectedIcon() != null) {
b.getSelectedIcon().paintIcon(b, g, iconRect.x + JBUI.scale(4), iconRect.y + JBUI.scale(2));
} else if (!selected && b.getIcon() != null) {
@@ -160,7 +161,7 @@ public class DarculaCheckBoxUI extends MetalCheckBoxUI {
g.drawLine(off, y1, w - off + JBUI.scale(1), y1);
}
protected void drawText(JComponent c, Graphics2D g, JCheckBox b, FontMetrics fm, Rectangle textRect, String text) {
protected void drawText(JComponent c, Graphics2D g, AbstractButton b, FontMetrics fm, Rectangle textRect, String text) {
//text
if(text != null) {
View view = (View) c.getClientProperty(BasicHTML.propertyKey);
@@ -266,7 +267,7 @@ public class DarculaCheckBoxUI extends MetalCheckBoxUI {
return EmptyIcon.create(JBUI.scale(20)).asUIResource();
}
protected boolean isIndeterminate(JCheckBox checkBox) {
protected boolean isIndeterminate(AbstractButton checkBox) {
return "indeterminate".equals(checkBox.getClientProperty("JButton.selectedState"));
}
}
@@ -21,6 +21,7 @@ import com.intellij.ui.ColorUtil;
import com.intellij.ui.Gray;
import com.intellij.ui.JBGradientPaint;
import com.intellij.util.ui.EmptyIcon;
import com.intellij.util.ui.JBInsets;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import sun.swing.SwingUtilities2;
@@ -44,18 +45,19 @@ public class DarculaRadioButtonUI extends MetalRadioButtonUI {
@Override
public synchronized void paint(Graphics g2d, JComponent c) {
Graphics2D g = (Graphics2D)g2d;
Dimension size = c.getSize();
Rectangle viewRect = new Rectangle(size);
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
AbstractButton b = (AbstractButton) c;
//ButtonModel model = b.getModel();
Font f = c.getFont();
g.setFont(f);
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
JBInsets.removeFrom(viewRect, c.getInsets());
String text = SwingUtilities.layoutCompoundLabel(
c, fm, b.getText(), getDefaultIcon(),
b.getVerticalAlignment(), b.getHorizontalAlignment(),
@@ -191,9 +193,7 @@ public class DarculaRadioButtonUI extends MetalRadioButtonUI {
}
@Override
protected void paintFocus(Graphics g, Rectangle t, Dimension d) {
}
protected void paintFocus(Graphics g, Rectangle t, Dimension d) {}
@Override
public Icon getDefaultIcon() {
@@ -114,6 +114,7 @@ ComboBox.darcula.arrowFillColor=457dd7
ComboBox.darcula.arrowFocusedFillColor=2d82ed
RadioButtonUI=com.intellij.ide.ui.laf.darcula.ui.DarculaRadioButtonUI
RadioButton.border=com.intellij.ide.ui.laf.darcula.ui.DarculaCheckBoxBorder
RadioButton.darcula.selectionEnabledColor=ffffff
RadioButton.darcula.selectionDisabledColor=aaaaaa
RadioButton.darcula.selectionEnabledShadowColor=00000040