Package org.openstreetmap.josm.gui
Class MenuScroller
- java.lang.Object
-
- 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 of the menu.Implementation note: The default scrolling interval is 150 milliseconds.
- Since:
- 4593
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMenuScroller.MenuIconprivate classMenuScroller.MenuScrollItemprivate classMenuScroller.MenuScrollListenerprivate classMenuScroller.MenuScrollTimerprivate classMenuScroller.MouseScrollListener
-
Field Summary
Fields Modifier and Type Field Description private static intARROW_ICON_HEIGHTprivate MenuScroller.MenuScrollItemdownItemprivate intfirstIndexprivate javax.swing.JPopupMenumenuprivate java.awt.Component[]menuItemsprivate MenuScroller.MenuScrollListenermenuListenerprivate java.awt.event.MouseWheelListenermouseWheelListenerprivate inttopFixedCountprivate MenuScroller.MenuScrollItemupItem
-
Constructor Summary
Constructors Constructor Description MenuScroller(javax.swing.JMenu menu)Constructs aMenuScrollerthat scrolls a menu with the default scrolling interval.MenuScroller(javax.swing.JMenu menu, int interval)Constructs aMenuScrollerthat scrolls a menu with the specified scrolling interval.MenuScroller(javax.swing.JMenu menu, int interval, int topFixedCount)Constructs aMenuScrollerthat scrolls a menu with the specified scrolling interval, and the specified numbers of items fixed at the top of the menu.MenuScroller(javax.swing.JPopupMenu menu)Constructs aMenuScrollerthat scrolls a popup menu with the default scrolling interval.MenuScroller(javax.swing.JPopupMenu menu, int interval)Constructs aMenuScrollerthat scrolls a popup menu with the specified scrolling interval.MenuScroller(javax.swing.JPopupMenu menu, int interval, int topFixedCount)Constructs aMenuScrollerthat scrolls a popup menu with the specified scrolling interval, and the specified numbers of items fixed at the top of the popup menu.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private intcomputeScrollCount(int startIndex)voiddispose()Removes this MenuScroller from the associated menu and restores the default behavior of the menu.intgetTopFixedCount()Returns the number of items fixed at the top of the menu or popup menu.private voidrefreshMenu()static MenuScrollersetScrollerFor(javax.swing.JMenu menu)Registers a menu to be scrolled with the default scrolling interval.static MenuScrollersetScrollerFor(javax.swing.JMenu menu, int interval)Registers a menu to be scrolled, with the specified scrolling interval.static MenuScrollersetScrollerFor(javax.swing.JMenu menu, int interval, int topFixedCount)Registers a menu to be scrolled, with the specified scrolling interval, and the specified numbers of items fixed at the top of the menu.static MenuScrollersetScrollerFor(javax.swing.JPopupMenu menu)Registers a popup menu to be scrolled with the default scrolling interval.static MenuScrollersetScrollerFor(javax.swing.JPopupMenu menu, int interval)Registers a popup menu to be scrolled, with the specified scrolling interval.static MenuScrollersetScrollerFor(javax.swing.JPopupMenu menu, int interval, int topFixedCount)Registers a popup menu to be scrolled, with the specified scrolling interval, and the specified numbers of items fixed at the top of the popup menu.voidsetTopFixedCount(int topFixedCount)Sets the number of items to fix at the top of the menu or popup menu.
-
-
-
Field Detail
-
menu
private javax.swing.JPopupMenu menu
-
menuItems
private java.awt.Component[] menuItems
-
upItem
private final MenuScroller.MenuScrollItem upItem
-
downItem
private final MenuScroller.MenuScrollItem downItem
-
menuListener
private final MenuScroller.MenuScrollListener menuListener
-
mouseWheelListener
private final java.awt.event.MouseWheelListener mouseWheelListener
-
topFixedCount
private int topFixedCount
-
firstIndex
private int firstIndex
-
ARROW_ICON_HEIGHT
private static final int ARROW_ICON_HEIGHT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MenuScroller
public MenuScroller(javax.swing.JMenu menu)
Constructs aMenuScrollerthat scrolls a menu with the default scrolling interval.- Parameters:
menu- the menu- Throws:
java.lang.IllegalArgumentException- if scrollCount is 0 or negative
-
MenuScroller
public MenuScroller(javax.swing.JPopupMenu menu)
Constructs aMenuScrollerthat scrolls a popup menu with the default scrolling interval.- Parameters:
menu- the popup menu- Throws:
java.lang.IllegalArgumentException- if scrollCount is 0 or negative
-
MenuScroller
public MenuScroller(javax.swing.JMenu menu, int interval)
Constructs aMenuScrollerthat scrolls a menu with the specified scrolling interval.- Parameters:
menu- the menuinterval- the scroll interval, in milliseconds- Throws:
java.lang.IllegalArgumentException- if scrollCount or interval is 0 or negative- Since:
- 7463
-
MenuScroller
public MenuScroller(javax.swing.JPopupMenu menu, int interval)
Constructs aMenuScrollerthat scrolls a popup menu with the specified scrolling interval.- Parameters:
menu- the popup menuinterval- the scroll interval, in milliseconds- Throws:
java.lang.IllegalArgumentException- if scrollCount or interval is 0 or negative- Since:
- 7463
-
MenuScroller
public MenuScroller(javax.swing.JMenu menu, int interval, int topFixedCount)
Constructs aMenuScrollerthat scrolls a menu with the specified scrolling interval, and the specified numbers of items fixed at the top of the menu.- Parameters:
menu- the menuinterval- the scroll interval, in millisecondstopFixedCount- the number of items to fix at the top. May be 0- Throws:
java.lang.IllegalArgumentException- if scrollCount or interval is 0 or negative or if topFixedCount is negative- Since:
- 7463
-
MenuScroller
public MenuScroller(javax.swing.JPopupMenu menu, int interval, int topFixedCount)
Constructs aMenuScrollerthat scrolls a popup menu with the specified scrolling interval, and the specified numbers of items fixed at the top of the popup menu.- Parameters:
menu- the popup menuinterval- the scroll interval, in millisecondstopFixedCount- the number of items to fix at the top. May be 0- Throws:
java.lang.IllegalArgumentException- if scrollCount or interval is 0 or negative or if topFixedCount is negative- Since:
- 7463
-
-
Method Detail
-
computeScrollCount
private int computeScrollCount(int startIndex)
-
setScrollerFor
public static MenuScroller setScrollerFor(javax.swing.JMenu menu)
Registers a menu to be scrolled with 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 scrolling interval.- Parameters:
menu- the popup menu- Returns:
- the MenuScroller
-
setScrollerFor
public static MenuScroller setScrollerFor(javax.swing.JMenu menu, int interval)
Registers a menu to be scrolled, with the specified scrolling interval.- Parameters:
menu- the menuinterval- the scroll interval, in milliseconds- Returns:
- the MenuScroller
- Throws:
java.lang.IllegalArgumentException- if scrollCount or interval is 0 or negative- Since:
- 7463
-
setScrollerFor
public static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu, int interval)
Registers a popup menu to be scrolled, with the specified scrolling interval.- Parameters:
menu- the popup menuinterval- the scroll interval, in milliseconds- Returns:
- the MenuScroller
- Throws:
java.lang.IllegalArgumentException- if scrollCount or interval is 0 or negative- Since:
- 7463
-
setScrollerFor
public static MenuScroller setScrollerFor(javax.swing.JMenu menu, int interval, int topFixedCount)
Registers a menu to be scrolled, with the specified scrolling interval, and the specified numbers of items fixed at the top of the menu.- Parameters:
menu- the menuinterval- the scroll interval, in millisecondstopFixedCount- the number of items to fix at the top. May be 0.- Returns:
- the MenuScroller
- Throws:
java.lang.IllegalArgumentException- if scrollCount or interval is 0 or negative or if topFixedCount is negative- Since:
- 7463
-
setScrollerFor
public static MenuScroller setScrollerFor(javax.swing.JPopupMenu menu, int interval, int topFixedCount)
Registers a popup menu to be scrolled, with the specified scrolling interval, and the specified numbers of items fixed at the top of the popup menu.- Parameters:
menu- the popup menuinterval- the scroll interval, in millisecondstopFixedCount- the number of items to fix at the top. May be 0- Returns:
- the MenuScroller
- Throws:
java.lang.IllegalArgumentException- if scrollCount or interval is 0 or negative or if topFixedCount is negative- Since:
- 7463
-
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
-
dispose
public void dispose()
Removes this MenuScroller from the associated menu and restores the default behavior of the menu.
-
refreshMenu
private void refreshMenu()
-
-