diff --git a/src/main/java/envoy/client/Client.java b/src/main/java/envoy/client/net/Client.java
similarity index 88%
rename from src/main/java/envoy/client/Client.java
rename to src/main/java/envoy/client/net/Client.java
index 145c1bb..0920aab 100644
--- a/src/main/java/envoy/client/Client.java
+++ b/src/main/java/envoy/client/net/Client.java
@@ -1,4 +1,4 @@
-package envoy.client;
+package envoy.client.net;
import java.io.Closeable;
import java.io.IOException;
@@ -9,16 +9,17 @@ import java.util.logging.Logger;
import javax.naming.TimeLimitExceededException;
+import envoy.client.Config;
import envoy.client.database.LocalDb;
-import envoy.client.net.MessageCache;
-import envoy.client.net.ReceivedMessageProcessor;
-import envoy.client.net.Receiver;
import envoy.client.util.EnvoyLog;
import envoy.data.*;
import envoy.event.IdGeneratorRequest;
import envoy.util.SerializationUtils;
/**
+ * Establishes a connection to the server, performs a handshake and delivers
+ * certain objects to the server.
+ *
* Project: envoy-client
* File: Client.java
* Created: 28 Sep 2019
@@ -30,17 +31,17 @@ import envoy.util.SerializationUtils;
*/
public class Client implements Closeable {
+ // Connection handling
private Socket socket;
private Receiver receiver;
private boolean online;
- private volatile User sender;
- private User recipient;
-
- private volatile Contacts contacts;
-
- private Config config = Config.getInstance();
+ // Asynchronously initialized during handshake
+ private volatile User sender;
+ private volatile Contacts contacts;
+ // Configuration and logging
+ private static final Config config = Config.getInstance();
private static final Logger logger = EnvoyLog.getLogger(Client.class.getSimpleName());
/**
@@ -172,26 +173,6 @@ public class Client implements Closeable {
*/
public void setSender(User sender) { this.sender = sender; }
- /**
- * @return the current recipient of the current chat.
- * @since Envoy v0.1-alpha
- */
- public User getRecipient() { return recipient; }
-
- /**
- * Sets the recipient.
- *
- * @param recipient the recipient to set
- * @since Envoy v0.1-alpha
- */
- public void setRecipient(User recipient) { this.recipient = recipient; }
-
- /**
- * @return true, if a recipient is selected
- * @since Envoy v0.1-alpha
- */
- public boolean hasRecipient() { return recipient != null; }
-
/**
* @return the {@link Receiver} used by this {@link Client}
*/
diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java
index 1263a16..b92446a 100644
--- a/src/main/java/envoy/client/ui/ChatWindow.java
+++ b/src/main/java/envoy/client/ui/ChatWindow.java
@@ -10,11 +10,11 @@ import javax.swing.*;
import javax.swing.border.EmptyBorder;
import envoy.client.Chat;
-import envoy.client.Client;
import envoy.client.Settings;
import envoy.client.database.LocalDb;
import envoy.client.event.MessageCreationEvent;
import envoy.client.event.ThemeChangeEvent;
+import envoy.client.net.Client;
import envoy.client.ui.list.ComponentList;
import envoy.client.ui.settings.SettingsScreen;
import envoy.client.util.EnvoyLog;
@@ -175,8 +175,7 @@ public class ChatWindow extends JFrame {
// Read current Chat
currentChat.read();
- // Set recipient in client and chat title
- client.setRecipient(user);
+ // Set chat title
textPane.setText(currentChat.getRecipient().getName());
// Update model and scroll down
@@ -257,7 +256,7 @@ public class ChatWindow extends JFrame {
}
private void postMessage() {
- if (!client.hasRecipient()) {
+ if (userList.isSelectionEmpty()) {
JOptionPane.showMessageDialog(this, "Please select a recipient!", "Cannot send message", JOptionPane.INFORMATION_MESSAGE);
return;
}
@@ -275,7 +274,6 @@ public class ChatWindow extends JFrame {
// Add message to PersistentLocalDb and update UI
currentChat.appendMessage(message);
- // messageList.setModel(currentChat.getModel());
// Clear text field
messageEnterTextArea.setText("");
diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java
index 1bdbe73..272e1ec 100644
--- a/src/main/java/envoy/client/ui/Startup.java
+++ b/src/main/java/envoy/client/ui/Startup.java
@@ -11,12 +11,12 @@ import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
-import envoy.client.Client;
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.net.Client;
import envoy.client.net.MessageCache;
import envoy.client.util.EnvoyLog;
import envoy.data.LoginCredentials;