Changeset 2028 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-09-02T22:01:39+02:00 (15 years ago)
Author:
Gubaer
Message:

applied #3368: patch by xeen: make prefs tab strip react to scroll events

File:
1 edited

Legend:

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

    r2017 r2028  
    77import java.awt.GridBagLayout;
    88import java.awt.ScrollPane;
     9import java.awt.event.MouseWheelEvent;
     10import java.awt.event.MouseWheelListener;
    911import java.util.ArrayList;
    1012import java.util.Collection;
     
    3335 * @author imi
    3436 */
    35 public class PreferenceDialog extends JTabbedPane {
     37public class PreferenceDialog extends JTabbedPane implements MouseWheelListener {
    3638
    3739    private final static Collection<PreferenceSettingFactory> settingsFactory = new LinkedList<PreferenceSettingFactory>();
     
    116118    public PreferenceDialog() {
    117119        super(JTabbedPane.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT);
     120
     121        super.addMouseWheelListener(this);
    118122
    119123        for (PreferenceSettingFactory factory:settingsFactory) {
     
    174178        settingsFactory.add(new AdvancedPreference.Factory());
    175179    }
     180
     181    /**
     182     * This mouse wheel listener reacts when a scroll is carried out over the
     183     * tab strip and scrolls one tab/down or up, selecting it immediately.
     184     */
     185    public void mouseWheelMoved(MouseWheelEvent wev) {
     186        // Ensure the cursor is over the tab strip
     187        if(super.indexAtLocation(wev.getPoint().x, wev.getPoint().y) < 0)
     188            return;
     189
     190        // Get currently selected tab
     191        int newTab = super.getSelectedIndex() + wev.getWheelRotation();
     192
     193        // Ensure the new tab index is sound
     194        newTab = newTab < 0 ? 0 : newTab;
     195        newTab = newTab >= super.getTabCount() ? super.getTabCount() - 1 : newTab;
     196
     197        // select new tab
     198        super.setSelectedIndex(newTab);
     199    }
    176200}
Note: See TracChangeset for help on using the changeset viewer.