Fixed formatting
This commit is contained in:
parent
b88d4993ef
commit
018753e115
@ -47,14 +47,14 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
private JPanel contentPane = new JPanel();
|
||||
|
||||
private Client client;
|
||||
private Client client;
|
||||
private LocalDB localDB;
|
||||
|
||||
private JList<User> userList = new JList<>();
|
||||
private Chat currentChat;
|
||||
|
||||
public ChatWindow(Client client, LocalDB localDB) {
|
||||
this.client = client;
|
||||
this.client = client;
|
||||
this.localDB = localDB;
|
||||
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
@ -66,9 +66,7 @@ public class ChatWindow extends JFrame {
|
||||
addWindowListener(new WindowAdapter() {
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
localDB.saveToLocalDB();
|
||||
}
|
||||
public void windowClosing(WindowEvent e) { localDB.saveToLocalDB(); }
|
||||
});
|
||||
|
||||
contentPane.setBackground(new Color(0, 0, 0));
|
||||
@ -149,8 +147,7 @@ public class ChatWindow extends JFrame {
|
||||
|
||||
postButton.addActionListener((evt) -> {
|
||||
if (!client.hasRecipient()) {
|
||||
JOptionPane.showMessageDialog(this, "Please select a recipient!", "Cannot send message",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
JOptionPane.showMessageDialog(this, "Please select a recipient!", "Cannot send message", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -170,7 +167,8 @@ public class ChatWindow extends JFrame {
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(this,
|
||||
"An exception occured while sending a message. See the log for more details.",
|
||||
"Exception occured", JOptionPane.ERROR_MESSAGE);
|
||||
"Exception occured",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
@ -197,18 +195,12 @@ public class ChatWindow extends JFrame {
|
||||
userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
userList.addListSelectionListener((listSelectionEvent) -> {
|
||||
if (!listSelectionEvent.getValueIsAdjusting()) {
|
||||
@SuppressWarnings(
|
||||
"unchecked"
|
||||
)
|
||||
@SuppressWarnings("unchecked")
|
||||
final JList<User> selectedUserList = (JList<User>) listSelectionEvent.getSource();
|
||||
final User user = selectedUserList.getSelectedValue();
|
||||
client.setRecipient(user);
|
||||
|
||||
currentChat = localDB.getChats()
|
||||
.stream()
|
||||
.filter(chat -> chat.getRecipient().getID() == user.getID())
|
||||
.findFirst()
|
||||
.get();
|
||||
currentChat = localDB.getChats().stream().filter(chat -> chat.getRecipient().getID() == user.getID()).findFirst().get();
|
||||
|
||||
client.setRecipient(user);
|
||||
|
||||
@ -253,10 +245,8 @@ public class ChatWindow extends JFrame {
|
||||
userListModel.addElement(user);
|
||||
|
||||
// Check if user exists in local DB
|
||||
if (localDB.getChats()
|
||||
.stream()
|
||||
.filter(c -> c.getRecipient().getID() == user.getID())
|
||||
.count() == 0) localDB.getChats().add(new Chat(user));
|
||||
if (localDB.getChats().stream().filter(c -> c.getRecipient().getID() == user.getID()).count() == 0)
|
||||
localDB.getChats().add(new Chat(user));
|
||||
});
|
||||
SwingUtilities.invokeLater(() -> userList.setModel(userListModel));
|
||||
}).start();
|
||||
@ -273,9 +263,7 @@ public class ChatWindow extends JFrame {
|
||||
Messages unreadMessages = client.getUnreadMessages(client.getSender().getID());
|
||||
for (int i = 0; i < unreadMessages.getMessage().size(); i++)
|
||||
for (int j = 0; j < localDB.getChats().size(); j++)
|
||||
if (localDB.getChats().get(j)
|
||||
.getRecipient()
|
||||
.getID() == unreadMessages.getMessage().get(i).getMetaData().getSender())
|
||||
if (localDB.getChats().get(j).getRecipient().getID() == unreadMessages.getMessage().get(i).getMetaData().getSender())
|
||||
localDB.getChats().get(j).appendMessage(unreadMessages.getMessage().get(i));
|
||||
}).start();
|
||||
}
|
||||
|
Reference in New Issue
Block a user