Moved client to net package, removed unnecessary recipient property

This commit is contained in:
Kai S. K. Engelbart 2020-02-04 19:46:18 +01:00
parent 388987f438
commit 7424cc900f
3 changed files with 15 additions and 36 deletions

View File

@ -1,4 +1,4 @@
package envoy.client; package envoy.client.net;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
@ -9,16 +9,17 @@ import java.util.logging.Logger;
import javax.naming.TimeLimitExceededException; import javax.naming.TimeLimitExceededException;
import envoy.client.Config;
import envoy.client.database.LocalDb; 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.client.util.EnvoyLog;
import envoy.data.*; import envoy.data.*;
import envoy.event.IdGeneratorRequest; import envoy.event.IdGeneratorRequest;
import envoy.util.SerializationUtils; import envoy.util.SerializationUtils;
/** /**
* Establishes a connection to the server, performs a handshake and delivers
* certain objects to the server.<br>
* <br>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>Client.java</strong><br> * File: <strong>Client.java</strong><br>
* Created: <strong>28 Sep 2019</strong><br> * Created: <strong>28 Sep 2019</strong><br>
@ -30,17 +31,17 @@ import envoy.util.SerializationUtils;
*/ */
public class Client implements Closeable { public class Client implements Closeable {
// Connection handling
private Socket socket; private Socket socket;
private Receiver receiver; private Receiver receiver;
private boolean online; private boolean online;
private volatile User sender; // Asynchronously initialized during handshake
private User recipient; private volatile User sender;
private volatile Contacts contacts;
private volatile Contacts contacts;
private Config config = Config.getInstance();
// Configuration and logging
private static final Config config = Config.getInstance();
private static final Logger logger = EnvoyLog.getLogger(Client.class.getSimpleName()); 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; } 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} * @return the {@link Receiver} used by this {@link Client}
*/ */

View File

@ -10,11 +10,11 @@ import javax.swing.*;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import envoy.client.Chat; import envoy.client.Chat;
import envoy.client.Client;
import envoy.client.Settings; import envoy.client.Settings;
import envoy.client.database.LocalDb; import envoy.client.database.LocalDb;
import envoy.client.event.MessageCreationEvent; import envoy.client.event.MessageCreationEvent;
import envoy.client.event.ThemeChangeEvent; import envoy.client.event.ThemeChangeEvent;
import envoy.client.net.Client;
import envoy.client.ui.list.ComponentList; import envoy.client.ui.list.ComponentList;
import envoy.client.ui.settings.SettingsScreen; import envoy.client.ui.settings.SettingsScreen;
import envoy.client.util.EnvoyLog; import envoy.client.util.EnvoyLog;
@ -175,8 +175,7 @@ public class ChatWindow extends JFrame {
// Read current Chat // Read current Chat
currentChat.read(); currentChat.read();
// Set recipient in client and chat title // Set chat title
client.setRecipient(user);
textPane.setText(currentChat.getRecipient().getName()); textPane.setText(currentChat.getRecipient().getName());
// Update model and scroll down // Update model and scroll down
@ -257,7 +256,7 @@ public class ChatWindow extends JFrame {
} }
private void postMessage() { private void postMessage() {
if (!client.hasRecipient()) { if (userList.isSelectionEmpty()) {
JOptionPane.showMessageDialog(this, "Please select a recipient!", "Cannot send message", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(this, "Please select a recipient!", "Cannot send message", JOptionPane.INFORMATION_MESSAGE);
return; return;
} }
@ -275,7 +274,6 @@ public class ChatWindow extends JFrame {
// Add message to PersistentLocalDb and update UI // Add message to PersistentLocalDb and update UI
currentChat.appendMessage(message); currentChat.appendMessage(message);
// messageList.setModel(currentChat.getModel());
// Clear text field // Clear text field
messageEnterTextArea.setText(""); messageEnterTextArea.setText("");

View File

@ -11,12 +11,12 @@ import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import envoy.client.Client;
import envoy.client.Config; import envoy.client.Config;
import envoy.client.Settings; import envoy.client.Settings;
import envoy.client.database.LocalDb; import envoy.client.database.LocalDb;
import envoy.client.database.PersistentLocalDb; import envoy.client.database.PersistentLocalDb;
import envoy.client.database.TransientLocalDb; import envoy.client.database.TransientLocalDb;
import envoy.client.net.Client;
import envoy.client.net.MessageCache; import envoy.client.net.MessageCache;
import envoy.client.util.EnvoyLog; import envoy.client.util.EnvoyLog;
import envoy.data.LoginCredentials; import envoy.data.LoginCredentials;