This commit is contained in:
@@ -54,10 +54,23 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// IntelliJTheme.setup(Calculator.class.getResourceAsStream("/DarkPurple.theme.json"));
|
// Load saved theme preference
|
||||||
FlatMacDarkLaf.setup();
|
String savedTheme = prefs.get(PREF_THEME, "MacDarkBlue");
|
||||||
// MacDarkRed.setup();
|
|
||||||
// MacDarkBlue.setup();
|
// 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("\nangel's awesome calculator (acc) " + Calculator.getVersion());
|
||||||
System.out.println("created by angel");
|
System.out.println("created by angel");
|
||||||
System.out.println("---------------------------------");
|
System.out.println("---------------------------------");
|
||||||
@@ -69,11 +82,6 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
if( SystemInfo.isLinux ) { // why is linux different
|
if( SystemInfo.isLinux ) { // why is linux different
|
||||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
UIManager.setLookAndFeel("com.formdev.flatlaf.themes.FlatMacDarkLaf");
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
EventQueue.invokeLater(new Runnable() {
|
EventQueue.invokeLater(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@@ -440,7 +448,7 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
|
|
||||||
private void PreferencesAction() {
|
private void PreferencesAction() {
|
||||||
JDialog dialog = new JDialog(this, "Preferences", true);
|
JDialog dialog = new JDialog(this, "Preferences", true);
|
||||||
dialog.setSize(320, 220);
|
dialog.setSize(400, 280);
|
||||||
dialog.setLocationRelativeTo(this);
|
dialog.setLocationRelativeTo(this);
|
||||||
dialog.setLayout(new BorderLayout(10, 10));
|
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.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||||
panel.setLayout(new GridLayout(0, 2, 8, 8));
|
panel.setLayout(new GridLayout(0, 2, 8, 8));
|
||||||
|
|
||||||
// Theme selector
|
// Color theme selector
|
||||||
JComboBox<String> themeBox = new JComboBox<>(new String[]{"Dark", "Light"});
|
JComboBox<String> colorThemeBox = new JComboBox<>(new String[]{
|
||||||
themeBox.setSelectedItem(prefs.get(PREF_THEME, "Dark"));
|
"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
|
// Font size
|
||||||
JSpinner fontSizeSpinner = new JSpinner(
|
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(
|
JCheckBox alwaysOnTopBox = new JCheckBox(
|
||||||
"Always on top",
|
"Always on top",
|
||||||
prefs.getBoolean(PREF_ALWAYS_ON_TOP, false)
|
prefs.getBoolean(PREF_ALWAYS_ON_TOP, false)
|
||||||
);
|
);
|
||||||
|
|
||||||
panel.add(new JLabel("Theme"));
|
panel.add(new JLabel("Color Theme:"));
|
||||||
panel.add(themeBox);
|
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(fontSizeSpinner);
|
||||||
|
|
||||||
panel.add(new JLabel(""));
|
panel.add(new JLabel(""));
|
||||||
@@ -479,7 +512,7 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
JButton close = new JButton("Close");
|
JButton close = new JButton("Close");
|
||||||
|
|
||||||
apply.addActionListener(e -> {
|
apply.addActionListener(e -> {
|
||||||
String theme = (String) themeBox.getSelectedItem();
|
String theme = (String) colorThemeBox.getSelectedItem();
|
||||||
int fontSize = (int) fontSizeSpinner.getValue();
|
int fontSize = (int) fontSizeSpinner.getValue();
|
||||||
boolean alwaysOnTop = alwaysOnTopBox.isSelected();
|
boolean alwaysOnTop = alwaysOnTopBox.isSelected();
|
||||||
|
|
||||||
@@ -506,11 +539,20 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
FlatAnimatedLafChange.showSnapshot();
|
FlatAnimatedLafChange.showSnapshot();
|
||||||
if ("Light".equals(theme)) {
|
switch (theme) {
|
||||||
FlatIntelliJLaf.setup();
|
case "Default" -> {
|
||||||
} else {
|
if (FlatLaf.isLafDark()) {
|
||||||
FlatDarculaLaf.setup();
|
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();
|
FlatLaf.updateUI();
|
||||||
FlatAnimatedLafChange.hideSnapshotWithAnimation();
|
FlatAnimatedLafChange.hideSnapshotWithAnimation();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@@ -691,6 +733,8 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
case "dark", "darcula" -> FlatDarculaLaf.setup();
|
case "dark", "darcula" -> FlatDarculaLaf.setup();
|
||||||
case "macdarkblue" -> MacDarkBlue.setup();
|
case "macdarkblue" -> MacDarkBlue.setup();
|
||||||
case "macdarkred" -> MacDarkRed.setup();
|
case "macdarkred" -> MacDarkRed.setup();
|
||||||
|
case "maclightblue" -> MacLightBlue.setup();
|
||||||
|
case "maclightred" -> MacLightRed.setup();
|
||||||
default -> FlatDarculaLaf.setup();
|
default -> FlatDarculaLaf.setup();
|
||||||
}
|
}
|
||||||
FlatLaf.updateUI();
|
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) {
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user