org.openstreetmap.josm.gui
Class MenuScroller

java.lang.Object
  extended by org.openstreetmap.josm.gui.MenuScroller

public class MenuScroller
extends java.lang.Object

A class that provides scrolling capabilities to a long menu dropdown or popup menu. A number of items can optionally be frozen at the top and/or bottom of the menu.

Implementation note: The default number of items to display at a time is 15, and the default scrolling interval is 125 milliseconds.


Nested Class Summary
private static class MenuScroller.MenuIcon
           
private  class MenuScroller.MenuScrollItem
           
private  class MenuScroller.MenuScrollListener
           
private  class MenuScroller.MenuScrollTimer
           
 
Field Summary
private  int bottomFixedCount
           
private  MenuScroller.MenuScrollItem downItem
           
private  int firstIndex
           
private  int interval
           
private  int keepVisibleIndex
           
private  javax.swing.JPopupMenu menu
           
private  java.awt.Component[] menuItems
           
private  MenuScroller.MenuScrollListener menuListener
           
private  int scrollCount
           
private  int topFixedCount
           
private  MenuScroller.MenuScrollItem upItem
           
 
Constructor Summary
MenuScroller(javax.swing.JMenu menu)
          Constructs a MenuScroller that scrolls a menu with the default number of items to display at a time, and default scrolling interval.
MenuScroller(javax.swing.JMenu menu, int scrollCount)
          Constructs a MenuScroller that scrolls a menu with the specified number of items to display at a time, and default scrolling interval.
MenuScroller(javax.swing.JMenu menu, int scrollCount, int interval)
          Constructs a MenuScroller that scrolls a menu with the specified number of items to display at a time, and specified scrolling interval.
MenuScroller(javax.swing.JMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)
          Constructs a MenuScroller that scrolls a menu with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the menu.
MenuScroller(javax.swing.JPopupMenu menu)
          Constructs a MenuScroller that scrolls a popup menu with the default number of items to display at a time, and default scrolling interval.
MenuScroller(javax.swing.JPopupMenu menu, int scrollCount)
          Constructs a MenuScroller that scrolls a popup menu with the specified number of items to display at a time, and default scrolling interval.
MenuScroller(javax.swing.JPopupMenu menu, int scrollCount, int interval)
          Constructs a MenuScroller that scrolls a popup menu with the specified number of items to display at a time, and specified scrolling interval.
MenuScroller(javax.swing.JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)
          Constructs a MenuScroller that scrolls a popup menu with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the popup menu.
 
Method Summary
 void dispose()
          Removes this MenuScroller from the associated menu and restores the default behavior of the menu.
 void finalize()
          Ensures that the dispose method of this MenuScroller is called when there are no more refrences to it.
 int getBottomFixedCount()
          Returns the number of items fixed at the bottom of the menu or popup menu.
 int getInterval()
          Returns the scroll interval in milliseconds
 int getscrollCount()
          Returns the number of items in the scrolling portion of the menu.
 int getTopFixedCount()
          Returns the number of items fixed at the top of the menu or popup menu.
 void keepVisible(int index)
          Scrolls the item at the specified index into view each time the menu is opened.
 void keepVisible(javax.swing.JMenuItem item)
          Scrolls the specified item into view each time the menu is opened.
private  void refreshMenu()
           
 void setBottomFixedCount(int bottomFixedCount)
          Sets the number of items to fix at the bottom of the menu or popup menu.
 void setInterval(int interval)
          Sets the scroll interval in milliseconds
 void setScrollCount(int scrollCount)
          Sets the number of items in the scrolling portion of the menu.
static MenuScroller setScrollerFor(javax.swing.JMenu menu)
          Registers a menu to be scrolled with the default number of items to display at a time and the default scrolling interval.
static MenuScroller setScrollerFor(javax.swing.JMenu menu, int scrollCount)
          Registers a menu to be scrolled with the default number of items to display at a time and the specified scrolling interval.
static MenuScroller setScrollerFor(javax.swing.JMenu menu, int scrollCount, int interval)
          Registers a menu to be scrolled, with the specified number of items to display at a time and the specified scrolling interval.
static MenuScroller setScrollerFor(javax.swing.JMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)
          Registers a menu to be scrolled, with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the menu.
static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu)
          Registers a popup menu to be scrolled with the default number of items to display at a time and the default scrolling interval.
static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu, int scrollCount)
          Registers a popup menu to be scrolled with the default number of items to display at a time and the specified scrolling interval.
static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu, int scrollCount, int interval)
          Registers a popup menu to be scrolled, with the specified number of items to display at a time and the specified scrolling interval.
static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount)
          Registers a popup menu to be scrolled, with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the popup menu.
 void setTopFixedCount(int topFixedCount)
          Sets the number of items to fix at the top of the menu or popup menu.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

menu

private javax.swing.JPopupMenu menu

menuItems

private java.awt.Component[] menuItems

upItem

private MenuScroller.MenuScrollItem upItem

downItem

private MenuScroller.MenuScrollItem downItem

menuListener

private final MenuScroller.MenuScrollListener menuListener

scrollCount

private int scrollCount

interval

private int interval

topFixedCount

private int topFixedCount

bottomFixedCount

private int bottomFixedCount

firstIndex

private int firstIndex

keepVisibleIndex

private int keepVisibleIndex
Constructor Detail

MenuScroller

public MenuScroller(javax.swing.JMenu menu)
Constructs a MenuScroller that scrolls a menu with the default number of items to display at a time, and default scrolling interval.

Parameters:
menu - the menu

MenuScroller

public MenuScroller(javax.swing.JPopupMenu menu)
Constructs a MenuScroller that scrolls a popup menu with the default number of items to display at a time, and default scrolling interval.

Parameters:
menu - the popup menu

MenuScroller

public MenuScroller(javax.swing.JMenu menu,
                    int scrollCount)
Constructs a MenuScroller that scrolls a menu with the specified number of items to display at a time, and default scrolling interval.

Parameters:
menu - the menu
scrollCount - the number of items to display at a time
Throws:
java.lang.IllegalArgumentException - if scrollCount is 0 or negative

MenuScroller

public MenuScroller(javax.swing.JPopupMenu menu,
                    int scrollCount)
Constructs a MenuScroller that scrolls a popup menu with the specified number of items to display at a time, and default scrolling interval.

Parameters:
menu - the popup menu
scrollCount - the number of items to display at a time
Throws:
java.lang.IllegalArgumentException - if scrollCount is 0 or negative

MenuScroller

public MenuScroller(javax.swing.JMenu menu,
                    int scrollCount,
                    int interval)
Constructs a MenuScroller that scrolls a menu with the specified number of items to display at a time, and specified scrolling interval.

Parameters:
menu - the menu
scrollCount - the number of items to display at a time
interval - the scroll interval, in milliseconds
Throws:
java.lang.IllegalArgumentException - if scrollCount or interval is 0 or negative

MenuScroller

public MenuScroller(javax.swing.JPopupMenu menu,
                    int scrollCount,
                    int interval)
Constructs a MenuScroller that scrolls a popup menu with the specified number of items to display at a time, and specified scrolling interval.

Parameters:
menu - the popup menu
scrollCount - the number of items to display at a time
interval - the scroll interval, in milliseconds
Throws:
java.lang.IllegalArgumentException - if scrollCount or interval is 0 or negative

MenuScroller

public MenuScroller(javax.swing.JMenu menu,
                    int scrollCount,
                    int interval,
                    int topFixedCount,
                    int bottomFixedCount)
Constructs a MenuScroller that scrolls a menu with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the menu.

Parameters:
menu - the menu
scrollCount - the number of items to display in the scrolling portion
interval - the scroll interval, in milliseconds
topFixedCount - the number of items to fix at the top. May be 0
bottomFixedCount - the number of items to fix at the bottom. May be 0
Throws:
java.lang.IllegalArgumentException - if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative

MenuScroller

public MenuScroller(javax.swing.JPopupMenu menu,
                    int scrollCount,
                    int interval,
                    int topFixedCount,
                    int bottomFixedCount)
Constructs a MenuScroller that scrolls a popup menu with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the popup menu.

Parameters:
menu - the popup menu
scrollCount - the number of items to display in the scrolling portion
interval - the scroll interval, in milliseconds
topFixedCount - the number of items to fix at the top. May be 0
bottomFixedCount - the number of items to fix at the bottom. May be 0
Throws:
java.lang.IllegalArgumentException - if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative
Method Detail

setScrollerFor

public static MenuScroller setScrollerFor(javax.swing.JMenu menu)
Registers a menu to be scrolled with the default number of items to display at a time and the default scrolling interval.

Parameters:
menu - the menu
Returns:
the MenuScroller

setScrollerFor

public static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu)
Registers a popup menu to be scrolled with the default number of items to display at a time and the default scrolling interval.

Parameters:
menu - the popup menu
Returns:
the MenuScroller

setScrollerFor

public static MenuScroller setScrollerFor(javax.swing.JMenu menu,
                                          int scrollCount)
Registers a menu to be scrolled with the default number of items to display at a time and the specified scrolling interval.

Parameters:
menu - the menu
scrollCount - the number of items to display at a time
Returns:
the MenuScroller
Throws:
java.lang.IllegalArgumentException - if scrollCount is 0 or negative

setScrollerFor

public static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu,
                                          int scrollCount)
Registers a popup menu to be scrolled with the default number of items to display at a time and the specified scrolling interval.

Parameters:
menu - the popup menu
scrollCount - the number of items to display at a time
Returns:
the MenuScroller
Throws:
java.lang.IllegalArgumentException - if scrollCount is 0 or negative

setScrollerFor

public static MenuScroller setScrollerFor(javax.swing.JMenu menu,
                                          int scrollCount,
                                          int interval)
Registers a menu to be scrolled, with the specified number of items to display at a time and the specified scrolling interval.

Parameters:
menu - the menu
scrollCount - the number of items to be displayed at a time
interval - the scroll interval, in milliseconds
Returns:
the MenuScroller
Throws:
java.lang.IllegalArgumentException - if scrollCount or interval is 0 or negative

setScrollerFor

public static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu,
                                          int scrollCount,
                                          int interval)
Registers a popup menu to be scrolled, with the specified number of items to display at a time and the specified scrolling interval.

Parameters:
menu - the popup menu
scrollCount - the number of items to be displayed at a time
interval - the scroll interval, in milliseconds
Returns:
the MenuScroller
Throws:
java.lang.IllegalArgumentException - if scrollCount or interval is 0 or negative

setScrollerFor

public static MenuScroller setScrollerFor(javax.swing.JMenu menu,
                                          int scrollCount,
                                          int interval,
                                          int topFixedCount,
                                          int bottomFixedCount)
Registers a menu to be scrolled, with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the menu.

Parameters:
menu - the menu
scrollCount - the number of items to display in the scrolling portion
interval - the scroll interval, in milliseconds
topFixedCount - the number of items to fix at the top. May be 0.
bottomFixedCount - the number of items to fix at the bottom. May be 0
Returns:
the MenuScroller
Throws:
java.lang.IllegalArgumentException - if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative

setScrollerFor

public static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu,
                                          int scrollCount,
                                          int interval,
                                          int topFixedCount,
                                          int bottomFixedCount)
Registers a popup menu to be scrolled, with the specified number of items to display in the scrolling region, the specified scrolling interval, and the specified numbers of items fixed at the top and bottom of the popup menu.

Parameters:
menu - the popup menu
scrollCount - the number of items to display in the scrolling portion
interval - the scroll interval, in milliseconds
topFixedCount - the number of items to fix at the top. May be 0
bottomFixedCount - the number of items to fix at the bottom. May be 0
Returns:
the MenuScroller
Throws:
java.lang.IllegalArgumentException - if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative

getInterval

public int getInterval()
Returns the scroll interval in milliseconds

Returns:
the scroll interval in milliseconds

setInterval

public void setInterval(int interval)
Sets the scroll interval in milliseconds

Parameters:
interval - the scroll interval in milliseconds
Throws:
java.lang.IllegalArgumentException - if interval is 0 or negative

getscrollCount

public int getscrollCount()
Returns the number of items in the scrolling portion of the menu.

Returns:
the number of items to display at a time

setScrollCount

public void setScrollCount(int scrollCount)
Sets the number of items in the scrolling portion of the menu.

Parameters:
scrollCount - the number of items to display at a time
Throws:
java.lang.IllegalArgumentException - if scrollCount is 0 or negative

getTopFixedCount

public int getTopFixedCount()
Returns the number of items fixed at the top of the menu or popup menu.

Returns:
the number of items

setTopFixedCount

public void setTopFixedCount(int topFixedCount)
Sets the number of items to fix at the top of the menu or popup menu.

Parameters:
topFixedCount - the number of items

getBottomFixedCount

public int getBottomFixedCount()
Returns the number of items fixed at the bottom of the menu or popup menu.

Returns:
the number of items

setBottomFixedCount

public void setBottomFixedCount(int bottomFixedCount)
Sets the number of items to fix at the bottom of the menu or popup menu.

Parameters:
bottomFixedCount - the number of items

keepVisible

public void keepVisible(javax.swing.JMenuItem item)
Scrolls the specified item into view each time the menu is opened. Call this method with null to restore the default behavior, which is to show the menu as it last appeared.

Parameters:
item - the item to keep visible
See Also:
keepVisible(int)

keepVisible

public void keepVisible(int index)
Scrolls the item at the specified index into view each time the menu is opened. Call this method with -1 to restore the default behavior, which is to show the menu as it last appeared.

Parameters:
index - the index of the item to keep visible
See Also:
keepVisible(javax.swing.JMenuItem)

dispose

public void dispose()
Removes this MenuScroller from the associated menu and restores the default behavior of the menu.


finalize

public void finalize()
              throws java.lang.Throwable
Ensures that the dispose method of this MenuScroller is called when there are no more refrences to it.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - if an error occurs.
See Also:
dispose()

refreshMenu

private void refreshMenu()


JOSM