Component to UIStateComponent

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

Purpose and Usage

AFC's UIStateComponent and UIComponent classes (UIStateComponent extends from UIComponent) add functionality to the component model.

One of the most important advantages is that instances of UIStateComponent and UIComponent can be associated with global IDs, which associate an ID with a component instantiated inside a method in the class. By doing this, you can remove global instances of component, and instead just have integers. This reduces the size of your classes. An example using UIPushButton, which replaces Button and extends from UIStateComponent, is below:

import com.ms.ui.*;
import com.ms.ui.event.*;

public class MyButton extends UIFrame implements IUIActionListener
{

/* These are the IDs for two buttons */

public static final int FOO_BUTTON = 101;
public static final int BAR_BUTTON = 102;

public static void main(String args[])
{

new MyButton();

}

public MyButton()
{

/* This code instantiates two buttons, one as a
/* string, the other as a UIText object */

UIPushButton fooButton =
new UIPushButton("foo");

fooButton.setID(FOO_BUTTON);
fooButton.addActionListener(this);

UIText barText = new UIText("bar");
UIPushButton barButton =
new UIPushButton(barText, UIPushButton.RAISED);

barButton.setID(BAR_BUTTON);
barButton.addActionListener(this);

/* This adds the buttons to a visible frame */

add(fooButton, "north");
add(barButton, "south");

setSize(200,200);
setVisible(true);

}

public void actionPerformed(UIActionEvent evt)
{

/* This code watches for the buttons to be pressed
/* by getting the IDs of actions, and bases the
/* output on those IDs. */

switch((evt.getActionItem()).getID())
{

case FOO_BUTTON:

System.out.println("Foo clicked");
break;

case BAR_BUTTON:

System.out.println("Bar clicked");
break;

}

}

}

 

In UIStateComponent the mechanism of giving keyboard focus is slightly different. Use the function isKeyable() to find out if this component can receive keyboard input or use isKeyable(true) to find out if all the ancestors of this control as well as this control can receive keyboard input. For transferring focus to another component in the same container as the current UIComponent, use the navigate() or passFocus() methods of the container. See Container usage for more information.

It is important to note a difference in the painting scheme between AWT and AFC. In AWT, repaint() executes asynchronously: it may not be executed immediately when called, and several pending repaints may be combined. In AFC, repaint() executes synchronously, which gives you more control.

Porting

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

 

AWT Code AFC Code Comments
bounds() getBounds() Deprecated in AWT 1.1
disable() setEnabled(false)  
enable(boolean) setEnabled(true) Deprecated in AWT 1.1
getComponentAt(int, int) getComponent(int, int)  
getComponentAt(Point) getComponent(Point)  
inside(int, int) contains(int, int) Deprecated in AWT 1.1
isFocusTraversable() isKeyable()  
locate(int, int) getComponent(int, int) Deprecated in AWT 1.1
location() getLocation() Deprecated in AWT 1.1
minimumSize() getMinimumSize() Deprecated in AWT 1.1
move(int, int) setLocation(int, int) Deprecated in AWT 1.1
nextFocus() (getParent()).navigate(getParent().getFocusComponent(),
UIAccessible.NAVDIR_NEXT, true)
see UIContainer: Deprecated in AWT 1.1
reshape(int, int, int, int) setBounds(int, int, int, int) Deprecated in AWT 1.1
resize(Dimension) setSize(Dimension) Deprecated in AWT 1.1
show() setVisible(true) Deprecated in AWT 1.1
show(boolean) setVisible(true) Deprecated in AWT 1.1
size() getSize() Deprecated in AWT 1.1
transferFocus() (getParent()).navigate(getParent().getFocusComponent(),
UIAccessible.NAVDIR_NEXT, true)
See UIContainer.

 

Unsupported Methods

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

 

AWT Code/Suggested AFC Code Comments
action(Event, Object)

action(Event, Object)

In AWT, the Object argument is the action event that was generated. In AFC, the Object argument is the UIComponent that threw the action event.
arg.toString()

arg.getName()

 
add(PopupMenu popup)

new UIContextMenu(IUIComponent, UIMenuList)

In AFC, you can create a context menu for a component by using UIContextMenu. UIMenuList is a list of items that will appear in the context menu. See PopupMenu for more information.
paramString()

getName(), etc.

Use the appropriate getXXX function to get the information you need.
BOTTOM_ALIGNMENT
CENTER_ALIGNMENT
LEFT_ALIGNMENT
RIGHT_ALIGNMENT
TOP_ALIGNMENT
addComponentListener(ComponentListener)
checkImage(Image, ImageObserver)
checkImage(Image, int, int, ImageObserver)
dispatchEvent(AWTEvent)
getAlignmentX()
getAlignmentY( )
getColorModel()
getLocale()
getTreeLock()
list()
list(PrintStream)
list(PrintStream, int)
list(PrintWriter)
list(PrintWriter, int)
remove(MenuComponent popup)
removeComponentListener(ComponentListener)
setLocale(Locale)

(no suggestions)