Changeset 15845 in josm


Ignore:
Timestamp:
2020-02-12T00:06:43+01:00 (6 weeks ago)
Author:
simon04
Message:

fix #18703 - Scroll through TabPreferenceSetting using mouse wheel

Location:
trunk/src/org/openstreetmap/josm/gui/preferences
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/DefaultTabPreferenceSetting.java

    r13431 r15845  
    4949        this.tabpane = tabpane;
    5050        this.subSettingMap = tabpane != null ? new HashMap<>() : null;
     51        if (tabpane != null) {
     52            tabpane.addMouseWheelListener(new PreferenceTabbedPane.WheelListener(tabpane));
     53        }
    5154    }
    5255
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r15844 r15845  
    7979 * @author imi
    8080 */
    81 public final class PreferenceTabbedPane extends JTabbedPane implements MouseWheelListener, ExpertModeChangeListener, ChangeListener {
     81public final class PreferenceTabbedPane extends JTabbedPane implements ExpertModeChangeListener, ChangeListener {
    8282
    8383    private final class PluginDownloadAfterTask implements Runnable {
     
    446446    public PreferenceTabbedPane() {
    447447        super(JTabbedPane.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT);
    448         super.addMouseWheelListener(this);
     448        super.addMouseWheelListener(new WheelListener(this));
    449449        super.getModel().addChangeListener(this);
    450450        ExpertToggleAction.addExpertModeChangeListener(this);
     
    578578     * tab strip and scrolls one tab/down or up, selecting it immediately.
    579579     */
    580     @Override
    581     public void mouseWheelMoved(MouseWheelEvent wev) {
    582         // Ensure the cursor is over the tab strip
    583         if (super.indexAtLocation(wev.getPoint().x, wev.getPoint().y) < 0)
    584             return;
    585 
    586         // Get currently selected tab
    587         int newTab = super.getSelectedIndex() + wev.getWheelRotation();
    588 
    589         // Ensure the new tab index is sound
    590         newTab = newTab < 0 ? 0 : newTab;
    591         newTab = newTab >= super.getTabCount() ? super.getTabCount() - 1 : newTab;
    592 
    593         // select new tab
    594         super.setSelectedIndex(newTab);
     580    static final class WheelListener implements MouseWheelListener {
     581
     582        final JTabbedPane tabbedPane;
     583
     584        WheelListener(JTabbedPane tabbedPane) {
     585            this.tabbedPane = tabbedPane;
     586        }
     587
     588        @Override
     589        public void mouseWheelMoved(MouseWheelEvent wev) {
     590            // Ensure the cursor is over the tab strip
     591            if (tabbedPane.indexAtLocation(wev.getPoint().x, wev.getPoint().y) < 0)
     592                return;
     593
     594            // Get currently selected tab && ensure the new tab index is sound
     595            int newTab = Utils.clamp(tabbedPane.getSelectedIndex() + wev.getWheelRotation(),
     596                    0, tabbedPane.getTabCount() - 1);
     597
     598            tabbedPane.setSelectedIndex(newTab);
     599        }
    595600    }
    596601
Note: See TracChangeset for help on using the changeset viewer.