|
@@ -3,9 +3,11 @@ package fr.insa.clavardator.ui.users;
|
3
|
3
|
import com.jfoenix.controls.JFXButton;
|
4
|
4
|
import fr.insa.clavardator.ui.ButtonPressEvent;
|
5
|
5
|
import fr.insa.clavardator.users.PeerUser;
|
|
6
|
+import javafx.application.Platform;
|
6
|
7
|
import javafx.fxml.FXML;
|
7
|
8
|
import javafx.fxml.Initializable;
|
8
|
9
|
|
|
10
|
+import java.beans.PropertyChangeEvent;
|
9
|
11
|
import java.net.URL;
|
10
|
12
|
import java.util.ResourceBundle;
|
11
|
13
|
|
|
@@ -42,8 +44,21 @@ public class UserListItemController implements Initializable {
|
42
|
44
|
resetBackground();
|
43
|
45
|
}
|
44
|
46
|
|
|
47
|
+
|
|
48
|
+ private void onUsernameChange(PropertyChangeEvent propertyChangeEvent) {
|
|
49
|
+ if (propertyChangeEvent.getPropertyName().equals("username")) {
|
|
50
|
+ final String newUsername = (String) propertyChangeEvent.getNewValue();
|
|
51
|
+ Platform.runLater(() -> button.setText(newUsername));
|
|
52
|
+ }
|
|
53
|
+ }
|
|
54
|
+
|
45
|
55
|
public void setUser(PeerUser user) {
|
|
56
|
+ if (this.user != null) {
|
|
57
|
+ // remove old observer before setting new user
|
|
58
|
+ this.user.removeObserver(this::onUsernameChange);
|
|
59
|
+ }
|
46
|
60
|
this.user = user;
|
|
61
|
+ user.addObserver(this::onUsernameChange);
|
47
|
62
|
indicatorController.setUser(user);
|
48
|
63
|
button.setText(user.getUsername());
|
49
|
64
|
resetBackground();
|