From f80fd5069c3c022f197b93a343d9f4f092fc8cf1 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 5 Feb 2020 20:58:30 +0100 Subject: [PATCH] Renamed database package to data, moved Chat to data package --- .../java/envoy/client/{ => data}/Chat.java | 2 +- .../client/{database => data}/LocalDb.java | 3 +- .../{database => data}/PersistentLocalDb.java | 2 +- .../{database => data}/TransientLocalDb.java | 2 +- src/main/java/envoy/client/net/Client.java | 2 +- src/main/java/envoy/client/ui/ChatWindow.java | 33 +++++++++---------- src/main/java/envoy/client/ui/Startup.java | 6 ++-- 7 files changed, 23 insertions(+), 27 deletions(-) rename src/main/java/envoy/client/{ => data}/Chat.java (99%) rename src/main/java/envoy/client/{database => data}/LocalDb.java (98%) rename src/main/java/envoy/client/{database => data}/PersistentLocalDb.java (98%) rename src/main/java/envoy/client/{database => data}/TransientLocalDb.java (92%) diff --git a/src/main/java/envoy/client/Chat.java b/src/main/java/envoy/client/data/Chat.java similarity index 99% rename from src/main/java/envoy/client/Chat.java rename to src/main/java/envoy/client/data/Chat.java index e67eb34..f10e816 100644 --- a/src/main/java/envoy/client/Chat.java +++ b/src/main/java/envoy/client/data/Chat.java @@ -1,4 +1,4 @@ -package envoy.client; +package envoy.client.data; import java.io.IOException; import java.io.Serializable; diff --git a/src/main/java/envoy/client/database/LocalDb.java b/src/main/java/envoy/client/data/LocalDb.java similarity index 98% rename from src/main/java/envoy/client/database/LocalDb.java rename to src/main/java/envoy/client/data/LocalDb.java index 58738e5..79368a8 100644 --- a/src/main/java/envoy/client/database/LocalDb.java +++ b/src/main/java/envoy/client/data/LocalDb.java @@ -1,8 +1,7 @@ -package envoy.client.database; +package envoy.client.data; import java.util.*; -import envoy.client.Chat; import envoy.data.IdGenerator; import envoy.data.User; diff --git a/src/main/java/envoy/client/database/PersistentLocalDb.java b/src/main/java/envoy/client/data/PersistentLocalDb.java similarity index 98% rename from src/main/java/envoy/client/database/PersistentLocalDb.java rename to src/main/java/envoy/client/data/PersistentLocalDb.java index d4d7523..7856517 100644 --- a/src/main/java/envoy/client/database/PersistentLocalDb.java +++ b/src/main/java/envoy/client/data/PersistentLocalDb.java @@ -1,4 +1,4 @@ -package envoy.client.database; +package envoy.client.data; import java.io.File; import java.io.IOException; diff --git a/src/main/java/envoy/client/database/TransientLocalDb.java b/src/main/java/envoy/client/data/TransientLocalDb.java similarity index 92% rename from src/main/java/envoy/client/database/TransientLocalDb.java rename to src/main/java/envoy/client/data/TransientLocalDb.java index f9124b1..433488a 100644 --- a/src/main/java/envoy/client/database/TransientLocalDb.java +++ b/src/main/java/envoy/client/data/TransientLocalDb.java @@ -1,4 +1,4 @@ -package envoy.client.database; +package envoy.client.data; /** * Implements a {@link LocalDb} in a way that does not persist any information diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java index 31b1d59..91e9040 100644 --- a/src/main/java/envoy/client/net/Client.java +++ b/src/main/java/envoy/client/net/Client.java @@ -10,7 +10,7 @@ import java.util.logging.Logger; import javax.naming.TimeLimitExceededException; import envoy.client.Config; -import envoy.client.database.LocalDb; +import envoy.client.data.LocalDb; import envoy.client.util.EnvoyLog; import envoy.data.*; import envoy.event.Event; diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index d018b40..3abd54a 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -10,9 +10,9 @@ import java.util.logging.Logger; import javax.swing.*; import javax.swing.border.EmptyBorder; -import envoy.client.Chat; import envoy.client.Settings; -import envoy.client.database.LocalDb; +import envoy.client.data.Chat; +import envoy.client.data.LocalDb; import envoy.client.event.MessageCreationEvent; import envoy.client.event.ThemeChangeEvent; import envoy.client.net.Client; @@ -175,13 +175,8 @@ public class ChatWindow extends JFrame { // Select current chat currentChat = localDb.getChats().stream().filter(chat -> chat.getRecipient().getId() == user.getId()).findFirst().get(); - // Read current Chat - try { - currentChat.read(client); - } catch (IOException e) { - e.printStackTrace(); - logger.log(Level.WARNING, "Could notify server about message status change", e); - } + // Read current chat + readCurrentChat(); // Set chat title textPane.setText(currentChat.getRecipient().getName()); @@ -221,15 +216,7 @@ public class ChatWindow extends JFrame { chat.appendMessage(message); // Read message and update UI if in current chat - if (chat == currentChat) { - try { - currentChat.read(client); - } catch (IOException e) { - e.printStackTrace(); - logger.log(Level.WARNING, "Could notify server about message status change", e); - } - messageList.synchronizeModel(); - } + if (chat == currentChat) readCurrentChat(); revalidate(); repaint(); @@ -356,6 +343,16 @@ public class ChatWindow extends JFrame { }).start(); } + private void readCurrentChat() { + try { + currentChat.read(client); + messageList.synchronizeModel(); + } catch (IOException e) { + e.printStackTrace(); + logger.log(Level.WARNING, "Couldn't notify server about message status change", e); + } + } + /** * Sets the {@link Client} used by this {@link ChatWindow}. * diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java index 272e1ec..9f308dc 100644 --- a/src/main/java/envoy/client/ui/Startup.java +++ b/src/main/java/envoy/client/ui/Startup.java @@ -13,9 +13,9 @@ import javax.swing.SwingUtilities; import envoy.client.Config; import envoy.client.Settings; -import envoy.client.database.LocalDb; -import envoy.client.database.PersistentLocalDb; -import envoy.client.database.TransientLocalDb; +import envoy.client.data.LocalDb; +import envoy.client.data.PersistentLocalDb; +import envoy.client.data.TransientLocalDb; import envoy.client.net.Client; import envoy.client.net.MessageCache; import envoy.client.util.EnvoyLog;