From 500555c8dbfb6ebdc64a8221dd65731529a93328 Mon Sep 17 00:00:00 2001 From: kske Date: Wed, 18 Dec 2019 22:07:05 +0100 Subject: [PATCH] Added Javadoc requested by @delvh --- .../java/envoy/client/ui/PrimaryButton.java | 10 +- .../envoy/client/ui/PrimaryScrollBar.java | 210 ++++++++++-------- .../envoy/client/ui/PrimaryScrollPane.java | 12 + 3 files changed, 132 insertions(+), 100 deletions(-) diff --git a/src/main/java/envoy/client/ui/PrimaryButton.java b/src/main/java/envoy/client/ui/PrimaryButton.java index fe93571..65c52a0 100644 --- a/src/main/java/envoy/client/ui/PrimaryButton.java +++ b/src/main/java/envoy/client/ui/PrimaryButton.java @@ -8,7 +8,7 @@ import javax.swing.JButton; * Project: envoy-client
* File: PrimaryButton.javaEvent.java
* Created: 07.12.2019
- * + * * @author Kai S. K. Engelbart * @author Maximilian Käfer * @since Envoy v0.2-alpha @@ -21,7 +21,7 @@ public class PrimaryButton extends JButton { /** * Creates a primary button - * + * * @param title the title of the button * @since Envoy 0.2-alpha */ @@ -29,9 +29,9 @@ public class PrimaryButton extends JButton { /** * Creates a primary button - * - * @param title the title of the button - * @param the size of the arc used to draw the round button edges + * + * @param title the title of the button + * @param arcSize the size of the arc used to draw the round button edges * @since Envoy 0.2-alpha */ public PrimaryButton(String title, int arcSize) { diff --git a/src/main/java/envoy/client/ui/PrimaryScrollBar.java b/src/main/java/envoy/client/ui/PrimaryScrollBar.java index 20bed6c..a7cb8fc 100644 --- a/src/main/java/envoy/client/ui/PrimaryScrollBar.java +++ b/src/main/java/envoy/client/ui/PrimaryScrollBar.java @@ -1,95 +1,115 @@ -package envoy.client.ui; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.RenderingHints; - -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JScrollBar; -import javax.swing.plaf.basic.BasicScrollBarUI; - -import envoy.client.Settings; - -/** - * Project: envoy-client
- * File: PrimaryScrollBar.java
- * Created: 14.12.2019
- * - * @author Maximilian Käfer - * @since Envoy v0.2-alpha - */ -public class PrimaryScrollBar extends BasicScrollBarUI { - - private final Dimension d = new Dimension(); - 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.scrollBarColor = scrollBarColor; - this.hoverColor = hoverColor; - this.draggingColor = draggingColor; - this.isVertical = isVertical; - } - - public PrimaryScrollBar(Theme theme, boolean isVertical) { - this(5, theme.getInteractableBackgroundColor(), new Color(theme.getInteractableBackgroundColor().getRGB() - 50), - new Color(theme.getInteractableBackgroundColor().getRGB() + 170), isVertical); - } - - @Override - protected JButton createDecreaseButton(int orientation) { - JButton button = new JButton(); - button.setPreferredSize(d); - return button; - } - - @Override - protected JButton createIncreaseButton(int orientation) { - JButton button = new JButton(); - button.setPreferredSize(d); - return button; - } - - @Override - 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; - JScrollBar sb = (JScrollBar) c; - - if (!sb.isEnabled()) return; - - if (isDragging) color = draggingColor; - else if (isThumbRollover()) color = hoverColor; - else color = scrollBarColor; - - g2.setPaint(color); - if (isVertical) { - g2.fillRoundRect(r.x - 9, r.y, r.width, r.height, arcSize, arcSize); - g2.setPaint(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor()); - g2.drawRoundRect(r.x - 9, r.y, r.width, r.height, arcSize, arcSize); - } 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(); - } - - @Override - protected void setThumbBounds(int x, int y, int width, int height) { - super.setThumbBounds(x, y, width, height); - scrollbar.repaint(); - } -} +package envoy.client.ui; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.RenderingHints; + +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JScrollBar; +import javax.swing.plaf.basic.BasicScrollBarUI; + +import envoy.client.Settings; + +/** + * Project: envoy-client
+ * File: PrimaryScrollBar.java
+ * Created: 14.12.2019
+ * + * @author Maximilian Käfer + * @since Envoy v0.2-alpha + */ +public class PrimaryScrollBar extends BasicScrollBarUI { + + private final Dimension d = new Dimension(); + private final int arcSize; + private final Color scrollBarColor; + private final Color hoverColor; + private final Color draggingColor; + private final boolean isVertical; + + /** + * Initializes a {@link PrimaryScrollBar} with a color scheme. + * + * @param arcSize the size of the arc used to draw the round scroll bar + * edges + * @param scrollBarColor the default color + * @param hoverColor the color while hovering + * @param draggingColor the color while dragging + * @param isVertical indicates whether this is a vertical + * {@link PrimaryScrollBar} + */ + 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; + } + + /** + * Initializes a {@link PrimaryScrollBar} using a color scheme specified in a + * {@link Theme} + * + * @param theme the {@link Theme} to be applied to this + * {@link PrimaryScrollBar} + * @param isVertical indicates whether this is a vertical + * {@link PrimaryScrollBar} + */ + public PrimaryScrollBar(Theme theme, boolean isVertical) { + this(5, theme.getInteractableBackgroundColor(), new Color(theme.getInteractableBackgroundColor().getRGB() - 50), + new Color(theme.getInteractableBackgroundColor().getRGB() + 170), isVertical); + } + + @Override + protected JButton createDecreaseButton(int orientation) { + JButton button = new JButton(); + button.setPreferredSize(d); + return button; + } + + @Override + protected JButton createIncreaseButton(int orientation) { + JButton button = new JButton(); + button.setPreferredSize(d); + return button; + } + + @Override + 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; + JScrollBar sb = (JScrollBar) c; + + if (!sb.isEnabled()) return; + + if (isDragging) color = draggingColor; + else if (isThumbRollover()) color = hoverColor; + else color = scrollBarColor; + + g2.setPaint(color); + if (isVertical) { + g2.fillRoundRect(r.x - 9, r.y, r.width, r.height, arcSize, arcSize); + g2.setPaint(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getCellColor()); + g2.drawRoundRect(r.x - 9, r.y, r.width, r.height, arcSize, arcSize); + } 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(); + } + + @Override + protected void setThumbBounds(int x, int y, int width, int height) { + super.setThumbBounds(x, y, width, height); + scrollbar.repaint(); + } +} diff --git a/src/main/java/envoy/client/ui/PrimaryScrollPane.java b/src/main/java/envoy/client/ui/PrimaryScrollPane.java index 61c348a..8b78a99 100644 --- a/src/main/java/envoy/client/ui/PrimaryScrollPane.java +++ b/src/main/java/envoy/client/ui/PrimaryScrollPane.java @@ -17,6 +17,11 @@ public class PrimaryScrollPane extends JScrollPane { private int verticalScrollBarMaximum = getVerticalScrollBar().getMaximum(); private boolean chatOpened = false; + /** + * Initializes a {@link JScrollPane} with the primary Envoy design scheme + * + * @since Envoy v0.2-alpha + */ public PrimaryScrollPane() { setBorder(null); } /** @@ -67,5 +72,12 @@ public class PrimaryScrollPane extends JScrollPane { }); } + /** + * Indicates a chat being opened by the user to this {@link PrimaryScrollPane} + * triggering it to automatically scroll down. + * + * @param chatOpened indicates the chat opening status + * @since Envoy v0.2-alpha + */ public void setChatOpened(boolean chatOpened) { this.chatOpened = chatOpened; } }