Feat/chat tests #317

Merged
m.ginkel merged 14 commits from feat/chat-tests into main 2026-04-27 00:52:31 +02:00
2 changed files with 19 additions and 21 deletions
Showing only changes of commit fe83057049 - Show all commits
@@ -21,7 +21,6 @@ import javafx.scene.control.MenuButton;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
import javafx.scene.control.Tab; import javafx.scene.control.Tab;
import javafx.scene.control.TabPane; import javafx.scene.control.TabPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority; import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
@@ -31,16 +30,10 @@ public class ChatBoxController {
private final ChatController chatController; private final ChatController chatController;
@FXML private VBox chatBox;
@FXML private TabPane chatTabPane; @FXML private TabPane chatTabPane;
@FXML private MenuButton addWhisperChatButton; @FXML private MenuButton addWhisperChatButton;
@FXML private HBox menuBox;
private FXMLLoader fxmlLoader;
private final List<String> activeWhisperChats; private final List<String> activeWhisperChats;
@FXML private final Map<String, Tab> usernameTabMap; @FXML private final Map<String, Tab> usernameTabMap;
@@ -77,7 +70,7 @@ public class ChatBoxController {
ChatModel globalChatModel = new ChatModel(global, username, -1, null); ChatModel globalChatModel = new ChatModel(global, username, -1, null);
chatController.getChatModelMap().put(new ChatController.ChatKey(global), globalChatModel); chatController.getChatModelMap().put(new ChatController.ChatKey(global), globalChatModel);
addChatTab("GLOBAL", globalChatModel, global); addChatTab("GLOBAL", globalChatModel, global);
addWhisperChatButton.setOnAction(event -> addWhisperChatButton.show()); addWhisperChatButton.setOnAction(_ -> addWhisperChatButton.show());
} }
/** /**
@@ -97,7 +90,7 @@ public class ChatBoxController {
MenuItem menuItem = new MenuItem(targetUserName); MenuItem menuItem = new MenuItem(targetUserName);
addWhisperChatButton.getItems().add(menuItem); addWhisperChatButton.getItems().add(menuItem);
menuItem.setOnAction( menuItem.setOnAction(
event -> _ ->
addWhisperChat( addWhisperChat(
targetUserName, targetUserName,
new ChatModel( new ChatModel(
@@ -131,7 +124,7 @@ public class ChatBoxController {
if (oldUsername.equals(item.getText())) { if (oldUsername.equals(item.getText())) {
item.setText(newUsername); item.setText(newUsername);
item.setOnAction( item.setOnAction(
event -> _ ->
addWhisperChat( addWhisperChat(
newUsername, newUsername,
new ChatModel( new ChatModel(
@@ -203,6 +196,15 @@ public class ChatBoxController {
try { try {
ChatViewController chatViewController = ChatViewController chatViewController =
new ChatViewController( new ChatViewController(
this.chatController, chatModel, this);
ChatKey chatKey;
if (chatType.equals(ChatType.WHISPER)) {
chatKey = new ChatKey(chatType, title);
} else {
chatKey = new ChatKey(chatType);
}
chatController.activeChatControllers.put(chatKey, chatViewController);
this.chatController, chatModel, this.username, this); this.chatController, chatModel, this.username, this);
ChatKey chatKey; ChatKey chatKey;
@@ -218,7 +220,7 @@ public class ChatBoxController {
VBox vbox = new VBox(); VBox vbox = new VBox();
VBox.setVgrow(vbox, Priority.ALWAYS); VBox.setVgrow(vbox, Priority.ALWAYS);
vbox.getChildren().add(load); vbox.getChildren().add(load);
chatModel.addListener((msg) -> chatViewController.showMessage(msg)); chatModel.addListener(chatViewController::showMessage);
Tab newChat = new Tab(title, vbox); Tab newChat = new Tab(title, vbox);
usernameTabMap.put(title, newChat); usernameTabMap.put(title, newChat);
chatTabPane.getTabs().add(newChat); chatTabPane.getTabs().add(newChat);
@@ -8,6 +8,10 @@ import java.util.ResourceBundle;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
@@ -20,10 +24,6 @@ public class ChatViewController implements Initializable {
@FXML private TextField inputField; @FXML private TextField inputField;
@FXML private VBox chatInterfaceVBox;
@FXML private HBox controlBar;
@FXML private ScrollPane scrollPane; @FXML private ScrollPane scrollPane;
@FXML private VBox chat; @FXML private VBox chat;
@@ -42,8 +42,6 @@ public class ChatViewController implements Initializable {
private final ChatModel chatModel; private final ChatModel chatModel;
private final String username;
private final ChatController controller; private final ChatController controller;
private static final int CHAT_PADDING = 20; private static final int CHAT_PADDING = 20;
@@ -51,10 +49,8 @@ public class ChatViewController implements Initializable {
public ChatViewController( public ChatViewController(
ChatController chatController, ChatController chatController,
ChatModel chatModel, ChatModel chatModel,
String username,
ChatBoxController chatBoxController) { ChatBoxController chatBoxController) {
this.controller = chatController; this.controller = chatController;
this.username = username;
this.chatModel = chatModel; this.chatModel = chatModel;
this.chatBoxController = chatBoxController; this.chatBoxController = chatBoxController;
tabIsOpen = true; tabIsOpen = true;
@@ -70,8 +66,8 @@ public class ChatViewController implements Initializable {
*/ */
@Override @Override
public void initialize(URL location, ResourceBundle resourceBundle) { public void initialize(URL location, ResourceBundle resourceBundle) {
inputField.setOnAction(event -> sendMessage()); inputField.setOnAction(_ -> sendMessage());
sendButton.setOnAction(event -> sendMessage()); sendButton.setOnAction(_ -> sendMessage());
scrollPane.vvalueProperty().bind(chat.heightProperty()); scrollPane.vvalueProperty().bind(chat.heightProperty());
} }