-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContactViewer.java
More file actions
116 lines (102 loc) · 5.05 KB
/
ContactViewer.java
File metadata and controls
116 lines (102 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package addressbook;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import java.io.IOException;
public class ContactViewer extends AnchorPane {
private Contact currentContact;
@FXML private GridPane grid;
@FXML private Label nameLabel;
@FXML private Label firstNameLabel;
@FXML private Label lastNameLabel;
@FXML private Label emailLabel;
@FXML private Label secondEmailLabel;
@FXML private Label officeLabel;
@FXML private Label departamentLabel;
@FXML private Label companyNameLabel;
@FXML private Label companyAddressLabel;
@FXML private Label companyWebsiteLabel;
@FXML private Label workPhoneNumber;
@FXML private Label hausePhoneNumberLabel;
@FXML private Label faxPhoneNumberLabel;
@FXML private Label mobilePhoneNumberLabel;
@FXML private Label pagerPhoneNumberLabel;
@FXML private Label addressLabel;
@FXML private Label cityLabel;
@FXML private Label voivodeshipLabel;
@FXML private Label postalCodeLabel;
@FXML private Label websiteLabel;
@FXML private Label birthdayLabel;
@FXML private Label info1Label;
@FXML private Label info2Label;
public ContactViewer() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("ContactViewerForm.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void setContact(Contact contact) {
currentContact = contact;
currentContact.nameProperty().addListener(new ChangeListener<>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (newValue.isEmpty()==false) {
nameLabel.setText(newValue);
} else {
nameLabel.setText(currentContact.getFirstName() + " " + currentContact.getLastName());
}
}
});
currentContact.firstNameProperty().addListener(new ChangeListener<>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (currentContact.getName().isEmpty()) {
nameLabel.setText(currentContact.getFirstName() + " " + currentContact.getLastName());
}
}
});
currentContact.lastNameProperty().addListener(new ChangeListener<>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (currentContact.getName().isEmpty()) {
nameLabel.setText(currentContact.getFirstName() + " " + currentContact.getLastName());
}
}
});
if (currentContact.getName().isEmpty()==true) {
nameLabel.setText(currentContact.getFirstName() + " " + currentContact.getLastName());
} else {
nameLabel.setText(currentContact.getName());
}
lastNameLabel.textProperty().bind(currentContact.lastNameProperty());
firstNameLabel.textProperty().bind(currentContact.firstNameProperty());
emailLabel.textProperty().bind(currentContact.emailProperty());
secondEmailLabel.textProperty().bind(currentContact.secondEmailProperty());
officeLabel.textProperty().bind(currentContact.officeProperty());
departamentLabel.textProperty().bind(currentContact.departamentProperty());
companyNameLabel.textProperty().bind(currentContact.companyAddressProperty());
companyAddressLabel.textProperty().bind(currentContact.addressProperty());
companyWebsiteLabel.textProperty().bind(currentContact.companyWebsiteProperty());
workPhoneNumber.textProperty().bind(currentContact.workPhoneNumberProperty());
hausePhoneNumberLabel.textProperty().bind(currentContact.hausePhoneNumberProperty());
faxPhoneNumberLabel.textProperty().bind(currentContact.faxPhoneNumberProperty());
mobilePhoneNumberLabel.textProperty().bind(currentContact.mobilePhoneNumberProperty());
pagerPhoneNumberLabel.textProperty().bind(currentContact.pagerPhoneNumberProperty());
addressLabel.textProperty().bind(currentContact.addressProperty());
cityLabel.textProperty().bind(currentContact.cityProperty());
voivodeshipLabel.textProperty().bind(currentContact.voivodeshipProperty());
postalCodeLabel.textProperty().bind(currentContact.postalCodeProperty());
websiteLabel.textProperty().bind(currentContact.websiteProperty());
birthdayLabel.textProperty().bind(currentContact.birthdayProperty());
info1Label.textProperty().bind(currentContact.info1Property());
info2Label.textProperty().bind(currentContact.info2Property());
}
}