Code:
public class EditPage extends VerticalManager implements ContentManager, TrackwheelListener {
private AccountImpl account;
public EditPage(long style, AccountInfo accInfo) {
super(style);
account = new AccountImpl(accInfo);
setContent(account.getFields());
}
/**
* Sets the content of the page.
*/
private void setContent(List fields) {
FontFamily fontFamily[] = FontFamily.getFontFamilies();
Font font = fontFamily[3].getFont(FontFamily.SCALABLE_FONT, 12);
Font textFont = fontFamily[3].getFont(FontFamily.SCALABLE_FONT, 16);
RulesManager rulesManager = new RulesManager(Manager.VERTICAL_SCROLL, 2 * fields.size());
ComponentsFactory componentFactory = ComponentsFactory.getInstance();
Field prevField = null;
LabelField label;
for (int i = 0; i < fields.size(); i++) {
AccountFieldImpl accountField = (AccountFieldImpl) fields.get(i);
String text = accountField.getName();
label = new LabelField(text);
label.setFont(font);
Field valueField = componentFactory.getComponent(accountField.getType(),
contentWidth - font.getAdvance(text) - 21, 17, textFont);
if (prevField == null) {
rulesManager.add(label, 8, 8);
rulesManager.add(valueField, XRule.PUT_AFTER, 5, label, 5);
} else {
rulesManager.add(label, 8, YRule.PUT_UNDER, 8, prevField);
rulesManager.add(valueField, XRule.PUT_AFTER, 5, label, YRule.PUT_UNDER, 5, prevField);
}
prevField = label;
}
add(rulesManager);
}
/**
* @see com.mycompany.ui.ContentManager#setThePosition(int, int)
*
* @param x - int
* @param y - int
*/
public void setThePosition(int x, int y) {
setPosition(x, y);
}
/**
* @see com.mycompany.ui.ContentManager#setLayout(int, int)
*
* @param width - int
* @param height - int
*/
public void setLayout(int width, int height) {
super.sublayout(width, height);
}
/**
* @see com.mycompany.ui.TrackwheelListener#trackwheelClick(int, int, Field)
*
* @param status - int
* @param time - int
* @param field - Field
*/
public boolean trackwheelClick(int status, int time, Field field) {
return true;
}
/**
* @see com.mycompany.ui.TrackwheelListener#trackwheelUnclick(int, int, Field)
*
* @param status - int
* @param time - int
* @param field - Field
*/
public boolean trackwheelUnclick(int status, int time, Field field) {
return true;
}
}
This is the UI page that is manager and holds all the ui field components. I have a class that is like custom manager to arrange the fields where i want. Here is a part of it:
Code:
public class RulesManager extends Manager {
public static final int ALIGN_LEFT_TO = 0;
public static final int ALIGN_RIGHT_TO = 1;
public static final int ALIGN_VERTICAL_AXIS = 2;
public static final int STICK_LEFT_TO = 3;
public static final int STICK_RIGHT_TO = 4;
public static final int ALIGN_UP_TO = 5;
public static final int ALIGN_DOWN_TO = 6;
public static final int ALIGN_HORIZONTAL_AXIS = 7;
public static final int STICK_UP_TO = 8;
public static final int STICK_DOWN_TO = 9;
/** the width of the manager; always has the display width value */
private int prefWidth;
/** the height of the manager; depends on the number of fields and their position */
private int prefHeight;
/** contains all the fields holds by the manager packed by FieldData objects */
private Vector fieldsData;
//........ some more methods
/**
* Adds a field to this manager with x and y coordinates.
*
* @param field - Field
* @param x - int
* @param y - int
*/
public void add(Field field, int x, int y) {
FieldData fd = new FieldData(field);
fd.setXExact(x);
fd.setYExact(y);
add(field);
prefHeight += field.getPreferredHeight() + y;
fieldsData.addElement(fd);
}
/**
* Adds a field to the manager.
*
* @param newField - Field
* @param xRule - XRule
* @param xOffset - int
* @param xrefField - Field
* @param yRule - YRule
* @param yOffset - int
* @param yrefField - Field
*/
public void add(Field newField, XRule xRule, int xOffset, Field xrefField, YRule yRule, int yOffset, Field yrefField) {
validateNewFieldNull(newField);
validateXRefField(newField, xrefField);
validateYRefField(newField, yrefField);
FieldData fd = new FieldData(newField);
fd.setXRef(xrefField, xRule.getId(), xOffset);
fd.setYRef(yrefField, yRule.getId(), yOffset);
add(newField);
fieldsData.addElement(fd);
}
/**
* @see net.rim.device.api.ui.Manager#sublayout(int, int)
*
* @param width - int
* @param height - int
*/
public void sublayout(int width, int height) {
int fieldsCount = fieldsData.size();
for (int j = 0; j < fieldsCount; j++) {
FieldData fieldData = (FieldData) fieldsData.elementAt(j);
Field field = fieldData.getField();
processRule(fieldData);
setPositionChild(field, fieldData.getX(), fieldData.getY());
layoutChild(field, field.getPreferredWidth(), field.getPreferredHeight());
}
setExtent(width, prefHeight);
}
I think it is a bit complicated to understand my code. But the problem is that this code works in 8120 simulator which is JDE 4.3.0, and not in 8100 (JDE 4.2.0)