Refactored to the new contact related classes in envoy-common
This commit is contained in:
parent
a93539ea06
commit
78d8c08573
2
pom.xml
2
pom.xml
@ -28,7 +28,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.informatik-ag-ngl</groupId>
|
||||
<artifactId>envoy-common</artifactId>
|
||||
<version>f~contacts-SNAPSHOT</version>
|
||||
<version>develop-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -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: <strong>envoy-client</strong><br>
|
||||
* File: <strong>AddContactEvent.java</strong><br>
|
||||
* Created: <strong>09.02.2020</strong><br>
|
||||
*
|
||||
*
|
||||
* @author Maximilian Käfer
|
||||
* @since Envoy v0.3-alpha
|
||||
*/
|
||||
@ -20,8 +20,8 @@ public class AddContactEvent implements Event<User> {
|
||||
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<User> {
|
||||
* @return the operation, which should be executed
|
||||
*/
|
||||
public Operation getOperation() { return operation; }
|
||||
|
||||
}
|
||||
|
@ -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: <strong>envoy-client</strong><br>
|
||||
@ -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
|
||||
|
@ -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<User> {
|
||||
|
||||
private PrimaryScrollPane scrollPane = new PrimaryScrollPane();
|
||||
|
||||
@Override
|
||||
public JComponent getListCellComponent(ComponentList<? extends User> list, User value, boolean isSelected) {
|
||||
final JPanel panel = new JPanel();
|
||||
@ -64,9 +62,7 @@ public class ContactsSearchRenderer implements ComponentListCellRenderer<User> {
|
||||
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<User> {
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
// TODO: Use this method properly
|
||||
public void setScrollPane(PrimaryScrollPane scrollPane) { this.scrollPane = scrollPane; }
|
||||
}
|
Reference in New Issue
Block a user