Package edu.wisc.ssec.mcidasv.ui
Class MenuScroller
java.lang.Object
edu.wisc.ssec.mcidasv.ui.MenuScroller
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 MenuScroller.java 1.5.0 04/02/12 License: use / modify without restrictions (see https://tips4java.wordpress.com/about/) Heavily modified for JOSM needs => drop unused features and replace static scrollcount approach by dynamic behaviour
- Author:
- Darryl, https://tips4java.wordpress.com/2009/02/01/menu-scroller/
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enum
private class
private class
private class
private class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private MenuScroller.MenuScrollItem
private int
private int
private JPopupMenu
private Component[]
private final MenuScroller.MenuScrollListener
private final MouseWheelListener
private JComponent
private int
private MenuScroller.MenuScrollItem
-
Constructor Summary
ConstructorsConstructorDescriptionMenuScroller
(JComponent parentComp, JMenu menu) MenuScroller
(JComponent parentComp, JMenu menu, int interval) MenuScroller
(JComponent parentComp, JMenu menu, int interval, int topFixedCount) MenuScroller
(JMenu menu) Constructs aMenuScroller
that scrolls a menu with the default scrolling interval.MenuScroller
(JMenu menu, int interval) Constructs aMenuScroller
that scrolls a menu with the specified scrolling interval.MenuScroller
(JMenu menu, int interval, int topFixedCount) Constructs aMenuScroller
that scrolls a menu with the specified scrolling interval, and the specified numbers of items fixed at the top of the menu.MenuScroller
(JPopupMenu menu) Constructs aMenuScroller
that scrolls a popup menu with the default scrolling interval.MenuScroller
(JPopupMenu menu, int interval) Constructs aMenuScroller
that scrolls a popup menu with the specified scrolling interval.MenuScroller
(JPopupMenu menu, int interval, int topFixedCount) Constructs aMenuScroller
that 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
Modifier and TypeMethodDescriptionprivate int
computeScrollCount
(int startIndex) void
dispose()
Removes this MenuScroller from the associated menu and restores the default behavior of the menu.int
Returns the scroll interval in millisecondsstatic Dimension
getMaxDimensionOnScreen
(JComponent parent, JComponent component) Computes the maximum dimension for a component to fit in screen displayingcomponent
.int
Returns the number of items fixed at the top of the menu or popup menu.private void
void
void
setInterval
(int interval) Sets the scroll interval in millisecondsvoid
setParent
(JComponent parent) static MenuScroller
setScrollerFor
(JMenu menu) Registers a menu to be scrolled with the default scrolling interval.static MenuScroller
setScrollerFor
(JMenu menu, int interval) Registers a menu to be scrolled, with the specified scrolling interval.static MenuScroller
setScrollerFor
(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 MenuScroller
setScrollerFor
(JPopupMenu menu) Registers a popup menu to be scrolled with the default scrolling interval.static MenuScroller
setScrollerFor
(JPopupMenu menu, int interval) Registers a popup menu to be scrolled, with the specified scrolling interval.static MenuScroller
setScrollerFor
(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.void
setTopFixedCount
(int topFixedCount) Sets the number of items to fix at the top of the menu or popup menu.
-
Field Details
-
parent
-
upItem
-
downItem
-
mouseWheelListener
-
interval
-
topFixedCount
-
firstIndex
-
ARROW_ICON_HEIGHT
- See Also:
-
-
Constructor Details
-
MenuScroller
Constructs aMenuScroller
that scrolls a menu with the default scrolling interval.- Parameters:
menu
- the menu- Throws:
IllegalArgumentException
- if scrollCount is 0 or negative
-
MenuScroller
-
MenuScroller
Constructs aMenuScroller
that scrolls a popup menu with the default scrolling interval.- Parameters:
menu
- the popup menu- Throws:
IllegalArgumentException
- if scrollCount is 0 or negative
-
MenuScroller
Constructs aMenuScroller
that scrolls a menu with the specified scrolling interval.- Parameters:
menu
- the menuinterval
- the scroll interval, in milliseconds- Throws:
IllegalArgumentException
- if scrollCount or interval is 0 or negative
-
MenuScroller
Constructs aMenuScroller
that scrolls a popup menu with the specified scrolling interval.- Parameters:
menu
- the popup menuinterval
- the scroll interval, in milliseconds- Throws:
IllegalArgumentException
- if scrollCount or interval is 0 or negative
-
MenuScroller
-
MenuScroller
Constructs aMenuScroller
that 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:
IllegalArgumentException
- if scrollCount or interval is 0 or negative or if topFixedCount is negative
-
MenuScroller
-
MenuScroller
Constructs aMenuScroller
that 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:
IllegalArgumentException
- if scrollCount or interval is 0 or negative or if topFixedCount is negative
-
-
Method Details
-
getMaxDimensionOnScreen
Computes the maximum dimension for a component to fit in screen displayingcomponent
.- Parameters:
component
- The component to get current screen info from. Must not benull
- Returns:
- Maximum dimension for a component to fit in current screen.
- Throws:
NullPointerException
- ifcomponent
isnull
.
-
computeScrollCount
-
setScrollerFor
Registers a menu to be scrolled with the default scrolling interval.- Parameters:
menu
- Menu to- Returns:
- the MenuScroller
-
setScrollerFor
Registers a popup menu to be scrolled with the default scrolling interval.- Parameters:
menu
- the popup menu- Returns:
- the MenuScroller
-
setScrollerFor
Registers a menu to be scrolled, with the specified scrolling interval.- Parameters:
menu
- the menuinterval
- the scroll interval, in milliseconds- Returns:
- the MenuScroller
- Throws:
IllegalArgumentException
- if scrollCount or interval is 0 or negative
-
setScrollerFor
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:
IllegalArgumentException
- if scrollCount or interval is 0 or negative
-
setScrollerFor
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:
IllegalArgumentException
- if scrollCount or interval is 0 or negative or if topFixedCount is negative
-
setScrollerFor
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:
IllegalArgumentException
- if scrollCount or interval is 0 or negative or if topFixedCount is negative
-
getInterval
Returns the scroll interval in milliseconds- Returns:
- the scroll interval in milliseconds
-
setInterval
Sets the scroll interval in milliseconds- Parameters:
interval
- the scroll interval in milliseconds- Throws:
IllegalArgumentException
- if interval is 0 or negative
-
getTopFixedCount
Returns the number of items fixed at the top of the menu or popup menu.- Returns:
- the number of items
-
setTopFixedCount
Sets the number of items to fix at the top of the menu or popup menu.- Parameters:
topFixedCount
- the number of items
-
dispose
Removes this MenuScroller from the associated menu and restores the default behavior of the menu. -
resetMenu
-
setParent
-
refreshMenu
-