mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-187791 Make JButtons colorable
This commit is contained in:
@@ -351,7 +351,8 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension prefSize = super.getPreferredSize();
|
||||
int width = prefSize.width + getArrowIcon(isEnabled()).getIconWidth() + JBUI.scale(5);
|
||||
width += UIUtil.isUnderWin10LookAndFeel() ? JBUI.scale(10) : 0;
|
||||
width += UIUtil.isUnderWin10LookAndFeel() ? JBUI.scale(10) :
|
||||
UIUtil.isUnderDefaultMacTheme() ? JBUI.scale(5) : 0;
|
||||
return new Dimension(width, isSmallVariant() ? JBUI.scale(24) : prefSize.height);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.ide.ui.laf.darcula;
|
||||
|
||||
import com.intellij.ide.IdeEventQueue;
|
||||
import com.intellij.ide.ui.laf.IntelliJLaf;
|
||||
import com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI;
|
||||
import com.intellij.ide.ui.laf.darcula.ui.DarculaEditorTextFieldBorder;
|
||||
import com.intellij.openapi.editor.event.EditorMouseAdapter;
|
||||
import com.intellij.openapi.editor.event.EditorMouseEvent;
|
||||
@@ -33,6 +34,7 @@ import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import javax.swing.text.JTextComponent;
|
||||
import javax.swing.text.Position;
|
||||
import java.awt.*;
|
||||
@@ -423,4 +425,15 @@ public class DarculaUIUtil {
|
||||
public static boolean isEmpty(Dimension d) {
|
||||
return d == null || d.width == 0 && d.height == 0;
|
||||
}
|
||||
|
||||
public static Color getButtonTextColor(@NotNull AbstractButton button) {
|
||||
Color fg = button.getForeground();
|
||||
if (fg instanceof UIResource && DarculaButtonUI.isDefaultButton(button)) {
|
||||
Color selectedFg = UIManager.getColor("Button.darcula.selectedButtonForeground");
|
||||
if (selectedFg != null) {
|
||||
return selectedFg;
|
||||
}
|
||||
}
|
||||
return fg;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-7
@@ -85,13 +85,14 @@ public class DarculaButtonPainter implements Border, UIResource {
|
||||
}
|
||||
|
||||
public Color getBorderColor(Component button) {
|
||||
return button.isEnabled() ?
|
||||
button.hasFocus() ?
|
||||
UIManager.getColor(DarculaButtonUI.isDefaultButton((JComponent)button) ?
|
||||
"Button.darcula.defaultFocusedBorderColor" : "Button.darcula.focusedBorderColor") :
|
||||
UIManager.getColor(button.isEnabled() && DarculaButtonUI.isDefaultButton((JComponent)button) ?
|
||||
"Button.darcula.defaultBorderColor" : "Button.darcula.borderColor")
|
||||
: UIManager.getColor("Button.darcula.disabledBorderColor");
|
||||
AbstractButton b = (AbstractButton)button;
|
||||
Color borderColor = (Color)b.getClientProperty("JButton.borderColor");
|
||||
return button.isEnabled() ? borderColor != null ? borderColor :
|
||||
button.hasFocus() ?
|
||||
UIManager.getColor(DarculaButtonUI.isDefaultButton(b) ? "Button.darcula.defaultFocusedBorderColor" : "Button.darcula.focusedBorderColor") :
|
||||
UIManager.getColor(button.isEnabled() && DarculaButtonUI.isDefaultButton(b) ? "Button.darcula.defaultBorderColor" : "Button.darcula.borderColor")
|
||||
|
||||
: UIManager.getColor("Button.darcula.disabledBorderColor");
|
||||
}
|
||||
|
||||
protected void paintShadow(Graphics2D g2, Rectangle r) {
|
||||
|
||||
+15
-23
@@ -26,14 +26,12 @@ import com.intellij.util.ui.JBInsets;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.MacUIUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import javax.swing.plaf.basic.BasicButtonUI;
|
||||
import javax.swing.plaf.basic.BasicHTML;
|
||||
import javax.swing.text.View;
|
||||
@@ -101,17 +99,8 @@ public class DarculaButtonUI extends BasicButtonUI {
|
||||
float bw = DarculaUIUtil.bw();
|
||||
|
||||
if (c.isEnabled()) {
|
||||
if (isSquare(c)) {
|
||||
g2.setPaint(UIUtil.getGradientPaint(r.x, r.y, getButtonColorStart(), r.x + r.width, r.y + r.height, getButtonColorEnd()));
|
||||
g2.fill(new RoundRectangle2D.Float(bw, bw, r.width - bw * 2, r.height - bw * 2, arc, arc));
|
||||
}
|
||||
else {
|
||||
g2.setPaint(isDefaultButton(c) ?
|
||||
UIUtil.getGradientPaint(0, 0, getDefaultButtonColorStart(), 0, r.height, getDefaultButtonColorEnd()) :
|
||||
UIUtil.getGradientPaint(0, 0, getButtonColorStart(), 0, r.height, getButtonColorEnd()));
|
||||
|
||||
g2.fill(new RoundRectangle2D.Float(bw, bw, r.width - bw * 2, r.height - bw * 2, arc, arc));
|
||||
}
|
||||
g2.setPaint(getBackground(c, r));
|
||||
g2.fill(new RoundRectangle2D.Float(bw, bw, r.width - bw * 2, r.height - bw * 2, arc, arc));
|
||||
}
|
||||
} finally {
|
||||
g2.dispose();
|
||||
@@ -120,6 +109,15 @@ public class DarculaButtonUI extends BasicButtonUI {
|
||||
}
|
||||
}
|
||||
|
||||
private Paint getBackground(JComponent c, Rectangle r) {
|
||||
Color backgroundColor = (Color)c.getClientProperty("JButton.backgroundColor");
|
||||
|
||||
return backgroundColor != null ? backgroundColor :
|
||||
isDefaultButton(c) ?
|
||||
UIUtil.getGradientPaint(0, 0, getDefaultButtonColorStart(), 0, r.height, getDefaultButtonColorEnd()) :
|
||||
UIUtil.getGradientPaint(0, 0, getButtonColorStart(), 0, r.height, getButtonColorEnd());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
if (paintDecorations((Graphics2D)g, c)) {
|
||||
@@ -134,7 +132,7 @@ public class DarculaButtonUI extends BasicButtonUI {
|
||||
|
||||
AbstractButton button = (AbstractButton)c;
|
||||
ButtonModel model = button.getModel();
|
||||
g.setColor(getTextColor(button));
|
||||
g.setColor(getButtonTextColor(button));
|
||||
|
||||
FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g);
|
||||
int mnemonicIndex = DarculaLaf.isAltPressed() ? button.getDisplayedMnemonicIndex() : -1;
|
||||
@@ -149,15 +147,9 @@ public class DarculaButtonUI extends BasicButtonUI {
|
||||
}
|
||||
}
|
||||
|
||||
public static Color getTextColor(@NotNull AbstractButton button) {
|
||||
Color fg = button.getForeground();
|
||||
if (fg instanceof UIResource && isDefaultButton(button)) {
|
||||
final Color selectedFg = UIManager.getColor("Button.darcula.selectedButtonForeground");
|
||||
if (selectedFg != null) {
|
||||
fg = selectedFg;
|
||||
}
|
||||
}
|
||||
return fg;
|
||||
protected Color getButtonTextColor(AbstractButton button) {
|
||||
Color textColor = (Color)button.getClientProperty("JButton.textColor");
|
||||
return textColor != null ? textColor : DarculaUIUtil.getButtonTextColor(button);
|
||||
}
|
||||
|
||||
public static Color getDisabledTextColor() {
|
||||
|
||||
+2
-4
@@ -1,10 +1,8 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.ui.laf.darcula.ui
|
||||
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil.bw
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil.lw
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil.*
|
||||
import com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI.getDisabledTextColor
|
||||
import com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI.getTextColor
|
||||
import com.intellij.ide.ui.laf.darcula.ui.DarculaComboBoxUI.getArrowButtonPreferredSize
|
||||
import com.intellij.ui.components.BasicOptionButtonUI
|
||||
import com.intellij.util.ui.JBUI
|
||||
@@ -55,7 +53,7 @@ open class DarculaOptionButtonUI : BasicOptionButtonUI() {
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
|
||||
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE)
|
||||
|
||||
g.color = if (b.isEnabled) getTextColor(b) else getDisabledTextColor()
|
||||
g.color = if (b.isEnabled) getButtonTextColor(b) else getDisabledTextColor()
|
||||
g.fill(DarculaComboBoxUI.getArrowShape(b))
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -32,8 +32,7 @@ import static com.intellij.ide.ui.laf.intellij.MacIntelliJButtonUI.ARC_SIZE;
|
||||
public class MacIntelliJButtonBorder implements Border, UIResource {
|
||||
@Override
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||
if (!c.hasFocus() ||
|
||||
c instanceof JComponent && UIUtil.isHelpButton(c)) return;
|
||||
if (!c.hasFocus() || c instanceof JComponent && UIUtil.isHelpButton(c)) return;
|
||||
|
||||
Graphics2D g2 = (Graphics2D)g.create();
|
||||
try {
|
||||
|
||||
+40
-32
@@ -19,6 +19,7 @@ import com.intellij.ide.ui.laf.IconCache;
|
||||
import com.intellij.ide.ui.laf.IntelliJLaf;
|
||||
import com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI;
|
||||
import com.intellij.ui.Gray;
|
||||
import com.intellij.util.ui.JBInsets;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.MacUIUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -41,7 +42,6 @@ public class MacIntelliJButtonUI extends DarculaButtonUI {
|
||||
return new MacIntelliJButtonUI();
|
||||
}
|
||||
|
||||
@SuppressWarnings("UseJBColor")
|
||||
@Override
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
if (!(c.getBorder() instanceof MacIntelliJButtonBorder) && !isComboButton(c)) {
|
||||
@@ -64,23 +64,12 @@ public class MacIntelliJButtonUI extends DarculaButtonUI {
|
||||
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, MacUIUtil.USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE);
|
||||
|
||||
float lw = getLineWidth(g2);
|
||||
Insets i = c.getBorder().getBorderInsets(c); // ComboButton adds arrow width to the insets, so take the bare border.
|
||||
Insets i = c.getInsets();
|
||||
|
||||
// Draw background
|
||||
Shape outerRect = new RoundRectangle2D.Float(i.left, i.top, w - (i.left + i.right), h - (i.top + i.bottom),
|
||||
ARC_SIZE, ARC_SIZE);
|
||||
Paint p;
|
||||
if (!b.isEnabled()) {
|
||||
p = Gray.xF1;
|
||||
} else if (isDefaultButton(c)) {
|
||||
p = IntelliJLaf.isGraphite() ?
|
||||
new GradientPaint(w/2, i.top, new Color(0xb2b2b7), w/2, h - (i.top + i.bottom), new Color(0x929297)) :
|
||||
new GradientPaint(w/2, i.top, new Color(0x68b2fa), w/2, h - (i.top + i.bottom), new Color(0x0e80ff));
|
||||
} else {
|
||||
p = Gray.xFF;
|
||||
}
|
||||
|
||||
g2.setPaint(p);
|
||||
g2.setPaint(getBackgroundPaint(c));
|
||||
g2.fill(outerRect);
|
||||
|
||||
// Draw outline
|
||||
@@ -90,9 +79,7 @@ public class MacIntelliJButtonUI extends DarculaButtonUI {
|
||||
w - lw*2 - (i.left + i.right),
|
||||
h - lw*2 - (i.top + i.bottom),
|
||||
ARC_SIZE - lw, ARC_SIZE - lw), false);
|
||||
|
||||
p = getBorderPaint(c);
|
||||
g2.setPaint(p);
|
||||
g2.setPaint(getBorderPaint(c));
|
||||
g2.fill(outline);
|
||||
|
||||
paintContents(g2, b);
|
||||
@@ -107,23 +94,37 @@ public class MacIntelliJButtonUI extends DarculaButtonUI {
|
||||
}
|
||||
|
||||
@SuppressWarnings("UseJBColor")
|
||||
public static Paint getBorderPaint(JComponent c) {
|
||||
int w = c.getWidth();
|
||||
int h = c.getHeight();
|
||||
Insets i = c.getBorder().getBorderInsets(c);
|
||||
Paint p;
|
||||
if (!c.isEnabled()) {
|
||||
p = new GradientPaint(w / 2, i.top, Gray.xD2, w / 2, h - (i.top + i.bottom), Gray.xC3);
|
||||
private static Paint getBackgroundPaint(JComponent b) {
|
||||
int h = b.getHeight();
|
||||
Insets i = b.getInsets();
|
||||
|
||||
if (!b.isEnabled()) {
|
||||
return Gray.xF1;
|
||||
} else if (isDefaultButton(b)) {
|
||||
return IntelliJLaf.isGraphite() ?
|
||||
new GradientPaint(0, i.top, new Color(0xb2b2b7), 0, h - (i.top + i.bottom), new Color(0x929297)) :
|
||||
new GradientPaint(0, i.top, new Color(0x68b2fa), 0, b.getHeight() - (i.top + i.bottom), new Color(0x0e80ff));
|
||||
} else {
|
||||
Color backgroundColor = (Color)b.getClientProperty("JButton.backgroundColor");
|
||||
return backgroundColor != null ? backgroundColor : Gray.xFF;
|
||||
}
|
||||
else if (isDefaultButton(c)) {
|
||||
p = IntelliJLaf.isGraphite() ?
|
||||
new GradientPaint(w / 2, i.top, new Color(0xa5a5ab), w / 2, h - (i.top + i.bottom), new Color(0x7d7d83)) :
|
||||
new GradientPaint(w / 2, i.top, new Color(0x4ba0f8), w / 2, h - (i.top + i.bottom), new Color(0x095eff));
|
||||
}
|
||||
|
||||
@SuppressWarnings("UseJBColor")
|
||||
public static Paint getBorderPaint(JComponent b) {
|
||||
int h = b.getHeight();
|
||||
Insets i = b.getBorder().getBorderInsets(b);
|
||||
|
||||
if (!b.isEnabled()) {
|
||||
return new GradientPaint(0, i.top, Gray.xD2, 0, h - (i.top + i.bottom), Gray.xC3);
|
||||
} else if (isDefaultButton(b)) {
|
||||
return IntelliJLaf.isGraphite() ?
|
||||
new GradientPaint(0, i.top, new Color(0xa5a5ab), 0, h - (i.top + i.bottom), new Color(0x7d7d83)) :
|
||||
new GradientPaint(0, i.top, new Color(0x4ba0f8), 0, h - (i.top + i.bottom), new Color(0x095eff));
|
||||
} else {
|
||||
Color borderColor = (Color)b.getClientProperty("JButton.borderColor");
|
||||
return borderColor != null ? borderColor : new GradientPaint(0, i.top, Gray.xC9, 0, h - (i.top + i.bottom), Gray.xAC);
|
||||
}
|
||||
else {
|
||||
p = new GradientPaint(w / 2, i.top, Gray.xC9, w / 2, h - (i.top + i.bottom), Gray.xAC);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -151,4 +152,11 @@ public class MacIntelliJButtonUI extends DarculaButtonUI {
|
||||
}
|
||||
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, -1, x, y);
|
||||
}
|
||||
|
||||
@Override protected void modifyViewRect(AbstractButton b, Rectangle rect) {
|
||||
JBInsets.removeFrom(rect, b.getInsets());
|
||||
if (isComboButton(b)) {
|
||||
JBInsets.removeFrom(rect, JBUI.insetsLeft(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-17
@@ -25,7 +25,6 @@ public class WinIntelliJButtonBorder implements Border, UIResource {
|
||||
|
||||
Graphics2D g2 = (Graphics2D)g.create();
|
||||
AbstractButton b = (AbstractButton)c;
|
||||
ButtonModel bm = b.getModel();
|
||||
Rectangle outerRect = new Rectangle(x, y, width, height);
|
||||
try {
|
||||
JBInsets.removeFrom(outerRect, getOuterInsets());
|
||||
@@ -33,34 +32,40 @@ public class WinIntelliJButtonBorder implements Border, UIResource {
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
|
||||
|
||||
Color color = UIManager.getColor("Button.intellij.native.borderColor");
|
||||
if (!c.isEnabled()) {
|
||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, DISABLED_ALPHA_LEVEL));
|
||||
} else if (bm.isPressed()) {
|
||||
color = UIManager.getColor("Button.intellij.native.pressedBorderColor");
|
||||
} else if (b.hasFocus() || bm.isRollover()) {
|
||||
color = UIManager.getColor("Button.intellij.native.focusedBorderColor");
|
||||
} else {
|
||||
if (DarculaButtonUI.isDefaultButton(b)) {
|
||||
color = UIManager.getColor("Button.intellij.native.focusedBorderColor");
|
||||
}
|
||||
}
|
||||
int bw = getBorderWidth(b);
|
||||
|
||||
Path2D border = new Path2D.Float(Path2D.WIND_EVEN_ODD);
|
||||
border.append(outerRect, false);
|
||||
|
||||
Rectangle innerRect = new Rectangle(outerRect);
|
||||
JBInsets.removeFrom(innerRect, JBUI.insets(bw));
|
||||
JBInsets.removeFrom(innerRect, JBUI.insets(getBorderWidth(b)));
|
||||
border.append(innerRect, false);
|
||||
|
||||
g2.setColor(color);
|
||||
g2.setColor(getBorderColor(b));
|
||||
if (!c.isEnabled()) {
|
||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, DISABLED_ALPHA_LEVEL));
|
||||
}
|
||||
|
||||
g2.fill(border);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static Color getBorderColor(AbstractButton b) {
|
||||
ButtonModel bm = b.getModel();
|
||||
|
||||
Color focusedBorderColor = (Color)b.getClientProperty("JButton.focusedBorderColor");
|
||||
if (bm.isPressed()) {
|
||||
return focusedBorderColor != null ?
|
||||
focusedBorderColor : UIManager.getColor("Button.intellij.native.pressedBorderColor");
|
||||
} else if (b.hasFocus() || bm.isRollover() || DarculaButtonUI.isDefaultButton(b)) {
|
||||
return focusedBorderColor != null ?
|
||||
focusedBorderColor : UIManager.getColor("Button.intellij.native.focusedBorderColor");
|
||||
} else {
|
||||
Color borderColor = (Color)b.getClientProperty("JButton.borderColor");
|
||||
return borderColor != null ? borderColor : UIManager.getColor("Button.intellij.native.borderColor");
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JBInsets getOuterInsets() {
|
||||
return JBUI.insets(1);
|
||||
|
||||
+37
-15
@@ -16,6 +16,7 @@
|
||||
package com.intellij.ide.ui.laf.intellij;
|
||||
|
||||
import com.intellij.ide.ui.laf.IconCache;
|
||||
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil;
|
||||
import com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI;
|
||||
import com.intellij.util.ui.JBInsets;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
@@ -73,8 +74,6 @@ public class WinIntelliJButtonUI extends DarculaButtonUI {
|
||||
help.paintIcon(c, g, i.left, i.top + (c.getHeight() - help.getIconHeight()) / 2);
|
||||
} else if (c instanceof AbstractButton) {
|
||||
AbstractButton b = (AbstractButton)c;
|
||||
ButtonModel bm = b.getModel();
|
||||
|
||||
Graphics2D g2 = (Graphics2D)g.create();
|
||||
try {
|
||||
Rectangle r = new Rectangle(c.getSize());
|
||||
@@ -89,15 +88,11 @@ public class WinIntelliJButtonUI extends DarculaButtonUI {
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, MacUIUtil.USE_QUARTZ ? RenderingHints.VALUE_STROKE_PURE : RenderingHints.VALUE_STROKE_NORMALIZE);
|
||||
|
||||
Color color = bm.isPressed() ? UIManager.getColor("Button.intellij.native.pressedBackgroundColor") :
|
||||
c.hasFocus() || bm.isRollover() ? UIManager.getColor("Button.intellij.native.focusedBackgroundColor") :
|
||||
c.getBackground();
|
||||
|
||||
if (!b.isEnabled()) {
|
||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, DISABLED_ALPHA_LEVEL));
|
||||
}
|
||||
|
||||
g2.setColor(color);
|
||||
g2.setColor(getBackgroundColor(b));
|
||||
g2.fill(r);
|
||||
|
||||
paintContents(g2, b);
|
||||
@@ -108,16 +103,11 @@ public class WinIntelliJButtonUI extends DarculaButtonUI {
|
||||
}
|
||||
|
||||
@Override protected void modifyViewRect(AbstractButton b, Rectangle rect) {
|
||||
if (!isComboButton(b)) {
|
||||
if (isComboButton(b)) {
|
||||
JBInsets.removeFrom(rect, JBUI.insetsLeft(6));
|
||||
} else {
|
||||
JBInsets.removeFrom(rect, b.getInsets());
|
||||
}
|
||||
|
||||
if (isComboButton(b)) {
|
||||
int delta = JBUI.scale(6);
|
||||
rect.x += delta;
|
||||
rect.width -= delta;
|
||||
}
|
||||
|
||||
rect.y -= JBUI.scale(1); // Move one pixel up
|
||||
}
|
||||
|
||||
@@ -151,4 +141,36 @@ public class WinIntelliJButtonUI extends DarculaButtonUI {
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Color getButtonTextColor(AbstractButton button) {
|
||||
Color focusedColor = (Color)button.getClientProperty("JButton.focusedTextColor");
|
||||
Color textColor = (Color)button.getClientProperty("JButton.textColor");
|
||||
|
||||
boolean focusedStyle = button.hasFocus() || button.getModel().isRollover();
|
||||
|
||||
if (focusedStyle && focusedColor != null) {
|
||||
return focusedColor;
|
||||
} else if (!focusedStyle && textColor != null) {
|
||||
return textColor;
|
||||
} else {
|
||||
return DarculaUIUtil.getButtonTextColor(button);
|
||||
}
|
||||
}
|
||||
|
||||
private static Color getBackgroundColor(AbstractButton b) {
|
||||
ButtonModel bm = b.getModel();
|
||||
|
||||
Color focusedColor = (Color)b.getClientProperty("JButton.focusedBackgroundColor");
|
||||
if (bm.isPressed()) {
|
||||
return focusedColor != null ?
|
||||
focusedColor : UIManager.getColor("Button.intellij.native.pressedBackgroundColor");
|
||||
} else if (b.hasFocus() || bm.isRollover()) {
|
||||
return focusedColor != null ?
|
||||
focusedColor :UIManager.getColor("Button.intellij.native.focusedBackgroundColor");
|
||||
} else {
|
||||
Color backgroundColor = (Color)b.getClientProperty("JButton.backgroundColor");
|
||||
return backgroundColor != null ? backgroundColor : b.getBackground();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.internal.ui;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
@SuppressWarnings("UseJBColor")
|
||||
public class ButtonStyleAction extends DumbAwareAction {
|
||||
private static final String TEXT_COLOR = "JButton.textColor";
|
||||
private static final String FOCUSED_TEXT_COLOR = "JButton.focusedTextColor";
|
||||
private static final String BACKGROUND_PROPERTY = "JButton.backgroundColor";
|
||||
private static final String FOCUSED_BACKGROUND_PROPERTY = "JButton.focusedBackgroundColor";
|
||||
private static final String BORDER_PROPERTY = "JButton.borderColor";
|
||||
private static final String FOCUSED_BORDER_PROPERTY = "JButton.focusedBorderColor";
|
||||
|
||||
private static final Color WHITE_BACKGROUND = new JBColor(Color.WHITE, new Color(0x3c3f41));
|
||||
private static final Color WHITE_FOREGROUND = new JBColor(Color.WHITE, new Color(0xbbbbbb));
|
||||
private static final Color GREEN_BACKGROUND = new JBColor(0x5d9b47, 0x457335);
|
||||
private static final Color GREEN_BORDER = new JBColor(0x5d9b47, 0x457335);
|
||||
private static final Color GREEN_FOCUSED_BACKGROUND = new Color(0xe1f6da);
|
||||
|
||||
private static final Color BLUE_BACKGROUND = new JBColor(0x1d73bf, 0x134d80);
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project != null) {
|
||||
new MyButtonStyleAction(project).show();
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyButtonStyleAction extends DialogWrapper {
|
||||
private MyButtonStyleAction(Project project) {
|
||||
super(project);
|
||||
init();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gc = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL,
|
||||
JBUI.insets(5), 0, 0);
|
||||
|
||||
JButton button1 = new JButton("Button 1");
|
||||
button1.putClientProperty(BACKGROUND_PROPERTY, WHITE_BACKGROUND);
|
||||
button1.putClientProperty(FOCUSED_BACKGROUND_PROPERTY, GREEN_FOCUSED_BACKGROUND);
|
||||
button1.putClientProperty(BORDER_PROPERTY, GREEN_BORDER);
|
||||
button1.putClientProperty(FOCUSED_BORDER_PROPERTY, GREEN_BORDER);
|
||||
button1.putClientProperty(FOCUSED_TEXT_COLOR, GREEN_BORDER);
|
||||
button1.putClientProperty(TEXT_COLOR, GREEN_BORDER);
|
||||
panel.add(button1, gc);
|
||||
|
||||
JButton button2 = new JButton("Button 2");
|
||||
//Color fg2 = button2.getForeground();
|
||||
//button2.setForeground(new JBColor(() -> button2.hasFocus() ? fg2 : Color.WHITE));
|
||||
button2.putClientProperty(TEXT_COLOR, WHITE_FOREGROUND);
|
||||
button2.putClientProperty(BACKGROUND_PROPERTY, BLUE_BACKGROUND);
|
||||
button2.putClientProperty(BORDER_PROPERTY, BLUE_BACKGROUND);
|
||||
gc.gridy++;
|
||||
panel.add(button2, gc);
|
||||
|
||||
JButton button3 = new JButton("Button 3");
|
||||
//Color fg3 = button3.getForeground();
|
||||
//button3.setForeground(new JBColor(() -> button3.hasFocus() ? fg3 : Color.WHITE));
|
||||
button3.putClientProperty(TEXT_COLOR, WHITE_FOREGROUND);
|
||||
button3.putClientProperty(BACKGROUND_PROPERTY, GREEN_BACKGROUND);
|
||||
button3.putClientProperty(FOCUSED_BACKGROUND_PROPERTY, GREEN_FOCUSED_BACKGROUND);
|
||||
button3.putClientProperty(BORDER_PROPERTY, GREEN_BORDER);
|
||||
button3.putClientProperty(FOCUSED_BORDER_PROPERTY, GREEN_BORDER);
|
||||
gc.gridy++;
|
||||
panel.add(button3, gc);
|
||||
|
||||
JButton button4 = new JButton("Button 4");
|
||||
gc.gridy++;
|
||||
panel.add(button4, gc);
|
||||
|
||||
gc.gridx++;
|
||||
gc.gridy = 0;
|
||||
gc.fill = GridBagConstraints.REMAINDER;
|
||||
gc.insets = JBUI.emptyInsets();
|
||||
gc.weightx = 1.0;
|
||||
panel.add(new JPanel(), gc);
|
||||
|
||||
gc.gridy++;
|
||||
panel.add(new JPanel(), gc);
|
||||
|
||||
gc.gridy++;
|
||||
panel.add(new JPanel(), gc);
|
||||
|
||||
gc.gridy++;
|
||||
panel.add(new JPanel(), gc);
|
||||
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -767,6 +767,7 @@
|
||||
text="Add Test Notification"/>
|
||||
<action id="TestMessageBoxAction" internal="true" class="com.intellij.diagnostic.TestMessageBoxAction" text="Show Test Dialog"/>
|
||||
<action id="ComponentPanelTestAction" internal="true" class="com.intellij.internal.ui.ComponentPanelTestAction" text="Show standard panels"/>
|
||||
<action id="ButtonStyleAction" internal="true" class="com.intellij.internal.ui.ButtonStyleAction" text="Button styles"/>
|
||||
<separator/>
|
||||
<action id="EditorRenderingBenchmarkAction" internal="true" class="com.intellij.internal.performance.EditorRenderingBenchmarkAction"
|
||||
text="Editor Rendering Benchmark"/>
|
||||
|
||||
Reference in New Issue
Block a user