fix
All checks were successful
Build the Jar / build (push) Successful in 12s

This commit is contained in:
2025-12-22 09:53:31 -06:00
parent fdbcb56b1b
commit f15534c4d5

View File

@@ -54,10 +54,23 @@ public class Calculator extends JFrame implements KeyListener {
}
public static void main(String[] args) {
// IntelliJTheme.setup(Calculator.class.getResourceAsStream("/DarkPurple.theme.json"));
FlatMacDarkLaf.setup();
// MacDarkRed.setup();
// MacDarkBlue.setup();
// Load saved theme preference
String savedTheme = prefs.get(PREF_THEME, "MacDarkBlue");
// Apply saved theme on startup
try {
switch (savedTheme) {
case "MacDarkBlue" -> MacDarkBlue.setup();
case "MacDarkRed" -> MacDarkRed.setup();
case "MacLightBlue" -> MacLightBlue.setup();
case "MacLightRed" -> MacLightRed.setup();
case "Default" -> FlatMacDarkLaf.setup();
default -> FlatMacDarkLaf.setup();
}
} catch (Exception e) {
FlatMacDarkLaf.setup();
}
System.out.println("\nangel's awesome calculator (acc) " + Calculator.getVersion());
System.out.println("created by angel");
System.out.println("---------------------------------");
@@ -69,11 +82,6 @@ public class Calculator extends JFrame implements KeyListener {
if( SystemInfo.isLinux ) { // why is linux different
JFrame.setDefaultLookAndFeelDecorated(true);
}
try {
UIManager.setLookAndFeel("com.formdev.flatlaf.themes.FlatMacDarkLaf");
} catch (Throwable e) {
e.printStackTrace();
}
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
@@ -440,7 +448,7 @@ public class Calculator extends JFrame implements KeyListener {
private void PreferencesAction() {
JDialog dialog = new JDialog(this, "Preferences", true);
dialog.setSize(320, 220);
dialog.setSize(400, 280);
dialog.setLocationRelativeTo(this);
dialog.setLayout(new BorderLayout(10, 10));
@@ -448,9 +456,31 @@ public class Calculator extends JFrame implements KeyListener {
panel.setBorder(new EmptyBorder(10, 10, 10, 10));
panel.setLayout(new GridLayout(0, 2, 8, 8));
// Theme selector
JComboBox<String> themeBox = new JComboBox<>(new String[]{"Dark", "Light"});
themeBox.setSelectedItem(prefs.get(PREF_THEME, "Dark"));
// Color theme selector
JComboBox<String> colorThemeBox = new JComboBox<>(new String[]{
"Default", "MacDarkBlue", "MacDarkRed", "MacLightBlue", "MacLightRed"
});
String savedTheme = prefs.get(PREF_THEME, "MacDarkBlue");
colorThemeBox.setSelectedItem(savedTheme);
// Light/Dark mode toggle
JComboBox<String> modeBox = new JComboBox<>(new String[]{"Dark", "Light"});
boolean isDark = isThemeDark(savedTheme);
modeBox.setSelectedItem(isDark ? "Dark" : "Light");
// Update color theme when mode changes
modeBox.addActionListener(e -> {
String currentTheme = (String) colorThemeBox.getSelectedItem();
String mode = (String) modeBox.getSelectedItem();
String counterpart = getThemeCounterpart(currentTheme, "Light".equals(mode));
colorThemeBox.setSelectedItem(counterpart);
});
// Update mode when color theme changes
colorThemeBox.addActionListener(e -> {
String theme = (String) colorThemeBox.getSelectedItem();
modeBox.setSelectedItem(isThemeDark(theme) ? "Dark" : "Light");
});
// Font size
JSpinner fontSizeSpinner = new JSpinner(
@@ -460,16 +490,19 @@ public class Calculator extends JFrame implements KeyListener {
)
);
// Always on top
// Always on top
JCheckBox alwaysOnTopBox = new JCheckBox(
"Always on top",
prefs.getBoolean(PREF_ALWAYS_ON_TOP, false)
);
panel.add(new JLabel("Theme"));
panel.add(themeBox);
panel.add(new JLabel("Color Theme:"));
panel.add(colorThemeBox);
panel.add(new JLabel("Font size"));
panel.add(new JLabel("Mode:"));
panel.add(modeBox);
panel.add(new JLabel("Font Size:"));
panel.add(fontSizeSpinner);
panel.add(new JLabel(""));
@@ -479,7 +512,7 @@ public class Calculator extends JFrame implements KeyListener {
JButton close = new JButton("Close");
apply.addActionListener(e -> {
String theme = (String) themeBox.getSelectedItem();
String theme = (String) colorThemeBox.getSelectedItem();
int fontSize = (int) fontSizeSpinner.getValue();
boolean alwaysOnTop = alwaysOnTopBox.isSelected();
@@ -506,11 +539,20 @@ public class Calculator extends JFrame implements KeyListener {
try {
FlatAnimatedLafChange.showSnapshot();
if ("Light".equals(theme)) {
FlatIntelliJLaf.setup();
} else {
FlatDarculaLaf.setup();
}
switch (theme) {
case "Default" -> {
if (FlatLaf.isLafDark()) {
FlatDarculaLaf.setup();
} else {
FlatIntelliJLaf.setup();
}
}
case "MacDarkBlue" -> MacDarkBlue.setup();
case "MacDarkRed" -> MacDarkRed.setup();
case "MacLightBlue" -> MacLightBlue.setup();
case "MacLightRed" -> MacLightRed.setup();
default -> FlatDarculaLaf.setup();
}
FlatLaf.updateUI();
FlatAnimatedLafChange.hideSnapshotWithAnimation();
} catch (Exception ex) {
@@ -691,6 +733,8 @@ public class Calculator extends JFrame implements KeyListener {
case "dark", "darcula" -> FlatDarculaLaf.setup();
case "macdarkblue" -> MacDarkBlue.setup();
case "macdarkred" -> MacDarkRed.setup();
case "maclightblue" -> MacLightBlue.setup();
case "maclightred" -> MacLightRed.setup();
default -> FlatDarculaLaf.setup();
}
FlatLaf.updateUI();
@@ -701,8 +745,42 @@ public class Calculator extends JFrame implements KeyListener {
}
}
/**
* Determines if a theme is dark mode
*/
private boolean isThemeDark(String theme) {
if (theme == null) return true;
return theme.toLowerCase().contains("dark") ||
"Default".equals(theme) && FlatLaf.isLafDark();
}
/**
* Gets the light/dark counterpart of a theme
* For example: MacDarkBlue <-> MacLightBlue
*/
private String getThemeCounterpart(String theme, boolean toLight) {
if (theme == null || "Default".equals(theme)) {
return "Default";
}
// Handle Mac themes
if (theme.startsWith("Mac")) {
if (toLight) {
// Switch to light variant
return theme.replace("Dark", "Light");
} else {
// Switch to dark variant
return theme.replace("Light", "Dark");
}
}
return theme;
}
private boolean isCustomMacTheme(String theme) {
return theme.equalsIgnoreCase("macdarkblue") || theme.equalsIgnoreCase("macdarkred");
String lower = theme.toLowerCase();
return lower.equals("macdarkblue") || lower.equals("macdarkred") ||
lower.equals("maclightblue") || lower.equals("maclightred");
}