Java Reference
In-Depth Information
switch (types[i]) {
case Contact.TYPE_HOME :
addSub(id, "Home", types[i]);
break;
case Contact.TYPE_WORK :
addSub(id, "Work", types[i]);
break;
// add other types here
}
}
}
// other data types are ignored
}
public void itemStateChanged(ItemEvent e) {
CardLayout cl = (CardLayout) (cardPane.getLayout());
cl.show(cardPane, (String) e.getItem());
}
public ContactDialog(Frame frame, ContactList contactList) {
super(frame, "Edit Contact", true);
this.contactList = contactList;
contact = contactList.createContact();
add(typeChoice, BorderLayout.NORTH);
add(cardPane, BorderLayout.CENTER);
typeChoice.addItemListener(this);
int[] ids = contactList.getSupportedFields();
for (int i = 0; i < ids.length; i++)
addField(ids[i]);
Panel buttonPane = new Panel();
buttonPane.add(okButton);
buttonPane.add(cancelButton);
okButton.addActionListener(this);
cancelButton.addActionListener(this);
add(buttonPane, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
result = false;
hide();
}
} );
pack();
}
public boolean edit(Contact contact, String title) {
setTitle(title);
this.contact = contact;
result = false;
for (int i = 0; i < fieldList.size(); i++) {
FieldInfo info = (FieldInfo) fieldList.elementAt(i);
String text =
contact.getDataType(info.id) == PIMElement.STRING
? contact.getString(info.id)
: contact.getTypedString(info.id, info.type);
info.field.setText(text == null ? "" : text);
}
show();
if (result) {
for (int i = 0; i < fieldList.size(); i++) {
FieldInfo info = (FieldInfo) fieldList.elementAt(i);
String text = info.field.getText();
Search WWH ::




Custom Search