Groovy Documentation

com.wordpress.tipsforjava.swing
[Java] Class MenuScroller

java.lang.Object
  com.wordpress.tipsforjava.swing.MenuScroller

public class MenuScroller
extends 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.

Authors:
Rob Camick
Darryl Burke


Nested Class Summary
private static enum 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 JMenu menu

private Component[] menuItems

private MenuScroller.MenuScrollListener menuListener

private JPopupMenu popupMenu

private int scrollCount

private int topFixedCount

private MenuScroller.MenuScrollItem upItem

 
Constructor Summary
MenuScroller(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(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(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(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(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(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(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(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 getTopFixedCount()

Returns the number of items fixed at the top of the menu or popup menu.

int getscrollCount()

Returns the number of items in the scrolling portion of the menu.

private void refreshMenu()

private void restoreMenuItems()

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

private void setMenuItems()

void setScrollCount(int scrollCount)

Sets the number of items in the scrolling portion of the menu.

static MenuScroller setScrollerFor(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(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(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(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(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(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(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(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.

private void setValues(int scrollCount, int interval, int topFixedCount, int bottomFixedCount)

MenuScroller valueOf(String name)

Returns the enum constant of this type with the specified name.

MenuScroller[] values()

Returns an array containing the constants of this enum type, in the order they are declared.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

bottomFixedCount

private int bottomFixedCount


downItem

private MenuScroller.MenuScrollItem downItem


firstIndex

private int firstIndex


interval

private int interval


menu

private JMenu menu


menuItems

private Component[] menuItems


menuListener

private final MenuScroller.MenuScrollListener menuListener


popupMenu

private JPopupMenu popupMenu


scrollCount

private int scrollCount


topFixedCount

private int topFixedCount


upItem

private MenuScroller.MenuScrollItem upItem


 
Constructor Detail

MenuScroller

public MenuScroller(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(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(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.

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


MenuScroller

public MenuScroller(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.

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


MenuScroller

public MenuScroller(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.

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


MenuScroller

public MenuScroller(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.

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


MenuScroller

public MenuScroller(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.

throws:
IllegalArgumentException if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative
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


MenuScroller

public MenuScroller(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.

throws:
IllegalArgumentException if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative
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


 
Method Detail

dispose

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


finalize

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

Throws:
Throwable if an error occurs.
See Also:
MenuScroller.dispose


getBottomFixedCount

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

Returns:
the number of items


getInterval

public int getInterval()
Returns the scroll interval in milliseconds

Returns:
the scroll interval in milliseconds


getTopFixedCount

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

Returns:
the number of items


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


refreshMenu

private void refreshMenu()


restoreMenuItems

private void restoreMenuItems()


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


setInterval

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

throws:
IllegalArgumentException if interval is 0 or negative
Parameters:
interval - the scroll interval in milliseconds


setMenuItems

private void setMenuItems()


setScrollCount

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

throws:
IllegalArgumentException if scrollCount is 0 or negative
Parameters:
scrollCount - the number of items to display at a time


setScrollerFor

public static MenuScroller setScrollerFor(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(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(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.

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


setScrollerFor

public static MenuScroller setScrollerFor(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.

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


setScrollerFor

public static MenuScroller setScrollerFor(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.

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


setScrollerFor

public static MenuScroller setScrollerFor(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.

throws:
IllegalArgumentException if scrollCount or interval is 0 or negative
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


setScrollerFor

public static MenuScroller setScrollerFor(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.

throws:
IllegalArgumentException if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative
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


setScrollerFor

public static MenuScroller setScrollerFor(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.

throws:
IllegalArgumentException if scrollCount or interval is 0 or negative or if topFixedCount or bottomFixedCount is negative
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


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


setValues

private void setValues(int scrollCount, int interval, int topFixedCount, int bottomFixedCount)


valueOf

MenuScroller valueOf(String name)
Returns the enum constant of this type with the specified name.


values

MenuScroller[] values()
Returns an array containing the constants of this enum type, in the order they are declared.


 

Groovy Documentation