Browse Source

Provide visual padding hints for slider.

pull/222/head
weisj 4 years ago
parent
commit
9a304ba971
  1. 9
      core/src/main/java/com/github/weisj/darklaf/ui/VisualPaddingProvider.java
  2. 11
      core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderListener.java
  3. 14
      core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderUI.java

9
core/src/main/java/com/github/weisj/darklaf/ui/VisualPaddingProvider.java

@ -39,7 +39,14 @@ public interface VisualPaddingProvider {
static void updateProperty(final JComponent c) {
Border b = DarkUIUtil.getUnwrappedBorder(c);
if (b instanceof VisualPaddingProvider) {
Insets ins = ((VisualPaddingProvider) b).getVisualPaddings(c);
updateProperty(c, ((VisualPaddingProvider) b).getVisualPaddings(c));
} else {
updateProperty(c, null);
}
}
static void updateProperty(final JComponent c, final Insets ins) {
if (ins != null) {
PropertyUtil.installProperty(c, VISUAL_PADDING_PROP,
new InsetsUIResource(ins.top, ins.left, ins.bottom, ins.right));
} else {

11
core/src/main/java/com/github/weisj/darklaf/ui/slider/DarkSliderListener.java

@ -29,6 +29,8 @@ import java.beans.PropertyChangeListener;
import javax.swing.*;
import com.github.weisj.darklaf.util.PropertyKey;
public class DarkSliderListener extends MouseAdapter implements PropertyChangeListener {
private final DarkSliderUI ui;
@ -73,10 +75,11 @@ public class DarkSliderListener extends MouseAdapter implements PropertyChangeLi
@Override
public void propertyChange(final PropertyChangeEvent evt) {
String key = evt.getPropertyName();
if (DarkSliderUI.KEY_VARIANT.equals(key)) {
slider.repaint();
} else if (DarkSliderUI.KEY_SHOW_VOLUME_ICON.equals(key)) {
ui.calculateGeometry();
if (DarkSliderUI.KEY_VARIANT.equals(key)
|| DarkSliderUI.KEY_SHOW_VOLUME_ICON.equals(key)
|| PropertyKey.ORIENTATION.equals(key)
|| PropertyKey.COMPONENT_ORIENTATION.equals(key)) {
ui.updateVisualPaddings();
slider.repaint();
}
}

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

@ -35,6 +35,7 @@ import com.github.weisj.darklaf.graphics.GraphicsContext;
import com.github.weisj.darklaf.graphics.GraphicsUtil;
import com.github.weisj.darklaf.graphics.PaintUtil;
import com.github.weisj.darklaf.icons.RotatableIcon;
import com.github.weisj.darklaf.ui.VisualPaddingProvider;
import com.github.weisj.darklaf.util.Alignment;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey;
@ -114,6 +115,12 @@ public class DarkSliderUI extends BasicSliderUI {
return PropertyUtil.isPropertyEqual(c, KEY_VARIANT, VARIANT_VOLUME);
}
@Override
public void installUI(final JComponent c) {
super.installUI(c);
updateVisualPaddings();
}
@Override
protected TrackListener createTrackListener(final JSlider slider) {
return new SnapTrackListener();
@ -134,6 +141,13 @@ public class DarkSliderUI extends BasicSliderUI {
return new DarkSliderListener(this, slider);
}
protected void updateVisualPaddings() {
calculateGeometry();
Rectangle r = new Rectangle(contentRect);
Insets ins = new Insets(r.y, r.x, slider.getHeight() - (r.y + r.height), slider.getWidth() - (r.x + r.width));
VisualPaddingProvider.updateProperty(slider, ins);
}
@Override
protected void uninstallListeners(final JSlider slider) {
super.uninstallListeners(slider);

Loading…
Cancel
Save