Browse Source

Improved slider thumb shape.

pull/173/head
weisj 5 years ago
parent
commit
818f651fe4
  1. 5
      core/src/main/java/com/github/weisj/darklaf/task/ThemeDefaultsInitTask.java
  2. 252
      core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java
  3. 17
      core/src/main/resources/com/github/weisj/darklaf/icons/control/slider.svg
  4. 17
      core/src/main/resources/com/github/weisj/darklaf/icons/control/sliderDisabled.svg
  5. 23
      core/src/main/resources/com/github/weisj/darklaf/icons/control/sliderFocused.svg
  6. 17
      core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSlider.svg
  7. 18
      core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSliderDisabled.svg
  8. 23
      core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSliderFocused.svg
  9. 48
      core/src/main/resources/com/github/weisj/darklaf/properties/icons/slider.properties
  10. 13
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/slider.properties

5
core/src/main/java/com/github/weisj/darklaf/task/ThemeDefaultsInitTask.java

@ -24,7 +24,6 @@
*/ */
package com.github.weisj.darklaf.task; package com.github.weisj.darklaf.task;
import java.awt.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.Properties; import java.util.Properties;
@ -49,8 +48,8 @@ public class ThemeDefaultsInitTask implements DefaultsInitTask {
"slider", "spinner", "splitPane", "statusBar", "slider", "spinner", "splitPane", "statusBar",
"tabbedPane", "tabFrame", "table", "taskPane", "text", "tabbedPane", "tabFrame", "table", "taskPane", "text",
"toggleButton", "toolBar", "toolTip", "tree", "misc"}; "toggleButton", "toolBar", "toolTip", "tree", "misc"};
private static final String[] ICON_PROPERTIES = new String[]{"checkBox", "radioButton", "dialog", "files", "frame", private static final String[] ICON_PROPERTIES = new String[]{"checkBox", "radioButton", "slider", "dialog", "files",
"indicator", "menu", "misc", "navigation"}; "frame", "indicator", "menu", "misc", "navigation"};
private final DefaultsAdjustmentTask userPreferenceAdjustment = new UserDefaultsAdjustmentTask(); private final DefaultsAdjustmentTask userPreferenceAdjustment = new UserDefaultsAdjustmentTask();
private final DefaultsAdjustmentTask accentColorAdjustment = new AccentColorAdjustmentTask(); private final DefaultsAdjustmentTask accentColorAdjustment = new AccentColorAdjustmentTask();
private final DefaultsAdjustmentTask foregroundGeneration = new ForegroundColorGenerationTask(); private final DefaultsAdjustmentTask foregroundGeneration = new ForegroundColorGenerationTask();

252
core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java

@ -27,11 +27,11 @@ package com.github.weisj.darklaf.ui.slider;
import java.awt.*; import java.awt.*;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.geom.Path2D;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.Dictionary; import java.util.Dictionary;
import java.util.Enumeration;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
@ -40,7 +40,10 @@ import javax.swing.plaf.basic.BasicSliderUI;
import com.github.weisj.darklaf.graphics.GraphicsContext; import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.GraphicsUtil; import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.graphics.PaintUtil; import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.icons.RotatableIcon;
import com.github.weisj.darklaf.listener.MouseClickListener; import com.github.weisj.darklaf.listener.MouseClickListener;
import com.github.weisj.darklaf.util.Alignment;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil; import com.github.weisj.darklaf.util.PropertyUtil;
@ -54,12 +57,9 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
public static final String KEY_SHOW_VOLUME_ICON = KEY_PREFIX + "volume.showIcon"; public static final String KEY_SHOW_VOLUME_ICON = KEY_PREFIX + "volume.showIcon";
public static final String KEY_VARIANT = KEY_PREFIX + "variant"; public static final String KEY_VARIANT = KEY_PREFIX + "variant";
public static final String KEY_INSTANT_SCROLL = KEY_PREFIX + "instantScrollEnabled"; public static final String KEY_INSTANT_SCROLL = KEY_PREFIX + "instantScrollEnabled";
public static final String KEY_SHOW_FOCUS_GLOW = KEY_PREFIX + "paintFocusGlow";
public static final String KEY_MANUAL_LABEL_ALIGN = KEY_PREFIX + "manualLabelAlign"; public static final String KEY_MANUAL_LABEL_ALIGN = KEY_PREFIX + "manualLabelAlign";
public static final String VARIANT_VOLUME = "volume"; public static final String VARIANT_VOLUME = "volume";
private static final int ICON_BAR_EXT = 5;
private static final int ICON_PAD = 10;
private final Rectangle iconRect = new Rectangle(0, 0, 0, 0); private final Rectangle iconRect = new Rectangle(0, 0, 0, 0);
private final MouseListener mouseListener = new MouseClickListener() { private final MouseListener mouseListener = new MouseClickListener() {
private boolean muted = false; private boolean muted = false;
@ -82,6 +82,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
protected int plainThumbRadius; protected int plainThumbRadius;
protected int arcSize; protected int arcSize;
protected int trackSize; protected int trackSize;
protected int iconPad;
protected Dimension thumbSize; protected Dimension thumbSize;
protected Color inactiveTickForeground; protected Color inactiveTickForeground;
protected Color trackBackground; protected Color trackBackground;
@ -94,8 +95,19 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
protected Color volumeThumbBackground; protected Color volumeThumbBackground;
protected Color volumeThumbInactiveBackground; protected Color volumeThumbInactiveBackground;
protected Color thumbBorderColor; protected Color thumbBorderColor;
protected Color thumbFocusBorderColor;
protected Color thumbInactiveBorderColor; protected Color thumbInactiveBorderColor;
protected RotatableIcon rotatableIcon;
protected Icon thumb;
protected Icon thumbDisabled;
protected Icon thumbFocused;
protected Icon volumeThumb;
protected Icon volumeThumbDisabled;
protected Icon volumeThumbFocused;
protected Icon volume0; protected Icon volume0;
protected Icon volume1; protected Icon volume1;
protected Icon volume2; protected Icon volume2;
@ -108,6 +120,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
protected Icon volume4Inactive; protected Icon volume4Inactive;
protected int focusBorderSize; protected int focusBorderSize;
protected boolean paintFocus;
protected RoundRectangle2D trackShape = new RoundRectangle2D.Double(); protected RoundRectangle2D trackShape = new RoundRectangle2D.Double();
public DarkSliderUI(final JSlider b) { public DarkSliderUI(final JSlider b) {
@ -119,7 +132,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
} }
private static boolean showVolumeIcon(final JComponent c) { private static boolean showVolumeIcon(final JComponent c) {
return isVolumeSlider(c) && PropertyUtil.getBooleanProperty(c, KEY_SHOW_VOLUME_ICON); return PropertyUtil.getBooleanProperty(c, KEY_SHOW_VOLUME_ICON);
} }
private static boolean isVolumeSlider(final JComponent c) { private static boolean isVolumeSlider(final JComponent c) {
@ -155,36 +168,44 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
} }
} }
@Override
protected void calculateFocusRect() {
focusRect.setRect(0, 0, slider.getWidth(), slider.getHeight());
DarkUIUtil.applyInsets(focusRect, focusInsets);
}
@Override @Override
protected void calculateContentRect() { protected void calculateContentRect() {
super.calculateContentRect(); contentRect.setRect(focusRect);
boolean horizontal = slider.getOrientation() == JSlider.HORIZONTAL;
if (showVolumeIcon(slider)) { if (showVolumeIcon(slider)) {
if (isHorizontal()) { if (horizontal) {
contentRect.width -= getVolumeIcon().getIconWidth() + ICON_PAD; contentRect.width -= getVolumeIcon().getIconWidth() + iconPad;
if (!slider.getComponentOrientation().isLeftToRight()) { if (!slider.getComponentOrientation().isLeftToRight()) {
contentRect.x += getVolumeIcon().getIconWidth() + ICON_PAD; contentRect.x += getVolumeIcon().getIconWidth() + iconPad;
} }
} else { } else {
contentRect.height -= getVolumeIcon().getIconHeight() + ICON_PAD; contentRect.height -= getVolumeIcon().getIconHeight() + iconPad;
if (!slider.getComponentOrientation().isLeftToRight()) { if (!slider.getComponentOrientation().isLeftToRight()) {
contentRect.y += getVolumeIcon().getIconHeight() + ICON_PAD; contentRect.y += getVolumeIcon().getIconHeight() + iconPad;
} }
} }
} }
} if (horizontal) {
int thumbWidth = getThumbWidth();
@Override contentRect.x += thumbWidth / 2;
protected void calculateTrackBuffer() { contentRect.width -= thumbWidth;
super.calculateTrackBuffer(); } else {
if (slider.getOrientation() == JSlider.HORIZONTAL) { int thumbHeight = getThumbHeight();
trackBuffer = 0; contentRect.y += thumbHeight / 2;
contentRect.height -= thumbHeight;
} }
adjustRect(contentRect);
} }
@Override @Override
protected void calculateTrackRect() { protected void calculateTrackBuffer() {
super.calculateTrackRect(); trackBuffer = 0;
adjustRect(trackRect);
} }
@Override @Override
@ -293,29 +314,13 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
protected void adjustRect(final Rectangle rectangle, final boolean outwards) { protected void adjustRect(final Rectangle rectangle, final boolean outwards) {
boolean horizontal = slider.getOrientation() == JSlider.HORIZONTAL; boolean horizontal = slider.getOrientation() == JSlider.HORIZONTAL;
if (horizontal) {
boolean ltr = slider.getComponentOrientation().isLeftToRight();
int left = ltr ? focusInsets.left : focusInsets.right;
int right = ltr ? focusInsets.right : focusInsets.left;
rectangle.x += left;
rectangle.width -= left + right;
} else {
rectangle.y += focusInsets.top;
rectangle.height -= focusInsets.top + focusInsets.bottom;
}
Dictionary<?, ?> dict = slider.getLabelTable(); Dictionary<?, ?> dict = slider.getLabelTable();
if (!slider.getPaintLabels() || dict == null || dict.isEmpty() || !horizontal) { if (!slider.getPaintLabels() || dict == null || dict.isEmpty() || !horizontal) {
return; return;
} }
int extra = getLowerHorizontalExtend(); int extra = getLowerHorizontalExtend();
int extend = getUpperHorizontalExtend(); int extend = getUpperHorizontalExtend();
int thumbWidth = getThumbWidth() / 2;
int factor = outwards ? 1 : -1; int factor = outwards ? 1 : -1;
extra -= thumbWidth;
extend -= thumbWidth;
rectangle.x -= factor * extra; rectangle.x -= factor * extra;
rectangle.width += factor * (extra + extend); rectangle.width += factor * (extra + extend);
} }
@ -327,7 +332,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
boolean adjustMin = PropertyUtil.getBooleanProperty(minLabel, KEY_MANUAL_LABEL_ALIGN); boolean adjustMin = PropertyUtil.getBooleanProperty(minLabel, KEY_MANUAL_LABEL_ALIGN);
int minPrefWidth = minLabel.getPreferredSize().width; int minPrefWidth = minLabel.getPreferredSize().width;
float adj = (adjustMin ? minLabel.getAlignmentX() : Component.CENTER_ALIGNMENT); float adj = (adjustMin ? minLabel.getAlignmentX() : Component.CENTER_ALIGNMENT);
return (int) (minPrefWidth * adj) + (ltr ? focusInsets.left : focusInsets.right); return (int) (minPrefWidth * adj);
} }
protected int getUpperHorizontalExtend() { protected int getUpperHorizontalExtend() {
@ -337,23 +342,35 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
boolean adjustMax = PropertyUtil.getBooleanProperty(maxLabel, KEY_MANUAL_LABEL_ALIGN); boolean adjustMax = PropertyUtil.getBooleanProperty(maxLabel, KEY_MANUAL_LABEL_ALIGN);
int maxPrefWidth = maxLabel.getPreferredSize().width; int maxPrefWidth = maxLabel.getPreferredSize().width;
float adj = (adjustMax ? maxLabel.getAlignmentX() : Component.CENTER_ALIGNMENT); float adj = (adjustMax ? maxLabel.getAlignmentX() : Component.CENTER_ALIGNMENT);
return (int) (maxPrefWidth * (1f - adj)) + (ltr ? focusInsets.right : focusInsets.left); return (int) (maxPrefWidth * (1f - adj));
} }
@Override
public Dimension getPreferredHorizontalSize() { public Dimension getPreferredHorizontalSize() {
Dimension dim = super.getPreferredHorizontalSize(); Dimension dim = super.getPreferredHorizontalSize();
Rectangle rect = new Rectangle(0, 0, 0, 0); Rectangle rect = new Rectangle(0, 0, 0, 0);
rect.setSize(dim); rect.setSize(dim);
adjustRect(rect, true); adjustRect(rect, true);
Dictionary<?, ?> dict = slider.getLabelTable();
if (dict != null && !dict.isEmpty()) {
int totalLabelWidth = 0;
Enumeration<?> labels = dict.elements();
while (labels.hasMoreElements()) {
Object obj = labels.nextElement();
if (obj instanceof Component) {
totalLabelWidth += ((Component) obj).getPreferredSize().width;
}
}
totalLabelWidth += getThumbWidth();
rect.width = Math.max(rect.width, totalLabelWidth);
}
return rect.getSize(); return rect.getSize();
} }
@Override @Override
public Dimension getThumbSize() { public Dimension getThumbSize() {
if (isPlainThumb()) { if (isPlainThumb()) {
return new Dimension(plainThumbRadius + 2 * focusBorderSize, int bw = 2 * getFocusBorderSize();
plainThumbRadius + 2 * focusBorderSize); return new Dimension(plainThumbRadius + bw, plainThumbRadius + bw);
} }
return isHorizontal() return isHorizontal()
? new Dimension(thumbSize.width, thumbSize.height) ? new Dimension(thumbSize.width, thumbSize.height)
@ -455,15 +472,12 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
public void paintThumb(final Graphics g2) { public void paintThumb(final Graphics g2) {
Graphics2D g = (Graphics2D) g2; Graphics2D g = (Graphics2D) g2;
GraphicsContext context = GraphicsUtil.setupStrokePainting(g); GraphicsContext context = GraphicsUtil.setupStrokePainting(g);
g.translate(thumbRect.x, thumbRect.y);
if (isPlainThumb()) { if (isPlainThumb()) {
paintPlainSliderThumb(g); paintPlainSliderThumb(g);
} else { } else {
paintSliderThumb(g); paintSliderThumb(g);
} }
g.translate(-thumbRect.x, -thumbRect.y);
context.restore(); context.restore();
} }
@ -493,12 +507,6 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
return inactiveTickForeground; return inactiveTickForeground;
} }
@Override
public void installUI(final JComponent c) {
super.installUI(c);
slider.putClientProperty(KEY_SHOW_FOCUS_GLOW, UIManager.getBoolean("Slider.paintFocusGlow"));
}
@Override @Override
protected void installDefaults(final JSlider slider) { protected void installDefaults(final JSlider slider) {
super.installDefaults(slider); super.installDefaults(slider);
@ -507,6 +515,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
trackSize = UIManager.getInt("Slider.trackThickness"); trackSize = UIManager.getInt("Slider.trackThickness");
plainThumbRadius = UIManager.getInt("Slider.plainThumbRadius"); plainThumbRadius = UIManager.getInt("Slider.plainThumbRadius");
thumbSize = UIManager.getDimension("Slider.thumbSize"); thumbSize = UIManager.getDimension("Slider.thumbSize");
iconPad = UIManager.getInt("Slider.iconPad");
inactiveTickForeground = UIManager.getColor("Slider.disabledTickColor"); inactiveTickForeground = UIManager.getColor("Slider.disabledTickColor");
trackBackground = UIManager.getColor("Slider.trackBackground"); trackBackground = UIManager.getColor("Slider.trackBackground");
selectedTrackBackground = UIManager.getColor("Slider.selectedTrackColor"); selectedTrackBackground = UIManager.getColor("Slider.selectedTrackColor");
@ -518,8 +527,18 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
volumeThumbBackground = UIManager.getColor("Slider.volume.activeThumbFill"); volumeThumbBackground = UIManager.getColor("Slider.volume.activeThumbFill");
volumeThumbInactiveBackground = UIManager.getColor("Slider.volume.inactiveThumbFill"); volumeThumbInactiveBackground = UIManager.getColor("Slider.volume.inactiveThumbFill");
thumbBorderColor = UIManager.getColor("Slider.thumbBorderColor"); thumbBorderColor = UIManager.getColor("Slider.thumbBorderColor");
thumbFocusBorderColor = UIManager.getColor("Slider.thumbFocusBorderColor");
thumbInactiveBorderColor = UIManager.getColor("Slider.thumbBorderColorDisabled"); thumbInactiveBorderColor = UIManager.getColor("Slider.thumbBorderColorDisabled");
focusBorderSize = UIManager.getInt("Slider.focusBorderSize"); focusBorderSize = UIManager.getInt("Slider.focusBorderSize");
paintFocus = UIManager.getBoolean("Slider.paintFocusGlow");
thumb = UIManager.getIcon("Slider.enabledThumb.icon");
thumbDisabled = UIManager.getIcon("Slider.disabledThumb.icon");
thumbFocused = UIManager.getIcon("Slider.focusedThumb.icon");
volumeThumb = UIManager.getIcon("Slider.volume.enabledThumb.icon");
volumeThumbDisabled = UIManager.getIcon("Slider.volume.disabledThumb.icon");
volumeThumbFocused = UIManager.getIcon("Slider.volume.focusedThumb.icon");
volume0 = UIManager.getIcon("Slider.volume.enabled_level_0.icon"); volume0 = UIManager.getIcon("Slider.volume.enabled_level_0.icon");
volume1 = UIManager.getIcon("Slider.volume.enabled_level_1.icon"); volume1 = UIManager.getIcon("Slider.volume.enabled_level_1.icon");
@ -531,26 +550,34 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
volume2Inactive = UIManager.getIcon("Slider.volume.disabled_level_2.icon"); volume2Inactive = UIManager.getIcon("Slider.volume.disabled_level_2.icon");
volume3Inactive = UIManager.getIcon("Slider.volume.disabled_level_3.icon"); volume3Inactive = UIManager.getIcon("Slider.volume.disabled_level_3.icon");
volume4Inactive = UIManager.getIcon("Slider.volume.disabled_level_4.icon"); volume4Inactive = UIManager.getIcon("Slider.volume.disabled_level_4.icon");
rotatableIcon = new RotatableIcon();
}
public int getFocusBorderSize() {
return paintFocus ? focusBorderSize : 0;
} }
protected void calculateIconRect() { protected void calculateIconRect() {
iconRect.width = getVolumeIcon().getIconWidth(); iconRect.width = getVolumeIcon().getIconWidth();
iconRect.height = getVolumeIcon().getIconHeight(); iconRect.height = getVolumeIcon().getIconHeight();
if (isHorizontal()) { if (isHorizontal()) {
int extraSpace = iconPad + getThumbWidth() / 2;
if (slider.getComponentOrientation().isLeftToRight()) { if (slider.getComponentOrientation().isLeftToRight()) {
iconRect.x = trackRect.x + trackRect.width + ICON_PAD; iconRect.x = trackRect.x + trackRect.width + extraSpace;
iconRect.y = trackRect.y + (trackRect.height - iconRect.height) / 2; iconRect.y = trackRect.y + (trackRect.height - iconRect.height) / 2;
} else { } else {
iconRect.x = trackRect.x - iconRect.width - ICON_PAD; iconRect.x = trackRect.x - iconRect.width - extraSpace;
iconRect.y = trackRect.y + (trackRect.height - iconRect.height) / 2; iconRect.y = trackRect.y + (trackRect.height - iconRect.height) / 2;
} }
} else { } else {
int extraSpace = iconPad + getThumbHeight() / 2;
if (slider.getComponentOrientation().isLeftToRight()) { if (slider.getComponentOrientation().isLeftToRight()) {
iconRect.x = trackRect.x + (trackRect.width - iconRect.width) / 2; iconRect.x = trackRect.x + (trackRect.width - iconRect.width) / 2;
iconRect.y = trackRect.y + trackRect.height + ICON_PAD; iconRect.y = trackRect.y + trackRect.height + extraSpace;
} else { } else {
iconRect.x = trackRect.x + (trackRect.width - iconRect.width) / 2; iconRect.x = trackRect.x + (trackRect.width - iconRect.width) / 2;
iconRect.y = trackRect.y - iconRect.height - ICON_PAD; iconRect.y = trackRect.y - iconRect.height - extraSpace;
} }
} }
} }
@ -591,11 +618,11 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
private Shape getHorizontalTrackShape(final RoundRectangle2D trackShape) { private Shape getHorizontalTrackShape(final RoundRectangle2D trackShape) {
int arc = arcSize; int arc = arcSize;
int yOff = (trackRect.height / 2) - trackSize / 2; int yOff = (trackRect.height / 2) - trackSize / 2;
int w = showVolumeIcon(slider) ? trackRect.width + getIconBarExt() : trackRect.width; int w = trackRect.width;
if (slider.getComponentOrientation().isLeftToRight()) { if (slider.getComponentOrientation().isLeftToRight()) {
trackShape.setRoundRect(trackRect.x, trackRect.y + yOff, w, trackSize, arc, arc); trackShape.setRoundRect(trackRect.x, trackRect.y + yOff, w, trackSize, arc, arc);
} else { } else {
trackShape.setRoundRect(trackRect.x - getIconBarExt(), trackRect.y + yOff, w, trackSize, arc, arc); trackShape.setRoundRect(trackRect.x, trackRect.y + yOff, w, trackSize, arc, arc);
} }
return trackShape; return trackShape;
} }
@ -612,22 +639,19 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
private Shape getVerticalTrackShape(final RoundRectangle2D trackShape) { private Shape getVerticalTrackShape(final RoundRectangle2D trackShape) {
int arc = arcSize; int arc = arcSize;
int xOff = (trackRect.width / 2) - trackSize / 2; int xOff = (trackRect.width / 2) - trackSize / 2;
int h = showVolumeIcon(slider) ? trackRect.height + getIconBarExt() : trackRect.height; int h = trackRect.height;
if (slider.getComponentOrientation().isLeftToRight()) { if (slider.getComponentOrientation().isLeftToRight()) {
trackShape.setRoundRect(trackRect.x + xOff, trackRect.y, trackSize, h, arc, arc); trackShape.setRoundRect(trackRect.x + xOff, trackRect.y, trackSize, h, arc, arc);
} else { } else {
trackShape.setRoundRect(trackRect.x + xOff, trackRect.y - getIconBarExt(), trackSize, h, arc, arc); trackShape.setRoundRect(trackRect.x + xOff, trackRect.y, trackSize, h, arc, arc);
} }
return trackShape; return trackShape;
} }
private int getIconBarExt() {
return isPlainThumb() && showVolumeIcon(slider) ? ICON_BAR_EXT : 0;
}
private void paintPlainSliderThumb(final Graphics2D g) { private void paintPlainSliderThumb(final Graphics2D g) {
g.translate(thumbRect.x, thumbRect.y);
int r = plainThumbRadius; int r = plainThumbRadius;
int bw = focusBorderSize; int bw = getFocusBorderSize();
g.setColor(getThumbColor()); g.setColor(getThumbColor());
PaintUtil.fillRoundRect(g, bw, bw, r, r, r); PaintUtil.fillRoundRect(g, bw, bw, r, r, r);
if (!isVolumeSlider(slider)) { if (!isVolumeSlider(slider)) {
@ -637,30 +661,50 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
if (paintFocus()) { if (paintFocus()) {
PaintUtil.paintFocusBorder(g, r + 2 * bw, r + 2 * bw, r + 2 * bw, bw); PaintUtil.paintFocusBorder(g, r + 2 * bw, r + 2 * bw, r + 2 * bw, bw);
} }
g.translate(-thumbRect.x, -thumbRect.y);
} }
protected boolean isPlainThumb() { protected boolean isPlainThumb() {
return !slider.getPaintTicks() || !PropertyUtil.getBooleanProperty(slider, KEY_THUMB_ARROW_SHAPE, true); return !slider.getPaintTicks() || !PropertyUtil.getBooleanProperty(slider, KEY_THUMB_ARROW_SHAPE, true);
} }
protected Icon getThumbIcon() {
boolean enabled = slider.isEnabled();
boolean focused = slider.hasFocus();
boolean volume = isVolumeSlider(slider);
Icon icon;
if (volume) {
icon = enabled ? focused ? volumeThumbFocused : volumeThumb : volumeThumbDisabled;
} else {
icon = enabled ? focused ? thumbFocused : thumb : thumbDisabled;
}
rotatableIcon.setIcon(icon);
if (isHorizontal()) {
rotatableIcon.setOrientation(Alignment.NORTH);
} else {
if (slider.getComponentOrientation().isLeftToRight()) {
rotatableIcon.setOrientation(Alignment.WEST);
} else {
rotatableIcon.setOrientation(Alignment.EAST);
}
}
return rotatableIcon;
}
private void paintSliderThumb(final Graphics2D g) { private void paintSliderThumb(final Graphics2D g) {
Path2D thumb = getThumbShape(); if (isHorizontal()) {
if (paintFocus()) { getThumbIcon().paintIcon(slider, g, thumbRect.x, thumbRect.y);
GraphicsContext config = new GraphicsContext(g); } else {
g.setComposite(PaintUtil.getGlowComposite()); int cx = thumbRect.x + thumbRect.width / 2;
g.setStroke(new BasicStroke(4f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 8)); int cy = thumbRect.y + thumbRect.height / 2;
PaintUtil.Outline.focus.setGraphicsColor(g, true); int x = cx - thumbRect.height / 2;
g.draw(thumb); int y = cy - thumbRect.width / 2;
config.restore(); getThumbIcon().paintIcon(slider, g, x, y);
} }
g.setColor(getThumbColor());
g.fill(thumb);
g.setColor(getThumbBorderColor());
g.draw(thumb);
} }
private boolean paintFocus() { private boolean paintFocus() {
return slider.hasFocus() && PropertyUtil.getBooleanProperty(slider, KEY_SHOW_FOCUS_GLOW); return slider.hasFocus() && paintFocus;
} }
protected int getThumbWidth() { protected int getThumbWidth() {
@ -671,58 +715,6 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
return thumbRect.height; return thumbRect.height;
} }
private Path2D getThumbShape() {
if (isHorizontal()) {
return getHorizontalThumbShape();
} else if (slider.getComponentOrientation().isLeftToRight()) {
return getVerticalThumbShapeLR();
} else {
return getVerticalThumbShapeRL();
}
}
private Path2D getHorizontalThumbShape() {
int w = thumbRect.width;
int h = thumbRect.height;
int cw = w / 2;
Path2D shape = new Path2D.Float(Path2D.WIND_EVEN_ODD);
shape.moveTo(1, 1);
shape.lineTo(w - 2, 1);
shape.lineTo(w - 2, h - cw - 1);
shape.lineTo(cw, h - 2);
shape.lineTo(1, h - cw - 1);
shape.closePath();
return shape;
}
private Path2D getVerticalThumbShapeLR() {
int w = thumbRect.width;
int h = thumbRect.height;
int cw = h / 2;
Path2D shape = new Path2D.Float(Path2D.WIND_EVEN_ODD);
shape.moveTo(2, 1);
shape.lineTo(w - cw - 1, 1);
shape.lineTo(w - 1, h - cw);
shape.lineTo(w - cw - 1, h - 2);
shape.lineTo(2, h - 2);
shape.closePath();
return shape;
}
private Path2D getVerticalThumbShapeRL() {
int w = thumbRect.width;
int h = thumbRect.height;
int cw = h / 2;
Path2D shape = new Path2D.Float(Path2D.WIND_EVEN_ODD);
shape.moveTo(w - 2, 1);
shape.lineTo(cw + 1, 1);
shape.lineTo(1, h - cw);
shape.lineTo(cw + 1, h - 2);
shape.lineTo(w - 2, h - 2);
shape.closePath();
return shape;
}
protected Color getThumbColor() { protected Color getThumbColor() {
if (isVolumeSlider(slider)) { if (isVolumeSlider(slider)) {
return slider.isEnabled() ? volumeThumbBackground : volumeThumbInactiveBackground; return slider.isEnabled() ? volumeThumbBackground : volumeThumbInactiveBackground;
@ -732,7 +724,7 @@ public class DarkSliderUI extends BasicSliderUI implements PropertyChangeListene
} }
protected Color getThumbBorderColor() { protected Color getThumbBorderColor() {
return slider.isEnabled() ? thumbBorderColor : thumbInactiveBorderColor; return slider.isEnabled() ? paintFocus() ? thumbFocusBorderColor : thumbBorderColor : thumbInactiveBorderColor;
} }
protected Color getTrackBackground() { protected Color getTrackBackground() {

17
core/src/main/resources/com/github/weisj/darklaf/icons/control/slider.svg

@ -0,0 +1,17 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="23" viewBox="0 0 20 23">
<defs id="colors">
<linearGradient id="Icons.Slider.activeFillColor">
<stop offset="0" stop-color="#43494A"/>
<stop offset="1" stop-color="#43494A"/>
</linearGradient>
<linearGradient id="Icons.Slider.borderColor">
<stop offset="0" stop-color="#6B6B6B"/>
<stop offset="1" stop-color="#6B6B6B"/>
</linearGradient>
</defs>
<g transform="translate(2,2)">
<path fill="url(#Icons.Slider.borderColor)"
d="M15,1v9.6l-7,7l-7-7V1H15 M16,0H0v11l8,8l8-8V0L16,0z"/>
<polyline fill="url(#Icons.Slider.activeFillColor)" points="15,1 15,10.6 8,17.6 1,10.6 1,1 15,1 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 776 B

17
core/src/main/resources/com/github/weisj/darklaf/icons/control/sliderDisabled.svg

@ -0,0 +1,17 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="23" viewBox="0 0 20 22">
<defs id="colors">
<linearGradient id="Icons.SliderDisabled.inactiveFillColor">
<stop offset="0" stop-color="#3C3F41"/>
<stop offset="1" stop-color="#3C3F41"/>
</linearGradient>
<linearGradient id="Icons.SliderDisabled.inactiveBorderColor">
<stop offset="0" stop-color="#545556"/>
<stop offset="1" stop-color="#545556"/>
</linearGradient>
</defs>
<g transform="translate(2,1)">
<path fill="url(#Icons.SliderDisabled.inactiveBorderColor)"
d="M15,1v9.6l-7,7l-7-7V1H15 M16,0H0v11l8,8l8-8V0L16,0z"/>
<polyline fill="url(#Icons.SliderDisabled.inactiveFillColor)" points="15,1 15,10.6 8,17.6 1,10.6 1,1 15,1 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 828 B

23
core/src/main/resources/com/github/weisj/darklaf/icons/control/sliderFocused.svg

@ -0,0 +1,23 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="23" viewBox="0 0 20 23">
<defs id="colors">
<linearGradient id="Icons.SliderFocused.activeFillColor">
<stop offset="0" stop-color="#43494A"/>
<stop offset="1" stop-color="#43494A"/>
</linearGradient>
<linearGradient id="Icons.SliderFocused.focusBorderColor">
<stop offset="0" stop-color="#466D94"/>
<stop offset="1" stop-color="#466D94"/>
</linearGradient>
<linearGradient id="Icons.SliderFocused.glowFocus" opacity="Icons.SliderFocused.glowOpacity">
<stop offset="0" stop-color="#3e84c9" stop-opacity="0.5"/>
<stop offset="1" stop-color="#3e84c9" stop-opacity="0.5"/>
</linearGradient>
</defs>
<g transform="translate(2,2)">
<path fill="url(#Icons.SliderFocused.glowFocus)" d="M16,0C16,0,16,0,16,0l0,11l-8,8H8l-8-8V0c0,0,0,0,0,0H16 M16-2H0c-1.1,0-2,0.9-2,2V11c0,0.5,0.2,1.1,0.6,1.4
l8,8C7,20.8,7.5,21,8,21s1-0.2,1.4-0.6l8-8C17.8,12,18,11.5,18,11V0C18-1.1,17.1-2,16-2L16-2z"/>
<path fill="url(#Icons.SliderFocused.focusBorderColor)"
d="M15,1v9.6l-7,7l-7-7V1H15 M16,0H0v11l8,8l8-8V0L16,0z"/>
<polyline fill="url(#Icons.SliderFocused.activeFillColor)" points="15,1 15,10.6 8,17.6 1,10.6 1,1 15,1 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

17
core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSlider.svg

@ -0,0 +1,17 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="23" viewBox="0 0 20 23">
<defs id="colors">
<linearGradient id="Icons.VolumeSlider.activeFillColor">
<stop offset="0" stop-color="#A0A0A0"/>
<stop offset="1" stop-color="#A0A0A0"/>
</linearGradient>
<linearGradient id="Icons.VolumeSlider.borderColor">
<stop offset="0" stop-color="#6B6B6B"/>
<stop offset="1" stop-color="#6B6B6B"/>
</linearGradient>
</defs>
<g transform="translate(2,2)">
<path fill="url(#Icons.VolumeSlider.borderColor)"
d="M15,1v9.6l-7,7l-7-7V1H15 M16,0H0v11l8,8l8-8V0L16,0z"/>
<polyline fill="url(#Icons.VolumeSlider.activeFillColor)" points="15,1 15,10.6 8,17.6 1,10.6 1,1 15,1 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 800 B

18
core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSliderDisabled.svg

@ -0,0 +1,18 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="23" viewBox="0 0 20 23">
<defs id="colors">
<linearGradient id="Icons.VolumeSliderDisabled.inactiveFillColor">
<stop offset="0" stop-color="#3C3F41"/>
<stop offset="1" stop-color="#3C3F41"/>
</linearGradient>
<linearGradient id="Icons.VolumeSliderDisabled.inactiveBorderColor">
<stop offset="0" stop-color="#545556"/>
<stop offset="1" stop-color="#545556"/>
</linearGradient>
</defs>
<g transform="translate(2,2)">
<path fill="url(#Icons.VolumeSliderDisabled.inactiveBorderColor)"
d="M15,1v9.6l-7,7l-7-7V1H15 M16,0H0v11l8,8l8-8V0L16,0z"/>
<polyline fill="url(#Icons.VolumeSliderDisabled.inactiveFillColor)"
points="15,1 15,10.6 8,17.6 1,10.6 1,1 15,1 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 870 B

23
core/src/main/resources/com/github/weisj/darklaf/icons/control/volumeSliderFocused.svg

@ -0,0 +1,23 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="23" viewBox="0 0 20 23">
<defs id="colors">
<linearGradient id="Icons.VolumeSliderFocused.activeFillColor">
<stop offset="0" stop-color="#A0A0A0"/>
<stop offset="1" stop-color="#A0A0A0"/>
</linearGradient>
<linearGradient id="Icons.VolumeSliderFocused.focusBorderColor">
<stop offset="0" stop-color="#466D94"/>
<stop offset="1" stop-color="#466D94"/>
</linearGradient>
<linearGradient id="Icons.VolumeSliderFocused.glowFocus" opacity="Icons.VolumeSlider.glowOpacity">
<stop offset="0" stop-color="#3e84c9" stop-opacity="0.5"/>
<stop offset="1" stop-color="#3e84c9" stop-opacity="0.5"/>
</linearGradient>
</defs>
<g transform="translate(2,2)">
<path fill="url(#Icons.VolumeSliderFocused.glowFocus)" d="M16,0C16,0,16,0,16,0l0,11l-8,8H8l-8-8V0c0,0,0,0,0,0H16 M16-2H0c-1.1,0-2,0.9-2,2V11c0,0.5,0.2,1.1,0.6,1.4
l8,8C7,20.8,7.5,21,8,21s1-0.2,1.4-0.6l8-8C17.8,12,18,11.5,18,11V0C18-1.1,17.1-2,16-2L16-2z"/>
<path fill="url(#Icons.VolumeSliderFocused.focusBorderColor)"
d="M15,1v9.6l-7,7l-7-7V1H15 M16,0H0v11l8,8l8-8V0L16,0z"/>
<polyline fill="url(#Icons.VolumeSliderFocused.activeFillColor)" points="15,1 15,10.6 8,17.6 1,10.6 1,1 15,1 "/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

48
core/src/main/resources/com/github/weisj/darklaf/properties/icons/slider.properties

@ -0,0 +1,48 @@
#
# MIT License
#
# Copyright (c) 2020 Jannis Weis
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#
# suppress inspection "UnusedProperty" for whole file
#
Icons.Slider.activeFillColor = %Slider.activeThumbFill
Icons.Slider.borderColor = %Slider.thumbBorderColor
Icons.SliderDisabled.inactiveFillColor = %Slider.inactiveThumbFill
Icons.SliderDisabled.inactiveBorderColor = %Slider.thumbBorderColorDisabled
Icons.SliderFocused.activeFillColor = %Slider.activeThumbFill
Icons.SliderFocused.focusBorderColor = %Slider.thumbFocusBorderColor
Icons.SliderFocused.glowFocus = %glowFocus
Icons.SliderFocused.glowOpacity = %glowOpacity
Icons.VolumeSlider.activeFillColor = %Slider.volume.activeThumbFill
Icons.VolumeSlider.borderColor = %Slider.thumbBorderColor
Icons.VolumeSliderDisabled.inactiveFillColor = %Slider.volume.inactiveThumbFill
Icons.VolumeSliderDisabled.inactiveBorderColor = %Slider.thumbBorderColorDisabled
Icons.VolumeSliderFocused.activeFillColor = %Slider.volume.activeThumbFill
Icons.VolumeSliderFocused.focusBorderColor = %Slider.thumbFocusBorderColor
Icons.VolumeSliderFocused.glowFocus = %glowFocus
Icons.VolumeSliderFocused.glowOpacity = %glowOpacity

13
core/src/main/resources/com/github/weisj/darklaf/properties/ui/slider.properties

@ -31,6 +31,7 @@ Slider.selectedTrackColor = %controlFillSecondary
Slider.disabledTrackColor = %controlFillDisabled Slider.disabledTrackColor = %controlFillDisabled
Slider.trackBackground = %controlBackground Slider.trackBackground = %controlBackground
Slider.thumbBorderColor = %controlBorder Slider.thumbBorderColor = %controlBorder
Slider.thumbFocusBorderColor = %controlBorderFocus
Slider.thumbBorderColorDisabled = %controlBorderDisabled Slider.thumbBorderColorDisabled = %controlBorderDisabled
Slider.inactiveThumbFill = %controlFillDisabled Slider.inactiveThumbFill = %controlFillDisabled
Slider.activeThumbFill = %widgetFill Slider.activeThumbFill = %widgetFill
@ -44,8 +45,9 @@ Slider.focusBorderSize = 2
Slider.arc = 4 Slider.arc = 4
Slider.trackThickness = 4 Slider.trackThickness = 4
Slider.plainThumbRadius = 12 Slider.plainThumbRadius = 12
Slider.thumbSize = 10,18 Slider.thumbSize = 20,23
Slider.focusInsets = 4,4,4,4 Slider.focusInsets = 1,1,1,1
Slider.iconPad = 2
Slider.horizontalSize = 200,21 Slider.horizontalSize = 200,21
Slider.verticalSize = 21,200 Slider.verticalSize = 21,200
@ -55,6 +57,13 @@ Slider.minimumVerticalSize = 21,36
#Icons #Icons
Slider.horizontalThumbIcon = empty(0,0) Slider.horizontalThumbIcon = empty(0,0)
Slider.verticalThumbIcon = empty(0,0) Slider.verticalThumbIcon = empty(0,0)
Slider.enabledThumb.icon = control/slider.svg[themed](20,23)
Slider.disabledThumb.icon = control/sliderDisabled.svg[themed](20,23)
Slider.focusedThumb.icon = control/sliderFocused.svg[themed](20,23)
Slider.volume.enabledThumb.icon = control/volumeSlider.svg[themed](20,23)
Slider.volume.disabledThumb.icon = control/volumeSliderDisabled.svg[themed](20,23)
Slider.volume.focusedThumb.icon = control/volumeSliderFocused.svg[themed](20,23)
Slider.volume.enabled_level_0.icon = indicator/speaker_0.svg[themed] Slider.volume.enabled_level_0.icon = indicator/speaker_0.svg[themed]
Slider.volume.enabled_level_1.icon = indicator/speaker_1.svg[themed] Slider.volume.enabled_level_1.icon = indicator/speaker_1.svg[themed]
Slider.volume.enabled_level_2.icon = indicator/speaker_2.svg[themed] Slider.volume.enabled_level_2.icon = indicator/speaker_2.svg[themed]

Loading…
Cancel
Save