From acb744a34d955fcdd16549db8dbbce28afd52f66 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 9 Nov 2019 17:47:18 +0100 Subject: [PATCH] Revised merge conflict changes --- src/main/java/envoy/client/LocalDB.java | 2 +- src/main/java/envoy/client/ui/ChatWindow.java | 68 ++++++++----------- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/main/java/envoy/client/LocalDB.java b/src/main/java/envoy/client/LocalDB.java index 84383b3..142b687 100644 --- a/src/main/java/envoy/client/LocalDB.java +++ b/src/main/java/envoy/client/LocalDB.java @@ -367,5 +367,5 @@ public class LocalDB { * @return the User who initialised the local Database * @since Envoy v0.1-alpha */ - public User getUser() { return client; } + public User getUser() { return sender; } } diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index e98a476..2a7ae11 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -125,8 +125,8 @@ public class ChatWindow extends JFrame { if (e.getKeyCode() == KeyEvent.VK_ENTER && ((SettingsScreen.enterToSend && e.getModifiersEx() == 0) || (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK))) { - postMessage(client, messageList); + postMessage(messageList); } } @@ -164,42 +164,9 @@ public class ChatWindow extends JFrame { gbc_moveSelectionPostButton.insets = new Insets(10, 10, 10, 10); + postButton.addActionListener((evt) -> { postMessage(messageList); }); + contentPane.add(postButton, gbc_moveSelectionPostButton); - postButton.addActionListener((evt) -> { - if (!client.hasRecipient()) { - JOptionPane.showMessageDialog(this, - "Please select a recipient!", - "Cannot send message", - JOptionPane.INFORMATION_MESSAGE); - } - - // Create and send message object - final Message message = localDB.createMessage(messageEnterTextArea.getText(), - currentChat.getRecipient()); - localDB.addWaitingMessageToLocalDB(message, currentChat); - messageList.setModel(currentChat.getModel()); - - contentPane.add(postButton, gbc_moveSelectionPostButton); - - if (!messageEnterTextArea.getText().isEmpty()) try { - - // Create and send message object - final Message message = localDB.createMessage(messageEnterTextArea.getText(), currentChat.getRecipient()); - localDB.addWaitingMessageToLocalDB(message, currentChat); - messageList.setModel(currentChat.getModel()); - - // Clear text field - messageEnterTextArea.setText(""); - contentPane.revalidate(); - } catch (Exception e) { - JOptionPane.showMessageDialog(this, - "An exception occured while sending a message. See the log for more details.", - "Exception occured", - JOptionPane.ERROR_MESSAGE); - e.printStackTrace(); - }); - - // Settings Button JButton settingsButton = new JButton("Settings"); settingsButton.setForeground(new Color(255, 255, 255)); @@ -208,7 +175,6 @@ public class ChatWindow extends JFrame { GridBagConstraints gbc_moveSelectionSettingsButton = new GridBagConstraints(); - gbc_moveSelectionSettingsButton.fill = GridBagConstraints.BOTH; gbc_moveSelectionSettingsButton.gridx = 2; gbc_moveSelectionSettingsButton.gridy = 0; @@ -291,7 +257,33 @@ public class ChatWindow extends JFrame { contentPane.revalidate(); } - + private void postMessage(JList messageList) { + if (!client.hasRecipient()) { + JOptionPane.showMessageDialog(this, + "Please select a recipient!", + "Cannot send message", + JOptionPane.INFORMATION_MESSAGE); + } + + if (!messageEnterTextArea.getText().isEmpty()) try { + + // Create and send message object + final Message message = localDB.createMessage(messageEnterTextArea.getText(), currentChat.getRecipient()); + localDB.addWaitingMessageToLocalDB(message, currentChat); + messageList.setModel(currentChat.getModel()); + + // Clear text field + messageEnterTextArea.setText(""); + contentPane.revalidate(); + } catch (Exception e) { + JOptionPane.showMessageDialog(this, + "An exception occured while sending a message. See the log for more details.", + "Exception occured", + JOptionPane.ERROR_MESSAGE); + e.printStackTrace(); + } + } + /** * Initializes the elements of the user list by downloading them from the * server.