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


Ignore:
Timestamp:
2013-01-10T01:57:33+01:00 (12 years ago)
Author:
Don-vip
Message:

Scrollable menus: update MenuScroller to last version + add mouse wheel scroll support + reset scroller when imagery menu is refreshed

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

Legend:

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

    r5660 r5664  
    7070    private Map_Rectifier_WMSmenuAction rectaction = new Map_Rectifier_WMSmenuAction();
    7171    private int offsPos;
     72    private MenuScroller menuScroller;
    7273
    7374    public ImageryMenu() {
    7475        super(tr("Imagery"));
     76        setupMenuScroller();
     77        MapView.addLayerChangeListener(this);
     78    }
     79   
     80    private final void setupMenuScroller() {
    7581        int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
    7682        int menuItemHeight = singleOffset.getPreferredSize().height;
    77         MenuScroller.setScrollerFor(this, (screenHeight / menuItemHeight)-1);
    78         MapView.addLayerChangeListener(this);
     83        menuScroller = MenuScroller.setScrollerFor(this, (screenHeight / menuItemHeight)-1);
    7984    }
    8085
    8186    public void refreshImageryMenu() {
     87        if (menuScroller != null) {
     88            menuScroller.dispose();
     89            menuScroller = null;
     90        }
     91        setupMenuScroller();
    8292        removeAll();
    8393
  • trunk/src/org/openstreetmap/josm/gui/MenuScroller.java

    r5088 r5664  
    11/**
    2  * @(#)MenuScroller.java        1.4.0 14/09/10
     2 * @(#)MenuScroller.java    1.5.0 04/02/12
    33 */
    44package org.openstreetmap.josm.gui;
     
    1010import java.awt.event.ActionEvent;
    1111import java.awt.event.ActionListener;
     12import java.awt.event.MouseWheelEvent;
     13import java.awt.event.MouseWheelListener;
     14
    1215import javax.swing.Icon;
    1316import javax.swing.JComponent;
     
    1518import javax.swing.JMenuItem;
    1619import javax.swing.JPopupMenu;
    17 import javax.swing.JSeparator;
    1820import javax.swing.MenuSelectionManager;
    1921import javax.swing.Timer;
     
    4143    private MenuScrollItem downItem;
    4244    private final MenuScrollListener menuListener = new MenuScrollListener();
     45    private final MouseWheelListener mouseWheelListener = new MouseScrollListener();
    4346    private int scrollCount;
    4447    private int interval;
     
    293296        this.menu = menu;
    294297        menu.addPopupMenuListener(menuListener);
     298        menu.addMouseWheelListener(mouseWheelListener);
    295299    }
    296300
     
    419423        if (menu != null) {
    420424            menu.removePopupMenuListener(menuListener);
     425            menu.removeMouseWheelListener(mouseWheelListener);
     426            menu.setPreferredSize(null);
    421427            menu = null;
    422428        }
     
    448454            }
    449455            if (topFixedCount > 0) {
    450                 menu.add(new JSeparator());
     456                menu.addSeparator();
    451457            }
    452458
     
    458464
    459465            if (bottomFixedCount > 0) {
    460                 menu.add(new JSeparator());
     466                menu.addSeparator();
    461467            }
    462468            for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
     
    475481        }
    476482    }
    477 
     483   
    478484    private class MenuScrollListener implements PopupMenuListener {
    479485
     
    590596        }
    591597    }
     598   
     599    private class MouseScrollListener implements MouseWheelListener {
     600        public void mouseWheelMoved(MouseWheelEvent mwe) {
     601            if (menu.getComponents().length > scrollCount) {
     602                firstIndex += mwe.getWheelRotation();
     603                refreshMenu();
     604            }
     605            mwe.consume(); // (Comment 16, Huw)
     606        }
     607    }
    592608}
Note: See TracChangeset for help on using the changeset viewer.