DefaultButton refactor: adding visual improvements, existing Classes and Methods, introducing AppTheme interface
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
package Resources.CustomAssets;
|
||||
|
||||
import GUI.AppTheme;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
public class DefaultButton extends JButton implements AppTheme {
|
||||
|
||||
private boolean selected;
|
||||
|
||||
public DefaultButton(String buttonLabel) {
|
||||
|
||||
super(buttonLabel);
|
||||
applyDefaultButtonStyle();
|
||||
applyCommon();
|
||||
|
||||
}
|
||||
|
||||
public void deSelect() {
|
||||
|
||||
selected = false;
|
||||
applyDefaultButtonStyle();
|
||||
|
||||
}
|
||||
|
||||
public void select() {
|
||||
|
||||
selected = true;
|
||||
applyFocusedButtonStyle();
|
||||
|
||||
}
|
||||
|
||||
private void applyDefaultButtonStyle() {
|
||||
|
||||
setBackground(medBrown);
|
||||
setForeground(darkestBrown);
|
||||
|
||||
}
|
||||
|
||||
private void applyFocusedButtonStyle() {
|
||||
|
||||
setBackground(darkestBrown);
|
||||
setForeground(lightAccent);
|
||||
|
||||
}
|
||||
|
||||
private void applyCommon() {
|
||||
|
||||
addMouseListener(
|
||||
new MouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {}
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) { applyFocusedButtonStyle(); }
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
|
||||
if (!selected) {
|
||||
|
||||
applyDefaultButtonStyle();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
setFocusPainted(false);
|
||||
setFont(buttonFont);
|
||||
setBorder(new EmptyBorder(3, 3, 3, 3));
|
||||
|
||||
repaint();
|
||||
revalidate();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package Resources.CustomAssets;
|
||||
|
||||
import javax.swing.border.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class RoundedBorder implements Border {
|
||||
|
||||
private int radius;
|
||||
|
||||
public RoundedBorder(int radius) {
|
||||
|
||||
this.radius = radius;
|
||||
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c) {
|
||||
|
||||
return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius);
|
||||
|
||||
}
|
||||
|
||||
public boolean isBorderOpaque() {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||
|
||||
g.drawRoundRect(x, y, width-1, height-1, radius, radius);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user