From 507e24951218b3667c47be38fe86849d6021acef Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sat, 14 Dec 2019 13:46:19 +0100 Subject: [PATCH] Revised code according to reviews by @delvh and @CyB3RC0nN0R --- src/main/java/envoy/client/ui/ChatWindow.java | 40 +++++++++---------- .../java/envoy/client/ui/PrimaryButton.java | 3 +- .../java/envoy/client/ui/PrimaryTextArea.java | 9 +++-- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 14065b0..1434148 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -53,16 +53,16 @@ public class ChatWindow extends JFrame { private Client client; private LocalDB localDB; // GUI components - private JPanel contentPane = new JPanel(); - private PrimaryTextArea messageEnterTextArea; - private JList userList = new JList<>(); + private JPanel contentPane = new JPanel(); + private PrimaryTextArea messageEnterTextArea = new PrimaryTextArea(space); + private JList userList = new JList<>(); private Chat currentChat; - private JList messageList = new JList<>(); - private JScrollPane scrollPane = new JScrollPane(); - private JTextPane textPane = new JTextPane(); + private JList messageList = new JList<>(); + private JScrollPane scrollPane = new JScrollPane(); + private JTextPane textPane = new JTextPane(); // private JCheckBox jCbChangeMode; - private PrimaryButton postButton; - private PrimaryButton settingsButton; + private PrimaryButton postButton = new PrimaryButton("Post"); + private PrimaryButton settingsButton = new PrimaryButton("Settings"); private static int space = 4; @@ -76,7 +76,8 @@ public class ChatWindow extends JFrame { setBounds(100, 100, 600, 800); setTitle("Envoy"); setLocationRelativeTo(null); - setIconImage(Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("envoy_logo.png"))); + setIconImage( + Toolkit.getDefaultToolkit().createImage(getClass().getClassLoader().getResource("envoy_logo.png"))); // Save chats when window closes addWindowListener(new WindowAdapter() { @@ -124,9 +125,6 @@ public class ChatWindow extends JFrame { gbc_scrollPane.insets = new Insets(space, space, space, space); contentPane.add(scrollPane, gbc_scrollPane); - // Checks for changed Message - messageEnterTextArea = new PrimaryTextArea(space); - // Message enter field messageEnterTextArea.addKeyListener(new KeyAdapter() { @@ -140,7 +138,6 @@ public class ChatWindow extends JFrame { } }); - GridBagConstraints gbc_messageEnterTextfield = new GridBagConstraints(); gbc_messageEnterTextfield.fill = GridBagConstraints.BOTH; gbc_messageEnterTextfield.gridx = 1; @@ -151,7 +148,6 @@ public class ChatWindow extends JFrame { contentPane.add(messageEnterTextArea, gbc_messageEnterTextfield); // Post Button - postButton = new PrimaryButton("Post"); GridBagConstraints gbc_moveSelectionPostButton = new GridBagConstraints(); gbc_moveSelectionPostButton.fill = GridBagConstraints.BOTH; @@ -164,8 +160,6 @@ public class ChatWindow extends JFrame { contentPane.add(postButton, gbc_moveSelectionPostButton); // Settings Button - settingsButton = new PrimaryButton("Settings"); - GridBagConstraints gbc_moveSelectionSettingsButton = new GridBagConstraints(); gbc_moveSelectionSettingsButton.fill = GridBagConstraints.BOTH; @@ -177,8 +171,8 @@ public class ChatWindow extends JFrame { settingsButton.addActionListener((evt) -> { try { SettingsScreen.open(); - changeChatWindowColors(Settings.getInstance().getCurrentTheme()); - } catch (Exception e) { + changeChatWindowColors(Settings.getInstance().getCurrentTheme()); + } catch (Exception e) { SettingsScreen.open(); logger.log(Level.WARNING, "An error occured while opening the settings screen", e); e.printStackTrace(); @@ -207,7 +201,11 @@ public class ChatWindow extends JFrame { 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(); // Set all unread messages in the chat to read readCurrentChat(); @@ -231,7 +229,7 @@ public class ChatWindow extends JFrame { gbc_userList.insets = new Insets(space, space, space, space); changeChatWindowColors(Settings.getInstance().getCurrentTheme()); - + contentPane.add(userList, gbc_userList); contentPane.revalidate(); @@ -240,7 +238,6 @@ public class ChatWindow extends JFrame { contentPane.revalidate(); } - /** * Used to immediately reload the ChatWindow when settings were changed. @@ -373,4 +370,3 @@ public class ChatWindow extends JFrame { */ private void readCurrentChat() { if (currentChat != null) { localDB.setMessagesToRead(currentChat); } } } - diff --git a/src/main/java/envoy/client/ui/PrimaryButton.java b/src/main/java/envoy/client/ui/PrimaryButton.java index 2e528db..fe93571 100644 --- a/src/main/java/envoy/client/ui/PrimaryButton.java +++ b/src/main/java/envoy/client/ui/PrimaryButton.java @@ -11,6 +11,7 @@ import javax.swing.JButton; * * @author Kai S. K. Engelbart * @author Maximilian Käfer + * @since Envoy v0.2-alpha */ public class PrimaryButton extends JButton { @@ -35,8 +36,6 @@ public class PrimaryButton extends JButton { */ public PrimaryButton(String title, int arcSize) { super(title); - // setForeground(new Color(255, 255, 255)); - // setBackground(new Color(102, 51, 153)); setBorderPainted(false); setFocusPainted(false); setContentAreaFilled(false); diff --git a/src/main/java/envoy/client/ui/PrimaryTextArea.java b/src/main/java/envoy/client/ui/PrimaryTextArea.java index 3f350ed..e4d6fa1 100644 --- a/src/main/java/envoy/client/ui/PrimaryTextArea.java +++ b/src/main/java/envoy/client/ui/PrimaryTextArea.java @@ -12,6 +12,7 @@ import javax.swing.border.EmptyBorder; * Created: 07.12.2019
* * @author Maximilian Käfer + * @since Envoy v0.2-alpha */ public class PrimaryTextArea extends JTextArea { @@ -20,7 +21,7 @@ public class PrimaryTextArea extends JTextArea { private int arcSize; /** - * Creates TextArea + * Creates the text area * * @param borderSpace * @since Envoy 0.2-alpha @@ -28,10 +29,10 @@ public class PrimaryTextArea extends JTextArea { public PrimaryTextArea(int borderSpace) { this(6, borderSpace); } /** - * Creates TextArea + * Creates the text area * * @param arcSize - * @param borderSpace + * @param borderSpace - the insets of the border on all four sides * @since Envoy 0.2-alpha */ public PrimaryTextArea(int arcSize, int borderSpace) { @@ -54,7 +55,7 @@ public class PrimaryTextArea extends JTextArea { } /** - * @return the arcSize + * @return the arcSize - the diameter of the arc at the four corners. * @since Envoy 0.2-alpha */ public int getArcSize() { return arcSize; }