Changeset 7346 in josm for trunk/src


Ignore:
Timestamp:
2014-07-28T22:33:16+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #10207 - UI tuning in menu scroller: ignore JSeparator in scroll count

File:
1 edited

Legend:

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

    r7291 r7346  
    2121import javax.swing.JMenuItem;
    2222import javax.swing.JPopupMenu;
     23import javax.swing.JSeparator;
    2324import javax.swing.MenuSelectionManager;
    2425import javax.swing.Timer;
     
    8384
    8485            if (maxHeight > 0) {
    85                 result = (maxHeight/itemHeight)-2;
     86                result = (maxHeight/itemHeight)-1;
    8687            }
    8788        }
     
    482483    private void refreshMenu() {
    483484        if (menuItems != null && menuItems.length > 0) {
     485
     486            int numOfNonSepItems = getNumberOfNonSeparatorItems(menuItems);
     487
    484488            firstIndex = Math.max(topFixedCount, firstIndex);
    485             firstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, firstIndex);
     489            firstIndex = Math.min(numOfNonSepItems - bottomFixedCount - scrollCount, firstIndex);
    486490
    487491            upItem.setEnabled(firstIndex > topFixedCount);
    488             downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);
     492            downItem.setEnabled(firstIndex + scrollCount < numOfNonSepItems - bottomFixedCount);
    489493
    490494            menu.removeAll();
     
    540544        private void setMenuItems() {
    541545            menuItems = menu.getComponents();
     546            int numOfNonSepItems = getNumberOfNonSeparatorItems(menuItems);
    542547            if (keepVisibleIndex >= topFixedCount
    543                     && keepVisibleIndex <= menuItems.length - bottomFixedCount
     548                    && keepVisibleIndex <= numOfNonSepItems - bottomFixedCount
    544549                    && (keepVisibleIndex > firstIndex + scrollCount
    545550                    || keepVisibleIndex < firstIndex)) {
     
    547552                firstIndex = Math.max(firstIndex, keepVisibleIndex - scrollCount + 1);
    548553            }
    549             if (menuItems.length > topFixedCount + scrollCount + bottomFixedCount) {
     554            if (numOfNonSepItems > topFixedCount + scrollCount + bottomFixedCount) {
    550555                refreshMenu();
    551556            }
     
    639644        @Override
    640645        public void mouseWheelMoved(MouseWheelEvent mwe) {
    641             if (menu.getComponents().length > scrollCount) {
     646            if (getNumberOfNonSeparatorItems(menu.getComponents()) > scrollCount) {
    642647                firstIndex += mwe.getWheelRotation();
    643648                refreshMenu();
     
    646651        }
    647652    }
     653
     654    private int getNumberOfNonSeparatorItems(Component[] items) {
     655        int result = 0;
     656        for (Component c : items) {
     657            if (!(c instanceof JSeparator)) {
     658                result++;
     659            }
     660        }
     661        return result;
     662    }
    648663}
Note: See TracChangeset for help on using the changeset viewer.