import java.util.Hashtable;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class ListAllEvents extends MainScreen {
// -----------------------------------------------------------------
VerticalFieldManager mainManager;
VerticalFieldManager listVFM;
HorizontalFieldManager rowHFM[];
int row_height;
LabelField[] eventTimeLabel;
LabelField[] eventNameLabel;
public ListAllEvents() {
createUI();
createEventHashtable();
}
// -------------- Create UI --------------------------------
public void createUI() {
mainManager = new VerticalFieldManager(
VerticalFieldManager.VERTICAL_SCROLL
| VerticalFieldManager.VERTICAL_SCROLLBAR
| VerticalFieldManager.USE_ALL_HEIGHT
| VerticalFieldManager.FIELD_LEFT | DrawStyle.LEFT) {
protected void sublayout(int maxWidth, int maxHeight) {
int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();
super.sublayout(displayWidth, displayHeight);
setExtent(displayWidth, displayHeight);
}
public void paint(Graphics g) {
g.setBackgroundColor(Color.WHITE);
g.clear();
super.paint(g);
}
};
add(mainManager);
}
// ----------------------------Create List
// ----------------------------------------
public void createList(Hashtable eventHashtable) {
listVFM = new VerticalFieldManager();
rowHFM = new HorizontalFieldManager[eventHashtable.size()];
eventTimeLabel = new LabelField[eventHashtable.size()];
eventNameLabel = new LabelField[eventHashtable.size()];
row_height = 90;
int j = 0;
int row_count = 0;
if (eventHashtable.size() > 0) {
EventItem ei = null;
for (int i = 0; i < eventHashtable.size(); i++) {
Object obj = eventHashtable.get(new Integer(i));
final EventItem item = (EventItem) obj;
if (item != null) {
String str_event_time = item.event_time;
String str_event_name = item.event_name;
rowHFM[row_count] = new HorizontalFieldManager(
HorizontalFieldManager.USE_ALL_HEIGHT) {
protected void sublayout(int maxWidth, int maxHeight) {
int displayWidth = Display.getWidth();
int displayHeight = 80;
super.sublayout(displayWidth, displayHeight);
setExtent(displayWidth, displayHeight);
}
};
rowHFM[row_count].setPadding(2, 2, 2, 2);
eventTimeLabel[row_count] = new LabelField(str_event_time) {
protected void layout(int maxWidth, int maxHeight) {
int displayWidth = (int) (Display.getWidth() / 2);
int displayHeight = maxHeight;
super.layout(displayWidth, displayHeight);
setExtent(displayWidth, displayHeight);
}
};
eventTimeLabel[row_count].setPadding(5, 0, 0, 2);
eventNameLabel[row_count] = new LabelField(str_event_name) {
protected void layout(int maxWidth, int maxHeight) {
int displayWidth = (int) (Display.getWidth() / 2);
int displayHeight = maxHeight;
super.layout(displayWidth, displayHeight);
setExtent(displayWidth, displayHeight);
}
};
eventNameLabel[row_count].setPadding(5, 0, 0, 2);
rowHFM[row_count].add(eventTimeLabel[row_count]);
rowHFM[row_count].add(eventNameLabel[row_count]);
listVFM.add(rowHFM[row_count]);
}
}
}
listVFM.setPadding(5, 2, 5, 2);
mainManager.add(listVFM);
}
public void createEventHashtable() {
String event_time1 = "8:00";
String event_time2 = "8:00";
String event_name1 = "Event 1";
String event_name2 = "Event 2";
Hashtable eventHashtable = new Hashtable();
eventHashtable.put(new Integer(0), new EventItem(event_time1,
event_name1));
eventHashtable.put(new Integer(1), new EventItem(event_time2,
event_name2));
createList(eventHashtable);
}
}
public class EventItem {
String event_time;
String event_name;
public EventItem(String event_time, String event_name) {
this.event_name = event_name;
this.event_time = event_time;
}
}