Added Javadoc requested by @delvh

This commit is contained in:
Kai S. K. Engelbart 2019-12-18 22:07:05 +01:00
parent 69153005cd
commit 500555c8db
3 changed files with 132 additions and 100 deletions

View File

@ -8,7 +8,7 @@ import javax.swing.JButton;
* Project: <strong>envoy-client</strong><br>
* File: <strong>PrimaryButton.javaEvent.java</strong><br>
* Created: <strong>07.12.2019</strong><br>
*
*
* @author Kai S. K. Engelbart
* @author Maximilian K&auml;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) {

View File

@ -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: <strong>envoy-client</strong><br>
* File: <strong>PrimaryScrollBar.java</strong><br>
* Created: <strong>14.12.2019</strong><br>
*
* @author Maximilian K&auml;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: <strong>envoy-client</strong><br>
* File: <strong>PrimaryScrollBar.java</strong><br>
* Created: <strong>14.12.2019</strong><br>
*
* @author Maximilian K&auml;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();
}
}

View File

@ -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; }
}