new button look

(cherry-picked from 6876db2)
This commit is contained in:
Konstantin Bulenkov
2012-11-28 07:43:25 +01:00
parent 61ae147776
commit 09d4da887f
2 changed files with 23 additions and 7 deletions
@@ -18,9 +18,9 @@ package com.intellij.ide.ui.laf.darcula.ui;
import com.intellij.ide.ui.laf.darcula.DarculaUIUtil;
import com.intellij.openapi.ui.GraphicsConfig;
import com.intellij.ui.Gray;
import com.intellij.util.ui.JBInsets;
import javax.swing.border.Border;
import javax.swing.plaf.InsetsUIResource;
import javax.swing.plaf.UIResource;
import java.awt.*;
@@ -28,13 +28,13 @@ import java.awt.*;
* @author Konstantin Bulenkov
*/
public class DarculaButtonPainter implements Border, UIResource {
private static final JBInsets myInsets = new JBInsets(6, 12, 6, 12);
private static final int myOffset = 4;
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
final Graphics2D g2d = (Graphics2D)g;
final int yOff = getBorderInsets(c).height() / 4;
final Insets ins = getBorderInsets(c);
final int yOff = (ins.top + ins.bottom) / 4;
int offset = getOffset();
if (c.hasFocus()) {
DarculaUIUtil.paintFocusRing(g2d, offset, yOff, width - 2 * offset, height - 2 * yOff);
@@ -42,7 +42,7 @@ public class DarculaButtonPainter implements Border, UIResource {
final GraphicsConfig config = new GraphicsConfig(g);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
g2d.setPaint(new GradientPaint(width / 2, y + yOff + 1, Gray._120.withAlpha(90), width / 2, height - 2*yOff, Gray._105.withAlpha(90)));
g2d.setPaint(new GradientPaint(width / 2, y + yOff + 1, Gray._80.withAlpha(90), width / 2, height - 2*yOff, Gray._90.withAlpha(90)));
g.drawRoundRect(x + offset + 1, y + yOff + 1, width - 2 * offset, height - 2*yOff, 5, 5);
((Graphics2D)g).setPaint(Gray._40.withAlpha(180));
@@ -53,8 +53,8 @@ public class DarculaButtonPainter implements Border, UIResource {
}
@Override
public JBInsets getBorderInsets(Component c) {
return myInsets;
public Insets getBorderInsets(Component c) {
return new InsetsUIResource(6, 12, 6, 12);
}
protected int getOffset() {
@@ -63,6 +63,6 @@ public class DarculaButtonPainter implements Border, UIResource {
@Override
public boolean isBorderOpaque() {
return true;
return false;
}
}
@@ -16,6 +16,7 @@
package com.intellij.ide.ui.laf.darcula.ui;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicButtonUI;
import java.awt.*;
@@ -31,6 +32,21 @@ public class DarculaButtonUI extends BasicButtonUI {
@Override
public void paint(Graphics g, JComponent c) {
if (c.isEnabled()) {
final Border border = c.getBorder();
if (border != null) {
final Insets ins = border.getBorderInsets(c);
final int yOff = (ins.top + ins.bottom) / 4;
if (((JButton)c).isDefaultButton()) {
((Graphics2D)g).setPaint(new GradientPaint(0, 0, new Color(0x384F6B), 0, c.getHeight(), new Color(0x233143)));
} else {
((Graphics2D)g).setPaint(new GradientPaint(0, 0, new Color(85, 90, 92), 0, c.getHeight(), new Color(65, 70, 72)));
}
g.fillRoundRect(5, yOff + 1, c.getWidth() - 2 * 4, c.getHeight() - 2 * yOff, 5, 5);
}
}
super.paint(g,c);
}
}