Package jmri.util
Class MenuScroller
java.lang.Object
jmri.util.MenuScroller
- All Implemented Interfaces:
MouseWheelListener,EventListener
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.
-
Constructor Summary
ConstructorsConstructorDescriptionMenuScroller(JMenu menu) Construct aMenuScrollerthat scrolls a menu with the default number of items to display at a time, and default scrolling interval.MenuScroller(JMenu menu, int scrollCount) Construct aMenuScrollerthat scrolls a menu with the specified number of items to display at a time, and default scrolling interval.MenuScroller(JMenu menu, int scrollCount, int interval) Construct aMenuScrollerthat scrolls a menu with the specified number of items to display at a time, and specified scrolling interval.MenuScroller(JMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount) Construct aMenuScrollerthat 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(JPopupMenu menu) Construct aMenuScrollerthat scrolls a popup menu with the default number of items to display at a time, and default scrolling interval.MenuScroller(JPopupMenu menu, int scrollCount) Construct aMenuScrollerthat scrolls a popup menu with the specified number of items to display at a time, and default scrolling interval.MenuScroller(JPopupMenu menu, int scrollCount, int interval) Construct aMenuScrollerthat scrolls a popup menu with the specified number of items to display at a time, and specified scrolling interval.MenuScroller(JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount) Construct aMenuScrollerthat 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
Modifier and TypeMethodDescriptionvoiddispose()Remove this MenuScroller from the associated menu and restores the default behavior of the menu.protected voidfinalize()Ensure that thedisposemethod of this MenuScroller is called when there are no more refrences to it.intReturn the number of items fixed at the bottom of the menu or popup menu.intReturn the scroll interval in milliseconds.intReturn the number of items in the scrolling portion of the menu.intReturn the number of items fixed at the top of the menu or popup menu.voidkeepVisible(int index) Scroll the item at the specified index into view each time the menu is opened.voidkeepVisible(JMenuItem item) Scroll the specified item into view each time the menu is opened.voidvoidsetBottomFixedCount(int bottomFixedCount) Set the number of items to fix at the bottom of the menu or popup menu.voidsetInterval(int interval) Set the scroll interval in milliseconds.voidsetScrollCount(int scrollCount) Set the number of items in the scrolling portion of the menu.static MenuScrollersetScrollerFor(JMenu menu) Register a menu to be scrolled with the default number of items to display at a time and the default scrolling interval.static MenuScrollersetScrollerFor(JMenu menu, int scrollCount) Register a menu to be scrolled with the default number of items to display at a time and the specified scrolling interval.static MenuScrollersetScrollerFor(JMenu menu, int scrollCount, int interval) Register a menu to be scrolled, with the specified number of items to display at a time and the specified scrolling interval.static MenuScrollersetScrollerFor(JMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount) Register 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 MenuScrollersetScrollerFor(JPopupMenu menu) Register a popup menu to be scrolled with the default number of items to display at a time and the default scrolling interval.static MenuScrollersetScrollerFor(JPopupMenu menu, int scrollCount) Register a popup menu to be scrolled with the default number of items to display at a time and the specified scrolling interval.static MenuScrollersetScrollerFor(JPopupMenu menu, int scrollCount, int interval) Register a popup menu to be scrolled, with the specified number of items to display at a time and the specified scrolling interval.static MenuScrollersetScrollerFor(JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount) Register 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.voidsetTopFixedCount(int topFixedCount) Set the number of items to fix at the top of the menu or popup menu.
-
Constructor Details
-
MenuScroller
Construct aMenuScrollerthat scrolls a menu with the default number of items to display at a time, and default scrolling interval.- Parameters:
menu- the menu
-
MenuScroller
Construct aMenuScrollerthat 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
Construct aMenuScrollerthat scrolls a menu with the specified number of items to display at a time, and default scrolling interval.- Parameters:
menu- the menuscrollCount- the number of items to display at a time- Throws:
IllegalArgumentException- if scrollCount is 0 or negative
-
MenuScroller
Construct aMenuScrollerthat scrolls a popup menu with the specified number of items to display at a time, and default scrolling interval.- Parameters:
menu- the popup menuscrollCount- the number of items to display at a time- Throws:
IllegalArgumentException- if scrollCount is 0 or negative
-
MenuScroller
Construct aMenuScrollerthat scrolls a menu with the specified number of items to display at a time, and specified scrolling interval.- Parameters:
menu- the menuscrollCount- the number of items to display at a timeinterval- the scroll interval, in milliseconds- Throws:
IllegalArgumentException- if scrollCount or interval is 0 or negative
-
MenuScroller
Construct aMenuScrollerthat scrolls a popup menu with the specified number of items to display at a time, and specified scrolling interval.- Parameters:
menu- the popup menuscrollCount- the number of items to display at a timeinterval- the scroll interval, in milliseconds- Throws:
IllegalArgumentException- if scrollCount or interval is 0 or negative
-
MenuScroller
public MenuScroller(JMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount) Construct aMenuScrollerthat 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 menuscrollCount- the number of items to display in the scrolling portioninterval- the scroll interval, in millisecondstopFixedCount- the number of items to fix at the top. May be 0bottomFixedCount- the number of items to fix at the bottom. May be 0- Throws:
IllegalArgumentException- if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative
-
MenuScroller
public MenuScroller(JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount) Construct aMenuScrollerthat 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 menuscrollCount- the number of items to display in the scrolling portioninterval- the scroll interval, in millisecondstopFixedCount- the number of items to fix at the top. May be 0bottomFixedCount- the number of items to fix at the bottom. May be 0- Throws:
IllegalArgumentException- if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative
-
-
Method Details
-
setScrollerFor
Register 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
Register 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
Register a menu to be scrolled with the default number of items to display at a time and the specified scrolling interval.- Parameters:
menu- the menuscrollCount- the number of items to display at a time- Returns:
- the MenuScroller
- Throws:
IllegalArgumentException- if scrollCount is 0 or negative
-
setScrollerFor
Register 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 menuscrollCount- the number of items to display at a time- Returns:
- the MenuScroller
- Throws:
IllegalArgumentException- if scrollCount is 0 or negative
-
setScrollerFor
Register a menu to be scrolled, with the specified number of items to display at a time and the specified scrolling interval.- Parameters:
menu- the menuscrollCount- the number of items to be displayed at a timeinterval- the scroll interval, in milliseconds- Returns:
- the MenuScroller
- Throws:
IllegalArgumentException- if scrollCount or interval is 0 or negative
-
setScrollerFor
Register 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 menuscrollCount- the number of items to be displayed at a timeinterval- the scroll interval, in milliseconds- Returns:
- the MenuScroller
- Throws:
IllegalArgumentException- if scrollCount or interval is 0 or negative
-
setScrollerFor
public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount) Register 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 menuscrollCount- the number of items to display in the scrolling portioninterval- the scroll interval, in millisecondstopFixedCount- 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:
IllegalArgumentException- if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative
-
setScrollerFor
public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval, int topFixedCount, int bottomFixedCount) Register 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 menuscrollCount- the number of items to display in the scrolling portioninterval- the scroll interval, in millisecondstopFixedCount- the number of items to fix at the top. May be 0bottomFixedCount- the number of items to fix at the bottom. May be 0- Returns:
- the MenuScroller
- Throws:
IllegalArgumentException- if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative
-
mouseWheelMoved
- Specified by:
mouseWheelMovedin interfaceMouseWheelListener
-
getInterval
Return the scroll interval in milliseconds.- Returns:
- the scroll interval in milliseconds
-
setInterval
Set the scroll interval in milliseconds.- Parameters:
interval- the scroll interval in milliseconds- Throws:
IllegalArgumentException- if interval is 0 or negative
-
getscrollCount
Return the number of items in the scrolling portion of the menu.- Returns:
- the number of items to display at a time
-
setScrollCount
Set the number of items in the scrolling portion of the menu.- Parameters:
scrollCount- the number of items to display at a time- Throws:
IllegalArgumentException- if scrollCount is 0 or negative
-
getTopFixedCount
Return the number of items fixed at the top of the menu or popup menu.- Returns:
- the number of items
-
setTopFixedCount
Set the number of items to fix at the top of the menu or popup menu.- Parameters:
topFixedCount- the number of items
-
getBottomFixedCount
Return the number of items fixed at the bottom of the menu or popup menu.- Returns:
- the number of items
-
setBottomFixedCount
Set the number of items to fix at the bottom of the menu or popup menu.- Parameters:
bottomFixedCount- the number of items
-
keepVisible
Scroll the specified item into view each time the menu is opened. Call this method withnullto restore the default behavior, which is to show the menu as it last appeared.- Parameters:
item- the item to keep visible- See Also:
-
keepVisible
Scroll the item at the specified index into view each time the menu is opened. Call this method with-1to 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:
-
dispose
Remove this MenuScroller from the associated menu and restores the default behavior of the menu. -
finalize
Ensure that thedisposemethod of this MenuScroller is called when there are no more refrences to it.
-