Choice to UIChoice

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

Choice extends Component: be sure to see its changes.

Purpose and Usage

In AWT, all items in a Choice component must be strings. AFC allows you to do this: however, it also allows you to enter UIComponents as Choice components. In this manner, not only can you have text components in your choice bar, but you can have images and even canvasses. You also have more control over the look of the components.

The transformation of AWT to AFC components is simple: to add text components, for example, you would replace

add("foo");

by

add(new UIText("Foo"));

In AFC, you cannot remove or select (by name) individual items when added as Strings to the Choice component: however, you can do so when added as UIComponents.

Porting

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

AWT Code AFC Code Comments
add(String) addString(String) better to add UIComponents--see above
addItem(String) addString(String) better to add UIComponents--see above
countItems() (getMenu()).getComponentCount()  
getItem(int) ((getMenu()).getComponent(int)).getName()  
getItemCount() (getMenu()).getComponentCount()  
getSelectedIndex() (getMenu()).getSelectedIndex()  
getSelectedItem() ((getMenu()).getSelectedItem()).getName()  
insert(String, int) (getMenu()).add(String, int) better to add UIComponents--see above
removeAll() (getMenu()).removeAll()  
select(int) (getMenu()).setSelectedIndex(int)  

Unsupported Methods

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

 

AWT Code/Suggested AFC Code Comments
getSelectedObjects()

(getMenu()).getSelectedItems()

The AWT code returns a single-item array containing an Object with the labels (as Strings) of the choice items. The AFC suggestion returns the items as UIComponents: to get the labels, you will have to invoke getName() on the components.
paramString()

getName()

The AFC code cannot return the whole string of current settings.
remove(String)

(getMenu()).remove(UIComponent)

Entries in the Choice component added as Strings cannot be removed individually: add them as UIComponents instead.
select(String)

(getMenu()).getSelectedItem(UIComponent)

Entries in the Choice component added as strings cannot be selected by name: add them as UIComponents instead.