From adb5c417c541ed85bdce5b6d1583faed96127d97 Mon Sep 17 00:00:00 2001 From: kske Date: Sun, 15 Dec 2019 16:26:11 +0100 Subject: [PATCH] Improved code style and formatting --- src/main/java/envoy/client/ui/ChatWindow.java | 33 ++++---- .../envoy/client/ui/PrimaryScrollBar.java | 83 ++++++++----------- 2 files changed, 48 insertions(+), 68 deletions(-) diff --git a/src/main/java/envoy/client/ui/ChatWindow.java b/src/main/java/envoy/client/ui/ChatWindow.java index 134734f..2e263da 100644 --- a/src/main/java/envoy/client/ui/ChatWindow.java +++ b/src/main/java/envoy/client/ui/ChatWindow.java @@ -49,22 +49,22 @@ public class ChatWindow extends JFrame { private static final long serialVersionUID = 6865098428255463649L; - // user specific objects + // User specific objects private Client client; private LocalDB localDB; + // GUI components - private JPanel contentPane = new JPanel(); - private PrimaryTextArea messageEnterTextArea = new PrimaryTextArea(space); - 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 JCheckBox jCbChangeMode; - private PrimaryButton postButton = new PrimaryButton("Post"); - private PrimaryButton settingsButton = new PrimaryButton("Settings"); + private JList messageList = new JList<>(); + private JScrollPane scrollPane = new JScrollPane(); private int verticalScrollBarMaximumValue = scrollPane.getVerticalScrollBar().getMaximum(); private boolean chatOpened = false; + private JTextPane textPane = new JTextPane(); + private PrimaryButton postButton = new PrimaryButton("Post"); + private PrimaryButton settingsButton = new PrimaryButton("Settings"); private static int space = 4; @@ -239,7 +239,7 @@ public class ChatWindow extends JFrame { /** * Used to immediately reload the ChatWindow when settings were changed. - * + * * @since Envoy v0.1-alpha */ public void changeChatWindowColors(String key) { @@ -260,8 +260,7 @@ public class ChatWindow extends JFrame { // Scroll Bar Styling scrollPane.getVerticalScrollBar().setBackground(theme.getCellColor()); scrollPane.getVerticalScrollBar() - .setUI(new PrimaryScrollBar(5, theme.getInteractableBackgroundColor(), - new Color(theme.getInteractableBackgroundColor().getRGB() - 50), + .setUI(new PrimaryScrollBar(5, theme.getInteractableBackgroundColor(), new Color(theme.getInteractableBackgroundColor().getRGB() - 50), new Color(theme.getInteractableBackgroundColor().getRGB() + 170), true)); scrollPane.getHorizontalScrollBar().setBackground(theme.getCellColor()); scrollPane.getHorizontalScrollBar() @@ -270,9 +269,7 @@ public class ChatWindow extends JFrame { // Autoscroll scrollPane.getVerticalScrollBar().addAdjustmentListener(e -> { - if ((verticalScrollBarMaximumValue - e.getAdjustable().getMaximum()) == 0) { - return; - } + if ((verticalScrollBarMaximumValue - e.getAdjustable().getMaximum()) == 0) { return; } if (chatOpened == true) { e.getAdjustable().setValue(e.getAdjustable().getMaximum()); @@ -280,8 +277,8 @@ public class ChatWindow extends JFrame { chatOpened = false; return; } - if (scrollPane.getVerticalScrollBar().getValue() - + scrollPane.getVerticalScrollBar().getVisibleAmount() + 100 >= scrollPane.getVerticalScrollBar().getMaximum()) { + if (scrollPane.getVerticalScrollBar().getValue() + scrollPane.getVerticalScrollBar().getVisibleAmount() + + 100 >= scrollPane.getVerticalScrollBar().getMaximum()) { e.getAdjustable().setValue(e.getAdjustable().getMaximum()); verticalScrollBarMaximumValue = scrollPane.getVerticalScrollBar().getMaximum(); } diff --git a/src/main/java/envoy/client/ui/PrimaryScrollBar.java b/src/main/java/envoy/client/ui/PrimaryScrollBar.java index a7dc073..845448c 100644 --- a/src/main/java/envoy/client/ui/PrimaryScrollBar.java +++ b/src/main/java/envoy/client/ui/PrimaryScrollBar.java @@ -16,23 +16,23 @@ import envoy.client.Settings; /** * Project: envoy-client
- * File: PrimaryScrollBar.javaEvent.java
+ * File: PrimaryScrollBar.java
* Created: 14.12.2019
- * + * * @author Maximilian Käfer * @since Envoy v0.2-alpha */ -public class PrimaryScrollBar extends BasicScrollBarUI{ - +public class PrimaryScrollBar extends BasicScrollBarUI { + private final Dimension d = new Dimension(); - private int arcSize; - private Color scrollBarColor; - private Color hoverColor; - private Color draggingColor; - private boolean isVertical; - + private final int arcSize; + private final Color scrollBarColor; + private final Color hoverColor; + private final Color draggingColor; + private final boolean isVertical; + public PrimaryScrollBar(int arcSize, Color scrollBarColor, Color hoverColor, Color draggingColor, boolean isVertical) { - this.arcSize = arcSize; + this.arcSize = arcSize; this.scrollBarColor = scrollBarColor; this.hoverColor = hoverColor; this.draggingColor = draggingColor; @@ -41,62 +41,45 @@ public class PrimaryScrollBar extends BasicScrollBarUI{ @Override protected JButton createDecreaseButton(int orientation) { - return new JButton() { - private static final long serialVersionUID = 1032443171070235890L; - - @Override - public Dimension getPreferredSize() { - return d; - } - }; + JButton button = new JButton(); + button.setPreferredSize(d); + return button; } - + @Override - protected JButton createIncreaseButton (int orientation) { - return new JButton() { - - private static final long serialVersionUID = 7575774542623215803L; - - @Override - public Dimension getPreferredSize() { - return d; - } - }; + protected JButton createIncreaseButton(int orientation) { + JButton button = new JButton(); + button.setPreferredSize(d); + return button; } + @Override - protected void paintTrack(Graphics g, JComponent c, Rectangle r) { - } - + protected void paintTrack(Graphics g, JComponent c, Rectangle r) {} + @Override protected void paintThumb(Graphics g, JComponent c, Rectangle r) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - Color color = null; - JScrollBar sb = (JScrollBar) c; - if (!sb.isEnabled() || (isVertical == true && r.width > r.height) || (isVertical == false && r.width < r.height)) { - return; - } else if (isDragging) { - color = draggingColor; - } else if (isThumbRollover()) { - color = hoverColor; - } else { - color = scrollBarColor; - } + Color color; + JScrollBar sb = (JScrollBar) c; + if (!sb.isEnabled() || (isVertical && r.width > r.height) || (!isVertical && r.width < r.height)) return; + + if (isDragging) color = draggingColor; + else if (isThumbRollover()) color = hoverColor; + else color = scrollBarColor; + + g2.setPaint(color); if (isVertical) { - 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) { - g2.setPaint(color); + } else { 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(); } + g2.dispose(); } @Override