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