documentation for all major modules

This commit is contained in:
Clément
2025-03-12 23:16:39 +01:00
parent 0b6f5193a0
commit dfdaae163b
4 changed files with 94 additions and 13 deletions

View File

@@ -45,25 +45,28 @@ public class ClientGuiController implements ClientListener {
this.client = client;
}
@FXML
public void initialize() throws SocketException {
client = new Client(new InetSocketAddress("localhost", 6665), this, UsernameSingleton.getInstance().getUsername());
Platform.runLater(() -> {
Stage stage = (Stage) vueContainer.getScene().getWindow();
// stage.setResizable(true); // Fixed a bug that made the close button disappear under my Wayland setup (don't know if it's the same for x11)
stage.setOnCloseRequest(event -> {
connected = false;
client.close();
@FXML
public void initialize() throws SocketException {
client = new Client(new InetSocketAddress("localhost", 6665), this, UsernameSingleton.getInstance().getUsername());
Platform.runLater(() -> {
Stage stage = (Stage) vueContainer.getScene().getWindow();
stage.setResizable(true); // Fixed a bug that made the close button disappear under my Wayland setup (don't know if it's the same for x11)
stage.setOnCloseRequest(event -> {
connected = false;
client.close();
});
chatList.heightProperty().addListener((obs, oldVal, newVal) -> chatPane.setVvalue(1.0));
});
chatList.heightProperty().addListener((obs, oldVal, newVal) -> chatPane.setVvalue(1.0));
});
}
}
@Override
public void handleDisconnect() {
System.out.println("Disconnected");
}
/**
* Create an alert dialog when the connection to the server fails.
*/
@Override
public void handleConnexionError() {
if(connected) {
@@ -79,6 +82,9 @@ public void initialize() throws SocketException {
}
}
/**
* Create an alert dialog when the connection to the server is successful.
*/
@Override
public void handleConnect() {
Platform.runLater(() -> {
@@ -88,6 +94,13 @@ public void initialize() throws SocketException {
alert.showAndWait();
});
}
/**
* Format and insert the received chat message into the chat list.
* @param time the time the message was sent
* @param chatter the name of the person who sent the message
* @param content the content of the message
*/
@Override
public void handleChatMessage(Instant time, String chatter, String content) {
String untagged = untag(content);
@@ -129,7 +142,10 @@ public void initialize() throws SocketException {
return result.toString();
}
/**
* Display the list of rooms in the room list.
* @param roomNames the list of room names
*/
@Override
public void handleRoomList(List<String> roomNames) {
Platform.runLater(() -> {
@@ -145,6 +161,10 @@ public void initialize() throws SocketException {
});
}
/**
* Create the chat (message wall + input) environment.
* @param roomName the name of the room
*/
private void createChatEnv(String roomName) {
Platform.runLater(() -> {
chatList.getChildren().clear();
@@ -177,8 +197,15 @@ public void initialize() throws SocketException {
});
}
/**
* Colorize the message according to the color codes.
* @param chatter the name of the person who sent the message
* @param content the content of the message
* @return the formatted message
*/
private TextFlow formatMessage(String chatter, String content) {
TextFlow textFlow = new TextFlow();
// Evil regex : match every sequence starting with a color code ending with the next color code
Pattern pattern = Pattern.compile("&([rbgyn])([^&]*)");
Matcher matcher = pattern.matcher(content);
int lastIndex = 0;