From 8eb7743057410f2e02657147f9db9bea9358e8cf Mon Sep 17 00:00:00 2001 From: kske Date: Fri, 25 Sep 2020 14:29:23 +0200 Subject: [PATCH 1/7] Remove Javadoc header from all source files Also removed SendEvent and simplified some other calls. --- client/src/main/java/envoy/client/Main.java | 9 +- .../main/java/envoy/client/data/Cache.java | 10 +- .../main/java/envoy/client/data/CacheMap.java | 7 +- .../src/main/java/envoy/client/data/Chat.java | 17 +- .../java/envoy/client/data/ClientConfig.java | 4 - .../main/java/envoy/client/data/Context.java | 7 +- .../java/envoy/client/data/GroupChat.java | 8 +- .../main/java/envoy/client/data/LocalDB.java | 99 +++++----- .../main/java/envoy/client/data/Settings.java | 4 - .../java/envoy/client/data/SettingsItem.java | 4 - .../envoy/client/data/audio/AudioPlayer.java | 4 - .../client/data/audio/AudioRecorder.java | 7 +- .../envoy/client/data/audio/package-info.java | 4 - .../envoy/client/data/commands/OnCall.java | 4 - .../client/data/commands/SystemCommand.java | 11 +- .../data/commands/SystemCommandBuilder.java | 7 +- .../data/commands/SystemCommandsMap.java | 4 - .../client/data/commands/package-info.java | 4 - .../java/envoy/client/event/BackEvent.java | 6 +- .../envoy/client/event/EnvoyCloseEvent.java | 6 +- .../java/envoy/client/event/SendEvent.java | 22 --- .../envoy/client/event/ThemeChangeEvent.java | 4 +- .../main/java/envoy/client/net/Client.java | 75 ++++---- .../GroupMessageStatusChangeProcessor.java | 4 - .../net/MessageStatusChangeProcessor.java | 4 - .../net/ReceivedGroupMessageProcessor.java | 4 - .../client/net/ReceivedMessageProcessor.java | 4 - .../main/java/envoy/client/net/Receiver.java | 4 - .../java/envoy/client/net/WriteProxy.java | 33 +--- .../envoy/client/ui/ClearableTextField.java | 169 ------------------ .../java/envoy/client/ui/ListViewRefresh.java | 7 +- .../main/java/envoy/client/ui/Restorable.java | 4 - .../java/envoy/client/ui/SceneContext.java | 4 - .../main/java/envoy/client/ui/Startup.java | 5 +- .../java/envoy/client/ui/StatusTrayIcon.java | 13 +- .../client/ui/{ => control}/AudioControl.java | 12 +- .../ui/{listcell => control}/ChatControl.java | 39 ++-- .../{listcell => control}/ContactControl.java | 9 +- .../{listcell => control}/MessageControl.java | 35 ++-- .../ProfilePicImageView.java | 9 +- .../TextInputContextMenu.java | 6 +- .../envoy/client/ui/control/package-info.java | 9 + .../envoy/client/ui/controller/ChatScene.java | 22 +-- .../ui/controller/ContactSearchTab.java | 16 +- .../ui/controller/GroupCreationTab.java | 23 +-- .../client/ui/controller/LoginScene.java | 10 +- .../client/ui/controller/SettingsScene.java | 28 +-- .../java/envoy/client/ui/controller/Tabs.java | 4 - .../client/ui/controller/package-info.java | 6 +- .../envoy/client/ui/custom/package-info.java | 14 -- .../client/ui/listcell/AbstractListCell.java | 11 +- .../client/ui/listcell/GenericListCell.java | 4 - .../client/ui/listcell/ListCellFactory.java | 7 +- .../client/ui/listcell/MessageListCell.java | 8 +- .../client/ui/listcell/package-info.java | 5 +- .../client/ui/settings/BugReportPane.java | 24 +-- .../ui/settings/DownloadSettingsPane.java | 15 +- .../ui/settings/GeneralSettingsPane.java | 4 - ...sPane.java => OnlineOnlySettingsPane.java} | 33 ++-- .../client/ui/settings/SettingsCheckbox.java | 4 - .../client/ui/settings/SettingsPane.java | 4 - .../client/ui/settings/UserSettingsPane.java | 36 ++-- .../client/ui/settings/package-info.java | 4 - .../envoy/client/{ui => util}/IconUtil.java | 27 +-- .../java/envoy/client/util/IssueUtil.java | 37 ++-- .../envoy/client/util/ReflectionUtil.java | 22 +-- .../java/envoy/client/util/package-info.java | 4 - client/src/main/java/module-info.java | 2 +- .../src/main/java/envoy/data/Attachment.java | 4 - common/src/main/java/envoy/data/Config.java | 16 +- .../src/main/java/envoy/data/ConfigItem.java | 4 - common/src/main/java/envoy/data/Contact.java | 7 +- common/src/main/java/envoy/data/Group.java | 10 +- .../main/java/envoy/data/GroupMessage.java | 7 +- .../src/main/java/envoy/data/IDGenerator.java | 6 +- .../java/envoy/data/LoginCredentials.java | 4 - common/src/main/java/envoy/data/Message.java | 13 +- .../main/java/envoy/data/MessageBuilder.java | 4 - common/src/main/java/envoy/data/User.java | 12 +- .../main/java/envoy/data/package-info.java | 2 +- .../java/envoy/event/ElementOperation.java | 9 +- common/src/main/java/envoy/event/Event.java | 10 +- .../main/java/envoy/event/GroupCreation.java | 11 +- .../java/envoy/event/GroupCreationResult.java | 4 - .../envoy/event/GroupMessageStatusChange.java | 4 - .../main/java/envoy/event/GroupResize.java | 41 +++-- .../java/envoy/event/HandshakeRejection.java | 4 - .../java/envoy/event/IDGeneratorRequest.java | 6 +- .../src/main/java/envoy/event/IsTyping.java | 13 +- .../main/java/envoy/event/IssueProposal.java | 6 +- .../java/envoy/event/MessageStatusChange.java | 4 - .../src/main/java/envoy/event/NameChange.java | 7 +- .../main/java/envoy/event/NewAuthToken.java | 4 - .../main/java/envoy/event/NoAttachments.java | 4 - .../envoy/event/PasswordChangeRequest.java | 4 - .../envoy/event/PasswordChangeResult.java | 4 - .../java/envoy/event/ProfilePicChange.java | 4 - .../java/envoy/event/UserStatusChange.java | 4 - .../envoy/event/contact/ContactOperation.java | 9 +- .../event/contact/UserSearchRequest.java | 4 - .../envoy/event/contact/UserSearchResult.java | 4 - .../envoy/event/contact/package-info.java | 6 +- .../java/envoy/exception/EnvoyException.java | 4 - common/src/main/java/envoy/util/Bounds.java | 6 - common/src/main/java/envoy/util/EnvoyLog.java | 7 +- .../java/envoy/util/SerializationUtils.java | 8 +- .../src/main/java/envoy/server/Startup.java | 13 +- .../java/envoy/server/data/ConfigItem.java | 8 +- .../main/java/envoy/server/data/Contact.java | 6 +- .../main/java/envoy/server/data/Group.java | 16 +- .../java/envoy/server/data/GroupMessage.java | 7 +- .../main/java/envoy/server/data/Message.java | 7 +- .../envoy/server/data/PersistenceManager.java | 4 - .../java/envoy/server/data/ServerConfig.java | 4 - .../src/main/java/envoy/server/data/User.java | 6 +- .../envoy/server/net/ConnectionManager.java | 9 +- .../server/net/ObjectMessageProcessor.java | 20 +-- .../envoy/server/net/ObjectMessageReader.java | 9 +- .../envoy/server/net/ObjectWriteProxy.java | 16 +- .../processors/ContactOperationProcessor.java | 7 +- .../processors/GroupCreationProcessor.java | 14 +- .../processors/GroupMessageProcessor.java | 10 +- .../GroupMessageStatusChangeProcessor.java | 16 +- .../processors/GroupResizeProcessor.java | 10 +- .../IDGeneratorRequestProcessor.java | 7 +- .../server/processors/IsTypingProcessor.java | 10 +- .../processors/IssueProposalProcessor.java | 10 +- .../processors/LoginCredentialProcessor.java | 6 +- .../server/processors/MessageProcessor.java | 13 +- .../MessageStatusChangeProcessor.java | 10 +- .../processors/NameChangeProcessor.java | 7 +- .../server/processors/ObjectProcessor.java | 6 +- .../PasswordChangeRequestProcessor.java | 7 +- .../processors/ProfilePicChangeProcessor.java | 4 - .../processors/UserSearchProcessor.java | 13 +- .../processors/UserStatusChangeProcessor.java | 7 +- .../envoy/server/util/AuthTokenGenerator.java | 4 - .../java/envoy/server/util/PasswordUtil.java | 8 +- .../java/envoy/server/util/VersionUtil.java | 4 - .../java/envoy/server/util/package-info.java | 4 - 140 files changed, 397 insertions(+), 1260 deletions(-) delete mode 100644 client/src/main/java/envoy/client/event/SendEvent.java delete mode 100644 client/src/main/java/envoy/client/ui/ClearableTextField.java rename client/src/main/java/envoy/client/ui/{ => control}/AudioControl.java (76%) rename client/src/main/java/envoy/client/ui/{listcell => control}/ChatControl.java (64%) rename client/src/main/java/envoy/client/ui/{listcell => control}/ContactControl.java (81%) rename client/src/main/java/envoy/client/ui/{listcell => control}/MessageControl.java (88%) rename client/src/main/java/envoy/client/ui/{custom => control}/ProfilePicImageView.java (85%) rename client/src/main/java/envoy/client/ui/{custom => control}/TextInputContextMenu.java (95%) create mode 100644 client/src/main/java/envoy/client/ui/control/package-info.java delete mode 100644 client/src/main/java/envoy/client/ui/custom/package-info.java rename client/src/main/java/envoy/client/ui/settings/{OnlyIfOnlineSettingsPane.java => OnlineOnlySettingsPane.java} (65%) rename client/src/main/java/envoy/client/{ui => util}/IconUtil.java (87%) diff --git a/client/src/main/java/envoy/client/Main.java b/client/src/main/java/envoy/client/Main.java index 842e37d..d64d075 100644 --- a/client/src/main/java/envoy/client/Main.java +++ b/client/src/main/java/envoy/client/Main.java @@ -9,16 +9,17 @@ import envoy.client.ui.Startup; *

* To allow Maven shading, the main method has to be separated from the * {@link Startup} class which extends {@link Application}. - *

- * Project: envoy-client
- * File: Main.java
- * Created: 05.07.2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ public final class Main { + /** + * A funny debug switch put in by {@code delvh} to enable easy debugging. + * + * @since Envoy Client v0.2-beta + */ private static final boolean debug = false; /** diff --git a/client/src/main/java/envoy/client/data/Cache.java b/client/src/main/java/envoy/client/data/Cache.java index 25b985e..1476cef 100644 --- a/client/src/main/java/envoy/client/data/Cache.java +++ b/client/src/main/java/envoy/client/data/Cache.java @@ -1,20 +1,14 @@ package envoy.client.data; import java.io.Serializable; -import java.util.LinkedList; -import java.util.Queue; +import java.util.*; import java.util.function.Consumer; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.logging.*; import envoy.util.EnvoyLog; /** * Stores elements in a queue to process them later. - *

- * Project: envoy-client
- * File: Cache.java
- * Created: 6 Feb 2020
* * @param the type of cached elements * @author Kai S. K. Engelbart diff --git a/client/src/main/java/envoy/client/data/CacheMap.java b/client/src/main/java/envoy/client/data/CacheMap.java index 8c1fcb2..69bd68e 100644 --- a/client/src/main/java/envoy/client/data/CacheMap.java +++ b/client/src/main/java/envoy/client/data/CacheMap.java @@ -1,16 +1,11 @@ package envoy.client.data; import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * Stores a heterogeneous map of {@link Cache} objects with different type * parameters. - *

- * Project: envoy-client
- * File: CacheMap.java
- * Created: 09.07.2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/data/Chat.java b/client/src/main/java/envoy/client/data/Chat.java index 81d6d97..8d3faed 100644 --- a/client/src/main/java/envoy/client/data/Chat.java +++ b/client/src/main/java/envoy/client/data/Chat.java @@ -1,25 +1,16 @@ package envoy.client.data; -import java.io.IOException; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; +import java.io.*; +import java.util.*; import envoy.client.net.WriteProxy; -import envoy.data.Contact; -import envoy.data.Message; +import envoy.data.*; import envoy.data.Message.MessageStatus; -import envoy.data.User; import envoy.event.MessageStatusChange; /** * Represents a chat between two {@link User}s * as a list of {@link Message} objects. - *

- * Project: envoy-client
- * File: Chat.java
- * Created: 19 Oct 2019
* * @author Maximilian Käfer * @author Leon Hofmeister @@ -51,7 +42,7 @@ public class Chat implements Serializable { public Chat(Contact recipient) { this.recipient = recipient; } @Override - public String toString() { return String.format("Chat[recipient=%s,messages=%d]", recipient, messages.size()); } + public String toString() { return String.format("%s[recipient=%s,messages=%d]", getClass().getSimpleName(), recipient, messages.size()); } /** * Generates a hash code based on the recipient. diff --git a/client/src/main/java/envoy/client/data/ClientConfig.java b/client/src/main/java/envoy/client/data/ClientConfig.java index 613b970..acd3216 100644 --- a/client/src/main/java/envoy/client/data/ClientConfig.java +++ b/client/src/main/java/envoy/client/data/ClientConfig.java @@ -7,10 +7,6 @@ import envoy.data.Config; /** * Implements a configuration specific to the Envoy Client with default values * and convenience methods. - *

- * Project: envoy-client
- * File: ClientConfig.java
- * Created: 01.03.2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/data/Context.java b/client/src/main/java/envoy/client/data/Context.java index a692f2e..a022ac3 100644 --- a/client/src/main/java/envoy/client/data/Context.java +++ b/client/src/main/java/envoy/client/data/Context.java @@ -2,16 +2,11 @@ package envoy.client.data; import javafx.stage.Stage; -import envoy.client.net.Client; -import envoy.client.net.WriteProxy; +import envoy.client.net.*; import envoy.client.ui.SceneContext; /** * Provides access to commonly used objects. - *

- * Project: client
- * File: Context.java
- * Created: 01.09.2020
* * @author Leon Hofmeister * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/data/GroupChat.java b/client/src/main/java/envoy/client/data/GroupChat.java index 39f5bd7..87208c3 100644 --- a/client/src/main/java/envoy/client/data/GroupChat.java +++ b/client/src/main/java/envoy/client/data/GroupChat.java @@ -4,19 +4,13 @@ import java.io.IOException; import java.time.Instant; import envoy.client.net.WriteProxy; -import envoy.data.Contact; -import envoy.data.GroupMessage; +import envoy.data.*; import envoy.data.Message.MessageStatus; -import envoy.data.User; import envoy.event.GroupMessageStatusChange; /** * Represents a chat between a user and a group * as a list of messages. - *

- * Project: envoy-client
- * File: GroupChat.java
- * Created: 05.07.2020
* * @author Maximilian Käfer * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/data/LocalDB.java b/client/src/main/java/envoy/client/data/LocalDB.java index 61e9988..c6b527d 100644 --- a/client/src/main/java/envoy/client/data/LocalDB.java +++ b/client/src/main/java/envoy/client/data/LocalDB.java @@ -22,10 +22,6 @@ import dev.kske.eventbus.EventListener; * For message ID generation a {@link IDGenerator} is stored as well. *

* The managed objects are stored inside a folder in the local file system. - *

- * Project: envoy-client
- * File: LocalDB.java
- * Created: 3 Feb 2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.3-alpha @@ -174,6 +170,26 @@ public final class LocalDB implements EventListener { }, 2000, ClientConfig.getInstance().getLocalDBSaveInterval() * 60000); } + /** + * Performs a contact name change if the corresponding contact is present. + * + * @param event the {@link NameChange} to process + * @since Envoy Client v0.1-beta + */ + public void replaceContactName(NameChange event) { + 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. + * + * @param event the {@link GroupResize} to process + * @since Envoy Client v0.1-beta + */ + public void updateGroup(GroupResize event) { + getChat(event.getGroupID()).map(Chat::getRecipient).map(Group.class::cast).ifPresent(event::apply); + } + /** * Stores all users. If the client user is specified, their chats will be stored * as well. The message id generator will also be saved if present. @@ -219,6 +235,26 @@ public final class LocalDB implements EventListener { */ public Map getUsers() { return users; } + /** + * Searches for a message by ID. + * + * @param id the ID of the message to search for + * @return an optional containing the message + * @since Envoy Client v0.1-beta + */ + public Optional getMessage(long id) { + return chats.stream().map(Chat::getMessages).flatMap(List::stream).filter(m -> m.getID() == id).findAny(); + } + + /** + * Searches for a chat by recipient ID. + * + * @param recipientID the ID of the chat's recipient + * @return an optional containing the chat + * @since Envoy Client v0.1-beta + */ + public Optional getChat(long recipientID) { return chats.stream().filter(c -> c.getRecipient().getID() == recipientID).findAny(); } + /** * @return all saved {@link Chat} objects that list the client user as the * sender @@ -278,59 +314,4 @@ public final class LocalDB implements EventListener { * @since Envoy Client v0.2-beta */ public String getAuthToken() { return authToken; } - - /** - * Searches for a message by ID. - * - * @param id the ID of the message to search for - * @return an optional containing the message - * @since Envoy Client v0.1-beta - */ - public Optional getMessage(long id) { - return chats.stream().map(Chat::getMessages).flatMap(List::stream).filter(m -> m.getID() == id).findAny(); - } - - /** - * Searches for a chat by recipient ID. - * - * @param recipientID the ID of the chat's recipient - * @return an optional containing the chat - * @since Envoy Client v0.1-beta - */ - public Optional getChat(long recipientID) { return chats.stream().filter(c -> c.getRecipient().getID() == recipientID).findAny(); } - - /** - * Performs a contact name change if the corresponding contact is present. - * - * @param event the {@link NameChange} to process - * @since Envoy Client v0.1-beta - */ - public void replaceContactName(NameChange event) { - 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. - * - * @param event the {@link GroupResize} to process - * @since Envoy Client v0.1-beta - */ - public void updateGroup(GroupResize event) { - chats.stream() - .map(Chat::getRecipient) - .filter(Group.class::isInstance) - .filter(g -> g.getID() == event.getGroupID() && g.getID() != user.getID()) - .map(Group.class::cast) - .findAny() - .ifPresent(group -> { - switch (event.getOperation()) { - case ADD: - group.getContacts().add(event.get()); - break; - case REMOVE: - group.getContacts().remove(event.get()); - break; - } - }); - } } diff --git a/client/src/main/java/envoy/client/data/Settings.java b/client/src/main/java/envoy/client/data/Settings.java index b75f165..90680d5 100644 --- a/client/src/main/java/envoy/client/data/Settings.java +++ b/client/src/main/java/envoy/client/data/Settings.java @@ -15,10 +15,6 @@ import dev.kske.eventbus.EventListener; * Manages all application settings, which are different objects that can be * changed during runtime and serialized them by using either the file system or * the {@link Preferences} API. - *

- * Project: envoy-client
- * File: Settings.java
- * Created: 11 Nov 2019
* * @author Leon Hofmeister * @author Maximilian Käfer diff --git a/client/src/main/java/envoy/client/data/SettingsItem.java b/client/src/main/java/envoy/client/data/SettingsItem.java index 9261242..3837071 100644 --- a/client/src/main/java/envoy/client/data/SettingsItem.java +++ b/client/src/main/java/envoy/client/data/SettingsItem.java @@ -8,10 +8,6 @@ import javax.swing.JComponent; /** * Encapsulates a persistent value that is directly or indirectly mutable by the * user. - *

- * Project: envoy-client
- * File: SettingsItem.java
- * Created: 23.12.2019
* * @param the type of this {@link SettingsItem}'s value * @author Kai S. K. Engelbart diff --git a/client/src/main/java/envoy/client/data/audio/AudioPlayer.java b/client/src/main/java/envoy/client/data/audio/AudioPlayer.java index 61982db..ec0440d 100644 --- a/client/src/main/java/envoy/client/data/audio/AudioPlayer.java +++ b/client/src/main/java/envoy/client/data/audio/AudioPlayer.java @@ -6,10 +6,6 @@ import envoy.exception.EnvoyException; /** * Plays back audio from a byte array. - *

- * Project: envoy-client
- * File: AudioPlayer.java
- * Created: 05.07.2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/data/audio/AudioRecorder.java b/client/src/main/java/envoy/client/data/audio/AudioRecorder.java index 251041a..38475ab 100644 --- a/client/src/main/java/envoy/client/data/audio/AudioRecorder.java +++ b/client/src/main/java/envoy/client/data/audio/AudioRecorder.java @@ -1,8 +1,7 @@ package envoy.client.data.audio; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; +import java.nio.file.*; import javax.sound.sampled.*; @@ -10,10 +9,6 @@ import envoy.exception.EnvoyException; /** * Records audio and exports it as a byte array. - *

- * Project: envoy-client
- * File: AudioRecorder.java
- * Created: 02.07.2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/data/audio/package-info.java b/client/src/main/java/envoy/client/data/audio/package-info.java index 3a172be..5e80e64 100644 --- a/client/src/main/java/envoy/client/data/audio/package-info.java +++ b/client/src/main/java/envoy/client/data/audio/package-info.java @@ -1,9 +1,5 @@ /** * Contains classes related to recording and playing back audio clips. - *

- * Project: envoy-client
- * File: package-info.java
- * Created: 05.07.2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/data/commands/OnCall.java b/client/src/main/java/envoy/client/data/commands/OnCall.java index dc9c015..941b4fa 100644 --- a/client/src/main/java/envoy/client/data/commands/OnCall.java +++ b/client/src/main/java/envoy/client/data/commands/OnCall.java @@ -5,10 +5,6 @@ import java.util.function.Supplier; /** * This interface defines an action that should be performed when a system * command gets called. - *

- * Project: envoy-client
- * File: OnCall.java
- * Created: 23.07.2020
* * @author Leon Hofmeister * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/data/commands/SystemCommand.java b/client/src/main/java/envoy/client/data/commands/SystemCommand.java index be13c83..a09bd69 100644 --- a/client/src/main/java/envoy/client/data/commands/SystemCommand.java +++ b/client/src/main/java/envoy/client/data/commands/SystemCommand.java @@ -1,10 +1,7 @@ package envoy.client.data.commands; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.function.Consumer; -import java.util.function.Supplier; +import java.util.*; +import java.util.function.*; /** * This class is the base class of all {@code SystemCommands} and contains an @@ -16,10 +13,6 @@ import java.util.function.Supplier; * function. This approach has one limitation:
* Order matters! Changing the order of arguments will likely result in * unexpected behavior. - *

- * Project: envoy-client
- * File: SystemCommand.java
- * Created: 16.07.2020
* * @author Leon Hofmeister * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/data/commands/SystemCommandBuilder.java b/client/src/main/java/envoy/client/data/commands/SystemCommandBuilder.java index 4d996f5..7d9cacb 100644 --- a/client/src/main/java/envoy/client/data/commands/SystemCommandBuilder.java +++ b/client/src/main/java/envoy/client/data/commands/SystemCommandBuilder.java @@ -1,15 +1,10 @@ package envoy.client.data.commands; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.function.Consumer; /** * This class acts as a builder for {@link SystemCommand}s. - *

- * Project: envoy-client
- * File: SystemCommandBuilder.java
- * Created: 23.07.2020
* * @author Leon Hofmeister * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/data/commands/SystemCommandsMap.java b/client/src/main/java/envoy/client/data/commands/SystemCommandsMap.java index 959e0dd..c1ecec4 100644 --- a/client/src/main/java/envoy/client/data/commands/SystemCommandsMap.java +++ b/client/src/main/java/envoy/client/data/commands/SystemCommandsMap.java @@ -10,10 +10,6 @@ import envoy.util.EnvoyLog; /** * This class stores all {@link SystemCommand}s used. - *

- * Project: envoy-client
- * File: SystemCommandsMap.java
- * Created: 17.07.2020
* * @author Leon Hofmeister * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/data/commands/package-info.java b/client/src/main/java/envoy/client/data/commands/package-info.java index b3f2b4f..0be1b13 100644 --- a/client/src/main/java/envoy/client/data/commands/package-info.java +++ b/client/src/main/java/envoy/client/data/commands/package-info.java @@ -1,10 +1,6 @@ /** * This package contains all classes that can be used as system commands.
* Every system command can be called using a specific syntax:"/<command>" - *

- * Project: envoy-client
- * File: package-info.java
- * Created: 16.07.2020
* * @author Leon Hofmeister * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/event/BackEvent.java b/client/src/main/java/envoy/client/event/BackEvent.java index 202e80f..ab40768 100644 --- a/client/src/main/java/envoy/client/event/BackEvent.java +++ b/client/src/main/java/envoy/client/event/BackEvent.java @@ -3,12 +3,8 @@ package envoy.client.event; import envoy.event.Event.Valueless; /** - * This event serves the purpose to trigger the tab change to tab 0 in + * This event serves the purpose of triggering the tab change to tab 0 in * {@link envoy.client.ui.controller.ChatScene}. - *

- * Project: client
- * File: BackEvent.java
- * Created: 23.08.2020
* * @author Maximilian Käfer * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/event/EnvoyCloseEvent.java b/client/src/main/java/envoy/client/event/EnvoyCloseEvent.java index cb9be17..dfe15ec 100644 --- a/client/src/main/java/envoy/client/event/EnvoyCloseEvent.java +++ b/client/src/main/java/envoy/client/event/EnvoyCloseEvent.java @@ -3,9 +3,9 @@ package envoy.client.event; import envoy.event.Event.Valueless; /** - * This event will be sent once Envoy is really closed. - * Its purpose is to forcefully stop other threads peacefully so that the VM can - * shutdown too. + * This event notifies various Envoy components of the application being about + * to shut down. This allows the graceful closing of connections, persisting + * local data etc. * * @author Leon Hofmeister * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/event/SendEvent.java b/client/src/main/java/envoy/client/event/SendEvent.java deleted file mode 100644 index f93e1d6..0000000 --- a/client/src/main/java/envoy/client/event/SendEvent.java +++ /dev/null @@ -1,22 +0,0 @@ -package envoy.client.event; - -import envoy.event.Event; - -/** - * Project: envoy-client
- * File: SendEvent.java
- * Created: 11.02.2020
- * - * @author: Maximilian Käfer - * @since Envoy Client v0.3-alpha - */ -public final class SendEvent extends Event> { - - private static final long serialVersionUID = 0L; - - /** - * @param value the event to send to the server - */ - public SendEvent(Event value) { super(value); } - -} diff --git a/client/src/main/java/envoy/client/event/ThemeChangeEvent.java b/client/src/main/java/envoy/client/event/ThemeChangeEvent.java index eac0afa..b269406 100644 --- a/client/src/main/java/envoy/client/event/ThemeChangeEvent.java +++ b/client/src/main/java/envoy/client/event/ThemeChangeEvent.java @@ -3,9 +3,7 @@ package envoy.client.event; import envoy.event.Event; /** - * Project: envoy-client
- * File: ThemeChangeEvent.java
- * Created: 15 Dec 2019
+ * Notifies UI components of a theme change. * * @author Kai S. K. Engelbart * @since Envoy Client v0.2-alpha diff --git a/client/src/main/java/envoy/client/net/Client.java b/client/src/main/java/envoy/client/net/Client.java index f2987b3..24f6664 100644 --- a/client/src/main/java/envoy/client/net/Client.java +++ b/client/src/main/java/envoy/client/net/Client.java @@ -6,22 +6,18 @@ import java.util.concurrent.TimeoutException; import java.util.logging.*; import envoy.client.data.*; -import envoy.client.event.*; +import envoy.client.event.EnvoyCloseEvent; import envoy.data.*; import envoy.event.*; -import envoy.event.Event; import envoy.event.contact.*; import envoy.util.*; import dev.kske.eventbus.*; +import dev.kske.eventbus.Event; /** * Establishes a connection to the server, performs a handshake and delivers * certain objects to the server. - *

- * Project: envoy-client
- * File: Client.java
- * Created: 28 Sep 2019
* * @author Kai S. K. Engelbart * @author Maximilian Käfer @@ -186,55 +182,48 @@ public final class Client implements EventListener, Closeable { cacheMap.getMap().values().forEach(Cache::relay); } + /** + * Sends an object to the server. + * + * @param obj the object to send + * @throws IllegalStateException if the client is not online + * @throws RuntimeException if the object serialization failed + * @since Envoy Client v0.2-beta + */ + public void send(Object obj) throws IllegalStateException, RuntimeException { + checkOnline(); + logger.log(Level.FINE, "Sending " + obj); + try { + SerializationUtils.writeBytesWithLength(obj, socket.getOutputStream()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + /** * Sends a message to the server. The message's status will be incremented once * it was delivered successfully. * * @param message the message to send - * @throws IOException if the message does not reach the server * @since Envoy Client v0.3-alpha */ - public void sendMessage(Message message) throws IOException { - writeObject(message); + public void sendMessage(Message message) { + send(message); message.nextStatus(); } - /** - * Sends an event to the server. - * - * @param evt the event to send - * @throws IOException if the event did not reach the server - */ - public void sendEvent(Event evt) throws IOException { if (online) writeObject(evt); } - /** * Requests a new {@link IDGenerator} from the server. * - * @throws IOException if the request does not reach the server * @since Envoy Client v0.3-alpha */ - public void requestIdGenerator() throws IOException { + public void requestIdGenerator() { logger.log(Level.INFO, "Requesting new id generator..."); - writeObject(new IDGeneratorRequest()); - } - - /** - * Sends the value of a send event to the server. - * - * @param evt the send event to extract the value from - * @since Envoy Client v0.2-beta - */ - @dev.kske.eventbus.Event - private void onSendEvent(SendEvent evt) { - try { - sendEvent(evt.get()); - } catch (final IOException e) { - logger.log(Level.WARNING, "An error occurred when trying to send " + evt, e); - } + send(new IDGeneratorRequest()); } @Override - @dev.kske.eventbus.Event(eventType = EnvoyCloseEvent.class, priority = 800) + @Event(eventType = EnvoyCloseEvent.class, priority = 800) public void close() { if (online) { logger.log(Level.INFO, "Closing connection..."); @@ -244,13 +233,13 @@ public final class Client implements EventListener, Closeable { } } - private void writeObject(Object obj) throws IOException { - checkOnline(); - logger.log(Level.FINE, "Sending " + obj); - SerializationUtils.writeBytesWithLength(obj, socket.getOutputStream()); - } - - private void checkOnline() { if (!online) throw new IllegalStateException("Client is not online"); } + /** + * Ensured that the client is online. + * + * @throws IllegalStateException if the client is not online + * @since Envoy Client v0.3-alpha + */ + private void checkOnline() throws IllegalStateException { if (!online) throw new IllegalStateException("Client is not online"); } /** * @return the {@link User} as which this client is logged in diff --git a/client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java b/client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java index cd365d7..c4aea7c 100644 --- a/client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java +++ b/client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java @@ -10,10 +10,6 @@ import envoy.util.EnvoyLog; import dev.kske.eventbus.EventBus; /** - * Project: envoy-client
- * File: GroupMessageStatusChangePocessor.java
- * Created: 03.07.2020
- * * @author Maximilian Käfer * @since Envoy Client v0.1-beta */ diff --git a/client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java b/client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java index e94c16a..36f3ed4 100644 --- a/client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java +++ b/client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java @@ -10,10 +10,6 @@ import envoy.util.EnvoyLog; import dev.kske.eventbus.EventBus; /** - * Project: envoy-client
- * File: MessageStatusChangeProcessor.java
- * Created: 4 Feb 2020
- * * @author Kai S. K. Engelbart * @since Envoy Client v0.3-alpha */ diff --git a/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java b/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java index ec5210b..a5d4cc3 100644 --- a/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java +++ b/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java @@ -10,10 +10,6 @@ import envoy.util.EnvoyLog; import dev.kske.eventbus.EventBus; /** - * Project: envoy-client
- * File: ReceivedGroupMessageProcessor.java
- * Created: 13.06.2020
- * * @author Maximilian Käfer * @since Envoy Client v0.1-beta */ diff --git a/client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java b/client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java index bda6b0f..3efcc1c 100644 --- a/client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java +++ b/client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java @@ -8,10 +8,6 @@ import envoy.data.Message.MessageStatus; import dev.kske.eventbus.EventBus; /** - * Project: envoy-client
- * File: ReceivedMessageProcessor.java
- * Created: 31.12.2019
- * * @author Kai S. K. Engelbart * @since Envoy Client v0.3-alpha */ diff --git a/client/src/main/java/envoy/client/net/Receiver.java b/client/src/main/java/envoy/client/net/Receiver.java index ac806ad..2f96604 100644 --- a/client/src/main/java/envoy/client/net/Receiver.java +++ b/client/src/main/java/envoy/client/net/Receiver.java @@ -11,10 +11,6 @@ import envoy.util.*; /** * Receives objects from the server and passes them to processor objects based * on their class. - *

- * Project: envoy-client
- * File: Receiver.java
- * Created: 30.12.2019
* * @author Kai S. K. Engelbart * @since Envoy Client v0.3-alpha diff --git a/client/src/main/java/envoy/client/net/WriteProxy.java b/client/src/main/java/envoy/client/net/WriteProxy.java index c2c672b..5ffd056 100644 --- a/client/src/main/java/envoy/client/net/WriteProxy.java +++ b/client/src/main/java/envoy/client/net/WriteProxy.java @@ -1,11 +1,8 @@ package envoy.client.net; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.logging.*; -import envoy.client.data.Cache; -import envoy.client.data.LocalDB; +import envoy.client.data.*; import envoy.data.Message; import envoy.event.MessageStatusChange; import envoy.util.EnvoyLog; @@ -14,10 +11,6 @@ import envoy.util.EnvoyLog; * Implements methods to send {@link Message}s and * {@link MessageStatusChange}s to the server or cache them inside a * {@link LocalDB} depending on the online status. - *

- * Project: envoy-client
- * File: WriteProxy.java
- * Created: 6 Feb 2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.3-alpha @@ -44,20 +37,12 @@ public final class WriteProxy { // Initialize cache processors for messages and message status change events localDB.getCacheMap().get(Message.class).setProcessor(msg -> { - try { - logger.log(Level.FINER, "Sending cached " + msg); - client.sendMessage(msg); - } catch (final IOException e) { - logger.log(Level.SEVERE, "Could not send cached message: ", e); - } + logger.log(Level.FINER, "Sending cached " + msg); + client.sendMessage(msg); }); localDB.getCacheMap().get(MessageStatusChange.class).setProcessor(evt -> { logger.log(Level.FINER, "Sending cached " + evt); - try { - client.sendEvent(evt); - } catch (final IOException e) { - logger.log(Level.SEVERE, "Could not send cached message status change event: ", e); - } + client.send(evt); }); } @@ -74,10 +59,9 @@ public final class WriteProxy { * inside the local database. * * @param message the message to send - * @throws IOException if the message could not be sent * @since Envoy Client v0.3-alpha */ - public void writeMessage(Message message) throws IOException { + public void writeMessage(Message message) { if (client.isOnline()) client.sendMessage(message); else localDB.getCacheMap().getApplicable(Message.class).accept(message); } @@ -87,11 +71,10 @@ public final class WriteProxy { * event is cached inside the local database. * * @param evt the event to send - * @throws IOException if the event could not be sent * @since Envoy Client v0.3-alpha */ - public void writeMessageStatusChange(MessageStatusChange evt) throws IOException { - if (client.isOnline()) client.sendEvent(evt); + public void writeMessageStatusChange(MessageStatusChange evt) { + if (client.isOnline()) client.send(evt); else localDB.getCacheMap().getApplicable(MessageStatusChange.class).accept(evt); } } diff --git a/client/src/main/java/envoy/client/ui/ClearableTextField.java b/client/src/main/java/envoy/client/ui/ClearableTextField.java deleted file mode 100644 index 9568629..0000000 --- a/client/src/main/java/envoy/client/ui/ClearableTextField.java +++ /dev/null @@ -1,169 +0,0 @@ -package envoy.client.ui; - -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.StringProperty; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; -import javafx.scene.control.*; -import javafx.scene.image.ImageView; -import javafx.scene.layout.Background; -import javafx.scene.layout.ColumnConstraints; -import javafx.scene.layout.GridPane; - -/** - * This class offers a text field that is automatically equipped with a clear - * button. - *

- * Project: envoy-client
- * File: ClearableTextField.java
- * Created: 25.06.2020
- * - * @author Leon Hofmeister - * @since Envoy Client v0.1-beta - */ -public final class ClearableTextField extends GridPane { - - private final TextField textField; - - private final Button clearButton; - - /** - * Constructs a new {@code ClearableTextField} with no initial text and icon - * size 16. - * - * @since Envoy Client v0.1-beta - */ - public ClearableTextField() { this("", 16); } - - /** - * Constructs a new {@code ClearableTextField} with initial text and a - * predetermined icon size. - * - * @param text the text that should be displayed by default - * @param size the size of the icon - * @since Envoy Client v0.1-beta - */ - public ClearableTextField(String text, int size) { - // initializing the textField and the button - textField = new TextField(text); - clearButton = new Button("", new ImageView(IconUtil.loadIconThemeSensitive("clear_button", size))); - clearButton.setOnAction(e -> textField.clear()); - clearButton.setFocusTraversable(false); - clearButton.getStyleClass().clear(); - clearButton.setBackground(Background.EMPTY); - // Adding the two elements to the GridPane - add(textField, 0, 0, 2, 1); - add(clearButton, 1, 0, 1, 1); - // Setting the percent - widths of the two columns. - // Used to locate the button on the right. - final var columnConstraints = new ColumnConstraints(); - columnConstraints.setPercentWidth(90); - getColumnConstraints().add(columnConstraints); - final var columnConstraints2 = new ColumnConstraints(); - columnConstraints2.setPercentWidth(10); - getColumnConstraints().add(columnConstraints2); - } - - /** - * @return the underlying {@code textField} - * @since Envoy Client v0.1-beta - */ - public TextField getTextField() { return textField; } - - /** - * This method offers the freedom to perform custom actions when the - * {@code clearButton} has been pressed. - *

- * The default is - * e -> {clearableTextField.getTextField().clear();} - * - * @param onClearButtonAction the action that should be performed - * @since Envoy Client v0.1-beta - */ - public void setClearButtonListener(EventHandler onClearButtonAction) { clearButton.setOnAction(onClearButtonAction); } - - /** - * @return the current property of the prompt text - * @see javafx.scene.control.TextInputControl#promptTextProperty() - * @since Envoy Client v0.1-beta - */ - public StringProperty promptTextProperty() { return textField.promptTextProperty(); } - - /** - * @return the current prompt text - * @see javafx.scene.control.TextInputControl#getPromptText() - * @since Envoy Client v0.1-beta - */ - public String getPromptText() { return textField.getPromptText(); } - - /** - * @param value the prompt text to display - * @see javafx.scene.control.TextInputControl#setPromptText(java.lang.String) - * @since Envoy Client v0.1-beta - */ - public void setPromptText(String value) { textField.setPromptText(value); } - - /** - * @return the current property of the tooltip - * @see javafx.scene.control.Control#tooltipProperty() - * @since Envoy Client v0.1-beta - */ - public ObjectProperty tooltipProperty() { return textField.tooltipProperty(); } - - /** - * @param value the new tooltip - * @see javafx.scene.control.Control#setTooltip(javafx.scene.control.Tooltip) - * @since Envoy Client v0.1-beta - */ - public void setTooltip(Tooltip value) { textField.setTooltip(value); } - - /** - * @return the current tooltip - * @see javafx.scene.control.Control#getTooltip() - * @since Envoy Client v0.1-beta - */ - public Tooltip getTooltip() { return textField.getTooltip(); } - - /** - * @return the current property of the context menu - * @see javafx.scene.control.Control#contextMenuProperty() - * @since Envoy Client v0.1-beta - */ - public ObjectProperty contextMenuProperty() { return textField.contextMenuProperty(); } - - /** - * @param value the new context menu - * @see javafx.scene.control.Control#setContextMenu(javafx.scene.control.ContextMenu) - * @since Envoy Client v0.1-beta - */ - public void setContextMenu(ContextMenu value) { textField.setContextMenu(value); } - - /** - * @return the current context menu - * @see javafx.scene.control.Control#getContextMenu() - * @since Envoy Client v0.1-beta - */ - public ContextMenu getContextMenu() { return textField.getContextMenu(); } - - /** - * @param value whether this ClearableTextField should be editable - * @see javafx.scene.control.TextInputControl#setEditable(boolean) - * @since Envoy Client v0.1-beta - */ - public void setEditable(boolean value) { textField.setEditable(value); } - - /** - * @return the current property whether this ClearableTextField is editable - * @see javafx.scene.control.TextInputControl#editableProperty() - * @since Envoy Client v0.1-beta - */ - public BooleanProperty editableProperty() { return textField.editableProperty(); } - - /** - * @return whether this {@code ClearableTextField} is editable - * @see javafx.scene.control.TextInputControl#isEditable() - * @since Envoy Client v0.1-beta - */ - public boolean isEditable() { return textField.isEditable(); } -} diff --git a/client/src/main/java/envoy/client/ui/ListViewRefresh.java b/client/src/main/java/envoy/client/ui/ListViewRefresh.java index 962b18c..635a12e 100644 --- a/client/src/main/java/envoy/client/ui/ListViewRefresh.java +++ b/client/src/main/java/envoy/client/ui/ListViewRefresh.java @@ -1,15 +1,10 @@ package envoy.client.ui; -import javafx.scene.control.ListCell; -import javafx.scene.control.ListView; +import javafx.scene.control.*; /** * This is a utility class that provides access to a refreshing mechanism for * elements that were added without notifying the underlying {@link ListView}. - *

- * Project: envoy-client
- * File: ListViewRefresh.java
- * Created: 16.07.2020
* * @author Leon Hofmeister * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/ui/Restorable.java b/client/src/main/java/envoy/client/ui/Restorable.java index e9e40eb..11d2a90 100644 --- a/client/src/main/java/envoy/client/ui/Restorable.java +++ b/client/src/main/java/envoy/client/ui/Restorable.java @@ -3,10 +3,6 @@ package envoy.client.ui; /** * This interface defines an action that should be performed when a scene gets * restored from the scene stack in {@link SceneContext}. - *

- * Project: envoy-client
- * File: Restorable.java
- * Created: 03.07.2020
* * @author Leon Hofmeister * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/ui/SceneContext.java b/client/src/main/java/envoy/client/ui/SceneContext.java index f26aaef..2507af8 100644 --- a/client/src/main/java/envoy/client/ui/SceneContext.java +++ b/client/src/main/java/envoy/client/ui/SceneContext.java @@ -23,10 +23,6 @@ import dev.kske.eventbus.*; *

* When a scene is loaded, the style sheet for the current theme is applied to * it. - *

- * Project: envoy-client
- * File: SceneContext.java
- * Created: 06.06.2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/ui/Startup.java b/client/src/main/java/envoy/client/ui/Startup.java index 2e6b5d2..c0be1c9 100644 --- a/client/src/main/java/envoy/client/ui/Startup.java +++ b/client/src/main/java/envoy/client/ui/Startup.java @@ -15,6 +15,7 @@ import envoy.client.event.EnvoyCloseEvent; import envoy.client.net.Client; import envoy.client.ui.SceneContext.SceneInfo; import envoy.client.ui.controller.LoginScene; +import envoy.client.util.IconUtil; import envoy.data.*; import envoy.data.User.UserStatus; import envoy.event.*; @@ -25,10 +26,6 @@ import dev.kske.eventbus.EventBus; /** * Handles application startup and shutdown. - *

- * Project: envoy-client
- * File: Startup.java
- * Created: 26.03.2020
* * @author Kai S. K. Engelbart * @author Maximilian Käfer diff --git a/client/src/main/java/envoy/client/ui/StatusTrayIcon.java b/client/src/main/java/envoy/client/ui/StatusTrayIcon.java index 8824bd8..301d1fe 100644 --- a/client/src/main/java/envoy/client/ui/StatusTrayIcon.java +++ b/client/src/main/java/envoy/client/ui/StatusTrayIcon.java @@ -6,16 +6,13 @@ import java.awt.TrayIcon.MessageType; import javafx.application.Platform; import javafx.stage.Stage; +import envoy.client.util.IconUtil; import envoy.data.Message; import dev.kske.eventbus.*; import dev.kske.eventbus.Event; /** - * Project: envoy-client
- * File: StatusTrayIcon.java
- * Created: 3 Dec 2019
- * * @author Kai S. K. Engelbart * @since Envoy Client v0.2-alpha */ @@ -32,7 +29,7 @@ public final class StatusTrayIcon implements EventListener { * A received {@link Message} is only displayed as a system tray notification if * this variable is set to {@code true}. */ - private boolean displayMessages = false; + private boolean displayMessages; /** * @return {@code true} if the status tray icon is supported on this platform @@ -90,10 +87,10 @@ public final class StatusTrayIcon implements EventListener { public void hide() { SystemTray.getSystemTray().remove(trayIcon); } @Event - private void onMessage(Message evt) { + private void onMessage(Message message) { if (displayMessages) trayIcon.displayMessage( - evt.hasAttachment() ? "New " + evt.getAttachment().getType().toString().toLowerCase() + " message received" : "New message received", - evt.getText(), + message.hasAttachment() ? "New " + message.getAttachment().getType().toString().toLowerCase() + " message received" : "New message received", + message.getText(), MessageType.INFO); } } diff --git a/client/src/main/java/envoy/client/ui/AudioControl.java b/client/src/main/java/envoy/client/ui/control/AudioControl.java similarity index 76% rename from client/src/main/java/envoy/client/ui/AudioControl.java rename to client/src/main/java/envoy/client/ui/control/AudioControl.java index d82fd24..fc2263b 100644 --- a/client/src/main/java/envoy/client/ui/AudioControl.java +++ b/client/src/main/java/envoy/client/ui/control/AudioControl.java @@ -1,11 +1,9 @@ -package envoy.client.ui; +package envoy.client.ui.control; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.logging.*; -import javafx.scene.control.Alert; +import javafx.scene.control.*; import javafx.scene.control.Alert.AlertType; -import javafx.scene.control.Button; import javafx.scene.layout.HBox; import envoy.client.data.audio.AudioPlayer; @@ -14,10 +12,6 @@ import envoy.util.EnvoyLog; /** * Enables the play back of audio clips through a button. - *

- * Project: envoy-client
- * File: AudioControl.java
- * Created: 05.07.2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/ui/listcell/ChatControl.java b/client/src/main/java/envoy/client/ui/control/ChatControl.java similarity index 64% rename from client/src/main/java/envoy/client/ui/listcell/ChatControl.java rename to client/src/main/java/envoy/client/ui/control/ChatControl.java index 402ef5d..eca5cb5 100644 --- a/client/src/main/java/envoy/client/ui/listcell/ChatControl.java +++ b/client/src/main/java/envoy/client/ui/control/ChatControl.java @@ -1,23 +1,17 @@ -package envoy.client.ui.listcell; +package envoy.client.ui.control; -import javafx.geometry.Insets; -import javafx.geometry.Pos; +import javafx.geometry.*; import javafx.scene.control.Label; -import javafx.scene.image.ImageView; +import javafx.scene.image.*; import javafx.scene.layout.*; import javafx.scene.shape.Rectangle; -import envoy.client.data.Chat; -import envoy.client.ui.IconUtil; -import envoy.data.Group; +import envoy.client.data.*; +import envoy.client.util.IconUtil; /** * Displays a chat using a contact control for the recipient and a label for the * unread message count. - *

- * Project: envoy-client
- * File: ContactControl.java
- * Created: 01.07.2020
* * @see ContactControl * @author Leon Hofmeister @@ -25,6 +19,9 @@ import envoy.data.Group; */ public final class ChatControl extends HBox { + private static final Image userIcon = IconUtil.loadIconThemeSensitive("user_icon", 32), + groupIcon = IconUtil.loadIconThemeSensitive("group_icon", 32); + /** * @param chat the chat to display * @since Envoy Client v0.1-beta @@ -32,10 +29,9 @@ public final class ChatControl extends HBox { public ChatControl(Chat chat) { setAlignment(Pos.CENTER_LEFT); setPadding(new Insets(0, 0, 3, 0)); - // profile pic - ImageView contactProfilePic; - if (chat.getRecipient() instanceof Group) contactProfilePic = new ImageView(IconUtil.loadIconThemeSensitive("group_icon", 32)); - else contactProfilePic = new ImageView(IconUtil.loadIconThemeSensitive("user_icon", 32)); + + // Profile picture + ImageView contactProfilePic = new ImageView(chat instanceof GroupChat ? groupIcon : userIcon); final var clip = new Rectangle(); clip.setWidth(32); clip.setHeight(32); @@ -43,14 +39,17 @@ public final class ChatControl extends HBox { clip.setArcWidth(32); contactProfilePic.setClip(clip); getChildren().add(contactProfilePic); - // spacing + + // Spacing final var leftSpacing = new Region(); leftSpacing.setPrefSize(8, 0); leftSpacing.setMinSize(8, 0); leftSpacing.setMaxSize(8, 0); getChildren().add(leftSpacing); + // Contact control getChildren().add(new ContactControl(chat.getRecipient())); + // Unread messages if (chat.getUnreadAmount() != 0) { final var spacing = new Region(); @@ -58,12 +57,12 @@ public final class ChatControl extends HBox { getChildren().add(spacing); final var unreadMessagesLabel = new Label(Integer.toString(chat.getUnreadAmount())); unreadMessagesLabel.setMinSize(15, 15); - final var vBox2 = new VBox(); - vBox2.setAlignment(Pos.CENTER_RIGHT); + final var vbox = new VBox(); + vbox.setAlignment(Pos.CENTER_RIGHT); unreadMessagesLabel.setAlignment(Pos.CENTER); unreadMessagesLabel.getStyleClass().add("unread-messages-amount"); - vBox2.getChildren().add(unreadMessagesLabel); - getChildren().add(vBox2); + vbox.getChildren().add(unreadMessagesLabel); + getChildren().add(vbox); } getStyleClass().add("list-element"); } diff --git a/client/src/main/java/envoy/client/ui/listcell/ContactControl.java b/client/src/main/java/envoy/client/ui/control/ContactControl.java similarity index 81% rename from client/src/main/java/envoy/client/ui/listcell/ContactControl.java rename to client/src/main/java/envoy/client/ui/control/ContactControl.java index f7a8999..8a85739 100644 --- a/client/src/main/java/envoy/client/ui/listcell/ContactControl.java +++ b/client/src/main/java/envoy/client/ui/control/ContactControl.java @@ -1,19 +1,14 @@ -package envoy.client.ui.listcell; +package envoy.client.ui.control; import javafx.scene.control.Label; import javafx.scene.layout.VBox; -import envoy.data.Contact; -import envoy.data.User; +import envoy.data.*; /** * Displays information about a contact in two rows. The first row contains the * name. The second row contains the online status (user) or the member count * (group). - *

- * Project: envoy-client
- * File: ContactControl.java
- * Created: 13.07.2020
* * @author Kai S. K. Engelbart * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/ui/listcell/MessageControl.java b/client/src/main/java/envoy/client/ui/control/MessageControl.java similarity index 88% rename from client/src/main/java/envoy/client/ui/listcell/MessageControl.java rename to client/src/main/java/envoy/client/ui/control/MessageControl.java index ff4674e..11f5681 100644 --- a/client/src/main/java/envoy/client/ui/listcell/MessageControl.java +++ b/client/src/main/java/envoy/client/ui/control/MessageControl.java @@ -1,4 +1,4 @@ -package envoy.client.ui.listcell; +package envoy.client.ui.control; import java.awt.Toolkit; import java.awt.datatransfer.StringSelection; @@ -6,37 +6,23 @@ import java.io.*; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.logging.*; -import javafx.geometry.Insets; -import javafx.geometry.Pos; -import javafx.scene.control.ContextMenu; -import javafx.scene.control.Label; -import javafx.scene.control.MenuItem; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; +import javafx.geometry.*; +import javafx.scene.control.*; +import javafx.scene.image.*; import javafx.scene.layout.*; import javafx.stage.FileChooser; -import envoy.client.data.Context; -import envoy.client.data.LocalDB; -import envoy.client.data.Settings; -import envoy.client.ui.AudioControl; -import envoy.client.ui.IconUtil; -import envoy.client.ui.SceneContext; -import envoy.data.GroupMessage; -import envoy.data.Message; +import envoy.client.data.*; +import envoy.client.ui.*; +import envoy.client.util.IconUtil; +import envoy.data.*; import envoy.data.Message.MessageStatus; -import envoy.data.User; import envoy.util.EnvoyLog; /** - * This class formats a single {@link Message} into a UI component. - *

- * Project: envoy-client
- * File: MessageControl.java
- * Created: 01.07.2020
+ * This class transforms a single {@link Message} into a UI component. * * @author Leon Hofmeister * @author Maximilian Käfer @@ -95,6 +81,7 @@ public final class MessageControl extends Label { contextMenu.getItems().addAll(copyMenuItem, deleteMenuItem, forwardMenuItem, quoteMenuItem, infoMenuItem); // Handling message attachment display + // TODO: Add missing attachment types if (message.hasAttachment()) { switch (message.getAttachment().getType()) { case PICTURE: diff --git a/client/src/main/java/envoy/client/ui/custom/ProfilePicImageView.java b/client/src/main/java/envoy/client/ui/control/ProfilePicImageView.java similarity index 85% rename from client/src/main/java/envoy/client/ui/custom/ProfilePicImageView.java rename to client/src/main/java/envoy/client/ui/control/ProfilePicImageView.java index 4708974..778b026 100644 --- a/client/src/main/java/envoy/client/ui/custom/ProfilePicImageView.java +++ b/client/src/main/java/envoy/client/ui/control/ProfilePicImageView.java @@ -1,15 +1,10 @@ -package envoy.client.ui.custom; +package envoy.client.ui.control; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; +import javafx.scene.image.*; import javafx.scene.shape.Rectangle; /** * Provides a set of convenience constructors for images that are displayed as profile pictures. - *

- * Project: envoy-client
- * File: ProfilePicImageView.java
- * Created: 30.07.2020
* * @author Leon Hofmeister * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/ui/custom/TextInputContextMenu.java b/client/src/main/java/envoy/client/ui/control/TextInputContextMenu.java similarity index 95% rename from client/src/main/java/envoy/client/ui/custom/TextInputContextMenu.java rename to client/src/main/java/envoy/client/ui/control/TextInputContextMenu.java index 02b1889..9925f7d 100644 --- a/client/src/main/java/envoy/client/ui/custom/TextInputContextMenu.java +++ b/client/src/main/java/envoy/client/ui/control/TextInputContextMenu.java @@ -1,4 +1,4 @@ -package envoy.client.ui.custom; +package envoy.client.ui.control; import java.util.function.Consumer; @@ -21,10 +21,6 @@ import javafx.scene.input.Clipboard; *

  • clear
  • *
  • Select all
  • * - *

    - * Project: client
    - * File: TextInputContextMenu.java
    - * Created: 20.09.2020
    * * @author Leon Hofmeister * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/ui/control/package-info.java b/client/src/main/java/envoy/client/ui/control/package-info.java new file mode 100644 index 0000000..6a091d0 --- /dev/null +++ b/client/src/main/java/envoy/client/ui/control/package-info.java @@ -0,0 +1,9 @@ +/** + * Defines custom UI controls. + * + * @author Kai S. K. Engelbart + * @author Leon Hofmeister + * @author Maximilian Käfer + * @since Envoy Client v0.2-beta + */ +package envoy.client.ui.control; diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 4ee5e38..baf05e4 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -30,9 +30,9 @@ import envoy.client.data.commands.*; import envoy.client.event.*; import envoy.client.net.*; import envoy.client.ui.*; -import envoy.client.ui.custom.TextInputContextMenu; +import envoy.client.ui.control.*; import envoy.client.ui.listcell.*; -import envoy.client.util.ReflectionUtil; +import envoy.client.util.*; import envoy.data.*; import envoy.data.Attachment.AttachmentType; import envoy.data.Message.MessageStatus; @@ -45,9 +45,7 @@ import dev.kske.eventbus.*; import dev.kske.eventbus.Event; /** - * Project: envoy-client
    - * File: ChatSceneController.java
    - * Created: 26.03.2020
    + * Controller for the chat scene. * * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta @@ -203,8 +201,8 @@ public final class ChatScene implements EventListener, Restorable { Tooltip.uninstall(contactSpecificOnlineOperations, onlyIfOnlineTooltip); contactSearchTab.setContent(new FXMLLoader().load(getClass().getResourceAsStream("/fxml/ContactSearchTab.fxml"))); groupCreationTab.setContent(new FXMLLoader().load(getClass().getResourceAsStream("/fxml/GroupCreationTab.fxml"))); - } catch (final IOException e2) { - logger.log(Level.SEVERE, "An error occurred when attempting to load tabs: ", e2); + } catch (final IOException e) { + logger.log(Level.SEVERE, "An error occurred when attempting to load tabs: ", e); } else { Tooltip.install(contactSpecificOnlineOperations, onlyIfOnlineTooltip); @@ -555,8 +553,8 @@ public final class ChatScene implements EventListener, Restorable { // Sending an IsTyping event if none has been sent for // IsTyping#millisecondsActive - if (currentChat.getLastWritingEvent() + IsTyping.millisecondsActive <= System.currentTimeMillis()) { - eventBus.dispatch(new SendEvent(new IsTyping(getChatID(), currentChat.getRecipient().getID()))); + if (client.isOnline() && currentChat.getLastWritingEvent() + IsTyping.millisecondsActive <= System.currentTimeMillis()) { + client.send(new IsTyping(getChatID(), currentChat.getRecipient().getID())); currentChat.lastWritingEventWasNow(); } @@ -665,7 +663,7 @@ public final class ChatScene implements EventListener, Restorable { return; } final var text = messageTextArea.getText().strip(); - if (!messageTextAreaCommands.executeIfAnyPresent(text)) try { + if (!messageTextAreaCommands.executeIfAnyPresent(text)) { // Creating the message and its metadata final var builder = new MessageBuilder(localDB.getUser().getID(), currentChat.getRecipient().getID(), localDB.getIDGenerator()) .setText(text); @@ -697,10 +695,6 @@ public final class ChatScene implements EventListener, Restorable { // Request a new ID generator if all IDs were used if (!localDB.getIDGenerator().hasNext() && client.isOnline()) client.requestIdGenerator(); - - } catch (final IOException e) { - logger.log(Level.SEVERE, "Error while sending message: ", e); - new Alert(AlertType.ERROR, "An error occured while sending the message!").showAndWait(); } // Clear text field and disable post button diff --git a/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java b/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java index a171489..336714f 100644 --- a/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java +++ b/client/src/main/java/envoy/client/ui/controller/ContactSearchTab.java @@ -7,8 +7,11 @@ import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.control.Alert.AlertType; -import envoy.client.event.*; -import envoy.client.ui.listcell.*; +import envoy.client.data.Context; +import envoy.client.event.BackEvent; +import envoy.client.net.Client; +import envoy.client.ui.control.ContactControl; +import envoy.client.ui.listcell.ListCellFactory; import envoy.data.User; import envoy.event.ElementOperation; import envoy.event.contact.*; @@ -25,10 +28,6 @@ import dev.kske.eventbus.*; *

    * To create a group, a button is available that loads the * {@link GroupCreationTab}. - *

    - * Project: envoy-client
    - * File: ContactSearchScene.java
    - * Created: 07.06.2020
    * * @author Leon Hofmeister * @author Maximilian Käfer @@ -46,6 +45,7 @@ public class ContactSearchTab implements EventListener { private final Alert alert = new Alert(AlertType.CONFIRMATION); + private static final Client client = Context.getInstance().getClient(); private static final EventBus eventBus = EventBus.getInstance(); private static final Logger logger = EnvoyLog.getLogger(ChatScene.class); @@ -77,7 +77,7 @@ public class ContactSearchTab implements EventListener { @FXML private void sendRequest() { final var text = searchBar.getText().strip(); - if (!text.isBlank()) eventBus.dispatch(new SendEvent(new UserSearchRequest(text))); + if (!text.isBlank()) client.send(new UserSearchRequest(text)); else userList.getItems().clear(); } @@ -106,7 +106,7 @@ public class ContactSearchTab implements EventListener { currentlySelectedUser = user; final var event = new ContactOperation(currentlySelectedUser, ElementOperation.ADD); // Sends the event to the server - eventBus.dispatch(new SendEvent(event)); + client.send(event); // Removes the chosen user and updates the UI userList.getItems().remove(currentlySelectedUser); eventBus.dispatch(event); diff --git a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java index d2f61a6..4243ce4 100644 --- a/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java +++ b/client/src/main/java/envoy/client/ui/controller/GroupCreationTab.java @@ -10,8 +10,9 @@ import javafx.scene.control.*; import javafx.scene.layout.HBox; import envoy.client.data.*; -import envoy.client.event.*; -import envoy.client.ui.listcell.*; +import envoy.client.event.BackEvent; +import envoy.client.ui.control.ContactControl; +import envoy.client.ui.listcell.ListCellFactory; import envoy.data.*; import envoy.event.GroupCreation; import envoy.event.contact.ContactOperation; @@ -27,10 +28,6 @@ import dev.kske.eventbus.*; * When the group creation button is pressed, a {@link GroupCreation} is sent to * the server. This controller enforces a valid group name and a non-empty * member list (excluding the client user). - *

    - * Project: envoy-client
    - * File: GroupCreationScene.java
    - * Created: 07.06.2020
    * * @author Maximilian Käfer * @since Envoy Client v0.1-beta @@ -137,8 +134,9 @@ public class GroupCreationTab implements EventListener { * @since Envoy Client v0.1-beta */ private void createGroup(String name) { - eventBus.dispatch(new SendEvent( - new GroupCreation(name, userList.getSelectionModel().getSelectedItems().stream().map(User::getID).collect(Collectors.toSet())))); + Context.getInstance() + .getClient() + .send(new GroupCreation(name, userList.getSelectionModel().getSelectedItems().stream().map(User::getID).collect(Collectors.toSet()))); } /** @@ -150,12 +148,7 @@ public class GroupCreationTab implements EventListener { * @since Envoy Client v0.1-beta */ public boolean groupNameAlreadyPresent(String newName) { - return localDB.getChats() - .stream() - .map(Chat::getRecipient) - .filter(Group.class::isInstance) - .map(Contact::getName) - .anyMatch(newName::equals); + return localDB.getChats().stream().map(Chat::getRecipient).filter(Group.class::isInstance).map(Contact::getName).anyMatch(newName::equals); } @FXML @@ -211,7 +204,7 @@ public class GroupCreationTab implements EventListener { userList.getItems().add((User) operation.get()); break; case REMOVE: - userList.getItems().removeIf(u -> u.equals(operation.get())); + userList.getItems().removeIf(operation.get()::equals); break; } }); diff --git a/client/src/main/java/envoy/client/ui/controller/LoginScene.java b/client/src/main/java/envoy/client/ui/controller/LoginScene.java index 30cb205..6176f8c 100644 --- a/client/src/main/java/envoy/client/ui/controller/LoginScene.java +++ b/client/src/main/java/envoy/client/ui/controller/LoginScene.java @@ -12,6 +12,7 @@ import javafx.scene.image.ImageView; import envoy.client.data.ClientConfig; import envoy.client.ui.*; +import envoy.client.util.IconUtil; import envoy.data.LoginCredentials; import envoy.event.HandshakeRejection; import envoy.util.*; @@ -19,9 +20,7 @@ import envoy.util.*; import dev.kske.eventbus.*; /** - * Project: envoy-client
    - * File: LoginDialog.java
    - * Created: 03.04.2020
    + * Controller for the login scene. * * @author Kai S. K. Engelbart * @author Maximilian Käfer @@ -101,20 +100,21 @@ public final class LoginScene implements EventListener { @FXML private void registerSwitchPressed() { + + // Update button text and register switch if (!registration) { - // case if the current mode is login loginButton.setText("Register"); loginButton.setPadding(new Insets(2, 116, 2, 116)); registerTextLabel.setText("Already an account?"); registerSwitch.setText("Login"); } else { - // case if the current mode is registration loginButton.setText("Login"); loginButton.setPadding(new Insets(2, 125, 2, 125)); registerTextLabel.setText("No account yet?"); registerSwitch.setText("Register"); } registration = !registration; + // Make repeat password field and label visible / invisible repeatPasswordField.setVisible(registration); offlineModeButton.setDisable(registration); diff --git a/client/src/main/java/envoy/client/ui/controller/SettingsScene.java b/client/src/main/java/envoy/client/ui/controller/SettingsScene.java index bd3a237..f69475a 100644 --- a/client/src/main/java/envoy/client/ui/controller/SettingsScene.java +++ b/client/src/main/java/envoy/client/ui/controller/SettingsScene.java @@ -1,20 +1,14 @@ package envoy.client.ui.controller; import javafx.fxml.FXML; -import javafx.scene.control.Label; -import javafx.scene.control.ListView; -import javafx.scene.control.TitledPane; +import javafx.scene.control.*; import envoy.client.data.Context; -import envoy.client.net.Client; -import envoy.client.ui.SceneContext; -import envoy.client.ui.listcell.AbstractListCell; +import envoy.client.ui.listcell.ListCellFactory; import envoy.client.ui.settings.*; /** - * Project: envoy-client
    - * File: SettingsSceneController.java
    - * Created: 10.04.2020
    + * Controller for the settings scene. * * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta @@ -27,20 +21,10 @@ public final class SettingsScene { @FXML private TitledPane titledPane; - private final Client client = Context.getInstance().getClient(); - private final SceneContext sceneContext = Context.getInstance().getSceneContext(); - @FXML private void initialize() { - settingsList.setCellFactory(listView -> new AbstractListCell<>(listView) { - - @Override - protected Label renderItem(SettingsPane item) { return new Label(item.getTitle()); } - }); - settingsList.getItems().add(new GeneralSettingsPane()); - settingsList.getItems().add(new UserSettingsPane(sceneContext, client.getSender(), client.isOnline())); - settingsList.getItems().add(new DownloadSettingsPane(sceneContext)); - settingsList.getItems().add(new BugReportPane(client.getSender(), client.isOnline())); + settingsList.setCellFactory(new ListCellFactory<>(pane -> new Label(pane.getTitle()))); + settingsList.getItems().addAll(new GeneralSettingsPane(), new UserSettingsPane(), new DownloadSettingsPane(), new BugReportPane()); } @FXML @@ -53,5 +37,5 @@ public final class SettingsScene { } @FXML - private void backButtonClicked() { sceneContext.pop(); } + private void backButtonClicked() { Context.getInstance().getSceneContext().pop(); } } diff --git a/client/src/main/java/envoy/client/ui/controller/Tabs.java b/client/src/main/java/envoy/client/ui/controller/Tabs.java index 0940cd3..9889e3d 100644 --- a/client/src/main/java/envoy/client/ui/controller/Tabs.java +++ b/client/src/main/java/envoy/client/ui/controller/Tabs.java @@ -2,10 +2,6 @@ package envoy.client.ui.controller; /** * Provides options to select different tabs. - *

    - * Project: client
    - * File: Tabs.java
    - * Created: 30.8.2020
    * * @author Maximilian Käfer * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/envoy/client/ui/controller/package-info.java b/client/src/main/java/envoy/client/ui/controller/package-info.java index 7989b8f..fcd4b35 100644 --- a/client/src/main/java/envoy/client/ui/controller/package-info.java +++ b/client/src/main/java/envoy/client/ui/controller/package-info.java @@ -1,11 +1,9 @@ /** * Contains JavaFX scene controllers. - *

    - * Project: envoy-client
    - * File: package-info.java
    - * Created: 08.06.2020
    * * @author Kai S. K. Engelbart + * @author Leon Hofmeister + * @author Maximilian Käfer * @since Envoy Client v0.1-beta */ package envoy.client.ui.controller; diff --git a/client/src/main/java/envoy/client/ui/custom/package-info.java b/client/src/main/java/envoy/client/ui/custom/package-info.java deleted file mode 100644 index 97a8f58..0000000 --- a/client/src/main/java/envoy/client/ui/custom/package-info.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * This package stores custom components for use in JavaFX. - * These components are also expected to be used via FXML. - *

    - * Project: envoy-client
    - * File: package-info.java
    - * Created: 30.07.2020
    - * - * @author Leon Hofmeister - * @author Maximilian Käfer - * @author Kai S. K. Engelbart - * @since Envoy Client v0.2-beta - */ -package envoy.client.ui.custom; diff --git a/client/src/main/java/envoy/client/ui/listcell/AbstractListCell.java b/client/src/main/java/envoy/client/ui/listcell/AbstractListCell.java index a763981..1e12021 100644 --- a/client/src/main/java/envoy/client/ui/listcell/AbstractListCell.java +++ b/client/src/main/java/envoy/client/ui/listcell/AbstractListCell.java @@ -1,17 +1,10 @@ package envoy.client.ui.listcell; -import javafx.scene.Cursor; -import javafx.scene.Node; -import javafx.scene.control.ContentDisplay; -import javafx.scene.control.ListCell; -import javafx.scene.control.ListView; +import javafx.scene.*; +import javafx.scene.control.*; /** * Provides a convenience frame for list cell creation. - *

    - * Project: envoy-client
    - * File: AbstractListCell.java
    - * Created: 18.07.2020
    * * @author Kai S. K. Engelbart * @param the type of element displayed by the list cell diff --git a/client/src/main/java/envoy/client/ui/listcell/GenericListCell.java b/client/src/main/java/envoy/client/ui/listcell/GenericListCell.java index 6b981a7..2959937 100644 --- a/client/src/main/java/envoy/client/ui/listcell/GenericListCell.java +++ b/client/src/main/java/envoy/client/ui/listcell/GenericListCell.java @@ -7,10 +7,6 @@ import javafx.scene.control.ListView; /** * A generic list cell rendering an item using a provided render function. - *

    - * Project: envoy-client
    - * File: GenericListCell.java
    - * Created: 18.07.2020
    * * @author Kai S. K. Engelbart * @param the type of element displayed by the list cell diff --git a/client/src/main/java/envoy/client/ui/listcell/ListCellFactory.java b/client/src/main/java/envoy/client/ui/listcell/ListCellFactory.java index 018a0ba..faac35f 100644 --- a/client/src/main/java/envoy/client/ui/listcell/ListCellFactory.java +++ b/client/src/main/java/envoy/client/ui/listcell/ListCellFactory.java @@ -3,17 +3,12 @@ package envoy.client.ui.listcell; import java.util.function.Function; import javafx.scene.Node; -import javafx.scene.control.ListCell; -import javafx.scene.control.ListView; +import javafx.scene.control.*; import javafx.util.Callback; /** * Provides a creation mechanism for generic list cells given a list view and a * conversion function. - *

    - * Project: envoy-client
    - * File: ListCellFactory.java
    - * Created: 13.07.2020
    * * @author Kai S. K. Engelbart * @param the type of object to display diff --git a/client/src/main/java/envoy/client/ui/listcell/MessageListCell.java b/client/src/main/java/envoy/client/ui/listcell/MessageListCell.java index 80cf215..efd2d73 100644 --- a/client/src/main/java/envoy/client/ui/listcell/MessageListCell.java +++ b/client/src/main/java/envoy/client/ui/listcell/MessageListCell.java @@ -1,17 +1,13 @@ package envoy.client.ui.listcell; -import javafx.geometry.Insets; -import javafx.geometry.Pos; +import javafx.geometry.*; import javafx.scene.control.ListView; +import envoy.client.ui.control.MessageControl; import envoy.data.Message; /** * A list cell containing messages represented as message controls. - *

    - * Project: envoy-client
    - * File: MessageListCell.java
    - * Created: 18.07.2020
    * * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta diff --git a/client/src/main/java/envoy/client/ui/listcell/package-info.java b/client/src/main/java/envoy/client/ui/listcell/package-info.java index ab0788e..dd5dd33 100644 --- a/client/src/main/java/envoy/client/ui/listcell/package-info.java +++ b/client/src/main/java/envoy/client/ui/listcell/package-info.java @@ -1,12 +1,9 @@ /** * This package contains custom list cells that are used to display certain * things. - *

    - * Project: envoy-client
    - * File: package-info.java
    - * Created: 30.06.2020
    * * @author Leon Hofmeister + * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ package envoy.client.ui.listcell; diff --git a/client/src/main/java/envoy/client/ui/settings/BugReportPane.java b/client/src/main/java/envoy/client/ui/settings/BugReportPane.java index 88b0397..1f2e98f 100644 --- a/client/src/main/java/envoy/client/ui/settings/BugReportPane.java +++ b/client/src/main/java/envoy/client/ui/settings/BugReportPane.java @@ -4,25 +4,17 @@ import javafx.event.EventHandler; import javafx.scene.control.*; import javafx.scene.input.InputEvent; -import envoy.client.event.SendEvent; import envoy.client.util.IssueUtil; -import envoy.data.User; import envoy.event.IssueProposal; -import dev.kske.eventbus.EventBus; - /** * This class offers the option for users to submit a bug report. Only the title * of a bug is needed to be sent. - *

    - * Project: client
    - * File: BugReportPane.java
    - * Created: Aug 4, 2020
    * * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ -public final class BugReportPane extends OnlyIfOnlineSettingsPane { +public final class BugReportPane extends OnlineOnlySettingsPane { private final Label titleLabel = new Label("Suggest a title for the bug:"); private final TextField titleTextField = new TextField(); @@ -36,12 +28,10 @@ public final class BugReportPane extends OnlyIfOnlineSettingsPane { /** * Creates a new {@code BugReportPane}. * - * @param user the user whose details to use - * @param online whether this user is currently online * @since Envoy Client v0.2-beta */ - public BugReportPane(User user, boolean online) { - super("Report a bug", online); + public BugReportPane() { + super("Report a bug"); setSpacing(10); setToolTipText("A bug can only be reported while being online"); @@ -68,12 +58,8 @@ public final class BugReportPane extends OnlyIfOnlineSettingsPane { // Displaying the submitReportButton submitReportButton.setDisable(true); - submitReportButton.setOnAction(e -> { - EventBus.getInstance() - .dispatch(new SendEvent(new IssueProposal(titleTextField.getText(), - IssueUtil.sanitizeIssueDescription(errorDetailArea.getText(), showUsernameInBugReport.isSelected() ? user.getName() : null), - true))); - }); + submitReportButton.setOnAction(e -> client.send(new IssueProposal(titleTextField.getText(), IssueUtil + .sanitizeIssueDescription(errorDetailArea.getText(), showUsernameInBugReport.isSelected() ? client.getSender().getName() : null), true))); getChildren().add(submitReportButton); } } diff --git a/client/src/main/java/envoy/client/ui/settings/DownloadSettingsPane.java b/client/src/main/java/envoy/client/ui/settings/DownloadSettingsPane.java index fe358c1..4bcb1d8 100644 --- a/client/src/main/java/envoy/client/ui/settings/DownloadSettingsPane.java +++ b/client/src/main/java/envoy/client/ui/settings/DownloadSettingsPane.java @@ -5,14 +5,10 @@ import javafx.scene.control.*; import javafx.scene.layout.HBox; import javafx.stage.DirectoryChooser; -import envoy.client.ui.SceneContext; +import envoy.client.data.Context; /** * Displays options for downloading {@link envoy.data.Attachment}s. - *

    - * Project: envoy-client
    - * File: DownloadSettingsPane.java
    - * Created: 27.07.2020
    * * @author Leon Hofmeister * @since Envoy Client v0.2-beta @@ -22,15 +18,14 @@ public final class DownloadSettingsPane extends SettingsPane { /** * Constructs a new {@code DownloadSettingsPane}. * - * @param sceneContext the {@code SceneContext} used to block input to the - * {@link javafx.stage.Stage} used in Envoy * @since Envoy Client v0.2-beta */ - public DownloadSettingsPane(SceneContext sceneContext) { + public DownloadSettingsPane() { super("Download"); setSpacing(15); setPadding(new Insets(15)); - // checkbox to disable asking + + // Checkbox to disable asking final var checkBox = new CheckBox(settings.getItems().get("autoSaveDownloads").getUserFriendlyName()); checkBox.setSelected(settings.isDownloadSavedWithoutAsking()); checkBox.setTooltip(new Tooltip("Determines whether a \"Select save location\" - dialogue will be shown when saving attachments.")); @@ -52,7 +47,7 @@ public final class DownloadSettingsPane extends SettingsPane { final var directoryChooser = new DirectoryChooser(); directoryChooser.setTitle("Select the directory where attachments should be saved to"); directoryChooser.setInitialDirectory(settings.getDownloadLocation()); - final var selectedDirectory = directoryChooser.showDialog(sceneContext.getStage()); + final var selectedDirectory = directoryChooser.showDialog(Context.getInstance().getSceneContext().getStage()); if (selectedDirectory != null) { currentPath.setText(selectedDirectory.getAbsolutePath()); diff --git a/client/src/main/java/envoy/client/ui/settings/GeneralSettingsPane.java b/client/src/main/java/envoy/client/ui/settings/GeneralSettingsPane.java index cb87294..873527d 100644 --- a/client/src/main/java/envoy/client/ui/settings/GeneralSettingsPane.java +++ b/client/src/main/java/envoy/client/ui/settings/GeneralSettingsPane.java @@ -9,10 +9,6 @@ import envoy.data.User.UserStatus; import dev.kske.eventbus.EventBus; /** - * Project: envoy-client
    - * File: GeneralSettingsPane.java
    - * Created: 18.04.2020
    - * * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ diff --git a/client/src/main/java/envoy/client/ui/settings/OnlyIfOnlineSettingsPane.java b/client/src/main/java/envoy/client/ui/settings/OnlineOnlySettingsPane.java similarity index 65% rename from client/src/main/java/envoy/client/ui/settings/OnlyIfOnlineSettingsPane.java rename to client/src/main/java/envoy/client/ui/settings/OnlineOnlySettingsPane.java index 95e375c..592b31b 100644 --- a/client/src/main/java/envoy/client/ui/settings/OnlyIfOnlineSettingsPane.java +++ b/client/src/main/java/envoy/client/ui/settings/OnlineOnlySettingsPane.java @@ -1,40 +1,39 @@ package envoy.client.ui.settings; import javafx.geometry.Insets; -import javafx.scene.control.Label; -import javafx.scene.control.Tooltip; -import javafx.scene.layout.Background; -import javafx.scene.layout.BackgroundFill; -import javafx.scene.layout.CornerRadii; +import javafx.scene.control.*; +import javafx.scene.layout.*; import javafx.scene.paint.Color; +import envoy.client.data.Context; +import envoy.client.net.Client; + /** * Inheriting from this class signifies that options should only be available if * the {@link envoy.data.User} is currently online. If the user is currently * offline, all {@link javafx.scene.Node} variables will be disabled and a * {@link Tooltip} will be displayed for the whole node. - *

    - * Project: client
    - * File: OnlyIfOnlineSettingsPane.java
    - * Created: 04.08.2020
    * * @author Leon Hofmeister + * @author Kai S. K. Engelbart * @since Envoy Client v0.2-beta */ -public abstract class OnlyIfOnlineSettingsPane extends SettingsPane { +public abstract class OnlineOnlySettingsPane extends SettingsPane { + + protected final Client client = Context.getInstance().getClient(); private final Tooltip beOnlineReminder = new Tooltip("You need to be online to modify your account."); /** - * @param title + * @param title the title of this pane * @since Envoy Client v0.2-beta */ - protected OnlyIfOnlineSettingsPane(String title, boolean online) { + protected OnlineOnlySettingsPane(String title) { super(title); - setDisable(!online); + setDisable(!client.isOnline()); - if (!online) { + if (!client.isOnline()) { final var infoLabel = new Label("You shall not pass!\n(... Unless you would happen to be online)"); infoLabel.setId("info-label-warning"); infoLabel.setWrapText(true); @@ -45,5 +44,11 @@ public abstract class OnlyIfOnlineSettingsPane extends SettingsPane { } else Tooltip.uninstall(this, beOnlineReminder); } + /** + * Sets the text of the tooltip displayed for this pane. + * + * @param text the text to display + * @since Envoy Client v0.2-beta + */ protected void setToolTipText(String text) { beOnlineReminder.setText(text); } } diff --git a/client/src/main/java/envoy/client/ui/settings/SettingsCheckbox.java b/client/src/main/java/envoy/client/ui/settings/SettingsCheckbox.java index b672d5a..b171d07 100644 --- a/client/src/main/java/envoy/client/ui/settings/SettingsCheckbox.java +++ b/client/src/main/java/envoy/client/ui/settings/SettingsCheckbox.java @@ -6,10 +6,6 @@ import javafx.scene.control.CheckBox; import envoy.client.data.SettingsItem; /** - * Project: envoy-client
    - * File: SettingsToggleButton.java
    - * Created: 18.04.2020
    - * * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ diff --git a/client/src/main/java/envoy/client/ui/settings/SettingsPane.java b/client/src/main/java/envoy/client/ui/settings/SettingsPane.java index be63f26..5dc9796 100644 --- a/client/src/main/java/envoy/client/ui/settings/SettingsPane.java +++ b/client/src/main/java/envoy/client/ui/settings/SettingsPane.java @@ -5,10 +5,6 @@ import javafx.scene.layout.VBox; import envoy.client.data.Settings; /** - * Project: envoy-client
    - * File: SettingsPane.java
    - * Created: 18.04.2020
    - * * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta */ diff --git a/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java b/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java index 498a940..5c6e730 100644 --- a/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java +++ b/client/src/main/java/envoy/client/ui/settings/UserSettingsPane.java @@ -14,24 +14,19 @@ import javafx.scene.input.InputEvent; import javafx.scene.layout.HBox; import javafx.stage.FileChooser; -import envoy.client.event.SendEvent; -import envoy.client.ui.*; -import envoy.client.ui.custom.ProfilePicImageView; -import envoy.data.User; +import envoy.client.data.Context; +import envoy.client.ui.control.ProfilePicImageView; +import envoy.client.util.IconUtil; import envoy.event.*; import envoy.util.*; import dev.kske.eventbus.EventBus; /** - * Project: envoy-client
    - * File: UserSettingsPane.java
    - * Created: 31.07.2020
    - * * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ -public final class UserSettingsPane extends OnlyIfOnlineSettingsPane { +public final class UserSettingsPane extends OnlineOnlySettingsPane { private boolean profilePicChanged, usernameChanged, validPassword; private byte[] currentImageBytes; @@ -50,13 +45,10 @@ public final class UserSettingsPane extends OnlyIfOnlineSettingsPane { /** * Creates a new {@code UserSettingsPane}. * - * @param sceneContext the {@code SceneContext} to block input to Envoy - * @param user the user who wants to customize his profile - * @param online whether this user is currently online * @since Envoy Client v0.2-beta */ - public UserSettingsPane(SceneContext sceneContext, User user, boolean online) { - super("User", online); + public UserSettingsPane() { + super("User"); setSpacing(10); // Display of profile pic change mechanism @@ -67,18 +59,19 @@ public final class UserSettingsPane extends OnlyIfOnlineSettingsPane { profilePic.setFitWidth(60); profilePic.setFitHeight(60); profilePic.setOnMouseClicked(e -> { - if (!online) return; + if (!client.isOnline()) return; final var pictureChooser = new FileChooser(); pictureChooser.setTitle("Select a new profile pic"); pictureChooser.setInitialDirectory(new File(System.getProperty("user.home"))); pictureChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Pictures", "*.png", "*.jpg", "*.bmp", "*.gif")); - final var file = pictureChooser.showOpenDialog(sceneContext.getStage()); + final var file = pictureChooser.showOpenDialog(Context.getInstance().getSceneContext().getStage()); if (file != null) { // Check max file size + // TODO: Move to config if (file.length() > 5E6) { new Alert(AlertType.WARNING, "The selected file exceeds the size limit of 5MB!").showAndWait(); return; @@ -96,7 +89,7 @@ public final class UserSettingsPane extends OnlyIfOnlineSettingsPane { hbox.getChildren().add(profilePic); // Displaying the username change mechanism - final var username = user.getName(); + final var username = client.getSender().getName(); newUsername = username; usernameTextField.setText(username); final EventHandler textChanged = e -> { @@ -133,7 +126,7 @@ public final class UserSettingsPane extends OnlyIfOnlineSettingsPane { } // Displaying the save button - saveButton.setOnAction(e -> save(user.getID(), currentPasswordField.getText())); + saveButton.setOnAction(e -> save(client.getSender().getID(), currentPasswordField.getText())); saveButton.setAlignment(Pos.BOTTOM_RIGHT); getChildren().add(saveButton); } @@ -150,7 +143,7 @@ public final class UserSettingsPane extends OnlyIfOnlineSettingsPane { if (profilePicChanged) { final var profilePicChangeEvent = new ProfilePicChange(currentImageBytes, userID); eventBus.dispatch(profilePicChangeEvent); - eventBus.dispatch(new SendEvent(profilePicChangeEvent)); + client.send(profilePicChangeEvent); logger.log(Level.INFO, "The user just changed his profile pic."); } @@ -158,8 +151,8 @@ public final class UserSettingsPane extends OnlyIfOnlineSettingsPane { final var validContactName = Bounds.isValidContactName(newUsername); if (usernameChanged && validContactName) { final var nameChangeEvent = new NameChange(userID, newUsername); - eventBus.dispatch(new SendEvent(nameChangeEvent)); eventBus.dispatch(nameChangeEvent); + client.send(nameChangeEvent); logger.log(Level.INFO, "The user just changed his name to " + newUsername + "."); } else if (!validContactName) { final var alert = new Alert(AlertType.ERROR); @@ -172,14 +165,13 @@ public final class UserSettingsPane extends OnlyIfOnlineSettingsPane { // The password was changed if (validPassword) { - eventBus.dispatch(new SendEvent(new PasswordChangeRequest(newPassword, oldPassword, userID))); + client.send(new PasswordChangeRequest(newPassword, oldPassword, userID)); logger.log(Level.INFO, "The user just tried to change his password!"); } else if (!(validPassword || newPassword.isBlank())) { final var alert = new Alert(AlertType.ERROR); alert.setTitle("Unequal Password"); alert.setContentText("Repeated password is unequal to the chosen new password"); alert.showAndWait(); - return; } } } diff --git a/client/src/main/java/envoy/client/ui/settings/package-info.java b/client/src/main/java/envoy/client/ui/settings/package-info.java index e908b93..ea3fdb6 100644 --- a/client/src/main/java/envoy/client/ui/settings/package-info.java +++ b/client/src/main/java/envoy/client/ui/settings/package-info.java @@ -1,10 +1,6 @@ /** * This package contains classes used for representing the settings * visually. - *

    - * Project: envoy-client
    - * File: package-info.java
    - * Created: 19 Apr 2020
    * * @author Leon Hofmeister * @author Kai S. K. Engelbart diff --git a/client/src/main/java/envoy/client/ui/IconUtil.java b/client/src/main/java/envoy/client/util/IconUtil.java similarity index 87% rename from client/src/main/java/envoy/client/ui/IconUtil.java rename to client/src/main/java/envoy/client/util/IconUtil.java index 2da4d35..42a8554 100644 --- a/client/src/main/java/envoy/client/ui/IconUtil.java +++ b/client/src/main/java/envoy/client/util/IconUtil.java @@ -1,9 +1,8 @@ -package envoy.client.ui; +package envoy.client.util; import java.awt.image.BufferedImage; import java.io.IOException; -import java.util.EnumMap; -import java.util.EnumSet; +import java.util.*; import java.util.logging.Level; import javax.imageio.ImageIO; @@ -16,10 +15,6 @@ import envoy.util.EnvoyLog; /** * Provides static utility methods for loading icons from the resource * folder. - *

    - * Project: envoy-client
    - * File: IconUtil.java
    - * Created: 16.03.2020
    * * @author Kai S. K. Engelbart * @since Envoy Client v0.1-beta @@ -35,15 +30,7 @@ public final class IconUtil { * @return the loaded image * @since Envoy Client v0.1-beta */ - public static Image load(String path) { - Image image = null; - try { - image = new Image(IconUtil.class.getResource(path).toExternalForm()); - } catch (final NullPointerException e) { - EnvoyLog.getLogger(IconUtil.class).log(Level.WARNING, String.format("Could not load image at path %s: ", path), e); - } - return image; - } + public static Image load(String path) { return new Image(IconUtil.class.getResource(path).toExternalForm()); } /** * Loads an image from the resource folder and scales it to the given size. @@ -54,13 +41,7 @@ public final class IconUtil { * @since Envoy Client v0.1-beta */ public static Image load(String path, int size) { - Image image = null; - try { - image = new Image(IconUtil.class.getResource(path).toExternalForm(), size, size, true, true); - } catch (final NullPointerException e) { - EnvoyLog.getLogger(IconUtil.class).log(Level.WARNING, String.format("Could not load image at path %s: ", path), e); - } - return image; + return new Image(IconUtil.class.getResource(path).toExternalForm(), size, size, true, true); } /** diff --git a/client/src/main/java/envoy/client/util/IssueUtil.java b/client/src/main/java/envoy/client/util/IssueUtil.java index 6c6e165..8933a67 100644 --- a/client/src/main/java/envoy/client/util/IssueUtil.java +++ b/client/src/main/java/envoy/client/util/IssueUtil.java @@ -2,39 +2,34 @@ package envoy.client.util; /** * Provides methods to handle outgoing issues. - *

    - * Project: client
    - * File: IssueUtil.java
    - * Created: 20.08.2020
    * * @author Leon Hofmeister + * @author Kai S. K. Engelbart * @since Envoy Client v0.2-beta */ public final class IssueUtil { - /** - * - * @since Envoy Client v0.2-beta - */ private IssueUtil() {} /** - * Performs actions to ensure the description of an issue will be displayed as - * intended by the user. + * Normalizes line breaks and appends the user name to the issue description if + * requested. * - * @param rawDescription the description to sanitize - * @param username the user who submitted the issue. Should be - * {@code null} if he does not want to be named. + * @param description the description to sanitize + * @param username the user who submitted the issue. Should be + * {@code null} if he does not want to be named. * @return the sanitized description * @since Envoy Client v0.2-beta */ - public static String sanitizeIssueDescription(String rawDescription, String username) { - // Appending the submitter name, if this option was enabled - rawDescription += username != null - ? (rawDescription.endsWith("\n") || rawDescription.endsWith("
    ") ? "" : "
    ") + String.format("Submitted by user %s.", username) - : ""; - // Markdown does not support "normal" line breaks. It uses "
    " - rawDescription = rawDescription.replaceAll(System.getProperty("line.separator", "\r?\n"), "
    "); - return rawDescription; + public static String sanitizeIssueDescription(String description, String username) { + + // Trim and replace line breaks by
    tags + description = description.trim().replaceAll(System.getProperty("line.separator"), "
    "); + + // Append user name if requested + if (username != null) + description += String.format("
    Submitted by user %s.", username); + + return description; } } diff --git a/client/src/main/java/envoy/client/util/ReflectionUtil.java b/client/src/main/java/envoy/client/util/ReflectionUtil.java index abdfd51..27ea492 100644 --- a/client/src/main/java/envoy/client/util/ReflectionUtil.java +++ b/client/src/main/java/envoy/client/util/ReflectionUtil.java @@ -1,17 +1,11 @@ package envoy.client.util; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; +import java.util.*; +import java.util.stream.*; import javafx.scene.Node; /** - * Project: envoy-client
    - * File: ReflectionUtil.java
    - * Created: 02.08.2020
    - * * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ @@ -20,8 +14,10 @@ public final class ReflectionUtil { private ReflectionUtil() {} /** - * Gets all declared variables of the given instance that have the specified - * class
    + * Gets all declared variable values of the given instance that have the + * specified + * class. + *

    * (i.e. can get all {@code JComponents} (Swing) or {@code Nodes} (JavaFX) in a * GUI class). *

    @@ -41,13 +37,11 @@ public final class ReflectionUtil { return Arrays.stream(instance.getClass().getDeclaredFields()).filter(field -> typeToReturn.isAssignableFrom(field.getType())).map(field -> { try { field.setAccessible(true); - final var value = field.get(instance); - return value; + return typeToReturn.cast(field.get(instance)); } catch (IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException(e); } - }).map(typeToReturn::cast);// field -> - // typeToReturn.isAssignableFrom(field.getClass())).map(typeToReturn::cast); + }); } /** diff --git a/client/src/main/java/envoy/client/util/package-info.java b/client/src/main/java/envoy/client/util/package-info.java index c6b342e..77db956 100644 --- a/client/src/main/java/envoy/client/util/package-info.java +++ b/client/src/main/java/envoy/client/util/package-info.java @@ -1,9 +1,5 @@ /** * This package contains utility classes for use in envoy-client. - *

    - * Project: envoy-client
    - * File: package-info.java
    - * Created: 02.08.2020
    * * @author Leon Hofmeister * @since Envoy Client v0.2-beta diff --git a/client/src/main/java/module-info.java b/client/src/main/java/module-info.java index 4382521..e0f86ba 100644 --- a/client/src/main/java/module-info.java +++ b/client/src/main/java/module-info.java @@ -20,7 +20,7 @@ module envoy.client { opens envoy.client.ui to javafx.graphics, javafx.fxml, dev.kske.eventbus; opens envoy.client.ui.controller to javafx.graphics, javafx.fxml, envoy.client.util, dev.kske.eventbus; - opens envoy.client.ui.custom to javafx.graphics, javafx.fxml; + opens envoy.client.ui.control to javafx.graphics, javafx.fxml; opens envoy.client.ui.settings to envoy.client.util; opens envoy.client.net to dev.kske.eventbus; opens envoy.client.data to dev.kske.eventbus; diff --git a/common/src/main/java/envoy/data/Attachment.java b/common/src/main/java/envoy/data/Attachment.java index 292284a..31e83fb 100644 --- a/common/src/main/java/envoy/data/Attachment.java +++ b/common/src/main/java/envoy/data/Attachment.java @@ -5,10 +5,6 @@ import java.io.Serializable; /** * This interface should be used for any type supposed to be a {@link Message} * attachment (i.e. images or sound). - *

    - * Project: envoy-common
    - * File: Attachment.java
    - * Created: 30 Dec 2019
    * * @author Leon Hofmeister * @author Kai S. K. Engelbart diff --git a/common/src/main/java/envoy/data/Config.java b/common/src/main/java/envoy/data/Config.java index 7b7c097..74798fb 100644 --- a/common/src/main/java/envoy/data/Config.java +++ b/common/src/main/java/envoy/data/Config.java @@ -1,7 +1,6 @@ package envoy.data; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.util.*; import java.util.function.Function; import java.util.logging.Level; @@ -19,10 +18,6 @@ import envoy.util.EnvoyLog; * default value or over command line argument. Developers that fail to provide * default values will be greeted with an error message the next time they try * to start Envoy... - *

    - * Project: envoy-client
    - * File: Config.java
    - * Created: 12 Oct 2019
    * * @author Kai S. K. Engelbart * @since Envoy Common v0.1-beta @@ -104,6 +99,7 @@ public class Config { public void loadAll(Class declaringClass, String propertiesFilePath, String[] args) { if (modificationDisabled) throw new IllegalStateException("Cannot change config after isInitialized has been called"); + // Load the defaults from the given .properties file first final var properties = new Properties(); try { @@ -120,6 +116,7 @@ public class Config { // Check if all configuration values have been initialized isInitialized(); + // Disable further editing of the config modificationDisabled = true; } @@ -130,10 +127,9 @@ public class Config { * @since Envoy Common v0.1-beta */ private void isInitialized() { - if (items.values().stream().map(ConfigItem::get).anyMatch(Objects::isNull)) - throw new IllegalStateException("config item(s) has/ have not been initialized:" - + items.values().stream().filter(configItem -> configItem.get() == null) - .map(ConfigItem::getCommandLong).collect(Collectors.toSet())); + String uninitialized = items.values().stream().filter(c -> c.get() == null).map(ConfigItem::getCommandLong).collect(Collectors.joining(", ")); + if(!uninitialized.isEmpty()) + throw new IllegalStateException("Config items uninitialized: " + uninitialized); } /** diff --git a/common/src/main/java/envoy/data/ConfigItem.java b/common/src/main/java/envoy/data/ConfigItem.java index 5f61750..e3bdc42 100644 --- a/common/src/main/java/envoy/data/ConfigItem.java +++ b/common/src/main/java/envoy/data/ConfigItem.java @@ -7,10 +7,6 @@ import java.util.function.Function; * line arguments and its default value. *

    * All {@code ConfigItem}s are automatically mandatory. - *

    - * Project: envoy-clientChess
    - * File: ConfigItem.javaEvent.java
    - * Created: 21.12.2019
    * * @author Kai S. K. Engelbart * @param the type of the config item's value diff --git a/common/src/main/java/envoy/data/Contact.java b/common/src/main/java/envoy/data/Contact.java index 3fe71da..278b056 100644 --- a/common/src/main/java/envoy/data/Contact.java +++ b/common/src/main/java/envoy/data/Contact.java @@ -1,16 +1,11 @@ package envoy.data; import java.io.Serializable; -import java.util.Objects; -import java.util.Set; +import java.util.*; /** * This class is the superclass for both {@link User} and {@link Group}.
    * It provides an id and a name for each user and group.
    - *
    - * Project: envoy-common
    - * File: Contact.java
    - * Created: 24 Mar 2020
    * * @author Leon Hofmeister * @since Envoy v0.1-beta diff --git a/common/src/main/java/envoy/data/Group.java b/common/src/main/java/envoy/data/Group.java index fd7d074..40a0cb1 100644 --- a/common/src/main/java/envoy/data/Group.java +++ b/common/src/main/java/envoy/data/Group.java @@ -1,15 +1,9 @@ package envoy.data; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.HashSet; -import java.util.Set; +import java.io.*; +import java.util.*; /** - * Project: envoy-common
    - * File: Group.java
    - * Created: 24 Mar 2020
    - * * @author Leon Hofmeister * @since Envoy Common v0.1-beta */ diff --git a/common/src/main/java/envoy/data/GroupMessage.java b/common/src/main/java/envoy/data/GroupMessage.java index 93b8658..fec27f8 100644 --- a/common/src/main/java/envoy/data/GroupMessage.java +++ b/common/src/main/java/envoy/data/GroupMessage.java @@ -1,14 +1,9 @@ package envoy.data; import java.time.Instant; -import java.util.Collections; -import java.util.Map; +import java.util.*; /** - * Project: envoy-common
    - * File: GroupMessage.java
    - * Created: 26.03.2020
    - * * @author Maximilian Käfer * @since Envoy Common v0.1-beta */ diff --git a/common/src/main/java/envoy/data/IDGenerator.java b/common/src/main/java/envoy/data/IDGenerator.java index 45d6966..3040538 100644 --- a/common/src/main/java/envoy/data/IDGenerator.java +++ b/common/src/main/java/envoy/data/IDGenerator.java @@ -3,11 +3,7 @@ package envoy.data; import java.io.Serializable; /** - * Generates increasing IDs between two numbers.
    - *
    - * Project: envoy-common
    - * File: IDGenerator.java
    - * Created: 31.12.2019
    + * Generates increasing IDs between two numbers. * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha diff --git a/common/src/main/java/envoy/data/LoginCredentials.java b/common/src/main/java/envoy/data/LoginCredentials.java index e4edd72..3848989 100644 --- a/common/src/main/java/envoy/data/LoginCredentials.java +++ b/common/src/main/java/envoy/data/LoginCredentials.java @@ -9,10 +9,6 @@ import java.time.Instant; *

    * If the authentication is performed with a token, the token is stored instead * of the password. - *

    - * Project: envoy-common
    - * File: LoginCredentials.java
    - * Created: 29.12.2019
    * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha diff --git a/common/src/main/java/envoy/data/Message.java b/common/src/main/java/envoy/data/Message.java index 3258e34..e642566 100644 --- a/common/src/main/java/envoy/data/Message.java +++ b/common/src/main/java/envoy/data/Message.java @@ -9,10 +9,6 @@ import dev.kske.eventbus.IEvent; * Represents a unique message with a unique, numeric ID. Further metadata * includes the sender and recipient {@link User}s, as well as the creation * date and the current {@link MessageStatus}.
    - *
    - * Project: envoy-common
    - * File: Message.java
    - * Created: 28.12.2019
    * * @author Kai S. K. Engelbart * @author Leon Hofmeister @@ -28,23 +24,22 @@ public class Message implements Serializable, IEvent { public enum MessageStatus { /** - * is selected, if a message was sent but not received by the server yet. + * The message has not yet been sent to the server */ WAITING, /** - * is selected, if a sent message was received by the server. + * The message has been sent to the server. */ SENT, /** - * is selected, if a message was delivered from the server to the recipient, but - * has not been read yet. + * The message has been received by its recipient. */ RECEIVED, /** - * is selected, if a recipient opened the corresponding chat of said message. + * The message has been read by its recipient. */ READ } diff --git a/common/src/main/java/envoy/data/MessageBuilder.java b/common/src/main/java/envoy/data/MessageBuilder.java index b1a3f74..9c5eb95 100644 --- a/common/src/main/java/envoy/data/MessageBuilder.java +++ b/common/src/main/java/envoy/data/MessageBuilder.java @@ -7,10 +7,6 @@ import envoy.data.Message.MessageStatus; /** * Provides a method of constructing the {@link Message} class.
    - *
    - * Project: envoy-common
    - * File: MessageBuilder.java
    - * Created: 31.12.2019
    * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha diff --git a/common/src/main/java/envoy/data/User.java b/common/src/main/java/envoy/data/User.java index a423934..ab83070 100644 --- a/common/src/main/java/envoy/data/User.java +++ b/common/src/main/java/envoy/data/User.java @@ -1,17 +1,11 @@ package envoy.data; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.HashSet; -import java.util.Set; +import java.io.*; +import java.util.*; /** * Represents a unique user with a unique, numeric ID, a name and a current * {@link UserStatus}.
    - *
    - * Project: envoy-common
    - * File: User.java
    - * Created: 28.12.2019
    * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha @@ -32,7 +26,7 @@ public final class User extends Contact { * * @since Envoy Common v0.2-alpha */ - public static enum UserStatus { + public enum UserStatus { /** * select this, if a user is online and can be interacted with diff --git a/common/src/main/java/envoy/data/package-info.java b/common/src/main/java/envoy/data/package-info.java index 39df4f5..10865d0 100644 --- a/common/src/main/java/envoy/data/package-info.java +++ b/common/src/main/java/envoy/data/package-info.java @@ -1,6 +1,6 @@ /** * This package contains all data objects that are used both by Envoy Client and - * by Envoy Server Standalone. + * by Envoy Server. * * @author Leon Hofmeister * @author Maximilian Käfer diff --git a/common/src/main/java/envoy/event/ElementOperation.java b/common/src/main/java/envoy/event/ElementOperation.java index b7d4c10..e585a84 100644 --- a/common/src/main/java/envoy/event/ElementOperation.java +++ b/common/src/main/java/envoy/event/ElementOperation.java @@ -1,13 +1,10 @@ package envoy.event; /** - * This enum declares all modification possibilities for a given container.
    + * This enum declares all modification possibilities for a given container. + *

    * These can be: {@link ElementOperation#ADD} or - * {@link ElementOperation#REMOVE}.
    - *
    - * Project: envoy-common
    - * File: ElementOperation.java
    - * Created: 25 Mar 2020
    + * {@link ElementOperation#REMOVE}. * * @author Leon Hofmeister * @since Envoy Common v0.1-beta diff --git a/common/src/main/java/envoy/event/Event.java b/common/src/main/java/envoy/event/Event.java index 33ccc24..da3bc72 100644 --- a/common/src/main/java/envoy/event/Event.java +++ b/common/src/main/java/envoy/event/Event.java @@ -8,10 +8,6 @@ import dev.kske.eventbus.IEvent; * This class serves as a convenience base class for all events. It implements * the {@link IEvent} interface and provides a generic value. For events without * a value there also is {@link envoy.event.Event.Valueless}. - *

    - * Project: envoy-common
    - * File: Event.java
    - * Created: 04.12.2019
    * * @author Kai S. K. Engelbart * @param the type of the Event @@ -34,11 +30,7 @@ public abstract class Event implements IEvent, Serializable { public String toString() { return String.format("%s[value=%s]", this.getClass().getSimpleName(), value); } /** - * Serves as a super class for events that do not carry a value.
    - *
    - * Project: envoy-common
    - * File: Event.java
    - * Created: 11 Feb 2020
    + * Serves as a super class for events that do not carry a value. * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha diff --git a/common/src/main/java/envoy/event/GroupCreation.java b/common/src/main/java/envoy/event/GroupCreation.java index e7a8a2c..02270ee 100644 --- a/common/src/main/java/envoy/event/GroupCreation.java +++ b/common/src/main/java/envoy/event/GroupCreation.java @@ -1,16 +1,11 @@ package envoy.event; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import envoy.data.User; /** - * This event creates a group with the given name.
    - *
    - * Project: envoy-common
    - * File: GroupCreation.java
    - * Created: 25 Mar 2020
    + * This event creates a group with the given name. * * @author Leon Hofmeister * @since Envoy Common v0.1-beta @@ -30,7 +25,7 @@ public final class GroupCreation extends Event { */ public GroupCreation(String value, Set initialMemberIDs) { super(value); - this.initialMemberIDs = (initialMemberIDs != null) ? initialMemberIDs : new HashSet<>(); + this.initialMemberIDs = initialMemberIDs != null ? initialMemberIDs : new HashSet<>(); } /** diff --git a/common/src/main/java/envoy/event/GroupCreationResult.java b/common/src/main/java/envoy/event/GroupCreationResult.java index a43621f..3944ec2 100644 --- a/common/src/main/java/envoy/event/GroupCreationResult.java +++ b/common/src/main/java/envoy/event/GroupCreationResult.java @@ -3,10 +3,6 @@ package envoy.event; /** * Used to communicate with a client that his request to create a group might * have been rejected as it might be disabled on his current server. - *

    - * Project: common
    - * File: GroupCreationResult.java
    - * Created: 22.08.2020
    * * @author Leon Hofmeister * @since Envoy Common v0.2-beta diff --git a/common/src/main/java/envoy/event/GroupMessageStatusChange.java b/common/src/main/java/envoy/event/GroupMessageStatusChange.java index 50f6ae3..30d286e 100644 --- a/common/src/main/java/envoy/event/GroupMessageStatusChange.java +++ b/common/src/main/java/envoy/event/GroupMessageStatusChange.java @@ -6,10 +6,6 @@ import envoy.data.GroupMessage; import envoy.data.Message.MessageStatus; /** - * Project: envoy-common
    - * File: GroupMessageStatusChange.java
    - * Created: 18.04.2020
    - * * @author Maximilian Käfer * @since Envoy Common v0.1-beta */ diff --git a/common/src/main/java/envoy/event/GroupResize.java b/common/src/main/java/envoy/event/GroupResize.java index 6aec843..c8e8c76 100644 --- a/common/src/main/java/envoy/event/GroupResize.java +++ b/common/src/main/java/envoy/event/GroupResize.java @@ -1,18 +1,15 @@ package envoy.event; -import envoy.data.Contact; -import envoy.data.Group; -import envoy.data.User; +import static envoy.event.ElementOperation.*; + +import envoy.data.*; /** * This event is used to communicate changes in the group size between client - * and server.
    + * and server. + *

    * Possible actions are adding or removing certain {@link User}s to or from a * certain {@link Group}. - *
    - * Project: envoy-common
    - * File: GroupResize.java
    - * Created: 25 Mar 2020
    * * @author Leon Hofmeister * @since Envoy Common v0.1-beta @@ -36,13 +33,13 @@ public final class GroupResize extends Event { */ public GroupResize(User user, Group group, ElementOperation operation) { super(user); - if (group.getContacts().contains(user)) { - if (operation.equals(ElementOperation.ADD)) throw new IllegalArgumentException( - "Cannot add " + user + " to group " + group.getID() + " because he is already a member of this group"); - } else if (operation.equals(ElementOperation.REMOVE)) - throw new IllegalArgumentException("Cannot remove " + user + " from group " + group.getID() + " because he is no part of this group"); - groupID = group.getID(); this.operation = operation; + if (group.getContacts().contains(user)) { + if (operation.equals(ADD)) + throw new IllegalArgumentException(String.format("Cannot add %s to %s!", user, group)); + } else if (operation.equals(REMOVE)) + throw new IllegalArgumentException(String.format("Cannot remove %s from %s!", user, group)); + groupID = group.getID(); } /** @@ -58,8 +55,22 @@ public final class GroupResize extends Event { public ElementOperation getOperation() { return operation; } /** - * {@inheritDoc} + * Applies the operation to a group. + * + * @param group the group to resize + * @since Envoy Common v0.2-beta */ + public void apply(Group group) { + switch (operation) { + case ADD: + group.getContacts().add(value); + break; + case REMOVE: + group.getContacts().remove(value); + break; + } + } + @Override public String toString() { return String.format("GroupResize[userid=%d,groupid=%d,operation=%s]", get(), groupID, operation); } } diff --git a/common/src/main/java/envoy/event/HandshakeRejection.java b/common/src/main/java/envoy/event/HandshakeRejection.java index b609085..6895fff 100644 --- a/common/src/main/java/envoy/event/HandshakeRejection.java +++ b/common/src/main/java/envoy/event/HandshakeRejection.java @@ -3,10 +3,6 @@ package envoy.event; /** * Signifies to the client that the handshake failed for the attached * reason. - *

    - * Project: envoy-common
    - * File: HandshakeRejection.java
    - * Created: 28 Jan 2020
    * * @author Kai S. K. Engelbart * @since Envoy Common v0.3-alpha diff --git a/common/src/main/java/envoy/event/IDGeneratorRequest.java b/common/src/main/java/envoy/event/IDGeneratorRequest.java index 70b49bd..09e8265 100644 --- a/common/src/main/java/envoy/event/IDGeneratorRequest.java +++ b/common/src/main/java/envoy/event/IDGeneratorRequest.java @@ -2,11 +2,7 @@ package envoy.event; /** * Signifies to the server that the client needs a new - * {@link envoy.data.IDGenerator} instance.
    - *
    - * Project: envoy-common
    - * File: IDGeneratorRequest.java
    - * Created: 28 Jan 2020
    + * {@link envoy.data.IDGenerator} instance. * * @author Kai S. K. Engelbart * @since Envoy Common v0.3-alpha diff --git a/common/src/main/java/envoy/event/IsTyping.java b/common/src/main/java/envoy/event/IsTyping.java index bb2d2c3..0b6f544 100644 --- a/common/src/main/java/envoy/event/IsTyping.java +++ b/common/src/main/java/envoy/event/IsTyping.java @@ -3,10 +3,6 @@ package envoy.event; /** * This event should be sent when a user is currently typing something in a * chat. - *

    - * Project: envoy-client
    - * File: IsTyping.java
    - * Created: 24.07.2020
    * * @author Leon Hofmeister * @since Envoy Client v0.2-beta @@ -18,7 +14,8 @@ public final class IsTyping extends Event { private static final long serialVersionUID = 1L; /** - * The number of milliseconds that this event will be active.
    + * The number of milliseconds that this event will be active. + *

    * Currently set to 3.5 seconds. * * @since Envoy Common v0.2-beta @@ -28,8 +25,8 @@ public final class IsTyping extends Event { /** * Creates a new {@code IsTyping} event with originator and recipient. * - * @param sourceID the id of the originator - * @param destinationID the id of the contact the user wrote to + * @param sourceID the ID of the originator + * @param destinationID the ID of the contact the user wrote to * @since Envoy Common v0.2-beta */ public IsTyping(Long sourceID, long destinationID) { @@ -38,7 +35,7 @@ public final class IsTyping extends Event { } /** - * @return the id of the contact in whose chat the user typed something + * @return the ID of the contact in whose chat the user typed something * @since Envoy Common v0.2-beta */ public long getDestinationID() { return destinationID; } diff --git a/common/src/main/java/envoy/event/IssueProposal.java b/common/src/main/java/envoy/event/IssueProposal.java index 5150a25..63c54f1 100644 --- a/common/src/main/java/envoy/event/IssueProposal.java +++ b/common/src/main/java/envoy/event/IssueProposal.java @@ -2,11 +2,7 @@ package envoy.event; /** * This class allows envoy users to send an issue proposal to the server who, if - * not disabled by its admin, will forward it directly to gitea. - *

    - * Project: common
    - * File: IssueProposal.java
    - * Created: 05.08.2020
    + * not disabled by its administrator, will forward it directly to Gitea. * * @author Leon Hofmeister * @since Envoy Common v0.2-beta diff --git a/common/src/main/java/envoy/event/MessageStatusChange.java b/common/src/main/java/envoy/event/MessageStatusChange.java index aa94e6d..33e2cb3 100644 --- a/common/src/main/java/envoy/event/MessageStatusChange.java +++ b/common/src/main/java/envoy/event/MessageStatusChange.java @@ -5,10 +5,6 @@ import java.time.Instant; import envoy.data.Message; /** - * Project: envoy-common
    - * File: MessageStatusChange.java
    - * Created: 6 Jan 2020
    - * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ diff --git a/common/src/main/java/envoy/event/NameChange.java b/common/src/main/java/envoy/event/NameChange.java index b4558a7..368f4bc 100644 --- a/common/src/main/java/envoy/event/NameChange.java +++ b/common/src/main/java/envoy/event/NameChange.java @@ -3,14 +3,11 @@ package envoy.event; import envoy.data.Contact; /** - * This event informs
    + * This event informs + *

    * a) the server of the name change of a user or a group. * b) another user of this users name change. * - * Project: envoy-common
    - * File: NameChange.java
    - * Created: 25 Mar 2020
    - * * @author Leon Hofmeister * @since Envoy Common v0.1-beta */ diff --git a/common/src/main/java/envoy/event/NewAuthToken.java b/common/src/main/java/envoy/event/NewAuthToken.java index 81af7b6..82dccca 100644 --- a/common/src/main/java/envoy/event/NewAuthToken.java +++ b/common/src/main/java/envoy/event/NewAuthToken.java @@ -2,10 +2,6 @@ package envoy.event; /** * This event can be used to transmit a new authentication token to a client. - *

    - * Project: envoy-common
    - * File: NewAuthToken.java
    - * Created: 19.09.2020
    * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-beta diff --git a/common/src/main/java/envoy/event/NoAttachments.java b/common/src/main/java/envoy/event/NoAttachments.java index aace460..3622569 100644 --- a/common/src/main/java/envoy/event/NoAttachments.java +++ b/common/src/main/java/envoy/event/NoAttachments.java @@ -3,10 +3,6 @@ package envoy.event; /** * This event is used so that the server can tell the client that attachments * will be filtered out. - *

    - * Project: common
    - * File: NoAttachments.java
    - * Created: 22.08.2020
    * * @author Leon Hofmeister * @since Envoy Common v0.2-beta diff --git a/common/src/main/java/envoy/event/PasswordChangeRequest.java b/common/src/main/java/envoy/event/PasswordChangeRequest.java index 0556e25..59ec8fb 100644 --- a/common/src/main/java/envoy/event/PasswordChangeRequest.java +++ b/common/src/main/java/envoy/event/PasswordChangeRequest.java @@ -3,10 +3,6 @@ package envoy.event; import envoy.data.Contact; /** - * Project: envoy-common
    - * File: PasswordChangeRequest.java
    - * Created: 31.07.2020
    - * * @author Leon Hofmeister * @since Envoy Common v0.2-beta */ diff --git a/common/src/main/java/envoy/event/PasswordChangeResult.java b/common/src/main/java/envoy/event/PasswordChangeResult.java index 363e416..716404c 100644 --- a/common/src/main/java/envoy/event/PasswordChangeResult.java +++ b/common/src/main/java/envoy/event/PasswordChangeResult.java @@ -3,10 +3,6 @@ package envoy.event; /** * This class acts as a notice to the user whether his * {@link envoy.event.PasswordChangeRequest} was successful. - *

    - * Project: envoy-common
    - * File: PasswordChangeResult.java
    - * Created: 01.08.2020
    * * @author Leon Hofmeister * @since Envoy Common v0.2-beta diff --git a/common/src/main/java/envoy/event/ProfilePicChange.java b/common/src/main/java/envoy/event/ProfilePicChange.java index ceb2eff..3400dc4 100644 --- a/common/src/main/java/envoy/event/ProfilePicChange.java +++ b/common/src/main/java/envoy/event/ProfilePicChange.java @@ -1,10 +1,6 @@ package envoy.event; /** - * Project: envoy-common
    - * File: ProfilePicChange.java
    - * Created: 31.07.2020
    - * * @author Leon Hofmeister * @since Envoy Common v0.2-beta */ diff --git a/common/src/main/java/envoy/event/UserStatusChange.java b/common/src/main/java/envoy/event/UserStatusChange.java index e8c1f94..5a26f50 100644 --- a/common/src/main/java/envoy/event/UserStatusChange.java +++ b/common/src/main/java/envoy/event/UserStatusChange.java @@ -4,10 +4,6 @@ import envoy.data.User; import envoy.data.User.UserStatus; /** - * Project: envoy-common
    - * File: UserStatusChange.java
    - * Created: 1 Feb 2020
    - * * @author Leon Hofmeister * @since Envoy Common v0.2-alpha */ diff --git a/common/src/main/java/envoy/event/contact/ContactOperation.java b/common/src/main/java/envoy/event/contact/ContactOperation.java index 48427d5..a31d147 100644 --- a/common/src/main/java/envoy/event/contact/ContactOperation.java +++ b/common/src/main/java/envoy/event/contact/ContactOperation.java @@ -1,15 +1,10 @@ package envoy.event.contact; import envoy.data.Contact; -import envoy.event.ElementOperation; -import envoy.event.Event; +import envoy.event.*; /** - * Signifies the modification of a contact list.
    - *
    - * Project: envoy-common
    - * File: ContactOperation.java
    - * Created: 05.02.2020
    + * Signifies the modification of a contact list. * * @author Maximilian Käfer * @since Envoy Common v0.2-alpha diff --git a/common/src/main/java/envoy/event/contact/UserSearchRequest.java b/common/src/main/java/envoy/event/contact/UserSearchRequest.java index f615f0c..6eb1925 100644 --- a/common/src/main/java/envoy/event/contact/UserSearchRequest.java +++ b/common/src/main/java/envoy/event/contact/UserSearchRequest.java @@ -4,10 +4,6 @@ import envoy.event.Event; /** * Requests a user search from the server. - *

    - * Project: envoy-common
    - * File: UserSearchRequest.java
    - * Created: 05.02.2020
    * * @author Maximilian Käfer * @since Envoy Common v0.2-alpha diff --git a/common/src/main/java/envoy/event/contact/UserSearchResult.java b/common/src/main/java/envoy/event/contact/UserSearchResult.java index 86b4c09..6b1358b 100644 --- a/common/src/main/java/envoy/event/contact/UserSearchResult.java +++ b/common/src/main/java/envoy/event/contact/UserSearchResult.java @@ -7,10 +7,6 @@ import envoy.event.Event; /** * Contains a list of users for which a search has been requested. - *

    - * Project: envoy-common
    - * File: UserSearchResult.java
    - * Created: 11 Feb 2020
    * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha diff --git a/common/src/main/java/envoy/event/contact/package-info.java b/common/src/main/java/envoy/event/contact/package-info.java index 375ea89..e1abec1 100644 --- a/common/src/main/java/envoy/event/contact/package-info.java +++ b/common/src/main/java/envoy/event/contact/package-info.java @@ -1,9 +1,5 @@ /** - * This package contains all contact-related events.
    - *
    - * Project: envoy-common
    - * File: package-info.java
    - * Created: 28 Mar 2020
    + * This package contains all contact-related events. * * @author Leon Hofmeister * @author Maximilian Käfer diff --git a/common/src/main/java/envoy/exception/EnvoyException.java b/common/src/main/java/envoy/exception/EnvoyException.java index 0c02a52..a09b460 100644 --- a/common/src/main/java/envoy/exception/EnvoyException.java +++ b/common/src/main/java/envoy/exception/EnvoyException.java @@ -1,10 +1,6 @@ package envoy.exception; /** - * Project: envoy-common
    - * File: EnvoyException.java
    - * Created: 27 Oct 2019
    - * * @author Kai S. K. Engelbart * @since Envoy v0.1-alpha */ diff --git a/common/src/main/java/envoy/util/Bounds.java b/common/src/main/java/envoy/util/Bounds.java index c5575e0..bfb038c 100644 --- a/common/src/main/java/envoy/util/Bounds.java +++ b/common/src/main/java/envoy/util/Bounds.java @@ -3,12 +3,6 @@ package envoy.util; import java.util.regex.Pattern; /** - * Implements contact name validation. - *

    - * Project: envoy-common
    - * File: Bounds.java
    - * Created: 25.06.2020
    - * * @author Kai S. K. Engelbart * @since Envoy Common v0.1-beta */ diff --git a/common/src/main/java/envoy/util/EnvoyLog.java b/common/src/main/java/envoy/util/EnvoyLog.java index e28189e..55f3a42 100644 --- a/common/src/main/java/envoy/util/EnvoyLog.java +++ b/common/src/main/java/envoy/util/EnvoyLog.java @@ -1,7 +1,6 @@ package envoy.util; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.logging.*; @@ -11,10 +10,6 @@ import envoy.data.Config; /** * Configures the {@link java.util.logging} API to output the log into the * console and a log file. - *

    - * Project: envoy-client
    - * File: EnvoyLogger.java
    - * Created: 14.12.2019
    * * @author Leon Hofmeister * @author Kai S. K. Engelbart diff --git a/common/src/main/java/envoy/util/SerializationUtils.java b/common/src/main/java/envoy/util/SerializationUtils.java index 54fca82..f556657 100644 --- a/common/src/main/java/envoy/util/SerializationUtils.java +++ b/common/src/main/java/envoy/util/SerializationUtils.java @@ -4,10 +4,6 @@ import java.io.*; /** * Defines utility methods related to serialization. - *

    - * Project: envoy-client
    - * File: SerializationUtils.java
    - * Created: 23.12.2019
    * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha @@ -34,8 +30,8 @@ public final class SerializationUtils { * @since Envoy Common v0.2-alpha */ public static int bytesToInt(byte[] bytes, int offset) { - return ((bytes[offset] & 0xFF) << 24) | ((bytes[offset + 1] & 0xFF) << 16) | ((bytes[offset + 2] & 0xFF) << 8) - | ((bytes[offset + 3] & 0xFF) << 0); + return (bytes[offset] & 0xFF) << 24 | (bytes[offset + 1] & 0xFF) << 16 | (bytes[offset + 2] & 0xFF) << 8 + | (bytes[offset + 3] & 0xFF) << 0; } /** diff --git a/server/src/main/java/envoy/server/Startup.java b/server/src/main/java/envoy/server/Startup.java index 4f3f0d1..6beafee 100755 --- a/server/src/main/java/envoy/server/Startup.java +++ b/server/src/main/java/envoy/server/Startup.java @@ -6,20 +6,13 @@ import java.util.logging.Level; import com.jenkov.nioserver.Server; -import envoy.server.data.PersistenceManager; -import envoy.server.data.ServerConfig; -import envoy.server.net.ConnectionManager; -import envoy.server.net.ObjectMessageProcessor; -import envoy.server.net.ObjectMessageReader; +import envoy.server.data.*; +import envoy.server.net.*; import envoy.server.processors.*; import envoy.util.EnvoyLog; /** - * Starts the server.
    - *
    - * Project: envoy-server-standalone
    - * File: Startup.java
    - * Created: 24.12.2019
    + * Starts the server. * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha diff --git a/server/src/main/java/envoy/server/data/ConfigItem.java b/server/src/main/java/envoy/server/data/ConfigItem.java index ba8a2fe..ba3fff5 100755 --- a/server/src/main/java/envoy/server/data/ConfigItem.java +++ b/server/src/main/java/envoy/server/data/ConfigItem.java @@ -1,14 +1,8 @@ package envoy.server.data; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; +import javax.persistence.*; /** - * Project: envoy-server-standalone
    - * File: ConfigItem.java
    - * Created: 28 Jan 2020
    - * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ diff --git a/server/src/main/java/envoy/server/data/Contact.java b/server/src/main/java/envoy/server/data/Contact.java index a1e626d..36a302f 100644 --- a/server/src/main/java/envoy/server/data/Contact.java +++ b/server/src/main/java/envoy/server/data/Contact.java @@ -7,11 +7,7 @@ import javax.persistence.*; /** * This class acts as a superclass for all contacts, being {@link User}s and - * {@link Group}s.
    - *
    - * Project: envoy-server-standalone
    - * File: Contact.java
    - * Created: 24.03.2020
    + * {@link Group}s. * * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-alpha diff --git a/server/src/main/java/envoy/server/data/Group.java b/server/src/main/java/envoy/server/data/Group.java index 232c13e..f0ccb50 100644 --- a/server/src/main/java/envoy/server/data/Group.java +++ b/server/src/main/java/envoy/server/data/Group.java @@ -2,17 +2,11 @@ package envoy.server.data; import java.util.stream.Collectors; -import javax.persistence.Entity; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; +import javax.persistence.*; /** * Represents a group inside the database. Referred to as "server group" as - * opposed to "group" from Envoy Common.
    - *
    - * Project: envoy-server-standalone
    - * File: Group.java
    - * Created: 24.03.2020
    + * opposed to "group" from Envoy Common. * * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-alpha @@ -32,14 +26,14 @@ public final class Group extends Contact { /** * Named query retrieving a group by name (parameter {@code :name}). - * + * * @since Envoy Server Standalone v0.1-beta */ public static final String findByName = "Group.findByName"; - + /** * Named query retrieving all pending groups for a specific user (parameter {@code :user}, {@code :lastSeen}). - * + * * @since Envoy Server Standalone v0.1-beta */ public static final String findPendingGroups = "Group.findPendingGroups"; diff --git a/server/src/main/java/envoy/server/data/GroupMessage.java b/server/src/main/java/envoy/server/data/GroupMessage.java index 0bcd4e3..444a935 100644 --- a/server/src/main/java/envoy/server/data/GroupMessage.java +++ b/server/src/main/java/envoy/server/data/GroupMessage.java @@ -1,18 +1,13 @@ package envoy.server.data; import java.time.Instant; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import javax.persistence.*; import envoy.data.Group; /** - * Project: envoy-server-standalone
    - * File: GroupMessage.java
    - * Created: 18.04.2020
    - * * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-beta */ diff --git a/server/src/main/java/envoy/server/data/Message.java b/server/src/main/java/envoy/server/data/Message.java index 2468fe6..bd5f006 100755 --- a/server/src/main/java/envoy/server/data/Message.java +++ b/server/src/main/java/envoy/server/data/Message.java @@ -7,10 +7,9 @@ import java.time.Instant; import javax.persistence.*; -import envoy.data.Attachment; +import envoy.data.*; import envoy.data.Attachment.AttachmentType; import envoy.data.Message.MessageStatus; -import envoy.data.MessageBuilder; /** * This JPA entity, which will be referred to as database message, stores the @@ -21,10 +20,6 @@ import envoy.data.MessageBuilder; * {@link Message#Message(envoy.data.Message)} constructor. A database message * can be converted to a regular message using the {@link Message#toCommon()} * method. In both cases, the objects will not contain references to each other. - *

    - * Project: envoy-server-standalone
    - * File: Message.java
    - * Created: 02.01.2020
    * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha diff --git a/server/src/main/java/envoy/server/data/PersistenceManager.java b/server/src/main/java/envoy/server/data/PersistenceManager.java index fbadbb9..f601fe5 100755 --- a/server/src/main/java/envoy/server/data/PersistenceManager.java +++ b/server/src/main/java/envoy/server/data/PersistenceManager.java @@ -9,10 +9,6 @@ import envoy.data.User.UserStatus; import envoy.server.net.ConnectionManager; /** - * Project: envoy-server-standalone
    - * File: PersistenceManager.java
    - * Created: 1 Jan 2020
    - * * @author Leon Hofmeister * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-alpha diff --git a/server/src/main/java/envoy/server/data/ServerConfig.java b/server/src/main/java/envoy/server/data/ServerConfig.java index b16733d..96f4d01 100644 --- a/server/src/main/java/envoy/server/data/ServerConfig.java +++ b/server/src/main/java/envoy/server/data/ServerConfig.java @@ -5,10 +5,6 @@ import static java.util.function.Function.identity; import envoy.data.Config; /** - * Project: server
    - * File: ServerConfig.java
    - * Created: 21.08.2020
    - * * @author Leon Hofmeister * @since Envoy Server v0.2-beta */ diff --git a/server/src/main/java/envoy/server/data/User.java b/server/src/main/java/envoy/server/data/User.java index 341ebd4..e4c0829 100755 --- a/server/src/main/java/envoy/server/data/User.java +++ b/server/src/main/java/envoy/server/data/User.java @@ -11,11 +11,7 @@ import envoy.data.User.UserStatus; /** * This class enables the storage of user specific data inside a database using * Hibernate. Its objects will be referred to as database users as opposed to - * the common user objects present on both the client and the server.
    - *
    - * Project: envoy-server-standalone
    - * File: User.java
    - * Created: 02.01.2020
    + * the common user objects present on both the client and the server. * * @author Kai S. K. Engelbart * @author Maximilian Käfer diff --git a/server/src/main/java/envoy/server/net/ConnectionManager.java b/server/src/main/java/envoy/server/net/ConnectionManager.java index a43b357..2dc7d2d 100755 --- a/server/src/main/java/envoy/server/net/ConnectionManager.java +++ b/server/src/main/java/envoy/server/net/ConnectionManager.java @@ -7,15 +7,10 @@ import java.util.stream.Collectors; import com.jenkov.nioserver.ISocketIdListener; import envoy.data.User.UserStatus; -import envoy.server.data.Group; -import envoy.server.data.PersistenceManager; +import envoy.server.data.*; import envoy.server.processors.UserStatusChangeProcessor; /** - * Project: envoy-server-standalone
    - * File: ConnectionManager.java
    - * Created: 03.01.2020
    - * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ @@ -110,6 +105,6 @@ public final class ConnectionManager implements ISocketIdListener { * @since Envoy Server Standalone v0.1-beta */ public Set getOnlineUsersOfGroup(Group group) { - return group.getContacts().stream().map(envoy.server.data.Contact::getID).filter(this::isOnline).collect(Collectors.toSet()); + return group.getContacts().stream().map(Contact::getID).filter(this::isOnline).collect(Collectors.toSet()); } } diff --git a/server/src/main/java/envoy/server/net/ObjectMessageProcessor.java b/server/src/main/java/envoy/server/net/ObjectMessageProcessor.java index 2e43079..876b6ac 100755 --- a/server/src/main/java/envoy/server/net/ObjectMessageProcessor.java +++ b/server/src/main/java/envoy/server/net/ObjectMessageProcessor.java @@ -1,26 +1,17 @@ package envoy.server.net; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; +import java.io.*; import java.lang.reflect.ParameterizedType; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.logging.*; -import com.jenkov.nioserver.IMessageProcessor; -import com.jenkov.nioserver.Message; -import com.jenkov.nioserver.WriteProxy; +import com.jenkov.nioserver.*; import envoy.server.processors.ObjectProcessor; import envoy.util.EnvoyLog; /** - * Handles incoming objects.
    - *
    - * Project: envoy-server-standalone
    - * File: ObjectMessageProcessor.java
    - * Created: 28.12.2019
    + * Handles incoming objects. * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha @@ -55,14 +46,13 @@ public final class ObjectMessageProcessor implements IMessageProcessor { for (@SuppressWarnings("rawtypes") ObjectProcessor p : processors) { Class c = (Class) ((ParameterizedType) p.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0]; - if (c.equals(obj.getClass())) { + if (c.equals(obj.getClass())) try { p.process(c.cast(obj), message.socketId, new ObjectWriteProxy(writeProxy)); break; } catch (IOException e) { logger.log(Level.SEVERE, "Exception during processor execution: ", e); } - } } } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); diff --git a/server/src/main/java/envoy/server/net/ObjectMessageReader.java b/server/src/main/java/envoy/server/net/ObjectMessageReader.java index ddd2dca..a86c589 100755 --- a/server/src/main/java/envoy/server/net/ObjectMessageReader.java +++ b/server/src/main/java/envoy/server/net/ObjectMessageReader.java @@ -2,19 +2,14 @@ package envoy.server.net; import java.io.IOException; import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import com.jenkov.nioserver.*; import envoy.util.SerializationUtils; /** - * This {@link IMessageReader} decodes serialized Java objects.
    - *
    - * Project: envoy-server-standalone
    - * File: ObjectMessageReader.java
    - * Created: 28.12.2019
    + * This {@link IMessageReader} decodes serialized Java objects. * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha diff --git a/server/src/main/java/envoy/server/net/ObjectWriteProxy.java b/server/src/main/java/envoy/server/net/ObjectWriteProxy.java index 4e8229e..650b030 100755 --- a/server/src/main/java/envoy/server/net/ObjectWriteProxy.java +++ b/server/src/main/java/envoy/server/net/ObjectWriteProxy.java @@ -5,19 +5,13 @@ import java.util.Set; import java.util.logging.Logger; import java.util.stream.Stream; -import com.jenkov.nioserver.Message; -import com.jenkov.nioserver.WriteProxy; +import com.jenkov.nioserver.*; import envoy.server.data.Contact; -import envoy.util.EnvoyLog; -import envoy.util.SerializationUtils; +import envoy.util.*; /** - * This class defines methods to send an object to a client.
    - *
    - * Project: envoy-server-standalone
    - * File: ObjectWriteProxy.java
    - * Created: 04.01.2020
    + * This class defines methods to send an object to a client. * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha @@ -68,7 +62,7 @@ public final class ObjectWriteProxy { /** * Sends an object to all contact in a set that are online. - * + * * @param contacts the contacts to send the object to * @param message the object to send * @since Envoy Server Standalone v0.1-beta @@ -77,7 +71,7 @@ public final class ObjectWriteProxy { /** * Sends an object to all contact in a set that are online. - * + * * @param contacts the contacts to send the object to * @param message the object to send * @since Envoy Server Standalone v0.1-beta diff --git a/server/src/main/java/envoy/server/processors/ContactOperationProcessor.java b/server/src/main/java/envoy/server/processors/ContactOperationProcessor.java index ba4f240..178bff4 100755 --- a/server/src/main/java/envoy/server/processors/ContactOperationProcessor.java +++ b/server/src/main/java/envoy/server/processors/ContactOperationProcessor.java @@ -5,15 +5,10 @@ import java.util.logging.Logger; import envoy.event.ElementOperation; import envoy.event.contact.ContactOperation; import envoy.server.data.PersistenceManager; -import envoy.server.net.ConnectionManager; -import envoy.server.net.ObjectWriteProxy; +import envoy.server.net.*; import envoy.util.EnvoyLog; /** - * Project: envoy-server-standalone
    - * File: ContactOperationProcessor.java
    - * Created: 08.02.2020
    - * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ diff --git a/server/src/main/java/envoy/server/processors/GroupCreationProcessor.java b/server/src/main/java/envoy/server/processors/GroupCreationProcessor.java index 2839aeb..8f40af2 100644 --- a/server/src/main/java/envoy/server/processors/GroupCreationProcessor.java +++ b/server/src/main/java/envoy/server/processors/GroupCreationProcessor.java @@ -4,20 +4,12 @@ import static envoy.server.Startup.config; import java.util.HashSet; -import envoy.event.ElementOperation; -import envoy.event.GroupCreation; -import envoy.event.GroupCreationResult; +import envoy.event.*; import envoy.event.contact.ContactOperation; -import envoy.server.data.Contact; -import envoy.server.data.PersistenceManager; -import envoy.server.net.ConnectionManager; -import envoy.server.net.ObjectWriteProxy; +import envoy.server.data.*; +import envoy.server.net.*; /** - * Project: envoy-server-standalone
    - * File: GroupCreationProcessor.java
    - * Created: 26.03.2020
    - * * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-beta */ diff --git a/server/src/main/java/envoy/server/processors/GroupMessageProcessor.java b/server/src/main/java/envoy/server/processors/GroupMessageProcessor.java index 4cb7c2c..77ab232 100644 --- a/server/src/main/java/envoy/server/processors/GroupMessageProcessor.java +++ b/server/src/main/java/envoy/server/processors/GroupMessageProcessor.java @@ -10,18 +10,12 @@ import java.util.logging.Logger; import javax.persistence.EntityExistsException; import envoy.data.GroupMessage; -import envoy.event.MessageStatusChange; -import envoy.event.NoAttachments; +import envoy.event.*; import envoy.server.data.PersistenceManager; -import envoy.server.net.ConnectionManager; -import envoy.server.net.ObjectWriteProxy; +import envoy.server.net.*; import envoy.util.EnvoyLog; /** - * Project: envoy-server-standalone
    - * File: GroupMessageProcessor.java
    - * Created: 18.04.2020
    - * * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-beta */ diff --git a/server/src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java b/server/src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java index 515639b..2604698 100644 --- a/server/src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java +++ b/server/src/main/java/envoy/server/processors/GroupMessageStatusChangeProcessor.java @@ -4,23 +4,15 @@ import static envoy.data.Message.MessageStatus.READ; import java.time.Instant; import java.util.Collections; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.logging.*; import envoy.data.Message.MessageStatus; -import envoy.event.GroupMessageStatusChange; -import envoy.event.MessageStatusChange; -import envoy.server.data.GroupMessage; -import envoy.server.data.PersistenceManager; -import envoy.server.net.ConnectionManager; -import envoy.server.net.ObjectWriteProxy; +import envoy.event.*; +import envoy.server.data.*; +import envoy.server.net.*; import envoy.util.EnvoyLog; /** - * Project: envoy-server-standalone
    - * File: GroupMessageStatusChangeProcessor.java
    - * Created: 03.07.2020
    - * * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-beta */ diff --git a/server/src/main/java/envoy/server/processors/GroupResizeProcessor.java b/server/src/main/java/envoy/server/processors/GroupResizeProcessor.java index 86ec875..0a5b697 100644 --- a/server/src/main/java/envoy/server/processors/GroupResizeProcessor.java +++ b/server/src/main/java/envoy/server/processors/GroupResizeProcessor.java @@ -1,16 +1,10 @@ package envoy.server.processors; import envoy.event.GroupResize; -import envoy.server.data.Contact; -import envoy.server.data.PersistenceManager; -import envoy.server.net.ConnectionManager; -import envoy.server.net.ObjectWriteProxy; +import envoy.server.data.*; +import envoy.server.net.*; /** - * Project: envoy-server-standalone
    - * File: GroupResizeProcessor.java
    - * Created: 03.04.2020
    - * * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-beta */ diff --git a/server/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java b/server/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java index edd6e7b..0cf9823 100755 --- a/server/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java +++ b/server/src/main/java/envoy/server/processors/IDGeneratorRequestProcessor.java @@ -4,15 +4,10 @@ import java.io.IOException; import envoy.data.IDGenerator; import envoy.event.IDGeneratorRequest; -import envoy.server.data.ConfigItem; -import envoy.server.data.PersistenceManager; +import envoy.server.data.*; import envoy.server.net.ObjectWriteProxy; /** - * Project: envoy-server-standalone
    - * File: IDGeneratorRequestProcessor.java
    - * Created: 28 Jan 2020
    - * * @author Kai S. K. Engelbart * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-alpha diff --git a/server/src/main/java/envoy/server/processors/IsTypingProcessor.java b/server/src/main/java/envoy/server/processors/IsTypingProcessor.java index a147ed1..aaf2987 100644 --- a/server/src/main/java/envoy/server/processors/IsTypingProcessor.java +++ b/server/src/main/java/envoy/server/processors/IsTypingProcessor.java @@ -3,17 +3,11 @@ package envoy.server.processors; import java.io.IOException; import envoy.event.IsTyping; -import envoy.server.data.PersistenceManager; -import envoy.server.data.User; -import envoy.server.net.ConnectionManager; -import envoy.server.net.ObjectWriteProxy; +import envoy.server.data.*; +import envoy.server.net.*; /** * This processor handles incoming {@link IsTyping} events. - *

    - * Project: envoy-server-standalone
    - * File: IsTypingProcessor.java
    - * Created: 24.07.2020
    * * @author Leon Hofmeister * @since Envoy Server v0.2-beta diff --git a/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java b/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java index 78feb21..aa00ff1 100644 --- a/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java +++ b/server/src/main/java/envoy/server/processors/IssueProposalProcessor.java @@ -3,10 +3,8 @@ package envoy.server.processors; import static envoy.server.Startup.config; import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.net.*; +import java.util.logging.*; import envoy.event.IssueProposal; import envoy.server.net.ObjectWriteProxy; @@ -15,10 +13,6 @@ import envoy.util.EnvoyLog; /** * This processor handles incoming {@link IssueProposal}s and automatically * creates a new issue on the gitea site, if not disabled by its administrator. - *

    - * Project: server
    - * File: IssueProposalProcessor.java
    - * Created: 05.08.2020
    * * @author Leon Hofmeister * @since Envoy Server v0.2-beta diff --git a/server/src/main/java/envoy/server/processors/LoginCredentialProcessor.java b/server/src/main/java/envoy/server/processors/LoginCredentialProcessor.java index b14346f..b6c362b 100755 --- a/server/src/main/java/envoy/server/processors/LoginCredentialProcessor.java +++ b/server/src/main/java/envoy/server/processors/LoginCredentialProcessor.java @@ -19,11 +19,7 @@ import envoy.server.util.*; import envoy.util.*; /** - * This {@link ObjectProcessor} handles {@link LoginCredentials}.
    - *
    - * Project: envoy-server-standalone
    - * File: LoginCredentialProcessor.java
    - * Created: 30.12.2019
    + * This {@link ObjectProcessor} handles {@link LoginCredentials}. * * @author Kai S. K. Engelbart * @author Maximilian Käfer diff --git a/server/src/main/java/envoy/server/processors/MessageProcessor.java b/server/src/main/java/envoy/server/processors/MessageProcessor.java index 5b03007..e7605d6 100755 --- a/server/src/main/java/envoy/server/processors/MessageProcessor.java +++ b/server/src/main/java/envoy/server/processors/MessageProcessor.java @@ -2,25 +2,18 @@ package envoy.server.processors; import static envoy.server.Startup.config; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.logging.*; import javax.persistence.EntityExistsException; import envoy.data.Message; -import envoy.event.MessageStatusChange; -import envoy.event.NoAttachments; +import envoy.event.*; import envoy.server.data.PersistenceManager; -import envoy.server.net.ConnectionManager; -import envoy.server.net.ObjectWriteProxy; +import envoy.server.net.*; import envoy.util.EnvoyLog; /** * This {@link ObjectProcessor} handles incoming {@link Message}s. - *

    - * Project: envoy-server-standalone
    - * File: MessageProcessor.java
    - * Created: 30.12.2019
    * * @author Kai S. K. Engelbart * @author Maximilian Käfer diff --git a/server/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java b/server/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java index 950f0c2..83f08fe 100755 --- a/server/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java +++ b/server/src/main/java/envoy/server/processors/MessageStatusChangeProcessor.java @@ -1,21 +1,15 @@ package envoy.server.processors; import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.logging.*; import envoy.data.Message.MessageStatus; import envoy.event.MessageStatusChange; import envoy.server.data.PersistenceManager; -import envoy.server.net.ConnectionManager; -import envoy.server.net.ObjectWriteProxy; +import envoy.server.net.*; import envoy.util.EnvoyLog; /** - * Project: envoy-server-standalone
    - * File: MessageStatusChangeProcessor.java
    - * Created: 10 Jan 2020
    - * * @author Leon Hofmeister * @since Envoy Server Standalone v0.1-alpha */ diff --git a/server/src/main/java/envoy/server/processors/NameChangeProcessor.java b/server/src/main/java/envoy/server/processors/NameChangeProcessor.java index aa6897f..7914c37 100644 --- a/server/src/main/java/envoy/server/processors/NameChangeProcessor.java +++ b/server/src/main/java/envoy/server/processors/NameChangeProcessor.java @@ -3,15 +3,10 @@ package envoy.server.processors; import java.io.IOException; import envoy.event.NameChange; -import envoy.server.data.Contact; -import envoy.server.data.PersistenceManager; +import envoy.server.data.*; import envoy.server.net.ObjectWriteProxy; /** - * Project: envoy-server-standalone
    - * File: NameChangeProcessor.java
    - * Created: 26 Mar 2020
    - * * @author Leon Hofmeister * @since Envoy Server Standalone v0.1-beta */ diff --git a/server/src/main/java/envoy/server/processors/ObjectProcessor.java b/server/src/main/java/envoy/server/processors/ObjectProcessor.java index ab6666e..cebd1f2 100755 --- a/server/src/main/java/envoy/server/processors/ObjectProcessor.java +++ b/server/src/main/java/envoy/server/processors/ObjectProcessor.java @@ -6,11 +6,7 @@ import envoy.server.net.ObjectWriteProxy; /** * This interface defines methods for processing objects of a specific - * type incoming from a client.
    - *
    - * Project: envoy-server-standalone
    - * File: ObjectProcessor.java
    - * Created: 30.12.2019
    + * type incoming from a client. * * @author Kai S. K. Engelbart * @param type of the request object diff --git a/server/src/main/java/envoy/server/processors/PasswordChangeRequestProcessor.java b/server/src/main/java/envoy/server/processors/PasswordChangeRequestProcessor.java index 4b811a8..b275967 100644 --- a/server/src/main/java/envoy/server/processors/PasswordChangeRequestProcessor.java +++ b/server/src/main/java/envoy/server/processors/PasswordChangeRequestProcessor.java @@ -3,18 +3,13 @@ package envoy.server.processors; import java.io.IOException; import java.util.logging.Level; -import envoy.event.PasswordChangeRequest; -import envoy.event.PasswordChangeResult; +import envoy.event.*; import envoy.server.data.PersistenceManager; import envoy.server.net.ObjectWriteProxy; import envoy.server.util.PasswordUtil; import envoy.util.EnvoyLog; /** - * Project: envoy-server-standalone
    - * File: PasswordChangeRequestProcessor.java
    - * Created: 31.07.2020
    - * * @author Leon Hofmeister * @since Envoy Server v0.2-beta */ diff --git a/server/src/main/java/envoy/server/processors/ProfilePicChangeProcessor.java b/server/src/main/java/envoy/server/processors/ProfilePicChangeProcessor.java index f777ed8..112170c 100644 --- a/server/src/main/java/envoy/server/processors/ProfilePicChangeProcessor.java +++ b/server/src/main/java/envoy/server/processors/ProfilePicChangeProcessor.java @@ -6,10 +6,6 @@ import envoy.event.ProfilePicChange; import envoy.server.net.ObjectWriteProxy; /** - * Project: envoy-server-standalone
    - * File: ProfilePicChangeProcessor.java
    - * Created: 01.08.2020
    - * * @author Leon Hofmeister * @since Envoy Server v0.2-beta */ diff --git a/server/src/main/java/envoy/server/processors/UserSearchProcessor.java b/server/src/main/java/envoy/server/processors/UserSearchProcessor.java index 3504217..7166d6a 100755 --- a/server/src/main/java/envoy/server/processors/UserSearchProcessor.java +++ b/server/src/main/java/envoy/server/processors/UserSearchProcessor.java @@ -4,18 +4,11 @@ import java.io.IOException; import java.util.stream.Collectors; import envoy.data.Contact; -import envoy.event.contact.UserSearchRequest; -import envoy.event.contact.UserSearchResult; -import envoy.server.data.PersistenceManager; -import envoy.server.data.User; -import envoy.server.net.ConnectionManager; -import envoy.server.net.ObjectWriteProxy; +import envoy.event.contact.*; +import envoy.server.data.*; +import envoy.server.net.*; /** - * Project: envoy-server-standalone
    - * File: UserSearchProcessor.java
    - * Created: 08.02.2020
    - * * @author Kai S. K. Engelbart * @author Maximilian Käfer * @since Envoy Server Standalone v0.1-alpha diff --git a/server/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java b/server/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java index 57a9b25..9350af0 100755 --- a/server/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java +++ b/server/src/main/java/envoy/server/processors/UserStatusChangeProcessor.java @@ -4,17 +4,12 @@ import java.util.logging.Logger; import envoy.data.User.UserStatus; import envoy.event.UserStatusChange; -import envoy.server.data.PersistenceManager; -import envoy.server.data.User; +import envoy.server.data.*; import envoy.server.net.ObjectWriteProxy; import envoy.util.EnvoyLog; /** * This processor handles incoming {@link UserStatusChange}. - *

    - * Project: envoy-server-standalone
    - * File: UserStatusChangeProcessor.java
    - * Created: 1 Feb 2020
    * * @author Leon Hofmeister * @since Envoy Server Standalone v0.1-alpha diff --git a/server/src/main/java/envoy/server/util/AuthTokenGenerator.java b/server/src/main/java/envoy/server/util/AuthTokenGenerator.java index b74c77a..c6fc928 100644 --- a/server/src/main/java/envoy/server/util/AuthTokenGenerator.java +++ b/server/src/main/java/envoy/server/util/AuthTokenGenerator.java @@ -4,10 +4,6 @@ import java.security.SecureRandom; /** * Provides a secure token generation algorithm. - *

    - * Project: envoy-server
    - * File: AuthTokenGenerator.java
    - * Created: 19.09.2020
    * * @author Kai S. K. Engelbart * @since Envoy Server v0.2-beta diff --git a/server/src/main/java/envoy/server/util/PasswordUtil.java b/server/src/main/java/envoy/server/util/PasswordUtil.java index f3e3b3e..80ba6c1 100644 --- a/server/src/main/java/envoy/server/util/PasswordUtil.java +++ b/server/src/main/java/envoy/server/util/PasswordUtil.java @@ -1,9 +1,7 @@ package envoy.server.util; import java.math.BigInteger; -import java.security.GeneralSecurityException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; +import java.security.*; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; @@ -11,10 +9,6 @@ import javax.crypto.spec.PBEKeySpec; /** * Provides a password hashing and comparison mechanism using the * {@code PBKDF2WithHmacSHA1} algorithm. - *

    - * Project: envoy-server-standalone
    - * File: PasswordUtil.java
    - * Created: 10.07.2020
    * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-beta diff --git a/server/src/main/java/envoy/server/util/VersionUtil.java b/server/src/main/java/envoy/server/util/VersionUtil.java index 2d50796..aa1d661 100644 --- a/server/src/main/java/envoy/server/util/VersionUtil.java +++ b/server/src/main/java/envoy/server/util/VersionUtil.java @@ -5,10 +5,6 @@ import java.util.regex.Pattern; /** * Implements a comparison algorithm between Envoy versions and defines minimal * and maximal client versions compatible with this server. - *

    - * Project: envoy-server-standalone
    - * File: VersionUtil.java
    - * Created: 23.06.2020
    * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-beta diff --git a/server/src/main/java/envoy/server/util/package-info.java b/server/src/main/java/envoy/server/util/package-info.java index f052882..3cfc809 100644 --- a/server/src/main/java/envoy/server/util/package-info.java +++ b/server/src/main/java/envoy/server/util/package-info.java @@ -1,9 +1,5 @@ /** * This package contains utility classes used in Envoy Server. - *

    - * Project: envoy-server-standalone
    - * File: package-info.java
    - * Created: 23.06.2020
    * * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-beta From f6eeeee79b77da9ec25b835a5c1122be96d24dc6 Mon Sep 17 00:00:00 2001 From: kske Date: Fri, 25 Sep 2020 15:28:14 +0200 Subject: [PATCH 2/7] Remove message and event processors from client --- .../main/java/envoy/client/data/LocalDB.java | 21 +++++++++++- .../main/java/envoy/client/net/Client.java | 27 +++++++--------- .../GroupMessageStatusChangeProcessor.java | 25 --------------- .../net/MessageStatusChangeProcessor.java | 32 ------------------- .../net/ReceivedGroupMessageProcessor.java | 29 ----------------- .../client/net/ReceivedMessageProcessor.java | 24 -------------- .../envoy/client/ui/controller/ChatScene.java | 2 +- .../envoy/client/util/ReflectionUtil.java | 3 +- 8 files changed, 33 insertions(+), 130 deletions(-) delete mode 100644 client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java delete mode 100644 client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java delete mode 100644 client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java delete mode 100644 client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java diff --git a/client/src/main/java/envoy/client/data/LocalDB.java b/client/src/main/java/envoy/client/data/LocalDB.java index c6b527d..44cd639 100644 --- a/client/src/main/java/envoy/client/data/LocalDB.java +++ b/client/src/main/java/envoy/client/data/LocalDB.java @@ -5,10 +5,11 @@ import java.nio.channels.*; import java.nio.file.StandardOpenOption; import java.time.Instant; import java.util.*; -import java.util.logging.Level; +import java.util.logging.*; import envoy.client.event.EnvoyCloseEvent; import envoy.data.*; +import envoy.data.Message.MessageStatus; import envoy.event.*; import envoy.exception.EnvoyException; import envoy.util.*; @@ -45,6 +46,8 @@ public final class LocalDB implements EventListener { private final File dbDir, idGeneratorFile, lastLoginFile, usersFile; + private static final Logger logger = EnvoyLog.getLogger(LocalDB.class); + /** * Constructs an empty local database. * @@ -219,6 +222,22 @@ public final class LocalDB implements EventListener { } } + @Event(priority = 150) + private void onMessage(Message msg) { if (msg.getStatus() == MessageStatus.SENT) msg.nextStatus(); } + + @Event(priority = 150) + private void onGroupMessage(GroupMessage msg) { + // TODO: Cancel event once EventBus is updated + if (msg.getStatus() == MessageStatus.WAITING || msg.getStatus() == MessageStatus.READ) + logger.warning("The groupMessage has the unexpected status " + msg.getStatus()); + } + + @Event(priority = 150, includeSubtypes = true) + private void onMessageStatusChange(MessageStatusChange evt) { + // TODO: Cancel event once EventBus is updated + if (evt.get().ordinal() < MessageStatus.RECEIVED.ordinal()) logger.warning("Received invalid " + evt); + } + /** * Stores a new authentication token. * diff --git a/client/src/main/java/envoy/client/net/Client.java b/client/src/main/java/envoy/client/net/Client.java index 24f6664..149052b 100644 --- a/client/src/main/java/envoy/client/net/Client.java +++ b/client/src/main/java/envoy/client/net/Client.java @@ -125,21 +125,16 @@ public final class Client implements EventListener, Closeable { receiver.removeAllProcessors(); // Process incoming messages - final var receivedMessageProcessor = new ReceivedMessageProcessor(); - final var receivedGroupMessageProcessor = new ReceivedGroupMessageProcessor(); - final var messageStatusChangeProcessor = new MessageStatusChangeProcessor(); - final var groupMessageStatusChangeProcessor = new GroupMessageStatusChangeProcessor(); - - receiver.registerProcessor(GroupMessage.class, receivedGroupMessageProcessor); - receiver.registerProcessor(Message.class, receivedMessageProcessor); - receiver.registerProcessor(MessageStatusChange.class, messageStatusChangeProcessor); - receiver.registerProcessor(GroupMessageStatusChange.class, groupMessageStatusChangeProcessor); + receiver.registerProcessor(GroupMessage.class, eventBus::dispatch); + receiver.registerProcessor(Message.class, eventBus::dispatch); + receiver.registerProcessor(MessageStatusChange.class, eventBus::dispatch); + receiver.registerProcessor(GroupMessageStatusChange.class, eventBus::dispatch); // Relay cached messages and message status changes - cacheMap.get(Message.class).setProcessor(receivedMessageProcessor); - cacheMap.get(GroupMessage.class).setProcessor(receivedGroupMessageProcessor); - cacheMap.get(MessageStatusChange.class).setProcessor(messageStatusChangeProcessor); - cacheMap.get(GroupMessageStatusChange.class).setProcessor(groupMessageStatusChangeProcessor); + cacheMap.get(Message.class).setProcessor(eventBus::dispatch); + cacheMap.get(GroupMessage.class).setProcessor(eventBus::dispatch); + cacheMap.get(MessageStatusChange.class).setProcessor(eventBus::dispatch); + cacheMap.get(GroupMessageStatusChange.class).setProcessor(eventBus::dispatch); // Process user status changes receiver.registerProcessor(UserStatusChange.class, eventBus::dispatch); @@ -176,7 +171,7 @@ public final class Client implements EventListener, Closeable { receiver.registerProcessor(GroupCreationResult.class, eventBus::dispatch); // Request a generator if none is present or the existing one is consumed - if (!localDB.hasIDGenerator() || !localDB.getIDGenerator().hasNext()) requestIdGenerator(); + if (!localDB.hasIDGenerator() || !localDB.getIDGenerator().hasNext()) requestIDGenerator(); // Relay caches cacheMap.getMap().values().forEach(Cache::relay); @@ -190,7 +185,7 @@ public final class Client implements EventListener, Closeable { * @throws RuntimeException if the object serialization failed * @since Envoy Client v0.2-beta */ - public void send(Object obj) throws IllegalStateException, RuntimeException { + public void send(Serializable obj) throws IllegalStateException, RuntimeException { checkOnline(); logger.log(Level.FINE, "Sending " + obj); try { @@ -217,7 +212,7 @@ public final class Client implements EventListener, Closeable { * * @since Envoy Client v0.3-alpha */ - public void requestIdGenerator() { + public void requestIDGenerator() { logger.log(Level.INFO, "Requesting new id generator..."); send(new IDGeneratorRequest()); } diff --git a/client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java b/client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java deleted file mode 100644 index c4aea7c..0000000 --- a/client/src/main/java/envoy/client/net/GroupMessageStatusChangeProcessor.java +++ /dev/null @@ -1,25 +0,0 @@ -package envoy.client.net; - -import java.util.function.Consumer; -import java.util.logging.Logger; - -import envoy.data.Message.MessageStatus; -import envoy.event.GroupMessageStatusChange; -import envoy.util.EnvoyLog; - -import dev.kske.eventbus.EventBus; - -/** - * @author Maximilian Käfer - * @since Envoy Client v0.1-beta - */ -public final class GroupMessageStatusChangeProcessor implements Consumer { - - private static final Logger logger = EnvoyLog.getLogger(GroupMessageStatusChangeProcessor.class); - - @Override - public void accept(GroupMessageStatusChange evt) { - if (evt.get().ordinal() < MessageStatus.RECEIVED.ordinal()) logger.warning("Received invalid group message status change " + evt); - else EventBus.getInstance().dispatch(evt); - } -} diff --git a/client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java b/client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java deleted file mode 100644 index 36f3ed4..0000000 --- a/client/src/main/java/envoy/client/net/MessageStatusChangeProcessor.java +++ /dev/null @@ -1,32 +0,0 @@ -package envoy.client.net; - -import java.util.function.Consumer; -import java.util.logging.Logger; - -import envoy.data.Message.MessageStatus; -import envoy.event.MessageStatusChange; -import envoy.util.EnvoyLog; - -import dev.kske.eventbus.EventBus; - -/** - * @author Kai S. K. Engelbart - * @since Envoy Client v0.3-alpha - */ -public final class MessageStatusChangeProcessor implements Consumer { - - private static final Logger logger = EnvoyLog.getLogger(MessageStatusChangeProcessor.class); - - /** - * Dispatches a {@link MessageStatusChange} if the status is - * {@code RECEIVED} or {@code READ}. - * - * @param evt the status change event - * @since Envoy Client v0.3-alpha - */ - @Override - public void accept(MessageStatusChange evt) { - if (evt.get().ordinal() < MessageStatus.RECEIVED.ordinal()) logger.warning("Received invalid message status change " + evt); - else EventBus.getInstance().dispatch(evt); - } -} diff --git a/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java b/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java deleted file mode 100644 index a5d4cc3..0000000 --- a/client/src/main/java/envoy/client/net/ReceivedGroupMessageProcessor.java +++ /dev/null @@ -1,29 +0,0 @@ -package envoy.client.net; - -import java.util.function.Consumer; -import java.util.logging.Logger; - -import envoy.data.GroupMessage; -import envoy.data.Message.MessageStatus; -import envoy.util.EnvoyLog; - -import dev.kske.eventbus.EventBus; - -/** - * @author Maximilian Käfer - * @since Envoy Client v0.1-beta - */ -public final class ReceivedGroupMessageProcessor implements Consumer { - - private static final Logger logger = EnvoyLog.getLogger(ReceivedGroupMessageProcessor.class); - - @Override - public void accept(GroupMessage groupMessage) { - if (groupMessage.getStatus() == MessageStatus.WAITING || groupMessage.getStatus() == MessageStatus.READ) - logger.warning("The groupMessage has the unexpected status " + groupMessage.getStatus()); - - // Dispatch event - EventBus.getInstance().dispatch(groupMessage); - } - -} diff --git a/client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java b/client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java deleted file mode 100644 index 3efcc1c..0000000 --- a/client/src/main/java/envoy/client/net/ReceivedMessageProcessor.java +++ /dev/null @@ -1,24 +0,0 @@ -package envoy.client.net; - -import java.util.function.Consumer; - -import envoy.data.Message; -import envoy.data.Message.MessageStatus; - -import dev.kske.eventbus.EventBus; - -/** - * @author Kai S. K. Engelbart - * @since Envoy Client v0.3-alpha - */ -public final class ReceivedMessageProcessor implements Consumer { - - @Override - public void accept(Message message) { - // Update status to RECEIVED - if (message.getStatus() == MessageStatus.SENT) message.nextStatus(); - - // Dispatch message - EventBus.getInstance().dispatch(message); - } -} diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index baf05e4..5299be6 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -694,7 +694,7 @@ public final class ChatScene implements EventListener, Restorable { scrollToMessageListEnd(); // 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(); } // Clear text field and disable post button diff --git a/client/src/main/java/envoy/client/util/ReflectionUtil.java b/client/src/main/java/envoy/client/util/ReflectionUtil.java index 27ea492..49273f8 100644 --- a/client/src/main/java/envoy/client/util/ReflectionUtil.java +++ b/client/src/main/java/envoy/client/util/ReflectionUtil.java @@ -15,8 +15,7 @@ public final class ReflectionUtil { /** * Gets all declared variable values of the given instance that have the - * specified - * class. + * specified class. *

    * (i.e. can get all {@code JComponents} (Swing) or {@code Nodes} (JavaFX) in a * GUI class). From 0efd1e559447a62ee1439cdd0a084931fda63f37 Mon Sep 17 00:00:00 2001 From: kske Date: Fri, 25 Sep 2020 15:56:08 +0200 Subject: [PATCH 3/7] Fold client receivers into event handlers --- .../main/java/envoy/client/data/LocalDB.java | 29 ++++++------------- .../main/java/envoy/client/net/Client.java | 11 ++++--- .../src/main/java/envoy/data/IDGenerator.java | 4 ++- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/client/src/main/java/envoy/client/data/LocalDB.java b/client/src/main/java/envoy/client/data/LocalDB.java index 44cd639..c5e154f 100644 --- a/client/src/main/java/envoy/client/data/LocalDB.java +++ b/client/src/main/java/envoy/client/data/LocalDB.java @@ -173,26 +173,6 @@ public final class LocalDB implements EventListener { }, 2000, ClientConfig.getInstance().getLocalDBSaveInterval() * 60000); } - /** - * Performs a contact name change if the corresponding contact is present. - * - * @param event the {@link NameChange} to process - * @since Envoy Client v0.1-beta - */ - public void replaceContactName(NameChange event) { - 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. - * - * @param event the {@link GroupResize} to process - * @since Envoy Client v0.1-beta - */ - public void updateGroup(GroupResize event) { - getChat(event.getGroupID()).map(Chat::getRecipient).map(Group.class::cast).ifPresent(event::apply); - } - /** * Stores all users. If the client user is specified, their chats will be stored * as well. The message id generator will also be saved if present. @@ -238,6 +218,14 @@ public final class LocalDB implements EventListener { if (evt.get().ordinal() < MessageStatus.RECEIVED.ordinal()) logger.warning("Received invalid " + evt); } + @Event(priority = 150) + private void onGroupResize(GroupResize evt) { getChat(evt.getGroupID()).map(Chat::getRecipient).map(Group.class::cast).ifPresent(evt::apply); } + + @Event(priority = 150) + private void onNameChange(NameChange evt) { + chats.stream().map(Chat::getRecipient).filter(c -> c.getID() == evt.getID()).findAny().ifPresent(c -> c.setName(evt.get())); + } + /** * Stores a new authentication token. * @@ -308,6 +296,7 @@ public final class LocalDB implements EventListener { * @param idGenerator the message ID generator to set * @since Envoy Client v0.3-alpha */ + @Event(priority = 150) public void setIDGenerator(IDGenerator idGenerator) { this.idGenerator = idGenerator; } /** diff --git a/client/src/main/java/envoy/client/net/Client.java b/client/src/main/java/envoy/client/net/Client.java index 149052b..1a327b0 100644 --- a/client/src/main/java/envoy/client/net/Client.java +++ b/client/src/main/java/envoy/client/net/Client.java @@ -75,7 +75,7 @@ public final class Client implements EventListener, Closeable { // authentication token receiver.registerProcessor(User.class, sender -> this.sender = sender); receiver.registerProcessors(cacheMap.getMap()); - receiver.registerProcessor(HandshakeRejection.class, evt -> { rejected = true; eventBus.dispatch(evt); }); + receiver.registerProcessor(HandshakeRejection.class, eventBus::dispatch); receiver.registerProcessor(NewAuthToken.class, eventBus::dispatch); rejected = false; @@ -140,10 +140,10 @@ public final class Client implements EventListener, Closeable { receiver.registerProcessor(UserStatusChange.class, eventBus::dispatch); // Process message ID generation - receiver.registerProcessor(IDGenerator.class, localDB::setIDGenerator); + receiver.registerProcessor(IDGenerator.class, eventBus::dispatch); // Process name changes - receiver.registerProcessor(NameChange.class, evt -> { localDB.replaceContactName(evt); eventBus.dispatch(evt); }); + receiver.registerProcessor(NameChange.class, eventBus::dispatch); // Process contact searches receiver.registerProcessor(UserSearchResult.class, eventBus::dispatch); @@ -152,7 +152,7 @@ public final class Client implements EventListener, Closeable { receiver.registerProcessor(ContactOperation.class, eventBus::dispatch); // Process group size changes - receiver.registerProcessor(GroupResize.class, evt -> { localDB.updateGroup(evt); eventBus.dispatch(evt); }); + receiver.registerProcessor(GroupResize.class, eventBus::dispatch); // Process IsTyping events receiver.registerProcessor(IsTyping.class, eventBus::dispatch); @@ -217,6 +217,9 @@ public final class Client implements EventListener, Closeable { send(new IDGeneratorRequest()); } + @Event(eventType = HandshakeRejection.class, priority = 1000) + private void onHandshakeRejection() { rejected = true; } + @Override @Event(eventType = EnvoyCloseEvent.class, priority = 800) public void close() { diff --git a/common/src/main/java/envoy/data/IDGenerator.java b/common/src/main/java/envoy/data/IDGenerator.java index 3040538..774c348 100644 --- a/common/src/main/java/envoy/data/IDGenerator.java +++ b/common/src/main/java/envoy/data/IDGenerator.java @@ -2,13 +2,15 @@ package envoy.data; import java.io.Serializable; +import dev.kske.eventbus.IEvent; + /** * Generates increasing IDs between two numbers. * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ -public final class IDGenerator implements Serializable { +public final class IDGenerator implements IEvent, Serializable { private final long end; private long current; From 86e189a40a51c397eaabc764e52647d5b59c9c4d Mon Sep 17 00:00:00 2001 From: kske Date: Fri, 25 Sep 2020 16:03:15 +0200 Subject: [PATCH 4/7] Dispatch received events to the event bus by default --- .../main/java/envoy/client/net/Client.java | 43 ------------------- .../main/java/envoy/client/net/Receiver.java | 16 +++++-- 2 files changed, 12 insertions(+), 47 deletions(-) diff --git a/client/src/main/java/envoy/client/net/Client.java b/client/src/main/java/envoy/client/net/Client.java index 1a327b0..9e1f632 100644 --- a/client/src/main/java/envoy/client/net/Client.java +++ b/client/src/main/java/envoy/client/net/Client.java @@ -9,7 +9,6 @@ import envoy.client.data.*; import envoy.client.event.EnvoyCloseEvent; import envoy.data.*; import envoy.event.*; -import envoy.event.contact.*; import envoy.util.*; import dev.kske.eventbus.*; @@ -75,8 +74,6 @@ public final class Client implements EventListener, Closeable { // authentication token receiver.registerProcessor(User.class, sender -> this.sender = sender); receiver.registerProcessors(cacheMap.getMap()); - receiver.registerProcessor(HandshakeRejection.class, eventBus::dispatch); - receiver.registerProcessor(NewAuthToken.class, eventBus::dispatch); rejected = false; @@ -124,52 +121,12 @@ public final class Client implements EventListener, Closeable { // Remove all processors as they are only used during the handshake receiver.removeAllProcessors(); - // Process incoming messages - receiver.registerProcessor(GroupMessage.class, eventBus::dispatch); - receiver.registerProcessor(Message.class, eventBus::dispatch); - receiver.registerProcessor(MessageStatusChange.class, eventBus::dispatch); - receiver.registerProcessor(GroupMessageStatusChange.class, eventBus::dispatch); - // Relay cached messages and message status changes cacheMap.get(Message.class).setProcessor(eventBus::dispatch); cacheMap.get(GroupMessage.class).setProcessor(eventBus::dispatch); cacheMap.get(MessageStatusChange.class).setProcessor(eventBus::dispatch); cacheMap.get(GroupMessageStatusChange.class).setProcessor(eventBus::dispatch); - // Process user status changes - receiver.registerProcessor(UserStatusChange.class, eventBus::dispatch); - - // Process message ID generation - receiver.registerProcessor(IDGenerator.class, eventBus::dispatch); - - // Process name changes - receiver.registerProcessor(NameChange.class, eventBus::dispatch); - - // Process contact searches - receiver.registerProcessor(UserSearchResult.class, eventBus::dispatch); - - // Process contact operations - receiver.registerProcessor(ContactOperation.class, eventBus::dispatch); - - // Process group size changes - receiver.registerProcessor(GroupResize.class, eventBus::dispatch); - - // Process IsTyping events - receiver.registerProcessor(IsTyping.class, eventBus::dispatch); - - // Process PasswordChangeResults - receiver.registerProcessor(PasswordChangeResult.class, eventBus::dispatch); - - // Process ProfilePicChanges - receiver.registerProcessor(ProfilePicChange.class, eventBus::dispatch); - - // Process requests to not send any more attachments as they will not be shown - // to other users - receiver.registerProcessor(NoAttachments.class, eventBus::dispatch); - - // Process group creation results - they might have been disabled on the server - receiver.registerProcessor(GroupCreationResult.class, eventBus::dispatch); - // Request a generator if none is present or the existing one is consumed if (!localDB.hasIDGenerator() || !localDB.getIDGenerator().hasNext()) requestIDGenerator(); diff --git a/client/src/main/java/envoy/client/net/Receiver.java b/client/src/main/java/envoy/client/net/Receiver.java index 2f96604..bc325a2 100644 --- a/client/src/main/java/envoy/client/net/Receiver.java +++ b/client/src/main/java/envoy/client/net/Receiver.java @@ -8,6 +8,8 @@ import java.util.logging.*; import envoy.util.*; +import dev.kske.eventbus.*; + /** * Receives objects from the server and passes them to processor objects based * on their class. @@ -22,7 +24,8 @@ public final class Receiver extends Thread { private final InputStream in; private final Map, Consumer> processors = new HashMap<>(); - private static final Logger logger = EnvoyLog.getLogger(Receiver.class); + private static final EventBus eventBus = EventBus.getInstance(); + private static final Logger logger = EnvoyLog.getLogger(Receiver.class); /** * Creates an instance of {@link Receiver}. @@ -77,9 +80,14 @@ public final class Receiver extends Thread { // Get appropriate processor @SuppressWarnings("rawtypes") final Consumer processor = processors.get(obj.getClass()); - if (processor == null) - logger.log(Level.WARNING, String.format("The received object has the %s for which no processor is defined.", obj.getClass())); - else processor.accept(obj); + + // Dispatch to the processor if present + if (processor != null) processor.accept(obj); + // Dispatch to the event bus if the object is an event without a processor + else if (obj instanceof IEvent) eventBus.dispatch((IEvent) obj); + // Notify if no processor could be located + else logger.log(Level.WARNING, + String.format("The received object has the %s for which no processor is defined.", obj.getClass())); } } catch (final SocketException | EOFException e) { // Connection probably closed by client. From 6d7afbaa8f8d7e5fc2b153f178ea23b8dec93b68 Mon Sep 17 00:00:00 2001 From: kske Date: Fri, 25 Sep 2020 19:19:54 +0200 Subject: [PATCH 5/7] Use ObservableList in LocalDB and Chat, reduce amount of UI refreshes --- .../src/main/java/envoy/client/data/Chat.java | 25 +++++++--- .../java/envoy/client/data/GroupChat.java | 3 +- .../main/java/envoy/client/data/LocalDB.java | 41 ++++++++-------- .../java/envoy/client/ui/ListViewRefresh.java | 31 ------------ .../envoy/client/ui/controller/ChatScene.java | 47 ++++++------------- 5 files changed, 54 insertions(+), 93 deletions(-) delete mode 100644 client/src/main/java/envoy/client/ui/ListViewRefresh.java diff --git a/client/src/main/java/envoy/client/data/Chat.java b/client/src/main/java/envoy/client/data/Chat.java index 8d3faed..1f88098 100644 --- a/client/src/main/java/envoy/client/data/Chat.java +++ b/client/src/main/java/envoy/client/data/Chat.java @@ -3,6 +3,8 @@ package envoy.client.data; import java.io.*; import java.util.*; +import javafx.collections.*; + import envoy.client.net.WriteProxy; import envoy.data.*; import envoy.data.Message.MessageStatus; @@ -19,8 +21,9 @@ import envoy.event.MessageStatusChange; */ public class Chat implements Serializable { - protected final Contact recipient; - protected final List messages = new ArrayList<>(); + protected final Contact recipient; + + protected transient ObservableList messages = FXCollections.observableArrayList(); protected int unreadAmount; @@ -29,7 +32,7 @@ public class Chat implements Serializable { */ protected transient long lastWritingEvent; - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; /** * Provides the list of messages that the recipient receives. @@ -41,6 +44,16 @@ public class Chat implements Serializable { */ public Chat(Contact recipient) { this.recipient = recipient; } + private void readObject(ObjectInputStream stream) throws ClassNotFoundException, IOException { + stream.defaultReadObject(); + messages = FXCollections.observableList((List) stream.readObject()); + } + + private void writeObject(ObjectOutputStream stream) throws IOException { + stream.defaultWriteObject(); + stream.writeObject(new ArrayList<>(messages)); + } + @Override public String toString() { return String.format("%s[recipient=%s,messages=%d]", getClass().getSimpleName(), recipient, messages.size()); } @@ -72,11 +85,9 @@ public class Chat implements Serializable { * * @param writeProxy the write proxy instance used to notify the server about * the message status changes - * @throws IOException if a {@link MessageStatusChange} could not be - * delivered to the server * @since Envoy Client v0.3-alpha */ - public void read(WriteProxy writeProxy) throws IOException { + public void read(WriteProxy writeProxy) { for (int i = messages.size() - 1; i >= 0; --i) { final Message m = messages.get(i); if (m.getSenderID() == recipient.getID()) if (m.getStatus() == MessageStatus.READ) break; @@ -127,7 +138,7 @@ public class Chat implements Serializable { * @return all messages in the current chat * @since Envoy Client v0.1-beta */ - public List getMessages() { return messages; } + public ObservableList getMessages() { return messages; } /** * @return the recipient of a message diff --git a/client/src/main/java/envoy/client/data/GroupChat.java b/client/src/main/java/envoy/client/data/GroupChat.java index 87208c3..188709c 100644 --- a/client/src/main/java/envoy/client/data/GroupChat.java +++ b/client/src/main/java/envoy/client/data/GroupChat.java @@ -1,6 +1,5 @@ package envoy.client.data; -import java.io.IOException; import java.time.Instant; import envoy.client.net.WriteProxy; @@ -32,7 +31,7 @@ public final class GroupChat extends Chat { } @Override - public void read(WriteProxy writeProxy) throws IOException { + public void read(WriteProxy writeProxy) { for (int i = messages.size() - 1; i >= 0; --i) { final GroupMessage gmsg = (GroupMessage) messages.get(i); if (gmsg.getSenderID() != sender.getID()) if (gmsg.getMemberStatuses().get(sender.getID()) == MessageStatus.READ) break; diff --git a/client/src/main/java/envoy/client/data/LocalDB.java b/client/src/main/java/envoy/client/data/LocalDB.java index c5e154f..eb3cfd5 100644 --- a/client/src/main/java/envoy/client/data/LocalDB.java +++ b/client/src/main/java/envoy/client/data/LocalDB.java @@ -7,6 +7,8 @@ import java.time.Instant; import java.util.*; import java.util.logging.*; +import javafx.collections.*; + import envoy.client.event.EnvoyCloseEvent; import envoy.data.*; import envoy.data.Message.MessageStatus; @@ -30,12 +32,12 @@ import dev.kske.eventbus.EventListener; public final class LocalDB implements EventListener { // Data - private User user; - private Map users = Collections.synchronizedMap(new HashMap<>()); - private List chats = Collections.synchronizedList(new ArrayList<>()); - private IDGenerator idGenerator; - private CacheMap cacheMap = new CacheMap(); - private String authToken; + private User user; + private Map users = Collections.synchronizedMap(new HashMap<>()); + private ObservableList chats = FXCollections.observableArrayList(); + private IDGenerator idGenerator; + private CacheMap cacheMap = new CacheMap(); + private String authToken; // State management private Instant lastSync = Instant.EPOCH; @@ -129,7 +131,7 @@ public final class LocalDB implements EventListener { if (user == null) throw new IllegalStateException("Client user is null, cannot initialize user storage"); userFile = new File(dbDir, user.getID() + ".db"); try (var in = new ObjectInputStream(new FileInputStream(userFile))) { - chats = (List) in.readObject(); + chats = FXCollections.observableList((List) in.readObject()); cacheMap = (CacheMap) in.readObject(); lastSync = (Instant) in.readObject(); } finally { @@ -189,8 +191,8 @@ public final class LocalDB implements EventListener { SerializationUtils.write(usersFile, users); // Save user data and last sync time stamp - if (user != null) - SerializationUtils.write(userFile, chats, cacheMap, Context.getInstance().getClient().isOnline() ? Instant.now() : lastSync); + if (user != null) SerializationUtils + .write(userFile, new ArrayList<>(chats), cacheMap, Context.getInstance().getClient().isOnline() ? Instant.now() : lastSync); // Save last login information if (authToken != null) SerializationUtils.write(lastLoginFile, user, authToken); @@ -212,10 +214,12 @@ public final class LocalDB implements EventListener { logger.warning("The groupMessage has the unexpected status " + msg.getStatus()); } - @Event(priority = 150, includeSubtypes = true) - private void onMessageStatusChange(MessageStatusChange evt) { - // TODO: Cancel event once EventBus is updated - if (evt.get().ordinal() < MessageStatus.RECEIVED.ordinal()) logger.warning("Received invalid " + evt); + @Event(priority = 150) + private void onMessageStatusChange(MessageStatusChange evt) { getMessage(evt.getID()).ifPresent(msg -> msg.setStatus(evt.get())); } + + @Event(priority = 150) + private void onGroupMessageStatusChange(GroupMessageStatusChange evt) { + this.getMessage(evt.getID()).ifPresent(msg -> msg.getMemberStatuses().replace(evt.getMemberID(), evt.get())); } @Event(priority = 150) @@ -249,8 +253,8 @@ public final class LocalDB implements EventListener { * @return an optional containing the message * @since Envoy Client v0.1-beta */ - public Optional getMessage(long id) { - return chats.stream().map(Chat::getMessages).flatMap(List::stream).filter(m -> m.getID() == id).findAny(); + public Optional getMessage(long id) { + return (Optional) chats.stream().map(Chat::getMessages).flatMap(List::stream).filter(m -> m.getID() == id).findAny(); } /** @@ -267,12 +271,7 @@ public final class LocalDB implements EventListener { * sender * @since Envoy Client v0.1-alpha **/ - public List getChats() { return chats; } - - /** - * @param chats the chats to set - */ - public void setChats(List chats) { this.chats = chats; } + public ObservableList getChats() { return chats; } /** * @return the {@link User} who initialized the local database diff --git a/client/src/main/java/envoy/client/ui/ListViewRefresh.java b/client/src/main/java/envoy/client/ui/ListViewRefresh.java deleted file mode 100644 index 635a12e..0000000 --- a/client/src/main/java/envoy/client/ui/ListViewRefresh.java +++ /dev/null @@ -1,31 +0,0 @@ -package envoy.client.ui; - -import javafx.scene.control.*; - -/** - * This is a utility class that provides access to a refreshing mechanism for - * elements that were added without notifying the underlying {@link ListView}. - * - * @author Leon Hofmeister - * @since Envoy Client v0.1-beta - */ -public final class ListViewRefresh { - - private ListViewRefresh() {} - - /** - * Deeply refreshes a {@code listview}, meaning it recomputes every single of - * its {@link ListCell}s. - *

    - * While it does work, it is not the most efficient algorithm possible. - * - * @param toRefresh the listView to refresh - * @param the type of its {@code listcells} - * @since Envoy Client v0.1-beta - */ - public static void deepRefresh(ListView toRefresh) { - final var items = toRefresh.getItems(); - toRefresh.setItems(null); - toRefresh.setItems(items); - } -} diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 5299be6..2bd678c 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -11,7 +11,7 @@ import java.util.logging.*; import javafx.animation.RotateTransition; import javafx.application.Platform; -import javafx.collections.*; +import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import javafx.fxml.*; import javafx.scene.control.*; @@ -167,7 +167,8 @@ public final class ChatScene implements EventListener, Restorable { messageList.setCellFactory(MessageListCell::new); chatList.setCellFactory(new ListCellFactory<>(ChatControl::new)); - // JavaFX provides an internal way of populating the context menu of a textarea. + // JavaFX provides an internal way of populating the context menu of a text + // area. // We, however, need additional functionality. messageTextArea.setContextMenu(new TextInputContextMenu(messageTextArea, e -> checkKeyCombination(null))); @@ -186,7 +187,7 @@ public final class ChatScene implements EventListener, Restorable { clip.setArcWidth(43); clientProfilePic.setClip(clip); - chatList.setItems(chats = new FilteredList<>(FXCollections.observableList(localDB.getChats()))); + chatList.setItems(chats = new FilteredList<>(localDB.getChats())); contactLabel.setText(localDB.getUser().getName()); initializeSystemCommandsMap(); @@ -228,12 +229,8 @@ public final class ChatScene implements EventListener, Restorable { // Read current chat or increment unread amount if (chat.equals(currentChat)) { - try { - currentChat.read(writeProxy); - } catch (final IOException e) { - logger.log(Level.WARNING, "Could not read current chat: ", e); - } - Platform.runLater(() -> { ListViewRefresh.deepRefresh(messageList); scrollToMessageListEnd(); }); + currentChat.read(writeProxy); + Platform.runLater(this::scrollToMessageListEnd); } else if (!ownMessage && message.getStatus() != MessageStatus.READ) chat.incrementUnreadAmount(); // Move chat with most recent unread messages to the top @@ -248,22 +245,12 @@ public final class ChatScene implements EventListener, Restorable { @Event private void onMessageStatusChange(MessageStatusChange evt) { - localDB.getMessage(evt.getID()).ifPresent(message -> { - message.setStatus(evt.get()); - // Update UI if in current chat and the current user was the sender of the - // message - if (currentChat != null && message.getSenderID() == client.getSender().getID()) Platform.runLater(messageList::refresh); - }); - } - @Event - private void onGroupMessageStatusChange(GroupMessageStatusChange evt) { - localDB.getMessage(evt.getID()).ifPresent(groupMessage -> { - ((GroupMessage) groupMessage).getMemberStatuses().replace(evt.getMemberID(), evt.get()); - - // Update UI if in current chat - if (currentChat != null && groupMessage.getRecipientID() == currentChat.getRecipient().getID()) Platform.runLater(messageList::refresh); - }); + // Update UI if in current chat and the current user was the sender of the + // message + if (currentChat != null) localDB.getMessage(evt.getID()) + .filter(msg -> msg.getSenderID() == client.getSender().getID()) + .ifPresent(msg -> Platform.runLater(messageList::refresh)); } @Event @@ -273,7 +260,7 @@ public final class ChatScene implements EventListener, Restorable { .filter(c -> c.getRecipient().getID() == evt.getID()) .findAny() .map(Chat::getRecipient) - .ifPresent(u -> { ((User) u).setStatus(evt.get()); Platform.runLater(() -> ListViewRefresh.deepRefresh(chatList)); }); + .ifPresent(u -> ((User) u).setStatus(evt.get())); } @Event @@ -318,6 +305,7 @@ public final class ChatScene implements EventListener, Restorable { clientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); chatList.setCellFactory(new ListCellFactory<>(ChatControl::new)); messageList.setCellFactory(MessageListCell::new); + // TODO: cache image if (currentChat.getRecipient() instanceof User) recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("user_icon", 43)); else recipientProfilePic.setImage(IconUtil.loadIconThemeSensitive("group_icon", 43)); } @@ -358,18 +346,14 @@ public final class ChatScene implements EventListener, Restorable { // Load the chat currentChat = localDB.getChat(user.getID()).get(); - messageList.setItems(FXCollections.observableList(currentChat.getMessages())); + messageList.setItems(currentChat.getMessages()); final var scrollIndex = messageList.getItems().size() - currentChat.getUnreadAmount(); messageList.scrollTo(scrollIndex); logger.log(Level.FINEST, "Loading chat with " + user + " at index " + scrollIndex); 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); - } + currentChat.read(writeProxy); // Discard the pending attachment if (recorder.isRecording()) { @@ -690,7 +674,6 @@ public final class ChatScene implements EventListener, Restorable { localDB.getChats().remove(currentChat); localDB.getChats().add(0, currentChat); }); - ListViewRefresh.deepRefresh(messageList); scrollToMessageListEnd(); // Request a new ID generator if all IDs were used From 5daff3620e5367d06f9fb0ec7f5b2781c2432979 Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 26 Sep 2020 12:10:22 +0200 Subject: [PATCH 6/7] Update UI on user status change --- client/src/main/java/envoy/client/data/LocalDB.java | 5 +++++ .../java/envoy/client/ui/controller/ChatScene.java | 11 ++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/client/src/main/java/envoy/client/data/LocalDB.java b/client/src/main/java/envoy/client/data/LocalDB.java index eb3cfd5..a06c063 100644 --- a/client/src/main/java/envoy/client/data/LocalDB.java +++ b/client/src/main/java/envoy/client/data/LocalDB.java @@ -222,6 +222,11 @@ public final class LocalDB implements EventListener { this.getMessage(evt.getID()).ifPresent(msg -> msg.getMemberStatuses().replace(evt.getMemberID(), evt.get())); } + @Event(priority = 150) + private void onUserStatusChange(UserStatusChange evt) { + this.getChat(evt.getID()).map(Chat::getRecipient).map(User.class::cast).ifPresent(u -> u.setStatus(evt.get())); + } + @Event(priority = 150) private void onGroupResize(GroupResize evt) { getChat(evt.getGroupID()).map(Chat::getRecipient).map(Group.class::cast).ifPresent(evt::apply); } diff --git a/client/src/main/java/envoy/client/ui/controller/ChatScene.java b/client/src/main/java/envoy/client/ui/controller/ChatScene.java index 2bd678c..c77438f 100644 --- a/client/src/main/java/envoy/client/ui/controller/ChatScene.java +++ b/client/src/main/java/envoy/client/ui/controller/ChatScene.java @@ -253,15 +253,8 @@ public final class ChatScene implements EventListener, Restorable { .ifPresent(msg -> Platform.runLater(messageList::refresh)); } - @Event - private void onUserStatusChange(UserStatusChange evt) { - chats.getSource() - .stream() - .filter(c -> c.getRecipient().getID() == evt.getID()) - .findAny() - .map(Chat::getRecipient) - .ifPresent(u -> ((User) u).setStatus(evt.get())); - } + @Event(eventType = UserStatusChange.class) + private void onUserStatusChange() { Platform.runLater(chatList::refresh); } @Event private void onContactOperation(ContactOperation operation) { From ede50ed3e5a74490f188f302ffdf520cceda9518 Mon Sep 17 00:00:00 2001 From: kske Date: Sun, 27 Sep 2020 12:06:01 +0200 Subject: [PATCH 7/7] Fix Javadoc errors spotted by @delvh --- common/src/main/java/envoy/util/Bounds.java | 2 ++ server/src/main/java/envoy/server/net/ObjectWriteProxy.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/envoy/util/Bounds.java b/common/src/main/java/envoy/util/Bounds.java index bfb038c..8f8f381 100644 --- a/common/src/main/java/envoy/util/Bounds.java +++ b/common/src/main/java/envoy/util/Bounds.java @@ -3,6 +3,8 @@ package envoy.util; import java.util.regex.Pattern; /** + * Implements contact name validation. + * * @author Kai S. K. Engelbart * @since Envoy Common v0.1-beta */ diff --git a/server/src/main/java/envoy/server/net/ObjectWriteProxy.java b/server/src/main/java/envoy/server/net/ObjectWriteProxy.java index 650b030..53f12fc 100755 --- a/server/src/main/java/envoy/server/net/ObjectWriteProxy.java +++ b/server/src/main/java/envoy/server/net/ObjectWriteProxy.java @@ -61,7 +61,7 @@ public final class ObjectWriteProxy { } /** - * Sends an object to all contact in a set that are online. + * Sends an object to all contacts in a set that are online. * * @param contacts the contacts to send the object to * @param message the object to send @@ -70,7 +70,7 @@ public final class ObjectWriteProxy { public void writeToOnlineContacts(Set contacts, Object message) { writeToOnlineContacts(contacts.stream(), message); } /** - * Sends an object to all contact in a set that are online. + * Sends an object to all contacts in a set that are online. * * @param contacts the contacts to send the object to * @param message the object to send