From c0954036a5b361eea4472db35524582cf5f7d624 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 11 Feb 2020 17:17:22 +0100 Subject: [PATCH] Adjusted to event system refactoring --- .settings/org.eclipse.jdt.core.prefs | 5 ++- .../envoy/client/event/AddContactEvent.java | 41 ------------------- .../client/event/MessageCreationEvent.java | 3 +- .../java/envoy/client/event/MessageEvent.java | 34 --------------- .../event/MessageModificationEvent.java | 3 +- .../envoy/client/event/SearchResultEvent.java | 32 --------------- .../envoy/client/event/ThemeChangeEvent.java | 8 +--- src/main/java/envoy/client/net/Client.java | 3 +- src/main/java/envoy/client/net/Receiver.java | 1 - src/main/java/envoy/client/ui/ChatWindow.java | 19 +++++---- .../client/ui/ContactsSearchRenderer.java | 3 +- 11 files changed, 21 insertions(+), 131 deletions(-) delete mode 100644 src/main/java/envoy/client/event/AddContactEvent.java delete mode 100644 src/main/java/envoy/client/event/MessageEvent.java delete mode 100644 src/main/java/envoy/client/event/SearchResultEvent.java diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 64c8c95..cbcb911 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -92,12 +92,13 @@ org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=ignore org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning @@ -126,4 +127,4 @@ org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.release=disabled -org.eclipse.jdt.core.compiler.source=1.8 \ No newline at end of file +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/main/java/envoy/client/event/AddContactEvent.java b/src/main/java/envoy/client/event/AddContactEvent.java deleted file mode 100644 index 087cfb3..0000000 --- a/src/main/java/envoy/client/event/AddContactEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -package envoy.client.event; - -import envoy.data.User; -import envoy.event.ContactOperationEvent.Operation; -import envoy.event.Event; - -/** - * Project: envoy-client
- * File: AddContactEvent.java
- * Created: 09.02.2020
- * - * @author Maximilian Käfer - * @since Envoy v0.3-alpha - */ -public class AddContactEvent implements Event { - - private User contact; - private Operation operation; - - private static final long serialVersionUID = 7855669140917046709L; - - /** - * Initializes a {@link AddContactEvent}. - * - * @param contact the user to be added to the contacts - * @param operation the operation, which should be executed - * @since Envoy v0.3-alpha - */ - public AddContactEvent(User contact, Operation operation) { - this.contact = contact; - this.operation = operation; - } - - @Override - public User get() { return contact; } - - /** - * @return the operation, which should be executed - */ - public Operation getOperation() { return operation; } -} diff --git a/src/main/java/envoy/client/event/MessageCreationEvent.java b/src/main/java/envoy/client/event/MessageCreationEvent.java index 72e47f5..4781943 100644 --- a/src/main/java/envoy/client/event/MessageCreationEvent.java +++ b/src/main/java/envoy/client/event/MessageCreationEvent.java @@ -1,6 +1,7 @@ package envoy.client.event; import envoy.data.Message; +import envoy.event.Event; /** * Project: envoy-client
@@ -10,7 +11,7 @@ import envoy.data.Message; * @author Kai S. K. Engelbart * @since Envoy v0.2-alpha */ -public class MessageCreationEvent extends MessageEvent { +public class MessageCreationEvent extends Event { private static final long serialVersionUID = -6451021678064566774L; diff --git a/src/main/java/envoy/client/event/MessageEvent.java b/src/main/java/envoy/client/event/MessageEvent.java deleted file mode 100644 index fb50109..0000000 --- a/src/main/java/envoy/client/event/MessageEvent.java +++ /dev/null @@ -1,34 +0,0 @@ -package envoy.client.event; - -import envoy.data.Message; -import envoy.event.Event; - -/** - * Project: envoy-client
- * File: MessageCreationEvent.java
- * Created: 4 Dec 2019
- * - * @author Kai S. K. Engelbart - * @since Envoy v0.2-alpha - */ -public class MessageEvent implements Event { - - private static final long serialVersionUID = 7658989461923112804L; - - /** - * the {@link Message} attached to this {@link MessageEvent}. - */ - protected final Message message; - - /** - * Initializes a {@link MessageEvent} conveying information about a - * {@link Message} object. - * - * @param message the {@link Message} object to attach to this event - * @since Envoy v0.2-alpha - */ - public MessageEvent(Message message) { this.message = message; } - - @Override - public Message get() { return message; } -} diff --git a/src/main/java/envoy/client/event/MessageModificationEvent.java b/src/main/java/envoy/client/event/MessageModificationEvent.java index 4077383..8ddaaf0 100644 --- a/src/main/java/envoy/client/event/MessageModificationEvent.java +++ b/src/main/java/envoy/client/event/MessageModificationEvent.java @@ -1,6 +1,7 @@ package envoy.client.event; import envoy.data.Message; +import envoy.event.Event; /** * Project: envoy-client
@@ -10,7 +11,7 @@ import envoy.data.Message; * @author Kai S. K. Engelbart * @since Envoy v0.2-alpha */ -public class MessageModificationEvent extends MessageEvent { +public class MessageModificationEvent extends Event { private static final long serialVersionUID = 4650039506439563116L; diff --git a/src/main/java/envoy/client/event/SearchResultEvent.java b/src/main/java/envoy/client/event/SearchResultEvent.java deleted file mode 100644 index dc834d3..0000000 --- a/src/main/java/envoy/client/event/SearchResultEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -package envoy.client.event; - -import java.util.List; - -import envoy.data.User; -import envoy.event.Event; - -/** - * Project: envoy-client
- * File: SearchResultEvent.java
- * Created: 08.02.2020
- * - * @author Maximilian Käfer - * @since Envoy v0.3-alpha - */ -public class SearchResultEvent implements Event> { - - private final List resultList; - - private static final long serialVersionUID = 2540321329192201277L; - - /** - * Initializes a {@link SearchResultEvent} - * - * @param resultList the List containing the contacts sent from the server - * @since Envoy v0.3-alpha - */ - public SearchResultEvent(List resultList) { this.resultList = resultList; } - - @Override - public List get() { return resultList; } -} diff --git a/src/main/java/envoy/client/event/ThemeChangeEvent.java b/src/main/java/envoy/client/event/ThemeChangeEvent.java index 02a15df..c164f72 100644 --- a/src/main/java/envoy/client/event/ThemeChangeEvent.java +++ b/src/main/java/envoy/client/event/ThemeChangeEvent.java @@ -11,10 +11,9 @@ import envoy.event.Event; * @author Kai S. K. Engelbart * @since Envoy v0.2-alpha */ -public class ThemeChangeEvent implements Event { +public class ThemeChangeEvent extends Event { private static final long serialVersionUID = 6756772448803774547L; - private final Theme theme; /** * Initializes a {@link ThemeChangeEvent} conveying information about the change @@ -23,8 +22,5 @@ public class ThemeChangeEvent implements Event { * @param theme the new currently used {@link Theme} object * @since Envoy v0.2-alpha */ - public ThemeChangeEvent(Theme theme) { this.theme = theme; } - - @Override - public Theme get() { return theme; } + public ThemeChangeEvent(Theme theme) { super(theme); } } diff --git a/src/main/java/envoy/client/net/Client.java b/src/main/java/envoy/client/net/Client.java index fec5570..550b7f2 100644 --- a/src/main/java/envoy/client/net/Client.java +++ b/src/main/java/envoy/client/net/Client.java @@ -12,7 +12,6 @@ import javax.naming.TimeLimitExceededException; import envoy.client.data.Cache; import envoy.client.data.Config; import envoy.client.data.LocalDb; -import envoy.client.event.SearchResultEvent; import envoy.client.util.EnvoyLog; import envoy.data.*; import envoy.event.*; @@ -115,7 +114,7 @@ public class Client implements Closeable { receiver.registerProcessor(IdGenerator.class, localDb::setIdGenerator); // Process contact searches - receiver.registerProcessor(Contacts.class, contacts -> EventBus.getInstance().dispatch(new SearchResultEvent(contacts.getContacts()))); + receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch); // Request a generator if none is present or the existing one is consumed if (!localDb.hasIdGenerator() || !localDb.getIdGenerator().hasNext()) requestIdGenerator(); diff --git a/src/main/java/envoy/client/net/Receiver.java b/src/main/java/envoy/client/net/Receiver.java index 5030241..25e7153 100644 --- a/src/main/java/envoy/client/net/Receiver.java +++ b/src/main/java/envoy/client/net/Receiver.java @@ -35,7 +35,6 @@ public class Receiver implements Runnable { */ public Receiver(InputStream in) { this.in = in; } - @SuppressWarnings("unchecked") @Override public void run() { diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index f5400a3..5a0898f 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -4,6 +4,7 @@ import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.io.IOException; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -15,7 +16,8 @@ import javax.swing.event.DocumentListener; import envoy.client.Settings; import envoy.client.data.Chat; import envoy.client.data.LocalDb; -import envoy.client.event.*; +import envoy.client.event.MessageCreationEvent; +import envoy.client.event.ThemeChangeEvent; import envoy.client.net.Client; import envoy.client.net.WriteProxy; import envoy.client.ui.list.ComponentList; @@ -27,7 +29,6 @@ import envoy.data.Message.MessageStatus; import envoy.data.MessageBuilder; import envoy.data.User; import envoy.event.*; -import envoy.event.ContactOperationEvent.Operation; /** * Project: envoy-client
@@ -189,7 +190,6 @@ public class ChatWindow extends JFrame { userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); userList.addListSelectionListener((listSelectionEvent) -> { if (client != null && localDb != null && !listSelectionEvent.getValueIsAdjusting()) { - @SuppressWarnings("unchecked") final JList selectedUserList = (JList) listSelectionEvent.getSource(); final User user = selectedUserList.getSelectedValue(); @@ -400,24 +400,25 @@ public class ChatWindow extends JFrame { repaint(); }); - EventBus.getInstance().register(SearchResultEvent.class, (evt) -> { + EventBus.getInstance().register(ContactSearchResult.class, (evt) -> { contactsModel.clear(); - final java.util.List contacts = ((SearchResultEvent) evt).get(); + final java.util.List contacts = (List) evt.get(); logger.info("Received contact search result " + contacts); contacts.forEach(contactsModel::add); revalidate(); repaint(); }); - EventBus.getInstance().register(AddContactEvent.class, (evt) -> { - User contact = ((AddContactEvent) evt).get(); - Operation operation = ((AddContactEvent) evt).getOperation(); + EventBus.getInstance().register(ContactOperationEvent.class, (evt) -> { + try { - client.sendEvent(new ContactOperationEvent(contact, operation)); + client.sendEvent(evt); } catch (IOException e) { e.printStackTrace(); } + User contact = (User) evt.get(); + // Clearing the search field and the searchResultList searchField.setText(""); contactsModel.clear(); diff --git a/src/main/java/envoy/client/ui/ContactsSearchRenderer.java b/src/main/java/envoy/client/ui/ContactsSearchRenderer.java index e346df8..c469475 100644 --- a/src/main/java/envoy/client/ui/ContactsSearchRenderer.java +++ b/src/main/java/envoy/client/ui/ContactsSearchRenderer.java @@ -7,7 +7,6 @@ import java.awt.Font; import javax.swing.*; import envoy.client.Settings; -import envoy.client.event.AddContactEvent; import envoy.client.ui.list.ComponentList; import envoy.client.ui.list.ComponentListCellRenderer; import envoy.data.User; @@ -62,7 +61,7 @@ public class ContactsSearchRenderer implements ComponentListCellRenderer { add.setBackground(list.getBackground()); add.setForeground(list.getForeground()); - add.addActionListener((evt) -> { EventBus.getInstance().dispatch(new AddContactEvent(value, ContactOperationEvent.Operation.ADD)); }); + add.addActionListener((evt) -> { EventBus.getInstance().dispatch(new ContactOperationEvent(value, ContactOperationEvent.Operation.ADD)); }); panel.add(add);