From 4d235c2cd97cb1ba9f67dc3dd11e3a10d4cca25e Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sun, 15 Dec 2019 20:18:43 +0100 Subject: [PATCH] Formatting * Split applyTheme method in applyTheme and autoscroll. * Added Javadoc --- src/main/java/envoy/client/ui/ChatWindow.java | 1 + .../envoy/client/ui/PrimaryScrollPane.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 3a28754..9595d43 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -250,6 +250,7 @@ public class ChatWindow extends JFrame { messageList.setBackground(theme.getCellColor()); // scrollPane scrollPane.applyTheme(theme); + scrollPane.autoscroll(); // messageEnterTextArea messageEnterTextArea.setCaretColor(theme.getTypingMessageColor()); diff --git a/src/main/java/envoy/client/ui/PrimaryScrollPane.java b/src/main/java/envoy/client/ui/PrimaryScrollPane.java index d4e0b28..904806a 100644 --- a/src/main/java/envoy/client/ui/PrimaryScrollPane.java +++ b/src/main/java/envoy/client/ui/PrimaryScrollPane.java @@ -8,6 +8,7 @@ import javax.swing.JScrollPane; * Created: 15 Dec 2019
* * @author Kai S. K. Engelbart + * @author Maximilian Käfer */ public class PrimaryScrollPane extends JScrollPane { @@ -18,6 +19,12 @@ public class PrimaryScrollPane extends JScrollPane { public PrimaryScrollPane() { setBorder(null); } + /** + * Styles the vertical and horizontal scroll bars. + * + * @param theme + * @since Envoy v0.2-alpha + */ public void applyTheme(Theme theme) { setForeground(theme.getBackgroundColor()); setBackground(theme.getCellColor()); @@ -26,7 +33,22 @@ public class PrimaryScrollPane extends JScrollPane { getVerticalScrollBar().setUI(new PrimaryScrollBar(theme, true)); getHorizontalScrollBar().setBackground(theme.getCellColor()); getHorizontalScrollBar().setUI(new PrimaryScrollBar(theme, false)); + } + /** + * Implements autoscroll functionality for the vertical scroll bar.
+ *
+ * Functionality to automatically scroll down when user views
+ * the bottom of the chat while there are new messages added.
+ *
+ * When chat is opened, the vertical scroll bar starts at the bottom.
+ *
+ * When rereading messages, the chat doesn't scroll down if new messages
+ * are added. (Besides see first point) + * + * @since Envoy v0.2-alpha + */ + public void autoscroll() { // Automatic scrolling to the bottom getVerticalScrollBar().addAdjustmentListener(e -> { if (verticalScrollBarMaximum == e.getAdjustable().getMaximum()) return;