Formatting

* Split applyTheme method in applyTheme and autoscroll.
* Added Javadoc
This commit is contained in:
DieGurke 2019-12-15 20:18:43 +01:00
parent 2405d4a6ad
commit 4d235c2cd9
2 changed files with 23 additions and 0 deletions

View File

@ -250,6 +250,7 @@ public class ChatWindow extends JFrame {
messageList.setBackground(theme.getCellColor()); messageList.setBackground(theme.getCellColor());
// scrollPane // scrollPane
scrollPane.applyTheme(theme); scrollPane.applyTheme(theme);
scrollPane.autoscroll();
// messageEnterTextArea // messageEnterTextArea
messageEnterTextArea.setCaretColor(theme.getTypingMessageColor()); messageEnterTextArea.setCaretColor(theme.getTypingMessageColor());

View File

@ -8,6 +8,7 @@ import javax.swing.JScrollPane;
* Created: <strong>15 Dec 2019</strong><br> * Created: <strong>15 Dec 2019</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @author Maximilian K&auml;fer
*/ */
public class PrimaryScrollPane extends JScrollPane { public class PrimaryScrollPane extends JScrollPane {
@ -18,6 +19,12 @@ public class PrimaryScrollPane extends JScrollPane {
public PrimaryScrollPane() { setBorder(null); } public PrimaryScrollPane() { setBorder(null); }
/**
* Styles the vertical and horizontal scroll bars.
*
* @param theme
* @since Envoy v0.2-alpha
*/
public void applyTheme(Theme theme) { public void applyTheme(Theme theme) {
setForeground(theme.getBackgroundColor()); setForeground(theme.getBackgroundColor());
setBackground(theme.getCellColor()); setBackground(theme.getCellColor());
@ -26,7 +33,22 @@ public class PrimaryScrollPane extends JScrollPane {
getVerticalScrollBar().setUI(new PrimaryScrollBar(theme, true)); getVerticalScrollBar().setUI(new PrimaryScrollBar(theme, true));
getHorizontalScrollBar().setBackground(theme.getCellColor()); getHorizontalScrollBar().setBackground(theme.getCellColor());
getHorizontalScrollBar().setUI(new PrimaryScrollBar(theme, false)); getHorizontalScrollBar().setUI(new PrimaryScrollBar(theme, false));
}
/**
* Implements <b>autoscroll functionality</b> for the vertical scroll bar. </br>
* </br>
* Functionality to automatically scroll down when user views </br>
* the bottom of the chat while there are new messages added. </br>
* </br>
* When chat is opened, the vertical scroll bar starts at the bottom. </br>
* </br>
* When rereading messages, the chat doesn't scroll down if new messages </br>
* are added. (Besides see first point)
*
* @since Envoy v0.2-alpha
*/
public void autoscroll() {
// Automatic scrolling to the bottom // Automatic scrolling to the bottom
getVerticalScrollBar().addAdjustmentListener(e -> { getVerticalScrollBar().addAdjustmentListener(e -> {
if (verticalScrollBarMaximum == e.getAdjustable().getMaximum()) return; if (verticalScrollBarMaximum == e.getAdjustable().getMaximum()) return;