Files
Projet-UDP/ChatApp/app/src/main/java/client/ClientLoading.java

86 lines
2.2 KiB
Java

package client;
import javafx.animation.RotateTransition;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.shape.Arc;
import javafx.stage.Stage;
import javafx.util.Duration;
import network.protocol.packets.ServerResponsePacket;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import static utilities.FxUtilities.centerStage;
public class ClientLoading implements ClientListener {
@FXML
private Arc spinnerArc;
private Client client;
public void initialize() throws IOException, InterruptedException {
// Création de l'animation de rotation
RotateTransition rotate = new RotateTransition(Duration.seconds(1), spinnerArc);
rotate.setByAngle(360);
rotate.setCycleCount(RotateTransition.INDEFINITE);
rotate.play();
}
public void setClient(Client client) {
this.client = client;
}
public void login() throws IOException {
var loader = new FXMLLoader(getClass().getResource("/client/clientVue.fxml"));
loader.load();
client.changeCallback(loader.getController());
((ClientGuiController) loader.getController()).setClient(client);
Stage stage = (Stage) spinnerArc.getScene().getWindow();
stage.setScene(new Scene(loader.getRoot(), 800, 600));
centerStage(stage);
stage.getScene().getStylesheets().add(getClass().getResource("clientStyle.css").toExternalForm());
}
@Override
public void handleDisconnect() {
System.out.println("Disconnected");
}
@Override
public void handleConnexionError() {
System.out.println("Connection error");
}
@Override
public void handleConnect() {
try {
login();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void handleChatMessage(Instant time, String chatter, String content) {
}
@Override
public void handleRoomList(List<String> roomNames) {
}
@Override
public void handleServerResponse(ServerResponsePacket.Response response) {
}
@Override
public void handleActualRoom(String roomName) {
}
}