Fixed weird toggle switch programming from @CyB3rC0nN0R

This commit is contained in:
DieGurke 2019-12-23 15:54:55 +01:00
parent 66cf42e0d9
commit 4ef0b3352c
2 changed files with 10 additions and 4 deletions

View File

@ -40,6 +40,7 @@ public class PrimaryToggleSwitch extends JButton {
setFocusPainted(false); setFocusPainted(false);
setContentAreaFilled(false); setContentAreaFilled(false);
state = settingsItem.get();
addActionListener((evt) -> { state = !state; settingsItem.set(state); revalidate(); repaint(); }); addActionListener((evt) -> { state = !state; settingsItem.set(state); revalidate(); repaint(); });
} }
@ -47,8 +48,13 @@ public class PrimaryToggleSwitch extends JButton {
public void paintComponent(Graphics g) { public void paintComponent(Graphics g) {
g.setColor(state ? Color.GREEN : Color.LIGHT_GRAY); g.setColor(state ? Color.GREEN : Color.LIGHT_GRAY);
g.fillRect(0, 0, getWidth(), getHeight()); g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(state ? Color.LIGHT_GRAY
: Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor()); g.setColor(Settings.getInstance().getThemes().get(Settings.getInstance().getCurrentTheme()).getInteractableBackgroundColor());
g.fillRect(0, getWidth() / 2, getWidth(), getHeight());
if (state) {
g.fillRect(25, 0, 25, 25);
} else {
g.fillRect(0, 0, 25, 25);
}
} }
} }

View File

@ -81,5 +81,5 @@ public class General extends SettingsPanel {
} }
@Override @Override
public ActionListener getOkButtonAction() { return null; } public ActionListener getOkButtonAction() { return (evt) -> {}; }
} }