improve username change detection
This commit is contained in:
parent
75ec382fb7
commit
1fe1681d8b
2 changed files with 18 additions and 1 deletions
|
@ -2,10 +2,12 @@ package fr.insa.clavardator.ui.chat;
|
|||
|
||||
import fr.insa.clavardator.ui.users.UserActiveIndicatorController;
|
||||
import fr.insa.clavardator.users.PeerUser;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Label;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ResourceBundle;
|
||||
|
@ -16,12 +18,26 @@ public class ChatHeaderController implements Initializable {
|
|||
private Label remoteUsernameLabel;
|
||||
@FXML
|
||||
private UserActiveIndicatorController indicatorController;
|
||||
private PeerUser user;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
}
|
||||
|
||||
private void onUsernameChange(PropertyChangeEvent propertyChangeEvent) {
|
||||
if (propertyChangeEvent.getPropertyName().equals("username")) {
|
||||
final String newUsername = (String) propertyChangeEvent.getNewValue();
|
||||
Platform.runLater(() -> remoteUsernameLabel.setText(newUsername));
|
||||
}
|
||||
}
|
||||
|
||||
public void setRemoteUser(PeerUser remoteUser) {
|
||||
if (this.user != null) {
|
||||
// remove old observer before setting new user
|
||||
this.user.removeObserver(this::onUsernameChange);
|
||||
}
|
||||
this.user = remoteUser;
|
||||
user.addObserver(this::onUsernameChange);
|
||||
remoteUsernameLabel.setText(remoteUser.getUsername());
|
||||
indicatorController.setUser(remoteUser);
|
||||
indicatorController.setSize(10.0);
|
||||
|
|
|
@ -2,6 +2,7 @@ package fr.insa.clavardator.ui.users;
|
|||
|
||||
import fr.insa.clavardator.users.PeerUser;
|
||||
import fr.insa.clavardator.util.Log;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.shape.Circle;
|
||||
|
@ -34,7 +35,7 @@ public class UserActiveIndicatorController implements Initializable {
|
|||
if (propertyChangeEvent.getPropertyName().equals("state")) {
|
||||
final PeerUser.State newState = (PeerUser.State) propertyChangeEvent.getNewValue();
|
||||
Log.v(this.getClass().getSimpleName(), "User state updated to " + newState.toString());
|
||||
updateState(newState == PeerUser.State.CONNECTED);
|
||||
Platform.runLater(() -> updateState(newState == PeerUser.State.CONNECTED));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue