From 11032bda27679e2d199467b5f0fb98b3a6f0388e Mon Sep 17 00:00:00 2001 From: bouclyma Date: Thu, 5 Dec 2024 11:39:51 +0100 Subject: [PATCH] =?UTF-8?q?feat(ChatController):=20Fin=20cr=C3=A9ation=20d?= =?UTF-8?q?u=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/rtgre/chat/ChatApplication.java | 2 +- .../main/java/rtgre/chat/ChatController.java | 41 +++++++++++++++++++ .../main/resources/rtgre/chat/chat-view.fxml | 2 +- .../resources/rtgre/chat/logging.properties | 2 +- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/chat/src/main/java/rtgre/chat/ChatApplication.java b/chat/src/main/java/rtgre/chat/ChatApplication.java index 7e436cb..b4e2085 100644 --- a/chat/src/main/java/rtgre/chat/ChatApplication.java +++ b/chat/src/main/java/rtgre/chat/ChatApplication.java @@ -31,7 +31,7 @@ public class ChatApplication extends Application { @Override public void start(Stage stage) throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(ChatApplication.class.getResource("chat-view.fxml")); - Scene scene = new Scene(fxmlLoader.load(), 320, 240); + Scene scene = new Scene(fxmlLoader.load(), 600, 400); stage.setTitle("Chat @BOUCLY_Emi (B2GA)"); stage.getIcons().add(new Image(Objects.requireNonNull(ChatApplication.class.getResourceAsStream("rt.png")))); diff --git a/chat/src/main/java/rtgre/chat/ChatController.java b/chat/src/main/java/rtgre/chat/ChatController.java index c1552c9..aab603f 100644 --- a/chat/src/main/java/rtgre/chat/ChatController.java +++ b/chat/src/main/java/rtgre/chat/ChatController.java @@ -1,5 +1,8 @@ package rtgre.chat; +import javafx.application.Platform; +import javafx.beans.Observable; +import javafx.event.Event; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.*; @@ -7,6 +10,7 @@ import javafx.scene.image.Image; import javafx.scene.image.ImageView; import java.net.URL; +import java.util.Date; import java.util.Objects; import java.util.ResourceBundle; import java.util.logging.Logger; @@ -25,6 +29,10 @@ public class ChatController implements Initializable { public ListView postListView; public ListView roomsListView; public ListView contactListView; + public TextField messageTextField; + public Button sendButton; + public Label statusLabel; + public Label dateTimeLabel; @Override @@ -34,5 +42,38 @@ public class ChatController implements Initializable { Image image = new Image(Objects.requireNonNull(ChatController.class.getResourceAsStream("anonymous.png"))); this.avatarImageView.setImage(image); + Thread dateTimeLoop = new Thread(this::dateTimeLoop); + dateTimeLoop.setDaemon(true); + dateTimeLoop.start(); + + hostComboBox.getItems().addAll("localhost:2024"); + hostComboBox.getItems().addAll("localhost:2025"); + hostComboBox.setValue("localhost:2024"); + hostComboBox.setOnAction(this::statusNameUpdate); + + statusLabel.setText("not connected to " + hostComboBox.getValue()); + + + + } + + private void statusNameUpdate(Event event) { + statusLabel.setText("not connected to " + hostComboBox.getValue()); + + } + + + private void dateTimeLoop() { + while (true) { + try { + String datetime = "%1$ta %1$te %1$tb %1$tY - %1$tH:%1$tM".formatted(new Date()); + // System.out.println(datetime); + Platform.runLater(() -> dateTimeLabel.setText(datetime)); + Thread.sleep(60000); + } catch (Exception e) { + System.out.println(e); + } + } + } } \ No newline at end of file diff --git a/chat/src/main/resources/rtgre/chat/chat-view.fxml b/chat/src/main/resources/rtgre/chat/chat-view.fxml index 33ce53e..a389c65 100644 --- a/chat/src/main/resources/rtgre/chat/chat-view.fxml +++ b/chat/src/main/resources/rtgre/chat/chat-view.fxml @@ -114,7 +114,7 @@ diff --git a/chat/src/main/resources/rtgre/chat/logging.properties b/chat/src/main/resources/rtgre/chat/logging.properties index 4ba3400..df9bc2f 100644 --- a/chat/src/main/resources/rtgre/chat/logging.properties +++ b/chat/src/main/resources/rtgre/chat/logging.properties @@ -9,7 +9,7 @@ handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter # Nom du fichier de logs -java.util.logging.FileHandler.pattern=out/java%u.log +java.util.logging.FileHandler.pattern=../out/java%u.log # Format de logs plus compact sur 1 seule ligne java.util.logging.SimpleFormatter.format=%1$tF %1$tT.%1$tL | %4$-7s | %2$s | %5$s %6$s%n