diff --git a/chat/src/main/java/module-info.java b/chat/src/main/java/module-info.java index 8c040f9..34c52c5 100644 --- a/chat/src/main/java/module-info.java +++ b/chat/src/main/java/module-info.java @@ -1,6 +1,7 @@ module rtgre.chat { requires javafx.controls; requires javafx.fxml; + requires java.logging; opens rtgre.chat to javafx.fxml; diff --git a/chat/src/main/java/rtgre/chat/ChatApplication.java b/chat/src/main/java/rtgre/chat/ChatApplication.java index fe3fe1c..b4e2085 100644 --- a/chat/src/main/java/rtgre/chat/ChatApplication.java +++ b/chat/src/main/java/rtgre/chat/ChatApplication.java @@ -3,16 +3,40 @@ package rtgre.chat; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; +import javafx.scene.image.Image; import javafx.stage.Stage; import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.LogManager; +import java.util.logging.Logger; public class ChatApplication extends Application { + public static final Logger LOGGER = Logger.getLogger(ChatApplication.class.getCanonicalName()); + public class EssaiLogger { + /* . . . */ + static { + try { + InputStream is = EssaiLogger.class.getClassLoader() + .getResource("logging.properties").openStream(); + LogManager.getLogManager().readConfiguration(is); + } catch (Exception e) { + LOGGER.log(Level.INFO, "Cannot read configuration file", e); + } + } + /* . . . */ + } @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")))); + stage.setMinWidth(600); + stage.setMinHeight(400); stage.setScene(scene); stage.show(); } diff --git a/chat/src/main/java/rtgre/chat/ChatController.java b/chat/src/main/java/rtgre/chat/ChatController.java index 9e9051f..aab603f 100644 --- a/chat/src/main/java/rtgre/chat/ChatController.java +++ b/chat/src/main/java/rtgre/chat/ChatController.java @@ -1,14 +1,79 @@ package rtgre.chat; +import javafx.application.Platform; +import javafx.beans.Observable; +import javafx.event.Event; import javafx.fxml.FXML; -import javafx.scene.control.Label; +import javafx.fxml.Initializable; +import javafx.scene.control.*; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; -public class ChatController { - @FXML - private Label welcomeText; +import java.net.URL; +import java.util.Date; +import java.util.Objects; +import java.util.ResourceBundle; +import java.util.logging.Logger; + +import static rtgre.chat.ChatApplication.LOGGER; +public class ChatController implements Initializable { + + public MenuItem hostAddMenuItem; + public MenuItem avatarMenuItem; + public MenuItem aboutMenuItem; + public ComboBox hostComboBox; + public TextField loginTextField; + public ToggleButton connectionButton; + public ImageView avatarImageView; + public SplitPane exchangeSplitPane; + public ListView postListView; + public ListView roomsListView; + public ListView contactListView; + public TextField messageTextField; + public Button sendButton; + public Label statusLabel; + public Label dateTimeLabel; + + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + LOGGER.info("Initialisation de l'interface graphique"); + + 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); + } + } - @FXML - protected void onHelloButtonClick() { - welcomeText.setText("Welcome to JavaFX Application!"); } } \ No newline at end of file diff --git a/chat/src/main/resources/rtgre/chat/anonymous.png b/chat/src/main/resources/rtgre/chat/anonymous.png new file mode 100644 index 0000000..01d5e63 Binary files /dev/null and b/chat/src/main/resources/rtgre/chat/anonymous.png differ diff --git a/chat/src/main/resources/rtgre/chat/chat-view.fxml b/chat/src/main/resources/rtgre/chat/chat-view.fxml index 460fcf5..a389c65 100644 --- a/chat/src/main/resources/rtgre/chat/chat-view.fxml +++ b/chat/src/main/resources/rtgre/chat/chat-view.fxml @@ -1,16 +1,123 @@ + + + + + + + + + + + + + + + - - - - - - - diff --git a/chat/src/main/resources/rtgre/chat/logging.properties b/chat/src/main/resources/rtgre/chat/logging.properties new file mode 100644 index 0000000..df9bc2f --- /dev/null +++ b/chat/src/main/resources/rtgre/chat/logging.properties @@ -0,0 +1,25 @@ +# Les logs sont envoyés sur la console *et* dans un fichier +handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler + +# Configuration par défaut pour ConsoleHandler +# java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter + +# Configuration de FileHandler. Par défaut, +# java.util.logging.FileHandler.formatter=java.util.logging.XMLFormater +java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter + +# Nom du fichier de logs +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 + +# niveaux : OFF / SEVERE / WARNING / INFO / CONFIG / FINE / FINER / FINEST / ALL +# Niveau global minimum pour les logs +.level=ALL + +# Niveau minimum pour les logs sur la console +java.util.logging.ConsoleHandler.level=FINE + +# Niveau minimum pour les logs dans le fichier +java.util.logging.FileHandler.level=ALL \ No newline at end of file diff --git a/chat/src/main/resources/rtgre/chat/rt.png b/chat/src/main/resources/rtgre/chat/rt.png new file mode 100644 index 0000000..db84b1d Binary files /dev/null and b/chat/src/main/resources/rtgre/chat/rt.png differ