From 78d8c08573f020fbd266d39dd8106308f7f2e0b6 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 10 Feb 2020 22:31:40 +0100 Subject: [PATCH] Refactored to the new contact related classes in envoy-common --- pom.xml | 2 +- .../envoy/client/event/AddContactEvent.java | 9 ++++---- src/main/java/envoy/client/ui/ChatWindow.java | 21 +++++++------------ .../client/ui/ContactsSearchRenderer.java | 11 ++-------- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/pom.xml b/pom.xml index c7abb5f..0b5487d 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ com.github.informatik-ag-ngl envoy-common - f~contacts-SNAPSHOT + develop-SNAPSHOT diff --git a/src/main/java/envoy/client/event/AddContactEvent.java b/src/main/java/envoy/client/event/AddContactEvent.java index 8f356fa..087cfb3 100644 --- a/src/main/java/envoy/client/event/AddContactEvent.java +++ b/src/main/java/envoy/client/event/AddContactEvent.java @@ -1,14 +1,14 @@ package envoy.client.event; import envoy.data.User; -import envoy.event.ContactOperation.Operation; +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 */ @@ -20,8 +20,8 @@ public class AddContactEvent implements Event { private static final long serialVersionUID = 7855669140917046709L; /** - * Initializes a {@link AddContactEvent} - * + * 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 @@ -38,5 +38,4 @@ public class AddContactEvent implements Event { * @return the operation, which should be executed */ public Operation getOperation() { return operation; } - } diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index eed9ae9..07c26b1 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -26,7 +26,7 @@ import envoy.data.Message.MessageStatus; import envoy.data.MessageBuilder; import envoy.data.User; import envoy.event.*; -import envoy.event.ContactOperation.Operation; +import envoy.event.ContactOperationEvent.Operation; /** * Project: envoy-client
@@ -261,8 +261,8 @@ public class ChatWindow extends JFrame { public void removeUpdate(DocumentEvent e) { if (client.isOnline()) { try { - if(!searchField.getText().isEmpty()) { - client.sendEvent(new ContactsRequest(searchField.getText(), client.getSender())); + if (!searchField.getText().isEmpty()) { + client.sendEvent(new ContactSearchRequest(searchField.getText())); } else { contactsModel.clear(); revalidate(); @@ -278,9 +278,7 @@ public class ChatWindow extends JFrame { public void insertUpdate(DocumentEvent e) { if (client.isOnline()) { try { - if(!searchField.getText().isEmpty()) { - client.sendEvent(new ContactsRequest(searchField.getText(), client.getSender())); - } + if (!searchField.getText().isEmpty()) { client.sendEvent(new ContactSearchRequest(searchField.getText())); } } catch (IOException e1) { e1.printStackTrace(); } @@ -407,10 +405,10 @@ public class ChatWindow extends JFrame { }); EventBus.getInstance().register(AddContactEvent.class, (evt) -> { - User contact = ((AddContactEvent) evt).get(); - Operation operation = ((AddContactEvent) evt).getOperation(); + User contact = ((AddContactEvent) evt).get(); + Operation operation = ((AddContactEvent) evt).getOperation(); try { - client.sendEvent(new ContactOperation(contact, operation)); + client.sendEvent(new ContactOperationEvent(contact, operation)); } catch (IOException e) { e.printStackTrace(); } @@ -565,7 +563,6 @@ public class ChatWindow extends JFrame { contentPane.remove(scrollPane); contentPane.add(searchPane, gbc_searchPane); contentPane.revalidate(); - contactRenderer.setScrollPane(possibleContacts); contentPane.repaint(); } @@ -575,9 +572,7 @@ public class ChatWindow extends JFrame { * @param client the {@link Client} used to send and receive messages * @since Envoy v0.2-alpha */ - public void setClient(Client client) { - this.client = client; - } + public void setClient(Client client) { this.client = client; } /** * Sets the {@link LocalDb} used by this {@link ChatWindow}. After diff --git a/src/main/java/envoy/client/ui/ContactsSearchRenderer.java b/src/main/java/envoy/client/ui/ContactsSearchRenderer.java index b435def..e346df8 100644 --- a/src/main/java/envoy/client/ui/ContactsSearchRenderer.java +++ b/src/main/java/envoy/client/ui/ContactsSearchRenderer.java @@ -11,7 +11,7 @@ import envoy.client.event.AddContactEvent; import envoy.client.ui.list.ComponentList; import envoy.client.ui.list.ComponentListCellRenderer; import envoy.data.User; -import envoy.event.ContactOperation.Operation; +import envoy.event.ContactOperationEvent; import envoy.event.EventBus; /** @@ -27,8 +27,6 @@ import envoy.event.EventBus; */ public class ContactsSearchRenderer implements ComponentListCellRenderer { - private PrimaryScrollPane scrollPane = new PrimaryScrollPane(); - @Override public JComponent getListCellComponent(ComponentList list, User value, boolean isSelected) { final JPanel panel = new JPanel(); @@ -64,9 +62,7 @@ public class ContactsSearchRenderer implements ComponentListCellRenderer { add.setBackground(list.getBackground()); add.setForeground(list.getForeground()); - add.addActionListener((evt) -> { - EventBus.getInstance().dispatch(new AddContactEvent(value, Operation.ADD)); - }); + add.addActionListener((evt) -> { EventBus.getInstance().dispatch(new AddContactEvent(value, ContactOperationEvent.Operation.ADD)); }); panel.add(add); @@ -81,7 +77,4 @@ public class ContactsSearchRenderer implements ComponentListCellRenderer { return panel; } - - // TODO: Use this method properly - public void setScrollPane(PrimaryScrollPane scrollPane) { this.scrollPane = scrollPane; } } \ No newline at end of file