Refactored to the new contact related classes in envoy-common

This commit is contained in:
Kai S. K. Engelbart 2020-02-10 22:31:40 +01:00
parent 128d5bec4a
commit c90bbbc262
4 changed files with 15 additions and 28 deletions

View File

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>com.github.informatik-ag-ngl</groupId> <groupId>com.github.informatik-ag-ngl</groupId>
<artifactId>envoy-common</artifactId> <artifactId>envoy-common</artifactId>
<version>f~contacts-SNAPSHOT</version> <version>develop-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -1,14 +1,14 @@
package envoy.client.event; package envoy.client.event;
import envoy.data.User; import envoy.data.User;
import envoy.event.ContactOperation.Operation; import envoy.event.ContactOperationEvent.Operation;
import envoy.event.Event; import envoy.event.Event;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
* File: <strong>AddContactEvent.java</strong><br> * File: <strong>AddContactEvent.java</strong><br>
* Created: <strong>09.02.2020</strong><br> * Created: <strong>09.02.2020</strong><br>
* *
* @author Maximilian K&auml;fer * @author Maximilian K&auml;fer
* @since Envoy v0.3-alpha * @since Envoy v0.3-alpha
*/ */
@ -20,8 +20,8 @@ public class AddContactEvent implements Event<User> {
private static final long serialVersionUID = 7855669140917046709L; 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 contact the user to be added to the contacts
* @param operation the operation, which should be executed * @param operation the operation, which should be executed
* @since Envoy v0.3-alpha * @since Envoy v0.3-alpha
@ -38,5 +38,4 @@ public class AddContactEvent implements Event<User> {
* @return the operation, which should be executed * @return the operation, which should be executed
*/ */
public Operation getOperation() { return operation; } public Operation getOperation() { return operation; }
} }

View File

@ -26,7 +26,7 @@ import envoy.data.Message.MessageStatus;
import envoy.data.MessageBuilder; import envoy.data.MessageBuilder;
import envoy.data.User; import envoy.data.User;
import envoy.event.*; import envoy.event.*;
import envoy.event.ContactOperation.Operation; import envoy.event.ContactOperationEvent.Operation;
/** /**
* Project: <strong>envoy-client</strong><br> * Project: <strong>envoy-client</strong><br>
@ -261,8 +261,8 @@ public class ChatWindow extends JFrame {
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
if (client.isOnline()) { if (client.isOnline()) {
try { try {
if(!searchField.getText().isEmpty()) { if (!searchField.getText().isEmpty()) {
client.sendEvent(new ContactsRequest(searchField.getText(), client.getSender())); client.sendEvent(new ContactSearchRequest(searchField.getText()));
} else { } else {
contactsModel.clear(); contactsModel.clear();
revalidate(); revalidate();
@ -278,9 +278,7 @@ public class ChatWindow extends JFrame {
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
if (client.isOnline()) { if (client.isOnline()) {
try { try {
if(!searchField.getText().isEmpty()) { if (!searchField.getText().isEmpty()) { client.sendEvent(new ContactSearchRequest(searchField.getText())); }
client.sendEvent(new ContactsRequest(searchField.getText(), client.getSender()));
}
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
@ -407,10 +405,10 @@ public class ChatWindow extends JFrame {
}); });
EventBus.getInstance().register(AddContactEvent.class, (evt) -> { EventBus.getInstance().register(AddContactEvent.class, (evt) -> {
User contact = ((AddContactEvent) evt).get(); User contact = ((AddContactEvent) evt).get();
Operation operation = ((AddContactEvent) evt).getOperation(); Operation operation = ((AddContactEvent) evt).getOperation();
try { try {
client.sendEvent(new ContactOperation(contact, operation)); client.sendEvent(new ContactOperationEvent(contact, operation));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -565,7 +563,6 @@ public class ChatWindow extends JFrame {
contentPane.remove(scrollPane); contentPane.remove(scrollPane);
contentPane.add(searchPane, gbc_searchPane); contentPane.add(searchPane, gbc_searchPane);
contentPane.revalidate(); contentPane.revalidate();
contactRenderer.setScrollPane(possibleContacts);
contentPane.repaint(); contentPane.repaint();
} }
@ -575,9 +572,7 @@ public class ChatWindow extends JFrame {
* @param client the {@link Client} used to send and receive messages * @param client the {@link Client} used to send and receive messages
* @since Envoy v0.2-alpha * @since Envoy v0.2-alpha
*/ */
public void setClient(Client client) { public void setClient(Client client) { this.client = client; }
this.client = client;
}
/** /**
* Sets the {@link LocalDb} used by this {@link ChatWindow}. After * Sets the {@link LocalDb} used by this {@link ChatWindow}. After

View File

@ -11,7 +11,7 @@ import envoy.client.event.AddContactEvent;
import envoy.client.ui.list.ComponentList; import envoy.client.ui.list.ComponentList;
import envoy.client.ui.list.ComponentListCellRenderer; import envoy.client.ui.list.ComponentListCellRenderer;
import envoy.data.User; import envoy.data.User;
import envoy.event.ContactOperation.Operation; import envoy.event.ContactOperationEvent;
import envoy.event.EventBus; import envoy.event.EventBus;
/** /**
@ -27,8 +27,6 @@ import envoy.event.EventBus;
*/ */
public class ContactsSearchRenderer implements ComponentListCellRenderer<User> { public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
private PrimaryScrollPane scrollPane = new PrimaryScrollPane();
@Override @Override
public JComponent getListCellComponent(ComponentList<? extends User> list, User value, boolean isSelected) { public JComponent getListCellComponent(ComponentList<? extends User> list, User value, boolean isSelected) {
final JPanel panel = new JPanel(); final JPanel panel = new JPanel();
@ -64,9 +62,7 @@ public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
add.setBackground(list.getBackground()); add.setBackground(list.getBackground());
add.setForeground(list.getForeground()); add.setForeground(list.getForeground());
add.addActionListener((evt) -> { add.addActionListener((evt) -> { EventBus.getInstance().dispatch(new AddContactEvent(value, ContactOperationEvent.Operation.ADD)); });
EventBus.getInstance().dispatch(new AddContactEvent(value, Operation.ADD));
});
panel.add(add); panel.add(add);
@ -81,7 +77,4 @@ public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
return panel; return panel;
} }
// TODO: Use this method properly
public void setScrollPane(PrimaryScrollPane scrollPane) { this.scrollPane = scrollPane; }
} }