List to UIList

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

List extends Component: be sure to see its changes.

Purpose and Usage

AFC's UIList class provides several advantages over the basic List class. UIList provides another selection option, EXTENDSELECT, which allows the user to select items by dragging the mouse or using the SHIFT key. Also, UIList uses the UIVerticalFlowLayout for its layout manager, which allows the list to span multiple columns (with MULTICOLUMN), and allows you to extend the width of the selectable area to the width of the column (with FILL). Thus you might declare a new UIList as

new UIList(UIList.EXTENDSELECT, UIVerticalFlowLayout.FILL);

You cannot set the number of visible rows in UIList. The ability to scroll in a list is provided by UIScrollViewer: typically, you will create a UIScrollViewer object to display your list control.

 

Porting

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

 

AWT Code AFC Code Comments
List() or
List(int) or
List(int, boolean)
UIList() or
UIList(int) or
UIList(int, int)
As explained above, the int's in the constructors mean different things. See the documentation for more information.
addItem(String) add(String)  
addItem(String, int) add(String, int)  
clear() removeAll() Deprecated in AWT 1.1
countItems() getComponentCount() Deprecated in AWT 1.1
delItem(int) remove(int) Deprecated in AWT 1.1
deselect(int) removeSelectedIndex(int)  
getItemCount() getComponentCount()  
getSelectedIndexes() getSelectedIndices()  
isMultipleMode() (getSelectionMode == UIList.MULTISELECT)  
minimumSize() getMinimumSize() Deprecated in AWT 1.1
preferredSize() getPreferredSize()  
replaceItem(String, int) remove(int);
add(String, int)
 
select(int) setSelectedIndex(int)  
setMultipleMode(boolean) setSelectionMode(boolean) true for MULTISELECT, false for SINGLESELECT
setMultipleSelections(boolean) setSelectionMode(boolean) true for MULTISELECT, false for SINGLESELECT: Deprecated in AWT 1.1

 

 

Unsupported Methods

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

 

AWT Code/Suggested AFC Code Comments
allowsMultipleSelections()

getStateCode()

check for UIAccessible.STATE_SYSTEM_MULTISELECTABLE; deprecated in AWT 1.1.
delItems(int, int)

remove(int)

Use repeatedly; deprecated in AWT 1.1.
getItem(int)

getComponent(int)

getComponent returns a UIComponent while getItem returns a String: you can then use getName.
getItems()

getComponents()

getComponent returns an array of UIComponents while getItems returns an array of Strings.
getMinimumSize(int)

(none)

In AFC you cannot specify the number of rows in a UIList, and so this function becomes unimportant.
getRows()

(no suggestions)

The number of rows displayed is not a property of UIList.
getSelectedItem()

(same)

This function exists in AFC, but it returns a UIComponent, while the AWT version returns a String.
getSelectedItems()

(same)

This function exists in AFC, but it returns an array of UIComponents, while the AWT version returns an array of Strings.
getSelectedObjects()

getSelectedItems()

The AFC version returns an array of UIComponents.
getVisibleIndex()

(no suggestions)

The number of visible rows displayed, and thus the currently visible one, is not a property of UIList.
isIndexSelected(int)

getSelectedItems()

Use getSelectedItems and see if the one you are looking for is selected.
isSelected()

getSelectedItems()

Use getSelectedItems and see if the one you are looking for is selected; Deprecated in AWT 1.1.
makeVisible(int)

(no suggestions)

The visibility of rows displayed is not a property of UIList.
minimumSize(int)

(no suggestions)

In AFC you cannot specify the number of rows in a UIList, and so this function becomes unimportant: deprecated in AWT 1.1.
paramString()

getName(), etc.

Use getXXX methods to get the specific information you want.
preferredSize(int)

(no suggestions)

In AFC you cannot specify the number of visible rows in a UIList, and so this function becomes unimportant: deprecated in AWT 1.1.
remove(String)

remove(UIComponent)

In AFC when you add a string, you get a UIComponent as the return value. You should save this value to later remove the component.