108 lines
3.1 KiB
Java
108 lines
3.1 KiB
Java
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.javaEvent.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 int arcSize;
|
|
private Color scrollBarColor;
|
|
private Color hoverColor;
|
|
private Color draggingColor;
|
|
private 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;
|
|
}
|
|
|
|
@Override
|
|
protected JButton createDecreaseButton(int orientation) {
|
|
return new JButton() {
|
|
private static final long serialVersionUID = 1032443171070235890L;
|
|
|
|
@Override
|
|
public Dimension getPreferredSize() {
|
|
return d;
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override
|
|
protected JButton createIncreaseButton (int orientation) {
|
|
return new JButton() {
|
|
|
|
private static final long serialVersionUID = 7575774542623215803L;
|
|
|
|
@Override
|
|
public Dimension getPreferredSize() {
|
|
return d;
|
|
}
|
|
};
|
|
}
|
|
@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 = 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;
|
|
}
|
|
|
|
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);
|
|
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();
|
|
}
|
|
}
|