From 6bfa3c2b79426c01f5f85c418a5c77ce4eb51ffb Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Sun, 15 Dec 2019 00:34:44 +0100 Subject: [PATCH] Horizontal Scroll Bar Implemented primaryScrollBar support for horizontal scroll bar as well. --- src/main/java/envoy/client/ui/ChatWindow.java | 10 ++++++- .../envoy/client/ui/PrimaryScrollBar.java | 26 ++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index a6510ec..6968f5c 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -262,7 +262,15 @@ public class ChatWindow extends JFrame { scrollPane.getVerticalScrollBar() .setUI(new PrimaryScrollBar(5, theme.getInteractableBackgroundColor(), new Color(theme.getInteractableBackgroundColor().getRGB() - 50), - new Color(theme.getInteractableBackgroundColor().getRGB() + 170))); + new Color(theme.getInteractableBackgroundColor().getRGB() + 170), true)); + scrollPane.getHorizontalScrollBar().setBackground(theme.getCellColor()); + scrollPane.getHorizontalScrollBar() + .setUI(new PrimaryScrollBar(5, theme.getInteractableBackgroundColor(), new Color(theme.getInteractableBackgroundColor().getRGB() - 50), + new Color(theme.getInteractableBackgroundColor().getRGB() + 170), false)); + // int currentVerticalScrollBarValue = + // scrollPane.getVerticalScrollBar().getValue() + + // scrollPane.getVerticalScrollBar().getVisibleAmount(); Work in Progress for + // autoscroll // messageEnterTextArea messageEnterTextArea.setCaretColor(theme.getTypingMessageColor()); messageEnterTextArea.setForeground(theme.getTypingMessageColor()); diff --git a/src/main/java/envoy/client/ui/PrimaryScrollBar.java b/src/main/java/envoy/client/ui/PrimaryScrollBar.java index aaaa0a0..546119b 100644 --- a/src/main/java/envoy/client/ui/PrimaryScrollBar.java +++ b/src/main/java/envoy/client/ui/PrimaryScrollBar.java @@ -29,12 +29,14 @@ public class PrimaryScrollBar extends BasicScrollBarUI{ private Color scrollBarColor; private Color hoverColor; private Color draggingColor; + private boolean isVertical; - public PrimaryScrollBar(int arcSize, Color scrollBarColor, Color hoverColor, Color draggingColor) { + public PrimaryScrollBar(int arcSize, Color scrollBarColor, Color hoverColor, Color draggingColor, boolean isVertical) { this.arcSize = arcSize; this.scrollBarColor = scrollBarColor; this.hoverColor = hoverColor; this.draggingColor = draggingColor; + this.isVertical = isVertical; } @Override @@ -71,7 +73,7 @@ public class PrimaryScrollBar extends BasicScrollBarUI{ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Color color = null; JScrollBar sb = (JScrollBar) c; - if (!sb.isEnabled() || r.width > r.height) { + if (!sb.isEnabled() || (isVertical == true && r.width > r.height) || (isVertical == false && r.width < r.height)) { return; } else if (isDragging) { color = draggingColor; @@ -80,11 +82,21 @@ public class PrimaryScrollBar extends BasicScrollBarUI{ } else { color = scrollBarColor; } - g2.setPaint(color); - g2.fillRoundRect(r.x + 9, r.y, r.width - 10, r.height, arcSize, arcSize); - g2.setPaint(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor()); - g2.drawRoundRect(r.x + 9, r.y, r.width - 10, r.height, arcSize, arcSize); - g2.dispose(); + + if (isVertical == true) { + g2.setPaint(color); + g2.fillRoundRect(r.x + 9, r.y, r.width - 10, r.height, arcSize, arcSize); + g2.setPaint(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor()); + g2.drawRoundRect(r.x + 9, r.y, r.width - 10, r.height, arcSize, arcSize); + g2.dispose(); + } + if (isVertical == false) { + g2.setPaint(color); + g2.fillRoundRect(r.x, r.y + 9, r.width, r.height - 10, arcSize, arcSize); + g2.setPaint(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor()); + g2.drawRoundRect(r.x, r.y + 9, r.width, r.height - 10, arcSize, arcSize); + g2.dispose(); + } } @Override