Merge branch 'develop' into f/groupMessages

Conflicts:
	src/main/java/envoy/client/ui/controller/ChatScene.java
This commit is contained in:
Kai S. K. Engelbart 2020-06-27 11:34:51 +02:00
commit e1e8315ace
35 changed files with 971 additions and 503 deletions

1
.github/CODEOWNERS vendored Normal file
View File

@ -0,0 +1 @@
* @CyB3RC0nN0R

View File

@ -1,6 +1,6 @@
# Envoy Client # Envoy Client
<a href="https://github.com/informatik-ag-ngl/envoy-client"><img src="https://raw.githubusercontent.com/informatik-ag-ngl/envoy-client/develop/src/main/resources/envoy_logo.png" align="left" width="200" height="200"></a> <a href="https://github.com/informatik-ag-ngl/envoy-client"><img src="https://raw.githubusercontent.com/informatik-ag-ngl/envoy-client/develop/src/main/resources/icons/envoy_logo.png" align="left" width="200" height="200"></a>
**Envoy Client** is one of two repositories needed to use the messenger Envoy.<br> **Envoy Client** is one of two repositories needed to use the messenger Envoy.<br>
The other one is <a href="https://github.com/informatik-ag-ngl/envoy-common">**Envoy Common**</a>. The other one is <a href="https://github.com/informatik-ag-ngl/envoy-common">**Envoy Common**</a>.

View File

@ -4,13 +4,14 @@ import java.io.Serializable;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
/** /**
* Stores elements in a queue to process them later.<br> * Stores elements in a queue to process them later.
* <br> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>Cache.java</strong><br> * File: <strong>Cache.java</strong><br>
* Created: <strong>6 Feb 2020</strong><br> * Created: <strong>6 Feb 2020</strong><br>
@ -25,7 +26,7 @@ public class Cache<T> implements Consumer<T>, Serializable {
private transient Consumer<T> processor; private transient Consumer<T> processor;
private static final Logger logger = EnvoyLog.getLogger(Cache.class); private static final Logger logger = EnvoyLog.getLogger(Cache.class);
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
/** /**
* Adds an element to the cache. * Adds an element to the cache.
@ -35,10 +36,13 @@ public class Cache<T> implements Consumer<T>, Serializable {
*/ */
@Override @Override
public void accept(T element) { public void accept(T element) {
logger.fine(String.format("Adding element %s to cache", element)); logger.log(Level.FINE, String.format("Adding element %s to cache", element));
elements.offer(element); elements.offer(element);
} }
@Override
public String toString() { return String.format("Cache[elements=" + elements + "]"); }
/** /**
* Sets the processor to which cached elements are relayed. * Sets the processor to which cached elements are relayed.
* *

View File

@ -4,16 +4,17 @@ import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import envoy.client.net.WriteProxy; import envoy.client.net.WriteProxy;
import envoy.data.*; import envoy.data.*;
import envoy.data.Message.MessageStatus; import envoy.data.Message.MessageStatus;
import envoy.event.MessageStatusChangeEvent; import envoy.event.MessageStatusChange;
/** /**
* Represents a chat between two {@link User}s <br> * Represents a chat between two {@link User}s
* as a list of {@link Message} objects. * as a list of {@link Message} objects.
* <br> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>Chat.java</strong><br> * File: <strong>Chat.java</strong><br>
* Created: <strong>19 Oct 2019</strong><br> * Created: <strong>19 Oct 2019</strong><br>
@ -31,7 +32,7 @@ public final class Chat implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Provides the list of messages that the recipient receives.<br> * Provides the list of messages that the recipient receives.<p>
* Saves the Messages in the corresponding chat at that Point. * Saves the Messages in the corresponding chat at that Point.
* *
* @param recipient the user who receives the messages * @param recipient the user who receives the messages
@ -42,6 +43,27 @@ public final class Chat implements Serializable {
@Override @Override
public String toString() { return String.format("Chat[recipient=%s,messages=%d]", recipient, messages.size()); } public String toString() { return String.format("Chat[recipient=%s,messages=%d]", recipient, messages.size()); }
/**
* Generates a hash code based on the recipient.
*
* @since Envoy Client v0.1-beta
*/
@Override
public int hashCode() { return Objects.hash(recipient); }
/**
* Tests equality to another object based on the recipient.
*
* @since Envoy Client v0.1-beta
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Chat)) return false;
Chat other = (Chat) obj;
return Objects.equals(recipient, other.recipient);
}
/** /**
* Sets the status of all chat messages received from the recipient to * Sets the status of all chat messages received from the recipient to
* {@code READ} starting from the bottom and stopping once a read message is * {@code READ} starting from the bottom and stopping once a read message is
@ -49,7 +71,7 @@ public final class Chat implements Serializable {
* *
* @param writeProxy the write proxy instance used to notify the server about * @param writeProxy the write proxy instance used to notify the server about
* the message status changes * the message status changes
* @throws IOException if a {@link MessageStatusChangeEvent} could not be * @throws IOException if a {@link MessageStatusChange} could not be
* delivered to the server * delivered to the server
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
@ -59,7 +81,7 @@ public final class Chat implements Serializable {
if (m.getSenderID() == recipient.getID()) if (m.getStatus() == MessageStatus.READ) break; if (m.getSenderID() == recipient.getID()) if (m.getStatus() == MessageStatus.READ) break;
else { else {
m.setStatus(MessageStatus.READ); m.setStatus(MessageStatus.READ);
writeProxy.writeMessageStatusChangeEvent(new MessageStatusChangeEvent(m)); writeProxy.writeMessageStatusChange(new MessageStatusChange(m));
} }
} }
} }

View File

@ -4,14 +4,15 @@ import java.io.File;
import java.util.function.Function; import java.util.function.Function;
import java.util.logging.Level; import java.util.logging.Level;
import envoy.client.ui.Startup;
import envoy.data.Config; import envoy.data.Config;
import envoy.data.ConfigItem; import envoy.data.ConfigItem;
import envoy.data.LoginCredentials; import envoy.data.LoginCredentials;
/** /**
* Implements a configuration specific to the Envoy Client with default values * Implements a configuration specific to the Envoy Client with default values
* and convenience methods.<br> * and convenience methods.
* <br> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>ClientConfig.java</strong><br> * File: <strong>ClientConfig.java</strong><br>
* Created: <strong>01.03.2020</strong><br> * Created: <strong>01.03.2020</strong><br>
@ -109,5 +110,5 @@ public class ClientConfig extends Config {
* the registration option * the registration option
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public LoginCredentials getLoginCredentials() { return new LoginCredentials(getUser(), getPassword(), false); } public LoginCredentials getLoginCredentials() { return new LoginCredentials(getUser(), getPassword(), false, Startup.VERSION); }
} }

View File

@ -3,14 +3,14 @@ package envoy.client.data;
import java.util.*; import java.util.*;
import envoy.data.*; import envoy.data.*;
import envoy.event.GroupResizeEvent; import envoy.event.GroupResize;
import envoy.event.MessageStatusChangeEvent; import envoy.event.MessageStatusChange;
import envoy.event.NameChangeEvent; import envoy.event.NameChange;
/** /**
* Stores information about the current {@link User} and their {@link Chat}s. * Stores information about the current {@link User} and their {@link Chat}s.
* For message ID generation a {@link IDGenerator} is stored as well.<br> * For message ID generation a {@link IDGenerator} is stored as well.
* <br> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>LocalDB.java</strong><br> * File: <strong>LocalDB.java</strong><br>
* Created: <strong>3 Feb 2020</strong><br> * Created: <strong>3 Feb 2020</strong><br>
@ -20,12 +20,12 @@ import envoy.event.NameChangeEvent;
*/ */
public abstract class LocalDB { public abstract class LocalDB {
protected User user; protected User user;
protected Map<String, Contact> users = new HashMap<>(); protected Map<String, Contact> users = new HashMap<>();
protected List<Chat> chats = new ArrayList<>(); protected List<Chat> chats = new ArrayList<>();
protected IDGenerator idGenerator; protected IDGenerator idGenerator;
protected Cache<Message> messageCache = new Cache<>(); protected Cache<Message> messageCache = new Cache<>();
protected Cache<MessageStatusChangeEvent> statusCache = new Cache<>(); protected Cache<MessageStatusChange> statusCache = new Cache<>();
/** /**
* Initializes a storage space for a user-specific list of chats. * Initializes a storage space for a user-specific list of chats.
@ -66,6 +66,25 @@ public abstract class LocalDB {
*/ */
public void loadIDGenerator() {} public void loadIDGenerator() {}
/**
* Synchronizes the contact list of the client user with the chat and user
* storage.
*
* @since Envoy Client v0.1-beta
*/
public void synchronize() {
user.getContacts().stream().filter(u -> u instanceof User && !users.containsKey(u.getName())).forEach(u -> users.put(u.getName(), u));
users.put(user.getName(), user);
// Synchronize user status data
for (Contact contact : users.values())
if (contact instanceof User)
getChat(contact.getID()).ifPresent(chat -> { ((User) chat.getRecipient()).setStatus(((User) contact).getStatus()); });
// Create missing chats
user.getContacts().stream().filter(u -> !u.equals(user) && getChat(u.getID()).isEmpty()).map(Chat::new).forEach(chats::add);
}
/** /**
* @return a {@code Map<String, User>} of all users stored locally with their * @return a {@code Map<String, User>} of all users stored locally with their
* user names as keys * user names as keys
@ -73,11 +92,6 @@ public abstract class LocalDB {
*/ */
public Map<String, Contact> getUsers() { return users; } public Map<String, Contact> getUsers() { return users; }
/**
* @param users the users to set
*/
public void setUsers(Map<String, Contact> users) { this.users = users; }
/** /**
* @return all saved {@link Chat} objects that list the client user as the * @return all saved {@link Chat} objects that list the client user as the
* sender * sender
@ -136,13 +150,13 @@ public abstract class LocalDB {
* @return the offline status cache * @return the offline status cache
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public Cache<MessageStatusChangeEvent> getStatusCache() { return statusCache; } public Cache<MessageStatusChange> getStatusCache() { return statusCache; }
/** /**
* @param statusCache the offline status cache to set * @param statusCache the offline status cache to set
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public void setStatusCache(Cache<MessageStatusChangeEvent> statusCache) { this.statusCache = statusCache; } public void setStatusCache(Cache<MessageStatusChange> statusCache) { this.statusCache = statusCache; }
/** /**
* Searches for a message by ID. * Searches for a message by ID.
@ -154,7 +168,7 @@ public abstract class LocalDB {
public Optional<Message> getMessage(long id) { public Optional<Message> getMessage(long id) {
return chats.stream().map(Chat::getMessages).flatMap(List::stream).filter(m -> m.getID() == id).findAny(); return chats.stream().map(Chat::getMessages).flatMap(List::stream).filter(m -> m.getID() == id).findAny();
} }
/** /**
* Searches for a chat by recipient ID. * Searches for a chat by recipient ID.
* *
@ -162,27 +176,25 @@ public abstract class LocalDB {
* @return an optional containing the chat * @return an optional containing the chat
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public Optional<Chat> getChat(long recipientID) { public Optional<Chat> getChat(long recipientID) { return chats.stream().filter(c -> c.getRecipient().getID() == recipientID).findAny(); }
return chats.stream().filter(c -> c.getRecipient().getID() == recipientID).findAny();
}
/** /**
* Performs a contact name change if the corresponding contact is present. * Performs a contact name change if the corresponding contact is present.
* *
* @param event the {@link NameChangeEvent} to process * @param event the {@link NameChange} to process
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public void replaceContactName(NameChangeEvent event) { public void replaceContactName(NameChange event) {
chats.stream().map(Chat::getRecipient).filter(c -> c.getID() == event.getID()).findAny().ifPresent(c -> c.setName(event.get())); chats.stream().map(Chat::getRecipient).filter(c -> c.getID() == event.getID()).findAny().ifPresent(c -> c.setName(event.get()));
} }
/** /**
* Performs a group resize operation if the corresponding group is present. * Performs a group resize operation if the corresponding group is present.
* *
* @param event the {@link GroupResizeEvent} to process * @param event the {@link GroupResize} to process
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public void updateGroup(GroupResizeEvent event) { public void updateGroup(GroupResize event) {
chats.stream() chats.stream()
.map(Chat::getRecipient) .map(Chat::getRecipient)
.filter(Group.class::isInstance) .filter(Group.class::isInstance)
@ -200,13 +212,4 @@ public abstract class LocalDB {
} }
}); });
} }
/**
* Creates a new {@link Chat} for all {@link Contact}s that do not have a chat.
*
* @since Envoy Client v0.1-beta
*/
public void createMissingChats() {
users.values().stream().filter(u -> !u.equals(user) && getChat(u.getID()).isEmpty()).map(Chat::new).forEach(chats::add);
}
} }

View File

@ -1,18 +1,18 @@
package envoy.client.data; package envoy.client.data;
import java.io.File; import java.io.*;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import envoy.data.ConfigItem;
import envoy.data.IDGenerator; import envoy.data.IDGenerator;
import envoy.data.Message;
import envoy.event.MessageStatusChange;
import envoy.util.SerializationUtils; import envoy.util.SerializationUtils;
/** /**
* Implements a {@link LocalDB} in a way that stores all information inside a * Implements a {@link LocalDB} in a way that stores all information inside a
* folder on the local file system.<br> * folder on the local file system.
* <br> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>PersistentLocalDB.java</strong><br> * File: <strong>PersistentLocalDB.java</strong><br>
* Created: <strong>27.10.2019</strong><br> * Created: <strong>27.10.2019</strong><br>
@ -21,92 +21,67 @@ import envoy.util.SerializationUtils;
* @author Maximilian K&auml;fer * @author Maximilian K&auml;fer
* @since Envoy Client v0.1-alpha * @since Envoy Client v0.1-alpha
*/ */
public class PersistentLocalDB extends LocalDB { public final class PersistentLocalDB extends LocalDB {
private File localDBDir, localDBFile, usersFile, idGeneratorFile, messageCacheFile, statusCacheFile; private File dbDir, userFile, idGeneratorFile, usersFile;
/** /**
* Initializes an empty local database without a directory. All changes made to * Constructs an empty local database. To serialize any user-specific data to
* this instance cannot be saved to the file system.<br> * the file system, call {@link PersistentLocalDB#initializeUserStorage()} first
* <br> * and then {@link PersistentLocalDB#save()}.
* This constructor shall be used in conjunction with the {@code ignoreLocalDB}
* {@link ConfigItem}.
* *
* @since Envoy Client v0.3-alpha * @param dbDir the directory in which to persist data
*/ * @throws IOException if {@code dbDir} is a file (and not a directory)
public PersistentLocalDB() {}
/**
* Constructs an empty local database. To serialize any chats to the file
* system, call {@link PersistentLocalDB#initializeUserStorage()}.
*
* @param localDBDir the directory in which to store users and chats
* @throws IOException if the PersistentLocalDB could not be initialized
* @since Envoy Client v0.1-alpha * @since Envoy Client v0.1-alpha
*/ */
public PersistentLocalDB(File localDBDir) throws IOException { public PersistentLocalDB(File dbDir) throws IOException {
this.localDBDir = localDBDir; this.dbDir = dbDir;
// Initialize local database directory // Test if the database directory is actually a directory
if (localDBDir.exists() && !localDBDir.isDirectory()) if (dbDir.exists() && !dbDir.isDirectory())
throw new IOException(String.format("LocalDBDir '%s' is not a directory!", localDBDir.getAbsolutePath())); throw new IOException(String.format("LocalDBDir '%s' is not a directory!", dbDir.getAbsolutePath()));
usersFile = new File(localDBDir, "users.db");
idGeneratorFile = new File(localDBDir, "id_generator.db"); // Initialize global files
idGeneratorFile = new File(dbDir, "id_gen.db");
usersFile = new File(dbDir, "users.db");
} }
/** /**
* Creates a database file for a user-specific list of chats.<br> * Creates a database file for a user-specific list of chats.
* {@inheritDoc}
* *
* @throws NullPointerException if the client user is not yet specified * @throws IllegalStateException if the client user is not specified
* @since Envoy Client v0.1-alpha * @since Envoy Client v0.1-alpha
*/ */
@Override @Override
public void initializeUserStorage() { public void initializeUserStorage() {
if (user == null) throw new NullPointerException("Client user is null"); if (user == null) throw new IllegalStateException("Client user is null, cannot initialize user storage");
localDBFile = new File(localDBDir, user.getID() + ".db"); userFile = new File(dbDir, user.getID() + ".db");
messageCacheFile = new File(localDBDir, user.getID() + "_message_cache.db");
statusCacheFile = new File(localDBDir, user.getID() + "_status_cache.db");
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void save() throws IOException { public void save() throws IOException {
// Save users // Save users
SerializationUtils.write(usersFile, users); SerializationUtils.write(usersFile, users);
// Save user data // Save user data
if (user != null) { if (user != null) SerializationUtils.write(userFile, chats, messageCache, statusCache);
SerializationUtils.write(localDBFile, chats);
SerializationUtils.write(messageCacheFile, messageCache);
SerializationUtils.write(statusCacheFile, statusCache);
}
// Save id generator // Save id generator
if (hasIDGenerator()) SerializationUtils.write(idGeneratorFile, idGenerator); if (hasIDGenerator()) SerializationUtils.write(idGeneratorFile, idGenerator);
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void loadUsers() throws ClassNotFoundException, IOException { users = SerializationUtils.read(usersFile, HashMap.class); } public void loadUsers() throws ClassNotFoundException, IOException { users = SerializationUtils.read(usersFile, HashMap.class); }
/**
* {@inheritDoc}
*/
@Override @Override
public void loadUserData() throws ClassNotFoundException, IOException { public void loadUserData() throws ClassNotFoundException, IOException {
chats = SerializationUtils.read(localDBFile, ArrayList.class); try (var in = new ObjectInputStream(new FileInputStream(userFile))) {
messageCache = SerializationUtils.read(messageCacheFile, Cache.class); chats = (ArrayList<Chat>) in.readObject();
statusCache = SerializationUtils.read(statusCacheFile, Cache.class); messageCache = (Cache<Message>) in.readObject();
statusCache = (Cache<MessageStatusChange>) in.readObject();
}
} }
/**
* {@inheritDoc}
*/
@Override @Override
public void loadIDGenerator() { public void loadIDGenerator() {
try { try {

View File

@ -11,8 +11,8 @@ import envoy.util.SerializationUtils;
/** /**
* Manages all application settings, which are different objects that can be * Manages all application settings, which are different objects that can be
* changed during runtime and serialized them by using either the file system or * changed during runtime and serialized them by using either the file system or
* the {@link Preferences} API.<br> * the {@link Preferences} API.
* <br> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>Settings.java</strong><br> * File: <strong>Settings.java</strong><br>
* Created: <strong>11 Nov 2019</strong><br> * Created: <strong>11 Nov 2019</strong><br>

View File

@ -7,8 +7,8 @@ import javax.swing.JComponent;
/** /**
* Encapsulates a persistent value that is directly or indirectly mutable by the * Encapsulates a persistent value that is directly or indirectly mutable by the
* user.<br> * user.
* <br> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>SettingsItem.java</strong><br> * File: <strong>SettingsItem.java</strong><br>
* Created: <strong>23.12.2019</strong><br> * Created: <strong>23.12.2019</strong><br>

View File

@ -2,8 +2,8 @@ package envoy.client.data;
/** /**
* Implements a {@link LocalDB} in a way that does not persist any information * Implements a {@link LocalDB} in a way that does not persist any information
* after application shutdown.<br> * after application shutdown.
* <br> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>TransientLocalDB.java</strong><br> * File: <strong>TransientLocalDB.java</strong><br>
* Created: <strong>3 Feb 2020</strong><br> * Created: <strong>3 Feb 2020</strong><br>
@ -11,5 +11,5 @@ package envoy.client.data;
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public class TransientLocalDB extends LocalDB { public final class TransientLocalDB extends LocalDB {
} }

View File

@ -8,7 +8,6 @@ import envoy.event.Event;
* Created: <strong>11.02.2020</strong><br> * Created: <strong>11.02.2020</strong><br>
* *
* @author: Maximilian K&aumlfer * @author: Maximilian K&aumlfer
*
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public class SendEvent extends Event<Event<?>> { public class SendEvent extends Event<Event<?>> {

View File

@ -3,10 +3,8 @@ package envoy.client.net;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import envoy.client.data.Cache; import envoy.client.data.Cache;
@ -15,15 +13,15 @@ import envoy.client.data.LocalDB;
import envoy.client.event.SendEvent; import envoy.client.event.SendEvent;
import envoy.data.*; import envoy.data.*;
import envoy.event.*; import envoy.event.*;
import envoy.event.contact.ContactOperationEvent; import envoy.event.contact.ContactOperation;
import envoy.event.contact.ContactSearchResult; import envoy.event.contact.ContactSearchResult;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
import envoy.util.SerializationUtils; import envoy.util.SerializationUtils;
/** /**
* Establishes a connection to the server, performs a handshake and delivers * Establishes a connection to the server, performs a handshake and delivers
* certain objects to the server.<br> * certain objects to the server.
* <br> * <p>
* 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>
@ -41,9 +39,8 @@ public class Client implements Closeable {
private boolean online; private boolean online;
// Asynchronously initialized during handshake // Asynchronously initialized during handshake
private volatile User sender; private volatile User sender;
private volatile Set<? extends Contact> contacts; private volatile boolean rejected;
private volatile boolean rejected;
// Configuration, logging and event management // Configuration, logging and event management
private static final ClientConfig config = ClientConfig.getInstance(); private static final ClientConfig config = ClientConfig.getInstance();
@ -56,34 +53,38 @@ public class Client implements Closeable {
* will block for up to 5 seconds. If the handshake does exceed this time limit, * will block for up to 5 seconds. If the handshake does exceed this time limit,
* an exception is thrown. * an exception is thrown.
* *
* @param credentials the login credentials of the user * @param credentials the login credentials of the user
* @param receivedMessageCache a message cache containing all unread messages * @param receivedMessageCache a message cache containing all unread
* from the server that can be relayed after * messages
* initialization * from the server that can be relayed
* @param receivedMessageStatusChangeEventCache an event cache containing all received messageStatusChangeEvents from the server that can be relayed after initialization * after
* initialization
* @param receivedMessageStatusChangeCache an event cache containing all
* received messageStatusChangeEvents
* from the server that can be relayed
* after initialization
* @throws TimeoutException if the server could not be reached * @throws TimeoutException if the server could not be reached
* @throws IOException if the login credentials could not be * @throws IOException if the login credentials could not be written
* written
* @throws InterruptedException if the current thread is interrupted while * @throws InterruptedException if the current thread is interrupted while
* waiting for the handshake response * waiting for the handshake response
*/ */
public void performHandshake(LoginCredentials credentials, Cache<Message> receivedMessageCache, public void performHandshake(LoginCredentials credentials, Cache<Message> receivedMessageCache,
Cache<MessageStatusChangeEvent> receivedMessageStatusChangeEventCache) Cache<MessageStatusChange> receivedMessageStatusChangeCache) throws TimeoutException, IOException, InterruptedException {
throws TimeoutException, IOException, InterruptedException {
if (online) throw new IllegalStateException("Handshake has already been performed successfully"); if (online) throw new IllegalStateException("Handshake has already been performed successfully");
// Establish TCP connection // Establish TCP connection
logger.finer(String.format("Attempting connection to server %s:%d...", config.getServer(), config.getPort())); logger.log(Level.FINER, String.format("Attempting connection to server %s:%d...", config.getServer(), config.getPort()));
socket = new Socket(config.getServer(), config.getPort()); socket = new Socket(config.getServer(), config.getPort());
logger.fine("Successfully established TCP connection to server"); logger.log(Level.FINE, "Successfully established TCP connection to server");
// Create object receiver // Create object receiver
receiver = new Receiver(socket.getInputStream()); receiver = new Receiver(socket.getInputStream());
// Register user creation processor, contact list processor and message cache // Register user creation processor, contact list processor and message cache
receiver.registerProcessor(User.class, sender -> { this.sender = sender; contacts = sender.getContacts(); }); receiver.registerProcessor(User.class, sender -> this.sender = sender);
receiver.registerProcessor(Message.class, receivedMessageCache); receiver.registerProcessor(Message.class, receivedMessageCache);
receiver.registerProcessor(MessageStatusChangeEvent.class, receivedMessageStatusChangeEventCache); receiver.registerProcessor(MessageStatusChange.class, receivedMessageStatusChangeCache);
receiver.registerProcessor(HandshakeRejectionEvent.class, evt -> { rejected = true; eventBus.dispatch(evt); }); receiver.registerProcessor(HandshakeRejection.class, evt -> { rejected = true; eventBus.dispatch(evt); });
rejected = false; rejected = false;
@ -114,30 +115,36 @@ public class Client implements Closeable {
// Remove all processors as they are only used during the handshake // Remove all processors as they are only used during the handshake
receiver.removeAllProcessors(); receiver.removeAllProcessors();
logger.info("Handshake completed."); logger.log(Level.INFO, "Handshake completed.");
} }
/** /**
* Initializes the {@link Receiver} used to process data sent from the server to * Initializes the {@link Receiver} used to process data sent from the server to
* this client. * this client.
* *
* @param localDB the local database used to persist the current * @param localDB the local database used to persist
* {@link IDGenerator} * the current
* @param receivedMessageCache a message cache containing all unread messages * {@link IDGenerator}
* from the server that can be relayed after * @param receivedMessageCache a message cache containing all unread
* initialization * messages
* @param receivedMessageStatusChangeEventCache an event cache containing all received messageStatusChangeEvents from the server that can be relayed after initialization * from the server that can be relayed
* after
* initialization
* @param receivedMessageStatusChangeCache an event cache containing all
* received messageStatusChangeEvents
* from the server that can be relayed
* after initialization
* @throws IOException if no {@link IDGenerator} is present and none could be * @throws IOException if no {@link IDGenerator} is present and none could be
* requested from the server * requested from the server
* @since Envoy Client v0.2-alpha * @since Envoy Client v0.2-alpha
*/ */
public void initReceiver(LocalDB localDB, Cache<Message> receivedMessageCache, public void initReceiver(LocalDB localDB, Cache<Message> receivedMessageCache, Cache<MessageStatusChange> receivedMessageStatusChangeCache)
Cache<MessageStatusChangeEvent> receivedMessageStatusChangeEventCache) throws IOException { throws IOException {
checkOnline(); checkOnline();
// Process incoming messages // Process incoming messages
final ReceivedMessageProcessor receivedMessageProcessor = new ReceivedMessageProcessor(); final ReceivedMessageProcessor receivedMessageProcessor = new ReceivedMessageProcessor();
final MessageStatusChangeEventProcessor messageStatusChangeEventProcessor = new MessageStatusChangeEventProcessor(); final MessageStatusChangeProcessor messageStatusChangeEventProcessor = new MessageStatusChangeProcessor();
// TODO: Define a cache // TODO: Define a cache
receiver.registerProcessor(GroupMessage.class, new ReceivedGroupMessageProcessor()); receiver.registerProcessor(GroupMessage.class, new ReceivedGroupMessageProcessor());
@ -148,33 +155,33 @@ public class Client implements Closeable {
receivedMessageCache.setProcessor(receivedMessageProcessor); receivedMessageCache.setProcessor(receivedMessageProcessor);
// Process message status changes // Process message status changes
receiver.registerProcessor(MessageStatusChangeEvent.class, messageStatusChangeEventProcessor); receiver.registerProcessor(MessageStatusChange.class, messageStatusChangeEventProcessor);
receivedMessageStatusChangeEventCache.setProcessor(messageStatusChangeEventProcessor); receivedMessageStatusChangeCache.setProcessor(messageStatusChangeEventProcessor);
// Process user status changes // Process user status changes
receiver.registerProcessor(UserStatusChangeEvent.class, eventBus::dispatch); receiver.registerProcessor(UserStatusChange.class, eventBus::dispatch);
// Process message ID generation // Process message ID generation
receiver.registerProcessor(IDGenerator.class, localDB::setIDGenerator); receiver.registerProcessor(IDGenerator.class, localDB::setIDGenerator);
// Process name changes // Process name changes
receiver.registerProcessor(NameChangeEvent.class, evt -> { localDB.replaceContactName(evt); eventBus.dispatch(evt); }); receiver.registerProcessor(NameChange.class, evt -> { localDB.replaceContactName(evt); eventBus.dispatch(evt); });
// Process contact searches // Process contact searches
receiver.registerProcessor(ContactSearchResult.class, eventBus::dispatch); receiver.registerProcessor(ContactSearchResult.class, eventBus::dispatch);
// Process contact operations // Process contact operations
receiver.registerProcessor(ContactOperationEvent.class, eventBus::dispatch); receiver.registerProcessor(ContactOperation.class, eventBus::dispatch);
// Process group size changes // Process group size changes
receiver.registerProcessor(GroupResizeEvent.class, evt -> { localDB.updateGroup(evt); eventBus.dispatch(evt); }); receiver.registerProcessor(GroupResize.class, evt -> { localDB.updateGroup(evt); eventBus.dispatch(evt); });
// Send event // Send event
eventBus.register(SendEvent.class, evt -> { eventBus.register(SendEvent.class, evt -> {
try { try {
sendEvent(evt.get()); sendEvent(evt.get());
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); logger.log(Level.WARNING, "An error occurred when trying to send " + evt, e);
} }
}); });
@ -221,36 +228,23 @@ public class Client implements Closeable {
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public void requestIdGenerator() throws IOException { public void requestIdGenerator() throws IOException {
logger.info("Requesting new id generator..."); logger.log(Level.INFO, "Requesting new id generator...");
writeObject(new IDGeneratorRequest()); writeObject(new IDGeneratorRequest());
} }
/**
* @return a {@code Map<String, User>} of all users on the server with their
* user names as keys
* @since Envoy Client v0.2-alpha
*/
public Map<String, Contact> getUsers() {
checkOnline();
final Map<String, Contact> users = new HashMap<>();
contacts.forEach(u -> users.put(u.getName(), u));
users.put(sender.getName(), sender);
return users;
}
@Override @Override
public void close() throws IOException { if (online) socket.close(); } public void close() throws IOException { if (online) socket.close(); }
private void writeObject(Object obj) throws IOException { private void writeObject(Object obj) throws IOException {
checkOnline(); checkOnline();
logger.fine("Sending " + obj); logger.log(Level.FINE, "Sending " + obj);
SerializationUtils.writeBytesWithLength(obj, socket.getOutputStream()); SerializationUtils.writeBytesWithLength(obj, socket.getOutputStream());
} }
private void checkOnline() { if (!online) throw new IllegalStateException("Client is not online"); } private void checkOnline() { if (!online) throw new IllegalStateException("Client is not online"); }
/** /**
* @return the sender object that represents this client. * @return the {@link User} as which this client is logged in
* @since Envoy Client v0.1-alpha * @since Envoy Client v0.1-alpha
*/ */
public User getSender() { return sender; } public User getSender() { return sender; }
@ -261,7 +255,7 @@ public class Client implements Closeable {
* @param clientUser the client user to set * @param clientUser the client user to set
* @since Envoy Client v0.2-alpha * @since Envoy Client v0.2-alpha
*/ */
public void setSender(User clientUser) { this.sender = clientUser; } public void setSender(User clientUser) { sender = clientUser; }
/** /**
* @return the {@link Receiver} used by this {@link Client} * @return the {@link Receiver} used by this {@link Client}
@ -273,16 +267,4 @@ public class Client implements Closeable {
* @since Envoy Client v0.2-alpha * @since Envoy Client v0.2-alpha
*/ */
public boolean isOnline() { return online; } public boolean isOnline() { return online; }
/**
* @return the contacts of this {@link Client}
* @since Envoy Client v0.3-alpha
*/
public Set<? extends Contact> getContacts() { return contacts; }
/**
* @param contacts the contacts to set
* @since Envoy Client v0.3-alpha
*/
public void setContacts(Set<? extends Contact> contacts) { this.contacts = contacts; }
} }

View File

@ -5,30 +5,30 @@ import java.util.logging.Logger;
import envoy.data.Message.MessageStatus; import envoy.data.Message.MessageStatus;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.event.MessageStatusChangeEvent; import envoy.event.MessageStatusChange;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>MessageStatusChangeEventProcessor.java</strong><br> * File: <strong>MessageStatusChangeProcessor.java</strong><br>
* Created: <strong>4 Feb 2020</strong><br> * Created: <strong>4 Feb 2020</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public class MessageStatusChangeEventProcessor implements Consumer<MessageStatusChangeEvent> { public class MessageStatusChangeProcessor implements Consumer<MessageStatusChange> {
private static final Logger logger = EnvoyLog.getLogger(MessageStatusChangeEventProcessor.class); private static final Logger logger = EnvoyLog.getLogger(MessageStatusChangeProcessor.class);
/** /**
* Dispatches a {@link MessageStatusChangeEvent} if the status is * Dispatches a {@link MessageStatusChange} if the status is
* {@code RECEIVED} or {@code READ}. * {@code RECEIVED} or {@code READ}.
* *
* @param evt the status change event * @param evt the status change event
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
@Override @Override
public void accept(MessageStatusChangeEvent evt) { public void accept(MessageStatusChange evt) {
if (evt.get().ordinal() < MessageStatus.RECEIVED.ordinal()) logger.warning("Received invalid message status change " + evt); if (evt.get().ordinal() < MessageStatus.RECEIVED.ordinal()) logger.warning("Received invalid message status change " + evt);
else EventBus.getInstance().dispatch(evt); else EventBus.getInstance().dispatch(evt);
} }

View File

@ -1,6 +1,7 @@
package envoy.client.net; package envoy.client.net;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import envoy.client.event.MessageCreationEvent; import envoy.client.event.MessageCreationEvent;
@ -23,7 +24,7 @@ public class ReceivedMessageProcessor implements Consumer<Message> {
@Override @Override
public void accept(Message message) { public void accept(Message message) {
if (message.getStatus() != MessageStatus.SENT) logger.warning("The message has the unexpected status " + message.getStatus()); if (message.getStatus() != MessageStatus.SENT) logger.log(Level.WARNING, "The message has the unexpected status " + message.getStatus());
else { else {
// Update status to RECEIVED // Update status to RECEIVED
message.nextStatus(); message.nextStatus();

View File

@ -45,7 +45,7 @@ public class Receiver extends Thread {
/** /**
* Starts the receiver loop. When an object is read, it is passed to the * Starts the receiver loop. When an object is read, it is passed to the
* appropriate processor. * appropriate processor.
* *
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
@Override @Override
@ -54,31 +54,31 @@ public class Receiver extends Thread {
try { try {
while (true) { while (true) {
// Read object length // Read object length
byte[] lenBytes = new byte[4]; final byte[] lenBytes = new byte[4];
in.read(lenBytes); in.read(lenBytes);
int len = SerializationUtils.bytesToInt(lenBytes, 0); final int len = SerializationUtils.bytesToInt(lenBytes, 0);
// Read object into byte array // Read object into byte array
byte[] objBytes = new byte[len]; final byte[] objBytes = new byte[len];
in.read(objBytes); in.read(objBytes);
try (ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(objBytes))) { try (ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(objBytes))) {
Object obj = oin.readObject(); final Object obj = oin.readObject();
logger.fine("Received " + obj); logger.log(Level.FINE, "Received " + obj);
// Get appropriate processor // Get appropriate processor
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Consumer processor = processors.get(obj.getClass()); final Consumer processor = processors.get(obj.getClass());
if (processor == null) if (processor == null)
logger.warning(String.format("The received object has the class %s for which no processor is defined.", obj.getClass())); logger.log(Level.WARNING, String.format(
"The received object has the class %s for which no processor is defined.", obj.getClass()));
else processor.accept(obj); else processor.accept(obj);
} }
} }
} catch (SocketException e) { } catch (final SocketException e) {
// Connection probably closed by client. // Connection probably closed by client.
} catch (Exception e) { } catch (final Exception e) {
logger.log(Level.SEVERE, "Error on receiver thread", e); logger.log(Level.SEVERE, "Error on receiver thread", e);
e.printStackTrace();
} }
} }
@ -94,7 +94,7 @@ public class Receiver extends Thread {
/** /**
* Removes all object processors registered at this {@link Receiver}. * Removes all object processors registered at this {@link Receiver}.
* *
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public void removeAllProcessors() { processors.clear(); } public void removeAllProcessors() { processors.clear(); }

View File

@ -6,14 +6,14 @@ import java.util.logging.Logger;
import envoy.client.data.LocalDB; import envoy.client.data.LocalDB;
import envoy.data.Message; import envoy.data.Message;
import envoy.event.MessageStatusChangeEvent; import envoy.event.MessageStatusChange;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
/** /**
* Implements methods to send {@link Message}s and * Implements methods to send {@link Message}s and
* {@link MessageStatusChangeEvent}s to the server or cache them inside a * {@link MessageStatusChange}s to the server or cache them inside a
* {@link LocalDB} depending on the online status.<br> * {@link LocalDB} depending on the online status.
* <br> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>WriteProxy.java</strong><br> * File: <strong>WriteProxy.java</strong><br>
* Created: <strong>6 Feb 2020</strong><br> * Created: <strong>6 Feb 2020</strong><br>
@ -45,27 +45,24 @@ public class WriteProxy {
// Initialize cache processors for messages and message status change events // Initialize cache processors for messages and message status change events
localDB.getMessageCache().setProcessor(msg -> { localDB.getMessageCache().setProcessor(msg -> {
try { try {
logger.finer("Sending cached " + msg); logger.log(Level.FINER, "Sending cached " + msg);
client.sendMessage(msg); client.sendMessage(msg);
} catch (final IOException e) {
// Update message state to SENT in localDB logger.log(Level.SEVERE, "Could not send cached message: ", e);
localDB.getMessage(msg.getID()).ifPresent(Message::nextStatus);
} catch (IOException e) {
logger.log(Level.SEVERE, "Could not send cached message", e);
} }
}); });
localDB.getStatusCache().setProcessor(evt -> { localDB.getStatusCache().setProcessor(evt -> {
logger.finer("Sending cached " + evt); logger.log(Level.FINER, "Sending cached " + evt);
try { try {
client.sendEvent(evt); client.sendEvent(evt);
} catch (IOException e) { } catch (final IOException e) {
logger.log(Level.SEVERE, "Could not send cached message status change event", e); logger.log(Level.SEVERE, "Could not send cached message status change event: ", e);
} }
}); });
} }
/** /**
* Sends cached {@link Message}s and {@link MessageStatusChangeEvent}s to the * Sends cached {@link Message}s and {@link MessageStatusChange}s to the
* server. * server.
* *
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
@ -99,7 +96,7 @@ public class WriteProxy {
* @throws IOException if the event could not be sent * @throws IOException if the event could not be sent
* @since Envoy Client v0.3-alpha * @since Envoy Client v0.3-alpha
*/ */
public void writeMessageStatusChangeEvent(MessageStatusChangeEvent evt) throws IOException { public void writeMessageStatusChange(MessageStatusChange evt) throws IOException {
if (client.isOnline()) client.sendEvent(evt); if (client.isOnline()) client.sendEvent(evt);
else localDB.getStatusCache().accept(evt); else localDB.getStatusCache().accept(evt);
} }

View File

@ -3,7 +3,6 @@ package envoy.client.ui;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import envoy.data.Contact; import envoy.data.Contact;
import envoy.data.Group; import envoy.data.Group;
@ -32,32 +31,19 @@ public class ContactListCell extends ListCell<Contact> {
setText(null); setText(null);
setGraphic(null); setGraphic(null);
} else { } else {
// the infoLabel displays specific contact info, i.e. status of a user or amount // Container with contact name
// of members in a group final var vbox = new VBox(new Label(contact.getName()));
Label infoLabel = null;
if (contact instanceof User) { if (contact instanceof User) {
// user specific info // Online status
infoLabel = new Label(((User) contact).getStatus().toString()); final var user = (User) contact;
Color textColor = null; final var statusLabel = new Label(user.getStatus().toString());
switch (((User) contact).getStatus()) { statusLabel.getStyleClass().add(user.getStatus().toString().toLowerCase());
case ONLINE: vbox.getChildren().add(statusLabel);
textColor = Color.LIMEGREEN; } else {
break; // Member count
case AWAY: vbox.getChildren().add(new Label(((Group) contact).getContacts().size() + " members"));
textColor = Color.ORANGERED; }
break; setGraphic(vbox);
case BUSY:
textColor = Color.RED;
break;
case OFFLINE:
textColor = Color.GRAY;
break;
}
infoLabel.setTextFill(textColor);
} else
// group specific infos
infoLabel = new Label(String.valueOf(((Group) contact).getContacts().size()) + " members");
setGraphic(new VBox(new Label(contact.getName()), infoLabel));
} }
} }
} }

View File

@ -1,6 +1,5 @@
package envoy.client.ui; package envoy.client.ui;
import java.io.IOException;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
@ -8,11 +7,11 @@ import javafx.scene.image.Image;
/** /**
* Provides static utility methods for loading icons from the resource * Provides static utility methods for loading icons from the resource
* folder.<br> * folder.
* <br> * <p>
* Project: <strong>envoy-client</strong> * Project: <strong>envoy-client</strong><br>
* File: <strong>IconUtil.java</strong> * File: <strong>IconUtil.java</strong><br>
* Created: <strong>16.03.2020</strong> * Created: <strong>16.03.2020</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
@ -23,46 +22,43 @@ public class IconUtil {
/** /**
* Loads an icon from the resource folder. * Loads an icon from the resource folder.
* *
* @param path the path to the icon inside the resource folder * @param path the path to the icon inside the resource folder
* @return the icon * @return the icon
* @throws IOException if the loading process failed
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public static Image load(String path) throws IOException { return new Image(IconUtil.class.getResource(path).toExternalForm()); } public static Image load(String path) { return new Image(IconUtil.class.getResource(path).toExternalForm()); }
/** /**
* Loads an icon from the resource folder and scales it to a given size. * Loads an icon from the resource folder and scales it to a given size.
* *
* @param path the path to the icon inside the resource folder * @param path the path to the icon inside the resource folder
* @param size the size to scale the icon to * @param size the size to scale the icon to
* @return the scaled icon * @return the scaled icon
* @throws IOException if the loading process failed
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public static Image load(String path, int size) throws IOException { public static Image load(String path, int size) {
return new Image(IconUtil.class.getResource(path).toExternalForm(), size, size, true, true); return new Image(IconUtil.class.getResource(path).toExternalForm(), size, size, true, true);
} }
/** /**
* *
* Loads icons specified by an enum. The images have to be named like the * Loads icons specified by an enum. The images have to be named like the
* lowercase enum constants with {@code .png} extension and be located inside a * lowercase enum constants with {@code .png} extension and be located inside a
* folder with the lowercase name of the enum, which must be contained inside * folder with the lowercase name of the enum, which must be contained inside
* the {@code /icons} folder. * the {@code /icons} folder.
* *
* @param <T> the enum that specifies the icons to load * @param <T> the enum that specifies the icons to load
* @param enumClass the class of the enum * @param enumClass the class of the enum
* @param size the size to scale the icons to * @param size the size to scale the icons to
* @return a map containing the loaded icons with the corresponding enum * @return a map containing the loaded icons with the corresponding enum
* constants as keys * constants as keys
* @throws IOException if the loading process failed
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public static <T extends Enum<T>> EnumMap<T, Image> loadByEnum(Class<T> enumClass, int size) throws IOException { public static <T extends Enum<T>> EnumMap<T, Image> loadByEnum(Class<T> enumClass, int size) {
var icons = new EnumMap<T, Image>(enumClass); final var icons = new EnumMap<T, Image>(enumClass);
var path = "/icons/" + enumClass.getSimpleName().toLowerCase() + "/"; final var path = "/icons/" + enumClass.getSimpleName().toLowerCase() + "/";
for (var e : EnumSet.allOf(enumClass)) for (final var e : EnumSet.allOf(enumClass))
icons.put(e, load(path + e.toString().toLowerCase() + ".png", size)); icons.put(e, load(path + e.toString().toLowerCase() + ".png", size));
return icons; return icons;
} }

View File

@ -1,18 +1,18 @@
package envoy.client.ui; package envoy.client.ui;
import java.io.IOException; import java.time.format.DateTimeFormatter;
import java.text.SimpleDateFormat;
import java.util.Map; import java.util.Map;
import javafx.geometry.Insets;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import envoy.data.Message; import envoy.data.Message;
import envoy.data.Message.MessageStatus; import envoy.data.Message.MessageStatus;
import envoy.data.User;
/** /**
* Displays a single message inside the message list. * Displays a single message inside the message list.
@ -20,40 +20,41 @@ import envoy.data.Message.MessageStatus;
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>MessageListCell.java</strong><br> * File: <strong>MessageListCell.java</strong><br>
* Created: <strong>28.03.2020</strong><br> * Created: <strong>28.03.2020</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public class MessageListCell extends ListCell<Message> { public class MessageListCell extends ListCell<Message> {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); private static User client;
private static Map<MessageStatus, Image> statusImages; private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");
private static final Map<MessageStatus, Image> statusImages = IconUtil.loadByEnum(MessageStatus.class, 16);
static {
try {
statusImages = IconUtil.loadByEnum(MessageStatus.class, 32);
} catch (IOException e) {
e.printStackTrace();
}
}
/** /**
* Displays the text, the data of creation and the status of a message. * Displays the text, the data of creation and the status of a message.
* *
* @since Envoy v0.1-beta * @since Envoy v0.1-beta
*/ */
@Override @Override
protected void updateItem(Message message, boolean empty) { protected void updateItem(Message message, boolean empty) {
super.updateItem(message, empty); super.updateItem(message, empty);
if(empty || message == null) { if (empty || message == null) {
setText(null); setText(null);
setGraphic(null); setGraphic(null);
} else { } else {
setGraphic(new HBox( final var cell = new VBox(new Label(dateFormat.format(message.getCreationDate())), new Label(message.getText()));
new VBox( if (message.getRecipientID() == client.getID()) {
new Label(dateFormat.format(message.getCreationDate())), cell.getChildren().add(new Label("", new ImageView(statusImages.get(message.getStatus()))));
new Label(message.getText())), cell.getStyleClass().add("own-message");
new Label("", new ImageView(statusImages.get(message.getStatus()))))); } else cell.getStyleClass().add("received-message");
cell.paddingProperty().setValue(new Insets(5, 20, 5, 20));
setGraphic(cell);
} }
} }
/**
* @param client the user who chats with another person
* @since Envoy Client v0.1-beta
*/
public static void setUser(User client) { MessageListCell.client = client; }
} }

View File

@ -2,6 +2,7 @@ package envoy.client.ui;
import java.io.IOException; import java.io.IOException;
import java.util.Stack; import java.util.Stack;
import java.util.logging.Level;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
@ -11,6 +12,7 @@ import javafx.stage.Stage;
import envoy.client.data.Settings; import envoy.client.data.Settings;
import envoy.client.event.ThemeChangeEvent; import envoy.client.event.ThemeChangeEvent;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.util.EnvoyLog;
/** /**
* Manages a stack of scenes. The most recently added scene is displayed inside * Manages a stack of scenes. The most recently added scene is displayed inside
@ -23,7 +25,7 @@ import envoy.event.EventBus;
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>SceneContext.java</strong><br> * File: <strong>SceneContext.java</strong><br>
* Created: <strong>06.06.2020</strong><br> * Created: <strong>06.06.2020</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
@ -31,43 +33,43 @@ public final class SceneContext {
/** /**
* Contains information about different scenes and their FXML resource files. * Contains information about different scenes and their FXML resource files.
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public static enum SceneInfo { public enum SceneInfo {
/** /**
* The main scene in which chats are displayed. * The main scene in which chats are displayed.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
CHAT_SCENE("/fxml/ChatScene.fxml"), CHAT_SCENE("/fxml/ChatScene.fxml"),
/** /**
* The scene in which settings are displayed. * The scene in which settings are displayed.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
SETTINGS_SCENE("/fxml/SettingsScene.fxml"), SETTINGS_SCENE("/fxml/SettingsScene.fxml"),
/** /**
* The scene in which the contact search is displayed. * The scene in which the contact search is displayed.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
CONTACT_SEARCH_SCENE("/fxml/ContactSearchScene.fxml"), CONTACT_SEARCH_SCENE("/fxml/ContactSearchScene.fxml"),
/** /**
* The scene in which the group creation screen is displayed. * The scene in which the group creation screen is displayed.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
GROUP_CREATION_SCENE("/fxml/GroupCreationScene.fxml"), GROUP_CREATION_SCENE("/fxml/GroupCreationScene.fxml"),
/** /**
* The scene in which the login screen is displayed. * The scene in which the login screen is displayed.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
LOGIN_SCENE("/fxml/LoginScene.fxml"); LOGIN_SCENE("/fxml/LoginScene.fxml");
@ -88,7 +90,7 @@ public final class SceneContext {
/** /**
* Initializes the scene context. * Initializes the scene context.
* *
* @param stage the stage in which scenes will be displayed * @param stage the stage in which scenes will be displayed
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
@ -99,7 +101,7 @@ public final class SceneContext {
/** /**
* Loads a new scene specified by a scene info. * Loads a new scene specified by a scene info.
* *
* @param sceneInfo specifies the scene to load * @param sceneInfo specifies the scene to load
* @throws RuntimeException if the loading process fails * @throws RuntimeException if the loading process fails
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
@ -117,14 +119,15 @@ public final class SceneContext {
applyCSS(); applyCSS();
stage.sizeToScene(); stage.sizeToScene();
stage.show(); stage.show();
} catch (IOException e) { } catch (final IOException e) {
EnvoyLog.getLogger(SceneContext.class).log(Level.SEVERE, String.format("Could not load scene for %s: ", sceneInfo), e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
/** /**
* Removes the current scene and displays the previous one. * Removes the current scene and displays the previous one.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public void pop() { public void pop() {

View File

@ -16,7 +16,7 @@ import envoy.client.net.Client;
import envoy.client.ui.SceneContext.SceneInfo; import envoy.client.ui.SceneContext.SceneInfo;
import envoy.client.ui.controller.LoginScene; import envoy.client.ui.controller.LoginScene;
import envoy.data.Message; import envoy.data.Message;
import envoy.event.MessageStatusChangeEvent; import envoy.event.MessageStatusChange;
import envoy.exception.EnvoyException; import envoy.exception.EnvoyException;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
@ -33,10 +33,17 @@ import envoy.util.EnvoyLog;
*/ */
public final class Startup extends Application { public final class Startup extends Application {
private LocalDB localDB; /**
private Client client; * The version of this client. Used to verify compatibility with the server.
private Cache<Message> messageCache; *
private Cache<MessageStatusChangeEvent> messageStatusCache; * @since Envoy Client v0.1-beta
*/
public static final String VERSION = "0.1-beta";
private LocalDB localDB;
private Client client;
private Cache<Message> messageCache;
private Cache<MessageStatusChange> messageStatusCache;
private static final ClientConfig config = ClientConfig.getInstance(); private static final ClientConfig config = ClientConfig.getInstance();
private static final Logger logger = EnvoyLog.getLogger(Startup.class); private static final Logger logger = EnvoyLog.getLogger(Startup.class);
@ -44,7 +51,7 @@ public final class Startup extends Application {
/** /**
* Loads the configuration, initializes the client and the local database and * Loads the configuration, initializes the client and the local database and
* delegates the rest of the startup process to {@link LoginScene}. * delegates the rest of the startup process to {@link LoginScene}.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
@Override @Override
@ -63,6 +70,7 @@ public final class Startup extends Application {
if (!config.isInitialized()) throw new EnvoyException("Configuration is not fully initialized"); if (!config.isInitialized()) throw new EnvoyException("Configuration is not fully initialized");
} catch (final Exception e) { } catch (final Exception e) {
new Alert(AlertType.ERROR, "Error loading configuration values:\n" + e); new Alert(AlertType.ERROR, "Error loading configuration values:\n" + e);
logger.log(Level.SEVERE, "Error loading configuration values: ", e);
e.printStackTrace(); e.printStackTrace();
System.exit(1); System.exit(1);
} }
@ -73,24 +81,24 @@ public final class Startup extends Application {
EnvoyLog.setFileLevelBarrier(config.getFileLevelBarrier()); EnvoyLog.setFileLevelBarrier(config.getFileLevelBarrier());
EnvoyLog.setConsoleLevelBarrier(config.getConsoleLevelBarrier()); EnvoyLog.setConsoleLevelBarrier(config.getConsoleLevelBarrier());
logger.log(Level.INFO, "Envoy starting...");
// Initialize the local database // Initialize the local database
if (config.isIgnoreLocalDB()) { if (config.isIgnoreLocalDB()) {
localDB = new TransientLocalDB(); localDB = new TransientLocalDB();
new Alert(AlertType.WARNING, "Ignoring local database.\nMessages will not be saved!").showAndWait(); new Alert(AlertType.WARNING, "Ignoring local database.\nMessages will not be saved!").showAndWait();
} else { } else try {
try { localDB = new PersistentLocalDB(new File(config.getHomeDirectory(), config.getLocalDB().getPath()));
localDB = new PersistentLocalDB(new File(config.getHomeDirectory(), config.getLocalDB().getPath())); } catch (final IOException e3) {
} catch (final IOException e3) { logger.log(Level.SEVERE, "Could not initialize local database: ", e3);
logger.log(Level.SEVERE, "Could not initialize local database", e3); new Alert(AlertType.ERROR, "Could not initialize local database!\n" + e3).showAndWait();
new Alert(AlertType.ERROR, "Could not initialize local database!\n" + e3).showAndWait(); System.exit(1);
System.exit(1); return;
return;
}
} }
// Initialize client and unread message cache // Initialize client and unread message cache
client = new Client(); client = new Client();
messageCache = new Cache<>(); messageCache = new Cache<>();
messageStatusCache = new Cache<>(); messageStatusCache = new Cache<>();
stage.setTitle("Envoy"); stage.setTitle("Envoy");
@ -103,20 +111,21 @@ public final class Startup extends Application {
/** /**
* Closes the client connection and saves the local database and settings. * Closes the client connection and saves the local database and settings.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
@Override @Override
public void stop() { public void stop() {
try { try {
logger.info("Closing connection..."); logger.log(Level.INFO, "Closing connection...");
client.close(); client.close();
logger.info("Saving local database and settings..."); logger.log(Level.INFO, "Saving local database and settings...");
localDB.save(); localDB.save();
Settings.getInstance().save(); Settings.getInstance().save();
logger.log(Level.INFO, "Envoy was terminated by its user");
} catch (final Exception e) { } catch (final Exception e) {
logger.log(Level.SEVERE, "Unable to save local files", e); logger.log(Level.SEVERE, "Unable to save local files: ", e);
} }
} }

View File

@ -4,11 +4,13 @@ import java.awt.*;
import java.awt.TrayIcon.MessageType; import java.awt.TrayIcon.MessageType;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.util.logging.Level;
import envoy.client.event.MessageCreationEvent; import envoy.client.event.MessageCreationEvent;
import envoy.data.Message; import envoy.data.Message;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.exception.EnvoyException; import envoy.exception.EnvoyException;
import envoy.util.EnvoyLog;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
@ -25,7 +27,7 @@ public class StatusTrayIcon {
* system tray. This includes displaying the icon, but also creating * system tray. This includes displaying the icon, but also creating
* notifications when new messages are received. * notifications when new messages are received.
*/ */
private TrayIcon trayIcon; private final TrayIcon trayIcon;
/** /**
* A received {@link Message} is only displayed as a system tray notification if * A received {@link Message} is only displayed as a system tray notification if
@ -46,16 +48,16 @@ public class StatusTrayIcon {
public StatusTrayIcon(Window focusTarget) throws EnvoyException { public StatusTrayIcon(Window focusTarget) throws EnvoyException {
if (!SystemTray.isSupported()) throw new EnvoyException("The Envoy tray icon is not supported."); if (!SystemTray.isSupported()) throw new EnvoyException("The Envoy tray icon is not supported.");
ClassLoader loader = Thread.currentThread().getContextClassLoader(); final ClassLoader loader = Thread.currentThread().getContextClassLoader();
Image img = Toolkit.getDefaultToolkit().createImage(loader.getResource("envoy_logo.png")); final Image img = Toolkit.getDefaultToolkit().createImage(loader.getResource("envoy_logo.png"));
trayIcon = new TrayIcon(img, "Envoy Client"); trayIcon = new TrayIcon(img, "Envoy Client");
trayIcon.setImageAutoSize(true); trayIcon.setImageAutoSize(true);
trayIcon.setToolTip("You are notified if you have unread messages."); trayIcon.setToolTip("You are notified if you have unread messages.");
PopupMenu popup = new PopupMenu(); final PopupMenu popup = new PopupMenu();
MenuItem exitMenuItem = new MenuItem("Exit"); final MenuItem exitMenuItem = new MenuItem("Exit");
exitMenuItem.addActionListener((evt) -> System.exit(0)); exitMenuItem.addActionListener(evt -> System.exit(0));
popup.add(exitMenuItem); popup.add(exitMenuItem);
trayIcon.setPopupMenu(popup); trayIcon.setPopupMenu(popup);
@ -71,7 +73,7 @@ public class StatusTrayIcon {
}); });
// Show the window if the user clicks on the icon // Show the window if the user clicks on the icon
trayIcon.addActionListener((evt) -> { focusTarget.setVisible(true); focusTarget.requestFocus(); }); trayIcon.addActionListener(evt -> { focusTarget.setVisible(true); focusTarget.requestFocus(); });
// Start processing message events // Start processing message events
// TODO: Handle other message types // TODO: Handle other message types
@ -90,7 +92,8 @@ public class StatusTrayIcon {
public void show() throws EnvoyException { public void show() throws EnvoyException {
try { try {
SystemTray.getSystemTray().add(trayIcon); SystemTray.getSystemTray().add(trayIcon);
} catch (AWTException e) { } catch (final AWTException e) {
EnvoyLog.getLogger(StatusTrayIcon.class).log(Level.INFO, "Could not display StatusTrayIcon: ", e);
throw new EnvoyException("Could not attach Envoy tray icon to system tray.", e); throw new EnvoyException("Could not attach Envoy tray icon to system tray.", e);
} }
} }

View File

@ -1,5 +1,7 @@
package envoy.client.ui.controller; package envoy.client.ui.controller;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -10,9 +12,11 @@ import javafx.collections.FXCollections;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import envoy.client.data.Chat; import envoy.client.data.Chat;
import envoy.client.data.LocalDB; import envoy.client.data.LocalDB;
@ -20,14 +24,12 @@ import envoy.client.data.Settings;
import envoy.client.event.MessageCreationEvent; import envoy.client.event.MessageCreationEvent;
import envoy.client.net.Client; import envoy.client.net.Client;
import envoy.client.net.WriteProxy; import envoy.client.net.WriteProxy;
import envoy.client.ui.ContactListCell; import envoy.client.ui.*;
import envoy.client.ui.MessageListCell;
import envoy.client.ui.SceneContext;
import envoy.data.*; import envoy.data.*;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.event.MessageStatusChangeEvent; import envoy.event.MessageStatusChange;
import envoy.event.UserStatusChangeEvent; import envoy.event.UserStatusChange;
import envoy.event.contact.ContactOperationEvent; import envoy.event.contact.ContactOperation;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
/** /**
@ -61,11 +63,19 @@ public final class ChatScene {
@FXML @FXML
private Label remainingChars; private Label remainingChars;
@FXML
private Label infoLabel;
@FXML
private MenuItem deleteContactMenuItem;
private LocalDB localDB; private LocalDB localDB;
private Client client; private Client client;
private WriteProxy writeProxy; private WriteProxy writeProxy;
private SceneContext sceneContext; private SceneContext sceneContext;
private boolean postingPermanentlyDisabled = false;
private Chat currentChat; private Chat currentChat;
private static final Settings settings = Settings.getInstance(); private static final Settings settings = Settings.getInstance();
@ -85,6 +95,8 @@ public final class ChatScene {
messageList.setCellFactory(listView -> new MessageListCell()); messageList.setCellFactory(listView -> new MessageListCell());
userList.setCellFactory(listView -> new ContactListCell()); userList.setCellFactory(listView -> new ContactListCell());
settingsButton.setGraphic(new ImageView(IconUtil.load("/icons/settings.png", 16)));
// Listen to received messages // Listen to received messages
eventBus.register(MessageCreationEvent.class, e -> { eventBus.register(MessageCreationEvent.class, e -> {
final var message = e.get(); final var message = e.get();
@ -100,16 +112,20 @@ public final class ChatScene {
localDB.getChat(message.getRecipientID()).ifPresent(chat -> { localDB.getChat(message.getRecipientID()).ifPresent(chat -> {
chat.getMessages().add(message); chat.getMessages().add(message);
// Update UI if in current chat if (chat.equals(currentChat)) {
if (chat == currentChat) try {
Platform.runLater(messageList::refresh); currentChat.read(writeProxy);
} catch (final IOException e1) {
logger.log(Level.WARNING, "Could not read current chat: ", e1);
}
Platform.runLater(() -> { messageList.refresh(); scrollToMessageListEnd(); });
}
}); });
} }
}); });
// Listen to message status changes // Listen to message status changes
eventBus.register(MessageStatusChangeEvent.class, e -> eventBus.register(MessageStatusChange.class, e -> localDB.getMessage(e.getID()).ifPresent(message -> {
localDB.getMessage(e.getID()).ifPresent(message -> {
message.setStatus(e.get()); message.setStatus(e.get());
// Update UI if in current chat // Update UI if in current chat
@ -117,19 +133,15 @@ public final class ChatScene {
})); }));
// Listen to user status changes // Listen to user status changes
eventBus.register(UserStatusChangeEvent.class, e -> eventBus.register(UserStatusChange.class,
userList.getItems() e -> userList.getItems()
.stream() .stream()
.filter(c -> c.getID() == e.getID()) .filter(c -> c.getID() == e.getID())
.findAny() .findAny()
.ifPresent(u -> { .ifPresent(u -> { ((User) u).setStatus(e.get()); Platform.runLater(userList::refresh); }));
((User) u).setStatus(e.get());
Platform.runLater(userList::refresh);
})
);
// Listen to contacts changes // Listen to contacts changes
eventBus.register(ContactOperationEvent.class, e -> { eventBus.register(ContactOperation.class, e -> {
final var contact = e.get(); final var contact = e.get();
switch (e.getOperationType()) { switch (e.getOperationType()) {
case ADD: case ADD:
@ -163,6 +175,9 @@ public final class ChatScene {
this.writeProxy = writeProxy; this.writeProxy = writeProxy;
userList.setItems(FXCollections.observableList(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList()))); userList.setItems(FXCollections.observableList(localDB.getChats().stream().map(Chat::getRecipient).collect(Collectors.toList())));
contactLabel.setText(localDB.getUser().getName());
MessageListCell.setUser(localDB.getUser());
if (!client.isOnline()) updateInfoLabel("You are offline", Color.YELLOW);
} }
/** /**
@ -173,23 +188,29 @@ public final class ChatScene {
@FXML @FXML
private void userListClicked() { private void userListClicked() {
final Contact user = userList.getSelectionModel().getSelectedItem(); final Contact user = userList.getSelectionModel().getSelectedItem();
if (user != null && (currentChat == null || user.getID() != currentChat.getRecipient().getID())) { if (user != null && (currentChat == null || !user.equals(currentChat.getRecipient()))) {
contactLabel.setText(user.getName()); logger.log(Level.FINEST, "Loading chat with " + user);
// LEON: JFC <===> JAVA FRIED CHICKEN <=/=> Java Foundation Classes // LEON: JFC <===> JAVA FRIED CHICKEN <=/=> Java Foundation Classes
// Load the chat or create a new one and add it to the LocalDB // Load the chat
currentChat = localDB currentChat = localDB.getChat(user.getID()).get();
.getChat(user.getID())
.orElseGet(() -> { final var chat = new Chat(user); localDB.getChats().add(chat); return chat; });
messageList.setItems(FXCollections.observableList(currentChat.getMessages())); messageList.setItems(FXCollections.observableList(currentChat.getMessages()));
deleteContactMenuItem.setText("Delete " + user.getName());
// Read the current chat
try {
currentChat.read(writeProxy);
} catch (final IOException e) {
logger.log(Level.WARNING, "Could not read current chat.", e);
}
remainingChars.setVisible(true); remainingChars.setVisible(true);
remainingChars remainingChars
.setText(String.format("remaining chars: %d/%d", MAX_MESSAGE_LENGTH - messageTextArea.getText().length(), MAX_MESSAGE_LENGTH)); .setText(String.format("remaining chars: %d/%d", MAX_MESSAGE_LENGTH - messageTextArea.getText().length(), MAX_MESSAGE_LENGTH));
} }
messageTextArea.setDisable(currentChat == null); messageTextArea.setDisable(currentChat == null || postingPermanentlyDisabled);
} }
/** /**
@ -214,6 +235,42 @@ public final class ChatScene {
sceneContext.<ContactSearchScene>getController().initializeData(sceneContext, localDB); sceneContext.<ContactSearchScene>getController().initializeData(sceneContext, localDB);
} }
/**
* Checks the text length of the {@code messageTextArea}, adjusts the
* {@code remainingChars} label and checks whether to send the message
* automatically.
*
* @param e the key event that will be analyzed for a post request
* @since Envoy Client v0.1-beta
*/
@FXML
private void checkKeyCombination(KeyEvent e) {
// Checks whether the text is too long
messageTextUpdated();
// Automatic sending of messages via (ctrl +) enter
checkPostConditions(e);
}
/**
* @param e the keys that have been pressed
* @since Envoy Client v0.1-beta
*/
@FXML
private void checkPostConditions(KeyEvent e) {
if (!postingPermanentlyDisabled) {
if (!postButton.isDisabled() && (settings.isEnterToSend() && e.getCode() == KeyCode.ENTER
|| !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown()))
postMessage();
postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null);
} else {
final var noMoreMessaging = "Go online to send messages";
if (!infoLabel.getText().equals(noMoreMessaging))
// Informing the user that he is a f*cking moron and should use Envoy online
// because he ran out of messageIDs to use
updateInfoLabel(noMoreMessaging, Color.RED);
}
}
/** /**
* Actions to perform when the text was updated in the messageTextArea. * Actions to perform when the text was updated in the messageTextArea.
* *
@ -227,29 +284,21 @@ public final class ChatScene {
messageTextArea.positionCaret(MAX_MESSAGE_LENGTH); messageTextArea.positionCaret(MAX_MESSAGE_LENGTH);
messageTextArea.setScrollTop(Double.MAX_VALUE); messageTextArea.setScrollTop(Double.MAX_VALUE);
} }
updateRemainingCharsLabel();
}
// Redesigning the remainingChars - Label /**
* Sets the text and text color of the {@code remainingChars} label.
*
* @since Envoy Client v0.1-beta
*/
private void updateRemainingCharsLabel() {
final int currentLength = messageTextArea.getText().length(); final int currentLength = messageTextArea.getText().length();
final int remainingLength = MAX_MESSAGE_LENGTH - currentLength; final int remainingLength = MAX_MESSAGE_LENGTH - currentLength;
remainingChars.setText(String.format("remaining chars: %d/%d", remainingLength, MAX_MESSAGE_LENGTH)); remainingChars.setText(String.format("remaining chars: %d/%d", remainingLength, MAX_MESSAGE_LENGTH));
remainingChars.setTextFill(Color.rgb(currentLength, remainingLength, 0, 1)); remainingChars.setTextFill(Color.rgb(currentLength, remainingLength, 0, 1));
} }
/**
* Actions to perform when a key has been entered.
*
* @param e the Keys that have been entered
* @since Envoy Client v0.1-beta
*/
@FXML
private void checkKeyCombination(KeyEvent e) {
// Automatic sending of messages via (ctrl +) enter
if (!postButton.isDisabled() && settings.isEnterToSend() && e.getCode() == KeyCode.ENTER
|| !settings.isEnterToSend() && e.getCode() == KeyCode.ENTER && e.isControlDown())
postMessage();
postButton.setDisable(messageTextArea.getText().isBlank() || currentChat == null);
}
/** /**
* Sends a new message or groupMessage to the server based on the text entered * Sends a new message or groupMessage to the server based on the text entered
* in the * in the
@ -259,6 +308,16 @@ public final class ChatScene {
*/ */
@FXML @FXML
private void postMessage() { private void postMessage() {
postingPermanentlyDisabled = !(client.isOnline() || localDB.getIDGenerator().hasNext());
if (postingPermanentlyDisabled) {
postButton.setDisable(true);
messageTextArea.setDisable(true);
messageTextArea.clear();
updateInfoLabel("You need to go online to send more messages", Color.RED);
return;
}
final var text = messageTextArea.getText().strip();
if (text.isBlank()) throw new IllegalArgumentException("A message without visible text can not be sent.");
try { try {
if (currentChat.getRecipient().getClass().equals(Group.class)) { if (currentChat.getRecipient().getClass().equals(Group.class)) {
// Create and send groupMessage // Create and send groupMessage
@ -283,17 +342,72 @@ public final class ChatScene {
// Add message to LocalDB and update UI // Add message to LocalDB and update UI
messageList.getItems().add(message); messageList.getItems().add(message);
} }
scrollToMessageListEnd();
// Request a new ID generator if all IDs were used // Request a new ID generator if all IDs were used
if (!localDB.getIDGenerator().hasNext() && client.isOnline()) client.requestIdGenerator(); if (!localDB.getIDGenerator().hasNext() && client.isOnline()) client.requestIdGenerator();
} catch (final IOException e) { } catch (final IOException e) {
logger.log(Level.SEVERE, "Error sending message", e); logger.log(Level.SEVERE, "Error while sending message: ", e);
new Alert(AlertType.ERROR, "An error occured while sending the message!").showAndWait(); new Alert(AlertType.ERROR, "An error occured while sending the message!").showAndWait();
} }
// Clear text field and disable post button // Clear text field and disable post button
messageTextArea.setText(""); messageTextArea.setText("");
postButton.setDisable(true); postButton.setDisable(true);
updateRemainingCharsLabel();
}
/**
* Scrolls to the bottom of the {@code messageList}.
*
* @since Envoy Client v0.1-beta
*/
private void scrollToMessageListEnd() { messageList.scrollTo(messageList.getItems().size() - 1); }
/**
* Updates the {@code infoLabel}.
*
* @param text the text to use
* @param textfill the color in which to display information
* @since Envoy Client v0.1-beta
*/
private void updateInfoLabel(String text, Paint textfill) {
infoLabel.setText(text);
infoLabel.setTextFill(textfill);
infoLabel.setVisible(true);
}
// Context menu actions
@FXML
private void copyMessage() {
try {
Toolkit.getDefaultToolkit()
.getSystemClipboard()
.setContents(new StringSelection(messageList.getSelectionModel().getSelectedItem().getText()), null);
} catch (final NullPointerException e) {}
}
@FXML
private void deleteMessage() { try {} catch (final NullPointerException e) {} }
@FXML
private void forwardMessage() { try {} catch (final NullPointerException e) {} }
@FXML
private void quoteMessage() { try {} catch (final NullPointerException e) {} }
@FXML
private void deleteContact() { try {} catch (final NullPointerException e) {} }
@FXML
private void copyAndPostMessage() {
final var messageText = messageTextArea.getText();
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(messageText), null);
postMessage();
messageTextArea.setText(messageText);
updateRemainingCharsLabel();
postButton.setDisable(messageText.isBlank());
} }
} }

View File

@ -15,7 +15,7 @@ import envoy.client.ui.SceneContext;
import envoy.data.Contact; import envoy.data.Contact;
import envoy.event.ElementOperation; import envoy.event.ElementOperation;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.event.contact.ContactOperationEvent; import envoy.event.contact.ContactOperation;
import envoy.event.contact.ContactSearchRequest; import envoy.event.contact.ContactSearchRequest;
import envoy.event.contact.ContactSearchResult; import envoy.event.contact.ContactSearchResult;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
@ -57,6 +57,7 @@ public class ContactSearchScene {
/** /**
* @param sceneContext enables the user to return to the chat scene * @param sceneContext enables the user to return to the chat scene
* @param localDB the local database to which new contacts are added
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public void initializeData(SceneContext sceneContext, LocalDB localDB) { public void initializeData(SceneContext sceneContext, LocalDB localDB) {
@ -67,10 +68,8 @@ public class ContactSearchScene {
@FXML @FXML
private void initialize() { private void initialize() {
contactList.setCellFactory(e -> new ContactListCell()); contactList.setCellFactory(e -> new ContactListCell());
eventBus.register(ContactSearchResult.class, response -> Platform.runLater(() -> { eventBus.register(ContactSearchResult.class,
contactList.getItems().clear(); response -> Platform.runLater(() -> { contactList.getItems().clear(); contactList.getItems().addAll(response.get()); }));
contactList.getItems().addAll(response.get());
}));
} }
/** /**
@ -108,20 +107,20 @@ public class ContactSearchScene {
} }
/** /**
* Sends an {@link ContactOperationEvent} for every selected contact to the * Sends an {@link ContactOperation} for every selected contact to the
* server. * server.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
@FXML @FXML
private void contactListClicked() { private void contactListClicked() {
final var contact = contactList.getSelectionModel().getSelectedItem(); final var contact = contactList.getSelectionModel().getSelectedItem();
if (contact != null) { if (contact != null) {
final var alert = new Alert(AlertType.CONFIRMATION); final var alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Add Contact to Contact List"); alert.setTitle("Add Contact to Contact List");
alert.setHeaderText("Add the user " + contact.getName() + " to your contact list?"); alert.setHeaderText("Add the user " + contact.getName() + " to your contact list?");
alert.showAndWait().filter(btn -> btn == ButtonType.OK).ifPresent(btn -> { alert.showAndWait().filter(btn -> btn == ButtonType.OK).ifPresent(btn -> {
final var event = new ContactOperationEvent(contact, ElementOperation.ADD); final var event = new ContactOperation(contact, ElementOperation.ADD);
// Sends the event to the server // Sends the event to the server
eventBus.dispatch(new SendEvent(event)); eventBus.dispatch(new SendEvent(event));
// Updates the UI // Updates the UI

View File

@ -5,15 +5,16 @@ import java.util.stream.Collectors;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType;
import envoy.client.data.LocalDB; import envoy.client.data.LocalDB;
import envoy.client.event.SendEvent; import envoy.client.event.SendEvent;
import envoy.client.ui.ContactListCell; import envoy.client.ui.ContactListCell;
import envoy.client.ui.SceneContext; import envoy.client.ui.SceneContext;
import envoy.data.Contact; import envoy.data.Contact;
import envoy.data.User;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.event.GroupCreationEvent; import envoy.event.GroupCreation;
import envoy.util.Bounds;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
@ -25,21 +26,18 @@ import envoy.event.GroupCreationEvent;
*/ */
public class GroupCreationScene { public class GroupCreationScene {
@FXML
private Button backButton;
@FXML @FXML
private Button createButton; private Button createButton;
@FXML @FXML
private TextField groupNameBar; private TextField groupNameField;
@FXML @FXML
private ListView<Contact> contactList; private ListView<Contact> contactList;
private SceneContext sceneContext; private SceneContext sceneContext;
private static EventBus eventBus = EventBus.getInstance(); private static final EventBus eventBus = EventBus.getInstance();
@FXML @FXML
private void initialize() { private void initialize() {
@ -49,27 +47,43 @@ public class GroupCreationScene {
/** /**
* @param sceneContext enables the user to return to the chat scene * @param sceneContext enables the user to return to the chat scene
* @param localDB the local database from which potential group members can
* be selected
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public void initializeData(SceneContext sceneContext, LocalDB localDB) { public void initializeData(SceneContext sceneContext, LocalDB localDB) {
this.sceneContext = sceneContext; this.sceneContext = sceneContext;
Platform.runLater(() -> contactList.getItems() Platform.runLater(() -> contactList.getItems()
.addAll(localDB.getUsers() .addAll(localDB.getUsers().values().stream().filter(c -> c.getID() != localDB.getUser().getID()).collect(Collectors.toList())));
.values()
.stream()
.filter(c -> c instanceof User && c.getID() != localDB.getUser().getID())
.collect(Collectors.toList())));
} }
/** /**
* Sends a {@link GroupCreationEvent} to the server. * Enables the {@code createButton} if at least one contact is selected.
*
* @since Envoy Client v0.1-beta
*/
@FXML
private void contactListClicked() { createButton.setDisable(contactList.getSelectionModel().isEmpty()); }
/**
* Sends a {@link GroupCreation} to the server and closes this scene.
* <p>
* If the given group name is not valid, an error is displayed instead.
* *
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
@FXML @FXML
private void sendGroupObject() { private void createButtonClicked() {
eventBus.dispatch(new SendEvent(new GroupCreationEvent(groupNameBar.getText(), final var name = groupNameField.getText();
contactList.getSelectionModel().getSelectedItems().stream().map(Contact::getID).collect(Collectors.toSet())))); if (!Bounds.isValidContactName(name)) {
new Alert(AlertType.ERROR, "The entered group name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait();
groupNameField.clear();
} else {
eventBus.dispatch(new SendEvent(new GroupCreation(name,
contactList.getSelectionModel().getSelectedItems().stream().map(Contact::getID).collect(Collectors.toSet()))));
new Alert(AlertType.INFORMATION, String.format("Group '%s' successfully created.", name)).showAndWait();
sceneContext.pop();
}
} }
@FXML @FXML

View File

@ -3,6 +3,7 @@ package envoy.client.ui.controller;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javafx.application.Platform; import javafx.application.Platform;
@ -10,19 +11,19 @@ import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Alert.AlertType;
import envoy.client.data.Cache; import envoy.client.data.*;
import envoy.client.data.ClientConfig;
import envoy.client.data.LocalDB;
import envoy.client.net.Client; import envoy.client.net.Client;
import envoy.client.ui.SceneContext; import envoy.client.ui.SceneContext;
import envoy.client.ui.Startup;
import envoy.data.LoginCredentials; import envoy.data.LoginCredentials;
import envoy.data.Message; import envoy.data.Message;
import envoy.data.User; import envoy.data.User;
import envoy.data.User.UserStatus; import envoy.data.User.UserStatus;
import envoy.event.EventBus; import envoy.event.EventBus;
import envoy.event.HandshakeRejectionEvent; import envoy.event.HandshakeRejection;
import envoy.event.MessageStatusChangeEvent; import envoy.event.MessageStatusChange;
import envoy.exception.EnvoyException; import envoy.exception.EnvoyException;
import envoy.util.Bounds;
import envoy.util.EnvoyLog; import envoy.util.EnvoyLog;
/** /**
@ -54,11 +55,11 @@ public final class LoginScene {
@FXML @FXML
private Label connectionLabel; private Label connectionLabel;
private Client client; private Client client;
private LocalDB localDB; private LocalDB localDB;
private Cache<Message> receivedMessageCache; private Cache<Message> receivedMessageCache;
private Cache<MessageStatusChangeEvent> receivedMessageStatusChangeEventCache; private Cache<MessageStatusChange> receivedMessageStatusChangeCache;
private SceneContext sceneContext; private SceneContext sceneContext;
private static final Logger logger = EnvoyLog.getLogger(LoginScene.class); private static final Logger logger = EnvoyLog.getLogger(LoginScene.class);
private static final EventBus eventBus = EventBus.getInstance(); private static final EventBus eventBus = EventBus.getInstance();
@ -69,29 +70,34 @@ public final class LoginScene {
connectionLabel.setText("Server: " + config.getServer() + ":" + config.getPort()); connectionLabel.setText("Server: " + config.getServer() + ":" + config.getPort());
// Show an alert after an unsuccessful handshake // Show an alert after an unsuccessful handshake
eventBus.register(HandshakeRejectionEvent.class, eventBus.register(HandshakeRejection.class, e -> Platform.runLater(() -> { new Alert(AlertType.ERROR, e.get()).showAndWait(); }));
e -> Platform.runLater(() -> { clearPasswordFields(); new Alert(AlertType.ERROR, e.get()).showAndWait(); }));
} }
/** /**
* Loads the login dialog using the FXML file {@code LoginDialog.fxml}. * Loads the login dialog using the FXML file {@code LoginDialog.fxml}.
* *
* @param client the client used to perform the handshake * @param client the client used to perform the
* @param localDB the local database used for offline login * handshake
* @param receivedMessageCache the cache storing messages received during * @param localDB the local database used for offline
* the handshake * login
* @param receivedMessageStatusChangeEventCache the cache storing messageStatusChangeEvents received during handshake * @param receivedMessageCache the cache storing messages received
* @param sceneContext the scene context used to initialize the chat * during
* scene * the handshake
* @param receivedMessageStatusChangeCache the cache storing
* messageStatusChangeEvents received
* during handshake
* @param sceneContext the scene context used to initialize
* the chat
* scene
* @since Envoy Client v0.1-beta * @since Envoy Client v0.1-beta
*/ */
public void initializeData(Client client, LocalDB localDB, Cache<Message> receivedMessageCache, public void initializeData(Client client, LocalDB localDB, Cache<Message> receivedMessageCache,
Cache<MessageStatusChangeEvent> receivedMessageStatusChangeEventCache, SceneContext sceneContext) { Cache<MessageStatusChange> receivedMessageStatusChangeCache, SceneContext sceneContext) {
this.client = client; this.client = client;
this.localDB = localDB; this.localDB = localDB;
this.receivedMessageCache = receivedMessageCache; this.receivedMessageCache = receivedMessageCache;
this.receivedMessageStatusChangeEventCache = receivedMessageStatusChangeEventCache; this.receivedMessageStatusChangeCache = receivedMessageStatusChangeCache;
this.sceneContext = sceneContext; this.sceneContext = sceneContext;
// Prepare handshake // Prepare handshake
localDB.loadIDGenerator(); localDB.loadIDGenerator();
@ -108,14 +114,19 @@ public final class LoginScene {
// Prevent registration with unequal passwords // Prevent registration with unequal passwords
if (registerCheckBox.isSelected() && !passwordField.getText().equals(repeatPasswordField.getText())) { if (registerCheckBox.isSelected() && !passwordField.getText().equals(repeatPasswordField.getText())) {
clearPasswordFields();
new Alert(AlertType.ERROR, "The entered password is unequal to the repeated one").showAndWait(); new Alert(AlertType.ERROR, "The entered password is unequal to the repeated one").showAndWait();
} else performHandshake(new LoginCredentials(userTextField.getText(), passwordField.getText().toCharArray(), registerCheckBox.isSelected())); repeatPasswordField.clear();
} else if (!Bounds.isValidContactName(userTextField.getText())) {
new Alert(AlertType.ERROR, "The entered user name is not valid (" + Bounds.CONTACT_NAME_PATTERN + ")").showAndWait();
userTextField.clear();
} else
performHandshake(
new LoginCredentials(userTextField.getText(), passwordField.getText().toCharArray(), registerCheckBox.isSelected(), Startup.VERSION));
} }
@FXML @FXML
private void offlineModeButtonPressed() { private void offlineModeButtonPressed() {
attemptOfflineMode(new LoginCredentials(userTextField.getText(), passwordField.getText().toCharArray(), false)); attemptOfflineMode(new LoginCredentials(userTextField.getText(), passwordField.getText().toCharArray(), false, Startup.VERSION));
} }
@FXML @FXML
@ -124,25 +135,24 @@ public final class LoginScene {
// Make repeat password field and label visible / invisible // Make repeat password field and label visible / invisible
repeatPasswordField.setVisible(registerCheckBox.isSelected()); repeatPasswordField.setVisible(registerCheckBox.isSelected());
repeatPasswordLabel.setVisible(registerCheckBox.isSelected()); repeatPasswordLabel.setVisible(registerCheckBox.isSelected());
clearPasswordFields();
} }
@FXML @FXML
private void abortLogin() { private void abortLogin() {
logger.info("The login process has been cancelled. Exiting..."); logger.log(Level.INFO, "The login process has been cancelled. Exiting...");
System.exit(0); System.exit(0);
} }
private void performHandshake(LoginCredentials credentials) { private void performHandshake(LoginCredentials credentials) {
try { try {
client.performHandshake(credentials, receivedMessageCache, receivedMessageStatusChangeEventCache); client.performHandshake(credentials, receivedMessageCache, receivedMessageStatusChangeCache);
if (client.isOnline()) { if (client.isOnline()) {
client.initReceiver(localDB, receivedMessageCache, receivedMessageStatusChangeEventCache); client.initReceiver(localDB, receivedMessageCache, receivedMessageStatusChangeCache);
loadChatScene(); loadChatScene();
} }
} catch (IOException | InterruptedException | TimeoutException e) { } catch (IOException | InterruptedException | TimeoutException e) {
logger.warning("Could not connect to server: " + e); logger.log(Level.WARNING, "Could not connect to server: ", e);
logger.finer("Attempting offline mode..."); logger.log(Level.FINER, "Attempting offline mode...");
attemptOfflineMode(credentials); attemptOfflineMode(credentials);
} }
} }
@ -154,10 +164,10 @@ public final class LoginScene {
final User clientUser = (User) localDB.getUsers().get(credentials.getIdentifier()); final User clientUser = (User) localDB.getUsers().get(credentials.getIdentifier());
if (clientUser == null) throw new EnvoyException("Could not enter offline mode: user name unknown"); if (clientUser == null) throw new EnvoyException("Could not enter offline mode: user name unknown");
client.setSender(clientUser); client.setSender(clientUser);
new Alert(AlertType.WARNING, "A connection to the server could not be established. Starting in offline mode.").showAndWait();
loadChatScene(); loadChatScene();
} catch (final Exception e) { } catch (final Exception e) {
new Alert(AlertType.ERROR, "Client error: " + e).showAndWait(); new Alert(AlertType.ERROR, "Client error: " + e).showAndWait();
logger.log(Level.SEVERE, "Offline mode could not be loaded: ", e);
System.exit(1); System.exit(1);
} }
} }
@ -174,22 +184,24 @@ public final class LoginScene {
} catch (final FileNotFoundException e) { } catch (final FileNotFoundException e) {
// The local database file has not yet been created, probably first login // The local database file has not yet been created, probably first login
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace();
new Alert(AlertType.ERROR, "Error while loading local database: " + e + "\nChats will not be stored locally.").showAndWait(); new Alert(AlertType.ERROR, "Error while loading local database: " + e + "\nChats will not be stored locally.").showAndWait();
logger.log(Level.WARNING, "Could not load local database: ", e);
} }
// Initialize write proxy // Initialize write proxy
final var writeProxy = client.createWriteProxy(localDB); final var writeProxy = client.createWriteProxy(localDB);
if (client.isOnline()) { localDB.synchronize();
// Save all users to the local database and flush cache if (client.isOnline()) writeProxy.flushCache();
localDB.setUsers(client.getUsers()); else
localDB.createMissingChats();
writeProxy.flushCache();
} else
// Set all contacts to offline mode // Set all contacts to offline mode
localDB.getUsers().values().stream().filter(User.class::isInstance).map(User.class::cast).forEach(u -> u.setStatus(UserStatus.OFFLINE)); localDB.getChats()
.stream()
.map(Chat::getRecipient)
.filter(User.class::isInstance)
.map(User.class::cast)
.forEach(u -> u.setStatus(UserStatus.OFFLINE));
// Load ChatScene // Load ChatScene
sceneContext.pop(); sceneContext.pop();
@ -200,11 +212,6 @@ public final class LoginScene {
// Relay unread messages from cache // Relay unread messages from cache
if (receivedMessageCache != null && client.isOnline()) receivedMessageCache.relay(); if (receivedMessageCache != null && client.isOnline()) receivedMessageCache.relay();
if (receivedMessageStatusChangeEventCache != null && client.isOnline()) receivedMessageStatusChangeEventCache.relay(); if (receivedMessageStatusChangeCache != null && client.isOnline()) receivedMessageStatusChangeCache.relay();
}
private void clearPasswordFields() {
passwordField.clear();
repeatPasswordField.clear();
} }
} }

View File

@ -1,7 +1,7 @@
/** /**
* This package contains classes used for representing the settings * This package contains classes used for representing the settings
* visually.<br> * visually.
* <br> * <p>
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>package-info.java</strong><br> * File: <strong>package-info.java</strong><br>
* Created: <strong>19 Apr 2020</strong><br> * Created: <strong>19 Apr 2020</strong><br>

View File

@ -1,3 +1,60 @@
.button { .button, .list-cell {
-fx-background-radius: 5em; -fx-background-radius: 5.0em;
}
.context-menu, .context-menu > * {
-fx-background-radius: 15px;
/*TODO: solution below does not work */
-fx-background-color: transparent;
}
.menu-item {
-fx-background-radius: 15.0px;
}
.button:hover {
-fx-scale-x: 1.05;
-fx-scale-y: 1.05;
}
.label {
-fx-background-color: transparent;
}
.scroll-bar:horizontal, .scroll-bar:horizontal *, .scroll-bar:horizontal > *{
-fx-background-color: transparent;
-fx-text-fill: transparent;
}
.online {
-fx-text-fill: limegreen;
}
.away {
-fx-text-fill: orangered;
}
.busy {
-fx-text-fill: red;
}
.offline {
-fx-text-fill: gray;
}
.received-message {
-fx-alignment: center-left;
-fx-background-radius: 4.0em;
-fx-text-alignment: right;
}
.own-message {
-fx-alignment: center-right;
-fx-background-radius: 4.0em;
-fx-text-alignment: left;
}
#remainingCharsLabel {
-fx-text-fill: #00FF00;
-fx-background-color: transparent;
} }

View File

@ -1,4 +1,39 @@
.button{ * {
-fx-background-color: rgb(105,0,153);
-fx-text-fill: white; -fx-text-fill: white;
} }
.root {
-fx-background-color: black;
}
.button {
-fx-background-color: rgb(105.0,0.0,153.0);
}
.button:pressed {
-fx-background-color: darkgray;
}
.button:disabled {
-fx-background-color: lightgray;
}
.list-view, .list-cell, .text-area .content, .text-field, .password-field, .tooltip, .pane, .pane .content, .vbox, .titled-pane > .title, .titled-pane > *.content, .context-menu, .menu-item {
-fx-background-color: dimgray;
}
.list-cell:selected, .list-cell:selected > *, .menu-item:hover {
-fx-background-color: rgb(105.0,0.0,153.0);
}
.received-message {
-fx-background-color: gray;
}
.own-message {
-fx-background-color: #8fa88f;
}
.alert.information.dialog-pane, .alert.warning.dialog-pane, .alert.error.dialog-pane {
-fx-background-color: black;
}

View File

@ -1,3 +1,16 @@
.button{ .button{
-fx-background-color: snow; -fx-background-color: orangered;
}
.list-cell:selected, .list-cell:selected > * {
-fx-background-color: orangered;
-fx-text-fill: black;
}
.received-message, .menu-item {
-fx-background-color: lightgray;
}
.own-message {
-fx-background-color: lightgreen;
} }

View File

@ -2,47 +2,187 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?> <?import javafx.scene.control.ListView?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TextArea?> <?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.ColumnConstraints?> <?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?> <?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?> <?import javafx.scene.layout.RowConstraints?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="400.0" minWidth="350.0" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="envoy.client.ui.controller.ChatScene"> <GridPane maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="400.0" minWidth="350.0" prefHeight="400.0" prefWidth="600.0"
xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="envoy.client.ui.controller.ChatScene">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="20.0" prefWidth="161.0" /> <ColumnConstraints hgrow="SOMETIMES"
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="65.0" prefWidth="357.0" /> maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="25.0"
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="6.285736083984375" percentWidth="15.0" prefWidth="48.000030517578125" /> prefWidth="161.0" />
<ColumnConstraints hgrow="SOMETIMES"
maxWidth="1.7976931348623157E308" minWidth="10.0" percentWidth="65.0"
prefWidth="357.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="10.0"
minWidth="10.0" percentWidth="10.0" prefWidth="10.0" />
</columnConstraints> </columnConstraints>
<rowConstraints> <rowConstraints>
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" percentHeight="10.0" prefHeight="70.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="1.7976931348623157E308"
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" percentHeight="70.0" prefHeight="326.2857404436384" vgrow="SOMETIMES" /> minHeight="10.0" percentHeight="10.0" prefHeight="70.0"
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" percentHeight="5.0" prefHeight="50.0" vgrow="SOMETIMES" /> vgrow="SOMETIMES" />
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" percentHeight="15.0" prefHeight="100.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="1.7976931348623157E308"
minHeight="10.0" percentHeight="7.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="1.7976931348623157E308"
minHeight="10.0" percentHeight="60.0" prefHeight="50.0"
vgrow="SOMETIMES" />
<RowConstraints maxHeight="50.0" minHeight="10.0"
percentHeight="2.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="1.7976931348623157E308"
minHeight="10.0" percentHeight="21.0" prefHeight="100.0"
vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<ListView fx:id="userList" onMouseClicked="#userListClicked" prefHeight="211.0" prefWidth="300.0" GridPane.rowIndex="1" GridPane.rowSpan="2147483647" /> <ListView fx:id="userList" onMouseClicked="#userListClicked"
<Label fx:id="contactLabel" prefHeight="16.0" prefWidth="250.0" text="Select a contact to chat with" GridPane.columnSpan="2" /> prefHeight="211.0" prefWidth="300.0" GridPane.rowIndex="1"
<Button fx:id="settingsButton" mnemonicParsing="true" onAction="#settingsButtonClicked" text="_Settings" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.valignment="CENTER" /> GridPane.rowSpan="2147483647">
<ListView fx:id="messageList" prefHeight="257.0" prefWidth="155.0" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.rowIndex="1" GridPane.rowSpan="2" /> <GridPane.margin>
<Button fx:id="postButton" defaultButton="true" disable="true" mnemonicParsing="true" onAction="#postMessage" prefHeight="10.0" prefWidth="65.0" text="_Post" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER" /> <Insets bottom="10.0" left="10.0" right="5.0" top="5.0" />
<TextArea fx:id="messageTextArea" disable="true" onInputMethodTextChanged="#messageTextUpdated" onKeyPressed="#checkKeyCombination" onKeyTyped="#messageTextUpdated" prefHeight="200.0" prefWidth="200.0" wrapText="true" GridPane.columnIndex="1" GridPane.rowIndex="3" /> </GridPane.margin>
<Button mnemonicParsing="true" onAction="#addContactButtonClicked" text="_Add Contacts" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER"> <padding>
<padding> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> </padding>
</padding> <contextMenu>
<GridPane.margin> <ContextMenu anchorLocation="CONTENT_TOP_LEFT">
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <items>
</GridPane.margin> <MenuItem fx:id="deleteContactMenuItem"
</Button> mnemonicParsing="false" onAction="#deleteContact" text="Delete" />
<Label fx:id="remainingChars" disable="true" ellipsisString="" maxHeight="30.0" maxWidth="180.0" prefHeight="30.0" prefWidth="180.0" text="remaining chars: 0/x" textFill="LIME" textOverrun="LEADING_WORD_ELLIPSIS" visible="false" GridPane.columnIndex="1" GridPane.rowIndex="2"> </items>
<GridPane.margin> </ContextMenu>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> </contextMenu>
</GridPane.margin> </ListView>
<padding> <Label fx:id="contactLabel" prefHeight="16.0" prefWidth="250.0"
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> text="Select a contact to chat with" GridPane.columnSpan="2">
</padding> <GridPane.margin>
</Label> <Insets left="15.0" right="5.0" top="5.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label>
<Button fx:id="settingsButton" mnemonicParsing="true"
onAction="#settingsButtonClicked" text="_Settings"
GridPane.columnIndex="1" GridPane.columnSpan="2"
GridPane.halignment="RIGHT" GridPane.valignment="CENTER">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="10.0" top="10.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
<ListView fx:id="messageList" prefHeight="257.0"
prefWidth="465.0" GridPane.columnIndex="1" GridPane.columnSpan="2"
GridPane.rowIndex="1" GridPane.rowSpan="2">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="10.0" top="5.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<contextMenu>
<ContextMenu anchorLocation="CONTENT_TOP_LEFT">
<items>
<MenuItem mnemonicParsing="false" onAction="#copyMessage"
text="Copy" />
<MenuItem mnemonicParsing="false"
onAction="#deleteMessage" text="Delete" />
<MenuItem mnemonicParsing="false"
onAction="#forwardMessage" text="Forward" />
<MenuItem mnemonicParsing="false"
onAction="#quoteMessage" text="Quote" />
</items>
</ContextMenu>
</contextMenu>
</ListView>
<Button fx:id="postButton" defaultButton="true" disable="true"
mnemonicParsing="true" onAction="#postMessage" prefHeight="10.0"
prefWidth="75.0" text="_Post" GridPane.columnIndex="2"
GridPane.halignment="CENTER" GridPane.rowIndex="4"
GridPane.valignment="BOTTOM">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="10.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<tooltip>
<Tooltip anchorLocation="WINDOW_TOP_LEFT" autoHide="true"
maxWidth="350.0"
text="Click this button to send the message. If it is disabled, you first have to select a contact to send it to. A message may automatically be sent when you press (Ctrl + ) Enter, according to your preferences. Additionally sends a message when pressing &quot;Alt&quot; + &quot;P&quot;."
wrapText="true" />
</tooltip>
<contextMenu>
<ContextMenu anchorLocation="CONTENT_TOP_LEFT">
<items>
<MenuItem mnemonicParsing="false"
onAction="#copyAndPostMessage" text="Copy and Send" />
</items>
</ContextMenu>
</contextMenu>
</Button>
<TextArea fx:id="messageTextArea" disable="true"
onInputMethodTextChanged="#messageTextUpdated"
onKeyPressed="#checkPostConditions" onKeyTyped="#checkKeyCombination"
prefHeight="200.0" prefWidth="200.0" wrapText="true"
GridPane.columnIndex="1" GridPane.rowIndex="4">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
</TextArea>
<Button mnemonicParsing="true"
onAction="#addContactButtonClicked" text="_Add Contacts"
GridPane.halignment="CENTER" GridPane.rowIndex="4"
GridPane.valignment="CENTER">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<GridPane.margin>
<Insets bottom="5.0" left="10.0" right="5.0" top="5.0" />
</GridPane.margin>
</Button>
<Label id="remainingCharsLabel" fx:id="remainingChars"
ellipsisString="" maxHeight="30.0" maxWidth="180.0" prefHeight="30.0"
prefWidth="180.0" text="remaining chars: 0/x" textFill="LIME"
textOverrun="LEADING_WORD_ELLIPSIS" visible="false"
GridPane.columnIndex="1" GridPane.rowIndex="3">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
<tooltip>
<Tooltip
text="Shows how many chars you can still enter in this message"
wrapText="true" />
</tooltip>
</Label>
<Label fx:id="infoLabel" text="Something happened"
textFill="#faa007" visible="false" GridPane.columnIndex="1"
GridPane.rowIndex="1">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label>
</children> </children>
</GridPane> </GridPane>

View File

@ -23,30 +23,45 @@
<Tooltip text="Enter a name. If an account by that name exists, it will be displayed below." wrapText="true" /> <Tooltip text="Enter a name. If an account by that name exists, it will be displayed below." wrapText="true" />
</tooltip> </tooltip>
</TextField> </TextField>
<Button fx:id="clearButton" disable="true" mnemonicParsing="true" onAction="#clear" text="Clea_r"> <Button fx:id="clearButton" disable="true" mnemonicParsing="true" onAction="#clear" prefHeight="26.0" prefWidth="110.0" text="Clea_r">
<tooltip> <tooltip>
<Tooltip autoHide="true" text="Clears the text to the left and the elements below" wrapText="true" /> <Tooltip autoHide="true" text="Clears the text to the left and the elements below" wrapText="true" />
</tooltip> </tooltip>
<HBox.margin>
<Insets bottom="5.0" left="5.0" right="10.0" top="5.0" />
</HBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button> </Button>
<Button fx:id="searchButton" defaultButton="true" disable="true" mnemonicParsing="true" onAction="#suggestContacts" prefHeight="26.0" prefWidth="71.0" text="_Search" textOverrun="LEADING_WORD_ELLIPSIS"> <Button fx:id="searchButton" defaultButton="true" disable="true" mnemonicParsing="true" onAction="#suggestContacts" prefHeight="26.0" prefWidth="124.0" text="_Search" textOverrun="LEADING_WORD_ELLIPSIS">
<padding> <padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding> </padding>
<HBox.margin> <HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" right="20.0" top="5.0" />
</HBox.margin> </HBox.margin>
<tooltip> <tooltip>
<Tooltip autoHide="true" text="Search for accounts with the name entered to the left" wrapText="true" /> <Tooltip autoHide="true" text="Search for accounts with the name entered to the left" wrapText="true" />
</tooltip> </tooltip>
</Button> </Button>
<Button mnemonicParsing="false" onAction="#newGroupButtonClicked" text="New Group"> <Button mnemonicParsing="false" onAction="#newGroupButtonClicked" prefHeight="26.0" prefWidth="139.0" text="New Group">
<HBox.margin> <HBox.margin>
<Insets left="100.0" /> <Insets bottom="5.0" left="20.0" right="5.0" top="5.0" />
</HBox.margin> </HBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button> </Button>
</children> </children>
</HBox> </HBox>
<ListView fx:id="contactList" onMouseClicked="#contactListClicked" prefHeight="314.0" prefWidth="600.0" /> <ListView fx:id="contactList" onMouseClicked="#contactListClicked" prefHeight="314.0" prefWidth="600.0">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin></ListView>
<Button fx:id="backButton" cancelButton="true" mnemonicParsing="true" onAction="#backButtonClicked" text="_Back"> <Button fx:id="backButton" cancelButton="true" mnemonicParsing="true" onAction="#backButtonClicked" text="_Back">
<VBox.margin> <VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />

View File

@ -14,7 +14,7 @@
<children> <children>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0"> <HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
<children> <children>
<TextField fx:id="groupNameBar" prefColumnCount="22" promptText="Enter Group Name"> <TextField fx:id="groupNameField" prefColumnCount="22" promptText="Enter Group Name">
<HBox.margin> <HBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</HBox.margin> </HBox.margin>
@ -31,10 +31,28 @@
<font> <font>
<Font size="16.0" /> <Font size="16.0" />
</font> </font>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label> </Label>
<ListView fx:id="contactList" prefHeight="314.0" prefWidth="600.0" /> <ListView fx:id="contactList" onMouseClicked="#contactListClicked" prefHeight="314.0" prefWidth="600.0">
<Button mnemonicParsing="false" onAction="#sendGroupObject" text="Create" /> <VBox.margin>
<Button fx:id="backButton" cancelButton="true" mnemonicParsing="true" onAction="#backButtonClicked" text="_Back"> <Insets bottom="5.0" left="10.0" right="10.0" top="5.0" />
</VBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding></ListView>
<Button fx:id="createButton" defaultButton="true" disable="true" mnemonicParsing="false" onAction="#createButtonClicked" text="Create">
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding></Button>
<Button cancelButton="true" mnemonicParsing="true" onAction="#backButtonClicked" text="_Back">
<VBox.margin> <VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin> </VBox.margin>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?> <?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.CheckBox?> <?import javafx.scene.control.CheckBox?>
@ -12,13 +13,18 @@
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<VBox prefHeight="206.0" prefWidth="440.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="envoy.client.ui.controller.LoginScene"> <VBox prefHeight="206.0" prefWidth="440.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="envoy.client.ui.controller.LoginScene">
<children> <children>
<Label text="User Login"> <Label text="User Login">
<font> <font>
<Font size="26.0" /> <Font size="26.0" />
</font> </font>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Label> </Label>
<GridPane> <GridPane>
<columnConstraints> <columnConstraints>
@ -31,19 +37,65 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<Label text="User Name:" /> <Label text="User Name:">
<Label text="Password" GridPane.rowIndex="1" /> <GridPane.margin>
<Label fx:id="repeatPasswordLabel" text="Repeat Password:" visible="false" GridPane.rowIndex="2" /> <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
<TextField fx:id="userTextField" GridPane.columnIndex="1" /> </GridPane.margin>
<PasswordField fx:id="passwordField" GridPane.columnIndex="1" GridPane.rowIndex="1" /> <padding>
<PasswordField fx:id="repeatPasswordField" promptText="Repeat the chosen password" visible="false" GridPane.columnIndex="1" GridPane.rowIndex="2" /> <Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding></Label>
<Label text="Password" GridPane.rowIndex="1">
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding>
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin></Label>
<Label fx:id="repeatPasswordLabel" text="Repeat Password:" visible="false" GridPane.rowIndex="2">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding></Label>
<TextField fx:id="userTextField" GridPane.columnIndex="1">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="5.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding></TextField>
<PasswordField fx:id="passwordField" GridPane.columnIndex="1" GridPane.rowIndex="1">
<GridPane.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding></PasswordField>
<PasswordField fx:id="repeatPasswordField" visible="false" GridPane.columnIndex="1" GridPane.rowIndex="2">
<GridPane.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="10.0" />
</GridPane.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding></PasswordField>
</children> </children>
</GridPane> </GridPane>
<CheckBox fx:id="registerCheckBox" mnemonicParsing="true" onAction="#registerCheckboxChanged" prefHeight="17.0" prefWidth="181.0" text="_Register" /> <CheckBox fx:id="registerCheckBox" mnemonicParsing="true" onAction="#registerCheckboxChanged" prefHeight="17.0" prefWidth="181.0" text="_Register">
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding>
<VBox.margin>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</VBox.margin></CheckBox>
<Label fx:id="connectionLabel" /> <Label fx:id="connectionLabel" />
<ButtonBar prefHeight="40.0" prefWidth="200.0"> <ButtonBar prefHeight="40.0" prefWidth="200.0">
<buttons> <buttons>
<Button mnemonicParsing="false" onAction="#abortLogin" text="Close" /> <Button mnemonicParsing="false" onAction="#abortLogin" text="Close">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
<Button mnemonicParsing="false" onAction="#offlineModeButtonPressed" text="Offline mode" /> <Button mnemonicParsing="false" onAction="#offlineModeButtonPressed" text="Offline mode" />
<Button defaultButton="true" mnemonicParsing="false" onAction="#loginButtonPressed" text="Login" /> <Button defaultButton="true" mnemonicParsing="false" onAction="#loginButtonPressed" text="Login" />
</buttons> </buttons>

View File

@ -9,16 +9,37 @@
<VBox alignment="TOP_RIGHT" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="envoy.client.ui.controller.SettingsScene"> <VBox alignment="TOP_RIGHT" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="envoy.client.ui.controller.SettingsScene">
<children> <children>
<HBox prefHeight="100.0" prefWidth="200.0"> <HBox prefHeight="389.0" prefWidth="600.0">
<children> <children>
<ListView fx:id="settingsList" onMouseClicked="#settingsListClicked" prefHeight="200.0" prefWidth="200.0" /> <ListView fx:id="settingsList" onMouseClicked="#settingsListClicked" prefHeight="200.0" prefWidth="200.0">
<TitledPane fx:id="titledPane" collapsible="false" prefHeight="200.0" prefWidth="200.0" /> <opaqueInsets>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</opaqueInsets>
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="5.0" top="10.0" />
</HBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding></ListView>
<TitledPane fx:id="titledPane" collapsible="false" prefHeight="325.0" prefWidth="300.0">
<HBox.margin>
<Insets bottom="10.0" left="5.0" right="10.0" top="10.0" />
</HBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding></TitledPane>
</children> </children>
</HBox> </HBox>
<Button defaultButton="true" mnemonicParsing="true" onMouseClicked="#backButtonClicked" text="_Back"> <Button defaultButton="true" mnemonicParsing="true" onMouseClicked="#backButtonClicked" text="_Back">
<opaqueInsets> <opaqueInsets>
<Insets /> <Insets />
</opaqueInsets> </opaqueInsets>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</Button> </Button>
</children> </children>
</VBox> </VBox>