112 lines
3.5 KiB
Java
112 lines
3.5 KiB
Java
package envoy.client.ui.primary;
|
|
|
|
import java.awt.*;
|
|
|
|
import javax.swing.JButton;
|
|
import javax.swing.JComponent;
|
|
import javax.swing.JScrollBar;
|
|
import javax.swing.plaf.basic.BasicScrollBarUI;
|
|
|
|
import envoy.client.data.Settings;
|
|
import envoy.client.ui.Theme;
|
|
|
|
/**
|
|
* Project: <strong>envoy-client</strong><br>
|
|
* File: <strong>PrimaryScrollBar.java</strong><br>
|
|
* Created: <strong>14.12.2019</strong><br>
|
|
*
|
|
* @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().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().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();
|
|
}
|
|
}
|