Changeset 7452 in josm


Ignore:
Timestamp:
2014-08-28T16:08:11+02:00 (10 years ago)
Author:
Don-vip
Message:

see #10397: menu scroller simplification: remove possibility to define a fixed number of items at the bottom of the menu (unused feature)

File:
1 edited

Legend:

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

    r7346 r7452  
    3333/**
    3434 * A class that provides scrolling capabilities to a long menu dropdown or
    35  * popup menu.  A number of items can optionally be frozen at the top and/or
    36  * bottom of the menu.
     35 * popup menu. A number of items can optionally be frozen at the top of the menu.
    3736 * <P>
    3837 * <B>Implementation note:</B>  The default number of items to display
     
    5251    private int interval;
    5352    private int topFixedCount;
    54     private int bottomFixedCount;
    5553    private int firstIndex = 0;
    5654    private int keepVisibleIndex = -1;
     
    169167     * Registers a menu to be scrolled, with the specified number of items
    170168     * to display in the scrolling region, the specified scrolling interval,
    171      * and the specified numbers of items fixed at the top and bottom of the
    172      * menu.
     169     * and the specified numbers of items fixed at the top of the menu.
    173170     *
    174171     * @param menu the menu
     
    176173     * @param interval the scroll interval, in milliseconds
    177174     * @param topFixedCount the number of items to fix at the top.  May be 0.
    178      * @param bottomFixedCount the number of items to fix at the bottom. May be 0
    179175     * @throws IllegalArgumentException if scrollCount or interval is 0 or
    180      * negative or if topFixedCount or bottomFixedCount is negative
     176     * negative or if topFixedCount is negative
    181177     * @return the MenuScroller
    182178     */
    183179    public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval,
    184             int topFixedCount, int bottomFixedCount) {
    185         return new MenuScroller(menu, scrollCount, interval,
    186                 topFixedCount, bottomFixedCount);
     180            int topFixedCount) {
     181        return new MenuScroller(menu, scrollCount, interval, topFixedCount);
    187182    }
    188183
     
    190185     * Registers a popup menu to be scrolled, with the specified number of items
    191186     * to display in the scrolling region, the specified scrolling interval,
    192      * and the specified numbers of items fixed at the top and bottom of the
    193      * popup menu.
     187     * and the specified numbers of items fixed at the top of the popup menu.
    194188     *
    195189     * @param menu the popup menu
     
    197191     * @param interval the scroll interval, in milliseconds
    198192     * @param topFixedCount the number of items to fix at the top.  May be 0
    199      * @param bottomFixedCount the number of items to fix at the bottom.  May be 0
    200193     * @throws IllegalArgumentException if scrollCount or interval is 0 or
    201      * negative or if topFixedCount or bottomFixedCount is negative
     194     * negative or if topFixedCount is negative
    202195     * @return the MenuScroller
    203196     */
    204197    public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval,
    205             int topFixedCount, int bottomFixedCount) {
    206         return new MenuScroller(menu, scrollCount, interval,
    207                 topFixedCount, bottomFixedCount);
     198            int topFixedCount) {
     199        return new MenuScroller(menu, scrollCount, interval, topFixedCount);
    208200    }
    209201
     
    267259     */
    268260    public MenuScroller(JMenu menu, int scrollCount, int interval) {
    269         this(menu, scrollCount, interval, 0, 0);
     261        this(menu, scrollCount, interval, 0);
    270262    }
    271263
     
    281273     */
    282274    public MenuScroller(JPopupMenu menu, int scrollCount, int interval) {
    283         this(menu, scrollCount, interval, 0, 0);
     275        this(menu, scrollCount, interval, 0);
    284276    }
    285277
     
    288280     * specified number of items to display in the scrolling region, the
    289281     * specified scrolling interval, and the specified numbers of items fixed at
    290      * the top and bottom of the menu.
     282     * the top of the menu.
    291283     *
    292284     * @param menu the menu
     
    294286     * @param interval the scroll interval, in milliseconds
    295287     * @param topFixedCount the number of items to fix at the top.  May be 0
    296      * @param bottomFixedCount the number of items to fix at the bottom.  May be 0
    297288     * @throws IllegalArgumentException if scrollCount or interval is 0 or
    298      * negative or if topFixedCount or bottomFixedCount is negative
    299      */
    300     public MenuScroller(JMenu menu, int scrollCount, int interval,
    301             int topFixedCount, int bottomFixedCount) {
    302         this(menu.getPopupMenu(), scrollCount, interval, topFixedCount, bottomFixedCount);
     289     * negative or if topFixedCount is negative
     290     */
     291    public MenuScroller(JMenu menu, int scrollCount, int interval, int topFixedCount) {
     292        this(menu.getPopupMenu(), scrollCount, interval, topFixedCount);
    303293    }
    304294
     
    307297     * specified number of items to display in the scrolling region, the
    308298     * specified scrolling interval, and the specified numbers of items fixed at
    309      * the top and bottom of the popup menu.
     299     * the top of the popup menu.
    310300     *
    311301     * @param menu the popup menu
     
    313303     * @param interval the scroll interval, in milliseconds
    314304     * @param topFixedCount the number of items to fix at the top.  May be 0
    315      * @param bottomFixedCount the number of items to fix at the bottom.  May be 0
    316305     * @throws IllegalArgumentException if scrollCount or interval is 0 or
    317      * negative or if topFixedCount or bottomFixedCount is negative
    318      */
    319     public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
    320             int topFixedCount, int bottomFixedCount) {
     306     * negative or if topFixedCount is negative
     307     */
     308    public MenuScroller(JPopupMenu menu, int scrollCount, int interval, int topFixedCount) {
    321309        if (scrollCount <= 0 || interval <= 0) {
    322310            throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
    323311        }
    324         if (topFixedCount < 0 || bottomFixedCount < 0) {
    325             throw new IllegalArgumentException("topFixedCount and bottomFixedCount cannot be negative");
     312        if (topFixedCount < 0) {
     313            throw new IllegalArgumentException("topFixedCount cannot be negative");
    326314        }
    327315
     
    331319        setInterval(interval);
    332320        setTopFixedCount(topFixedCount);
    333         setBottomFixedCount(bottomFixedCount);
    334321
    335322        this.menu = menu;
     
    406393        }
    407394        this.topFixedCount = topFixedCount;
    408     }
    409 
    410     /**
    411      * Returns the number of items fixed at the bottom of the menu or popup menu.
    412      *
    413      * @return the number of items
    414      */
    415     public int getBottomFixedCount() {
    416         return bottomFixedCount;
    417     }
    418 
    419     /**
    420      * Sets the number of items to fix at the bottom of the menu or popup menu.
    421      *
    422      * @param bottomFixedCount the number of items
    423      */
    424     public void setBottomFixedCount(int bottomFixedCount) {
    425         this.bottomFixedCount = bottomFixedCount;
    426395    }
    427396
     
    487456
    488457            firstIndex = Math.max(topFixedCount, firstIndex);
    489             firstIndex = Math.min(numOfNonSepItems - bottomFixedCount - scrollCount, firstIndex);
     458            firstIndex = Math.min(numOfNonSepItems - scrollCount, firstIndex);
    490459
    491460            upItem.setEnabled(firstIndex > topFixedCount);
    492             downItem.setEnabled(firstIndex + scrollCount < numOfNonSepItems - bottomFixedCount);
     461            downItem.setEnabled(firstIndex + scrollCount < numOfNonSepItems);
    493462
    494463            menu.removeAll();
     
    505474            }
    506475            menu.add(downItem);
    507 
    508             if (bottomFixedCount > 0) {
    509                 menu.addSeparator();
    510             }
    511             for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
    512                 menu.add(menuItems[i]);
    513             }
    514476
    515477            int preferredWidth = 0;
     
    546508            int numOfNonSepItems = getNumberOfNonSeparatorItems(menuItems);
    547509            if (keepVisibleIndex >= topFixedCount
    548                     && keepVisibleIndex <= numOfNonSepItems - bottomFixedCount
     510                    && keepVisibleIndex <= numOfNonSepItems
    549511                    && (keepVisibleIndex > firstIndex + scrollCount
    550512                    || keepVisibleIndex < firstIndex)) {
     
    552514                firstIndex = Math.max(firstIndex, keepVisibleIndex - scrollCount + 1);
    553515            }
    554             if (numOfNonSepItems > topFixedCount + scrollCount + bottomFixedCount) {
     516            if (numOfNonSepItems > topFixedCount + scrollCount) {
    555517                refreshMenu();
    556518            }
Note: See TracChangeset for help on using the changeset viewer.