Menu to UIMenuList

To convert from AWT to AFC, instances of java.awt.menu should be transformed into instances of com.ms.ui.UIMenuList.

Menu extends MenuItem: be sure to see its changes.

Purpose and Usage

A UIMenuList is a list of items to be displayed in a menu. The power of this is that you can build menus with all kinds of UIComponents, instead of being limited to Strings like in AWT. Anything that extends from UIComponent or implements the IUIComponent interface can be put in a UIMenuList.

UIMenuLists can implement two new styles from UIVerticalFlowLayout (the layout manager for UIMenuLists), MULTICOLUMN (to put the items into multiple columns) and FILL (which extends the clickable area of an item to the width of the menu column). So these are declared like

UIMenuList myMenuList = new UIMenuList(UIVerticalFlowLayout.FILL);

Typically, you will build a UIMenuList and then create a UIMenuButton with it, like

new UIMenuButton(String, /* flag */, myMenuList);

You can also use UIMenuItems (though those are better for submenus). Alternatively, you can build a context-sensitive menu by associating a UIMenuList with a UIComponent, like

new UIContextMenu(myComponent, myMenuList);

You can also add a UIMenuItem to a UIMenuList to make a submenu. If you add a UILine to a UIMenuList, you will add a separator. More details on UIMenuButton and UIContextMenu can be found in their documentation.

AFC does not support tear-off menus.

 

Porting

This is the set of changes you need to make to port all Menu methods to UIMenuList methods. Any method not listed here or below does not need to be changed.

 

AWT Code AFC Code Comments
Menu() UIMenuList() or
UIMenuList(int)
The int specifies a style (see above).
addSeparator() add( new UILine())  
countItems() getComponentCount() Deprecated in AWT 1.1
getItemCount() getComponentCount()  
insert(String, int) get(String, int)  
insertSeparator(int) add( new UILine(), int)  
isTearOff() false AFC doesn't support tear-off menus.

 

Unsupported Methods

Some methods in java.awt.Menu are not directly supported in com.ms.ui.UIMenuList. Those methods and suggested changes are described here.

 

AWT Code/Suggested AFC Code Comments
Menu(String)

UIMenuList()

The label of the menu has to be assigned to the UIMenuButton, UIMenuItem, or UIContextMenu associated with this list.
Menu(String, boolean)

UIMenuList()

The label of the menu has to be assigned to the UIMenuButton, UIMenuItem, or UIContextMenu associated with this list. AFC does not support tear-off menus.
add(MenuItem)

add(UIComponent) or
add(String)

AFC does not support MenuItem: add UIComponents or Strings instead.
getItem(int)

getComponent(int)

getComponent returns a UIComponent and getItem returns a String.
insert(MenuItem, int)

add(UIComponent, int) or
add(String, int)

AFC does not support MenuItem: add UIComponents or Strings instead.
paramString()

getName(), etc.

Call getName or one of the other getXXX functions to get the information you need.
remove(MenuComponent)

remove(UIComponent) or
remove(int)

AFC does not support MenuComponent: remove UIComponents or Strings instead.