Browse Source

Enable changing of spinner values through mouse wheel rotation.

pull/214/head
weisj 4 years ago
parent
commit
02e431481a
  1. 18
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerListener.java
  2. 2
      core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java
  3. 1
      core/src/main/resources/com/github/weisj/darklaf/properties/platform/mac.properties

18
core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerListener.java

@ -22,15 +22,13 @@
package com.github.weisj.darklaf.ui.spinner;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.*;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey;
public class DarkSpinnerListener extends MouseAdapter
@ -97,4 +95,16 @@ public class DarkSpinnerListener extends MouseAdapter
ui.updateBackground();
}
}
@Override
public void mouseWheelMoved(final MouseWheelEvent e) {
super.mouseWheelMoved(e);
if (!DarkUIUtil.hasFocus(spinner)) return;
int rotation = e.getWheelRotation();
if (rotation > 0) {
spinner.setValue(spinner.getPreviousValue());
} else if (rotation < 0) {
spinner.setValue(spinner.getNextValue());
}
}
}

2
core/src/main/java/com/github/weisj/darklaf/ui/spinner/DarkSpinnerUI.java

@ -91,6 +91,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements SpinnerConstants {
super.installListeners();
spinnerListener = createSpinnerListener();
spinner.addMouseListener(spinnerListener);
spinner.addMouseWheelListener(spinnerListener);
spinner.addPropertyChangeListener(spinnerListener);
}
@ -105,6 +106,7 @@ public class DarkSpinnerUI extends BasicSpinnerUI implements SpinnerConstants {
editor.getComponents()[0].removeFocusListener(spinnerListener);
}
spinner.removeMouseListener(spinnerListener);
spinner.removeMouseWheelListener(spinnerListener);
spinner.removePropertyChangeListener(spinnerListener);
spinnerListener = null;
}

1
core/src/main/resources/com/github/weisj/darklaf/properties/platform/mac.properties

@ -24,6 +24,7 @@
#
# suppress inspection "UnusedProperty" for whole file
#
macos.coloredTitleBar = true
ScrollBarUI = com.github.weisj.darklaf.ui.scrollpane.DarkMacScrollBarUI
ScrollBar.smallWidth = 10
ScrollBar.width = 12

Loading…
Cancel
Save