From e11fb136cfa0682068c06d3582efa07eaa3a88e1 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Tue, 12 Apr 2022 07:36:14 +0200 Subject: [PATCH] created Class Message --- .../client/ChatWindowController.java | 6 +-- .../multichat/client/ClientMessageList.java | 37 ++++++------------- .../ch/zhaw/pm2/multichat/client/Message.java | 35 ++++++++++++++++++ 3 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 client/src/main/java/ch/zhaw/pm2/multichat/client/Message.java diff --git a/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java b/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java index e9a704e..bc7e57c 100644 --- a/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java +++ b/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java @@ -170,17 +170,17 @@ public class ChatWindowController { } public void addMessage(String sender, String receiver, String message) { - messages.addMessage(ClientMessageList.MessageType.MESSAGE, sender, receiver, message); + messages.addMessage(new Message(Message.MessageType.MESSAGE, sender, receiver, message)); this.redrawMessageList(); } public void addInfo(String message) { - messages.addMessage(ClientMessageList.MessageType.INFO, null, null, message); + messages.addMessage(new Message(Message.MessageType.INFO, null, null, message)); this.redrawMessageList(); } public void addError(String message) { - messages.addMessage(ClientMessageList.MessageType.ERROR, null, null, message); + messages.addMessage(new Message(Message.MessageType.ERROR, null, null, message)); this.redrawMessageList(); } diff --git a/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientMessageList.java b/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientMessageList.java index 100cb67..55dec4d 100644 --- a/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientMessageList.java +++ b/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientMessageList.java @@ -5,47 +5,34 @@ import java.util.List; import java.util.Objects; public class ClientMessageList { - private final List typeList = new ArrayList<>(); - private final List senderList = new ArrayList<>(); - private final List receiverList = new ArrayList<>(); - private final List messageList = new ArrayList<>(); + private final List messages = new ArrayList<>(); private final ChatWindowController gui; public ClientMessageList(ChatWindowController gui) { this.gui = gui; } - public void addMessage(MessageType type, String sender, String receiver, String message) { - typeList.add(type); - senderList.add(sender); - receiverList.add(receiver); - messageList.add(message); + public void addMessage(Message message) { + messages.add(message); } public void writeFilteredMessages(String filter) { boolean showAll = filter == null || filter.isBlank(); gui.clearMessageArea(); - for(int i=0; i