1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.jhylafax.addressbook;
21
22 import static net.sf.jhylafax.JHylaFAX.i18n;
23 import javax.swing.JFrame;
24 import javax.swing.JLabel;
25 import javax.swing.JTextField;
26 import net.wimpi.pim.contact.facades.SimpleContact;
27 import org.xnap.commons.gui.DefaultDialog;
28 import com.jgoodies.forms.builder.DefaultFormBuilder;
29 import com.jgoodies.forms.layout.FormLayout;
30
31 public class EditContactDialog extends DefaultDialog {
32
33 private SimpleContact contact;
34 private JTextField firstNameTextField;
35 private JLabel firstNameLabel;
36 private JLabel lastNameLabel;
37 private JTextField lastNameTextField;
38 private JTextField companyTextField;
39 private JLabel companyLabel;
40 private JTextField faxNumberTextField;
41 private JLabel faxNumberLabel;
42
43 public EditContactDialog(JFrame owner, SimpleContact contact) {
44 super(owner);
45
46 setApplyOnEnter(true);
47
48 FormLayout layout = new FormLayout("left:max(40dlu;pref), 3dlu, pref:grow", "");
49 DefaultFormBuilder builder = new DefaultFormBuilder(layout);
50 builder.setDefaultDialogBorder();
51 setMainComponent(builder.getPanel());
52
53 firstNameTextField = new JTextField(20);
54 firstNameLabel = builder.append("", firstNameTextField);
55 builder.nextLine();
56
57 lastNameTextField = new JTextField(20);
58 lastNameLabel = builder.append("", lastNameTextField);
59 builder.nextLine();
60
61 companyTextField = new JTextField(20);
62 companyLabel = builder.append("", companyTextField);
63 builder.nextLine();
64
65 faxNumberTextField = new JTextField(20);
66 faxNumberLabel = builder.append("", faxNumberTextField);
67 builder.nextLine();
68
69 setContact(contact);
70 revert();
71
72 updateLabels();
73 pack();
74 }
75
76 public SimpleContact getContact()
77 {
78 return contact;
79 }
80
81 public void setContact(SimpleContact contact)
82 {
83 this.contact = contact;
84 }
85
86 public void revert()
87 {
88 firstNameTextField.setText(contact.getFirstname());
89 lastNameTextField.setText(contact.getLastname());
90 companyTextField.setText(contact.getCompany());
91 faxNumberTextField.setText(contact.getFaxNumber());
92 }
93
94 @Override
95 public boolean apply() {
96 contact.setFirstname(firstNameTextField.getText());
97 contact.setLastname(lastNameTextField.getText());
98 contact.setCompany(companyTextField.getText());
99 contact.setFaxNumber(faxNumberTextField.getText());
100 return true;
101 }
102
103 public void updateLabels() {
104 setTitle(i18n.tr("Edit Contact"));
105
106 firstNameLabel.setText(i18n.tr("First Name"));
107 lastNameLabel.setText(i18n.tr("Last Name"));
108 companyLabel.setText(i18n.tr("Company"));
109 faxNumberLabel.setText(i18n.tr("Fax"));
110 }
111
112 }