IDEA-171869 Win10 LAF Slider reworked and minor fixes in buttons and fonts

This commit is contained in:
Kirill Kirichenko
2017-05-30 18:37:45 +03:00
parent 3315ae385a
commit d171314449
6 changed files with 258 additions and 19 deletions
@@ -54,7 +54,7 @@ public class IntelliJLaf extends DarculaLaf {
}
}, myDisposable);
if (UIUtil.isUnderWin10LookAndFeel()) {
if (UIUtil.isUnderWindowsLookAndFeel()) {
try {
final String name = UIManager.getSystemLookAndFeelClassName();
return (BasicLookAndFeel)Class.forName(name).newInstance();
@@ -34,6 +34,10 @@ import static com.intellij.ide.ui.laf.intellij.WinIntelliJButtonUI.DISABLED_ALPH
public class WinIntelliJButtonBorder implements Border, UIResource {
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
paint(c, g, x, y, width, height);
}
static void paint(Component c, Graphics g, int x, int y, int width, int height) {
if (!(c instanceof AbstractButton) || DarculaButtonUI.isHelpButton((JComponent)c)) return;
Graphics2D g2 = (Graphics2D)g.create();
@@ -50,11 +54,11 @@ public class WinIntelliJButtonBorder implements Border, UIResource {
if (!c.isEnabled()) {
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, DISABLED_ALPHA_LEVEL));
} else if (b.hasFocus() || bm.isRollover()) {
color = UIManager.getColor("Button.intellij.native.focusedBorderColor");
} else if (bm.isPressed()) {
color = UIManager.getColor("Button.intellij.native.pressedBorderColor");
} else {
} else if (b.hasFocus() || bm.isRollover()) {
color = UIManager.getColor("Button.intellij.native.focusedBorderColor");
} else {
if (DarculaButtonUI.isDefaultButton(b)) {
bw = JBUI.scale(2);
color = UIManager.getColor("Button.intellij.native.focusedBorderColor");
@@ -65,11 +65,6 @@ public class WinIntelliJButtonUI extends DarculaButtonUI {
@Override
public void paint(Graphics g, JComponent c) {
if (!(c.getBorder() instanceof WinIntelliJButtonBorder) && !isComboButton(c)) {
super.paint(g, c);
return;
}
if (isHelpButton(c)) {
Icon help = MacIntelliJIconCache.getIcon("winHelp");
Insets i = c.getInsets();
@@ -96,6 +91,11 @@ public class WinIntelliJButtonUI extends DarculaButtonUI {
g2.dispose();
}
}
// Draw border for emptyBorder buttons
if (!(c.getBorder() instanceof WinIntelliJButtonBorder) && !isComboButton(c)) {
WinIntelliJButtonBorder.paint(c, g, 0, 0, c.getWidth(), c.getHeight());
}
}
@Override
@@ -343,12 +343,6 @@ public class WinIntelliJComboBoxUI extends DarculaComboBoxUI {
@Override protected void configureEditor() {
super.configureEditor();
if (Registry.is("ide.ui.composite.editor.for.combobox")) { // Copy from DarculaComboBoxUI
if (editor instanceof JPanel) {
editor.setFocusable(false);
}
}
if (editor != null) {
editorFocusListener = new FocusAdapter() {
@Override public void focusGained(FocusEvent e) {
@@ -15,19 +15,256 @@
*/
package com.intellij.ide.ui.laf.intellij;
import com.sun.java.swing.plaf.windows.WindowsSliderUI;
import com.intellij.util.ui.JBDimension;
import com.intellij.util.ui.JBUI;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSliderUI;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
public class WinIntelliJSliderUI extends BasicSliderUI {
private static final String HOVER_PROPERTY = "JSlider.mouseHover";
private static final String PRESSED_PROPERTY = "JSlider.mousePressed";
// TODO: rework it. This is temporary solution to get rid of ugly basic
public class WinIntelliJSliderUI extends WindowsSliderUI {
private WinIntelliJSliderUI() {
super(null); // super constructor is no-op. JSlider is assigned in installUI
}
@SuppressWarnings("MethodOverridesStaticMethodOfSuperclass")
private MouseListener mouseListener;
private Color ticksColor;
@SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "unused"})
public static ComponentUI createUI(JComponent b) {
return new WinIntelliJSliderUI();
}
@Override protected void installListeners(JSlider slider) {
super.installListeners(slider);
mouseListener = new MouseAdapter() {
@Override public void mousePressed(MouseEvent e) {
setProperty(e, PRESSED_PROPERTY, Boolean.TRUE);
}
@Override public void mouseReleased(MouseEvent e) {
setProperty(e, PRESSED_PROPERTY, Boolean.FALSE);
}
@Override public void mouseEntered(MouseEvent e) {
setProperty(e, HOVER_PROPERTY, Boolean.TRUE);
}
@Override public void mouseExited(MouseEvent e) {
setProperty(e, HOVER_PROPERTY, Boolean.FALSE);
}
private void setProperty(MouseEvent e, String property, Boolean value) {
JComponent c = (JComponent)e.getComponent();
c.putClientProperty(property, value);
c.repaint();
}
};
slider.addMouseListener(mouseListener);
}
@Override protected void uninstallListeners( JSlider slider ) {
super.uninstallListeners(slider);
if (mouseListener != null) {
slider.removeMouseListener(mouseListener);
}
}
@Override public void paintTrack(Graphics g) {
Graphics2D g2 = (Graphics2D)g.create();
try {
Rectangle2D coloredTrack, scaleRect;
int tw = JBUI.scale(1);
if (slider.getOrientation() == SwingConstants.HORIZONTAL) {
coloredTrack = new Rectangle2D.Double(trackRect.x - thumbRect.width/2,
trackRect.y + trackRect.height - JBUI.scale(10),
thumbRect.x - trackRect.x + thumbRect.width,
tw);
scaleRect = new Rectangle2D.Double(thumbRect.x + thumbRect.width/2,
trackRect.y + trackRect.height - JBUI.scale(10),
trackRect.x + trackRect.width - thumbRect.x - tw,
tw);
} else {
coloredTrack = new Rectangle2D.Double(trackRect.x + thumbRect.width - JBUI.scale(10),
trackRect.y - thumbRect.height/2,
tw,
thumbRect.y - trackRect.y + thumbRect.height);
scaleRect = new Rectangle2D.Double(trackRect.x + thumbRect.width - JBUI.scale(10),
thumbRect.y + thumbRect.height/2,
tw,
trackRect.y + trackRect.height - thumbRect.y - tw);
}
g2.setColor(getSliderColor());
g2.fill(coloredTrack);
Color scaleColor = UIManager.getColor(slider.isEnabled() ? "Button.intellij.native.borderColor" : "Slider.disabledForeground");
g2.setColor(scaleColor);
g2.fill(scaleRect);
} finally {
g2.dispose();
}
}
@Override protected void calculateTrackRect() {
int centerSpacing; // used to center sliders added using BorderLayout.CENTER (bug 4275631)
if (slider.getOrientation() == SwingConstants.HORIZONTAL) {
centerSpacing = thumbRect.height;
if (slider.getPaintLabels()) centerSpacing += getHeightOfTallestLabel();
trackRect.setBounds(contentRect.x + trackBuffer,
contentRect.y + (contentRect.height - centerSpacing)/2,
contentRect.width - (trackBuffer * 2),
thumbRect.height);
} else {
centerSpacing = thumbRect.width;
int offset = JBUI.scale(6);
if (slider.getComponentOrientation().isLeftToRight()) {
if (slider.getPaintLabels()) {
centerSpacing += getWidthOfWidestLabel();
offset = -offset;
}
} else {
if (slider.getPaintLabels()) {
centerSpacing -= getWidthOfWidestLabel();
}
}
trackRect.setBounds(contentRect.x + (contentRect.width - centerSpacing)/2 + offset,
contentRect.y + trackBuffer,
thumbRect.width,
contentRect.height - (trackBuffer * 2));
}
}
@Override protected void calculateTickRect() {
super.calculateTickRect();
if ( slider.getOrientation() == SwingConstants.HORIZONTAL ) {
tickRect.y -= JBUI.scale(5);
} else {
if (slider.getComponentOrientation().isLeftToRight()) {
tickRect.x -= JBUI.scale(5);
} else {
tickRect.x = trackRect.x + JBUI.scale(5);
}
}
}
@Override protected void calculateLabelRect() {
super.calculateLabelRect();
if (slider.getPaintLabels()) {
if (slider.getOrientation() == SwingConstants.VERTICAL) {
int distance = JBUI.scale(11); // Count tickRect
labelRect.x += slider.getComponentOrientation().isLeftToRight() ? distance : -distance;
} else {
labelRect.y += JBUI.scale(6);
}
}
}
@Override protected Dimension getThumbSize() {
return slider.getOrientation() == SwingConstants.VERTICAL ? new JBDimension(22, 8) : new JBDimension(8, 22);
}
@Override public void paintThumb(Graphics g) {
Graphics2D g2 = (Graphics2D)g.create();
try {
g2.translate(thumbRect.x, thumbRect.y);
Path2D thumb = new Path2D.Double(Path2D.WIND_NON_ZERO);
if (slider.getOrientation() == SwingConstants.VERTICAL) {
if (slider.getComponentOrientation().isLeftToRight()) {
thumb.moveTo(0, 0);
thumb.lineTo(thumbRect.width - JBUI.scale(4), 0);
thumb.lineTo(thumbRect.width, thumbRect.height / 2);
thumb.lineTo(thumbRect.width - JBUI.scale(4), thumbRect.height);
thumb.lineTo(0, thumbRect.height);
} else {
thumb.moveTo(thumbRect.width, 0);
thumb.lineTo(thumbRect.width, thumbRect.height);
thumb.lineTo(JBUI.scale(4), thumbRect.height);
thumb.lineTo(0, thumbRect.height/2);
thumb.lineTo(JBUI.scale(4), 0);
}
} else {
thumb.moveTo(0, 0);
thumb.lineTo(thumbRect.width, 0);
thumb.lineTo(thumbRect.width, thumbRect.height - JBUI.scale(4));
thumb.lineTo(thumbRect.width / 2, thumbRect.height);
thumb.lineTo(0, thumbRect.height - JBUI.scale(4));
}
thumb.closePath();
g2.setColor(getSliderColor());
g2.fill(thumb);
} finally {
g2.dispose();
}
}
@Override protected int getTickLength() {
return JBUI.scale(4);
}
@Override protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
Rectangle2D tick = new Rectangle2D.Double(x - 0.5, 0, JBUI.scale(1), tickBounds.height);
paintSliderTick(g, tick);
}
@Override protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
paintMinorTickForHorizSlider(g, tickBounds, x);
}
@Override protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
Rectangle2D tick = new Rectangle2D.Double(0, y - 0.5, tickBounds.width, JBUI.scale(1));
paintSliderTick(g, tick);
}
@Override protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
paintMinorTickForVertSlider(g, tickBounds, y);
}
private void paintSliderTick(Graphics g, Rectangle2D shape) {
Graphics2D g2 = (Graphics2D)g.create();
try {
g2.setColor(ticksColor);
g2.fill(shape);
} finally {
g2.dispose();
}
}
@Override public void paintTicks(Graphics g) {
ticksColor = UIManager.getColor(slider.isEnabled() ? "Button.intellij.native.borderColor" : "Slider.disabledForeground");
super.paintTicks(g);
}
@Override public void paintFocus(Graphics g) {}
private Color getSliderColor() {
if (slider.isEnabled()) {
if (slider.getClientProperty(PRESSED_PROPERTY) == Boolean.TRUE) {
return UIManager.getColor("Slider.pressedColor");
} else if (slider.getClientProperty(HOVER_PROPERTY) == Boolean.TRUE || slider.hasFocus()) {
return UIManager.getColor("Slider.focusedColor");
} else {
return UIManager.getColor("Slider.foreground");
}
} else {
return UIManager.getColor("Slider.disabledForeground");
}
}
}
@@ -143,6 +143,10 @@ Spinner.border=com.intellij.ide.ui.laf.intellij.WinIntelliJSpinnerBorder
SplitPane.highlight=e8e8e8
SliderUI=com.intellij.ide.ui.laf.intellij.WinIntelliJSliderUI
Slider.foreground=6e6e6e
Slider.disabledForeground=c0c0c0
Slider.pressedColor=005499
Slider.focusedColor=0784de
TreeUI=com.intellij.ide.ui.laf.darcula.ui.DarculaTreeUI
Tree.background=ffffff