Update src/main/java/dev/sillyangel/calc/Calculator.java
Some checks failed
Build the Jar / build (push) Failing after 19s

This commit is contained in:
2026-01-15 12:12:23 -06:00
parent c1ceaec939
commit 12e360b7b6

View File

@@ -4,7 +4,6 @@ package dev.sillyangel.calc;
// java to javax, com, dev
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
@@ -26,6 +25,7 @@ import com.formdev.flatlaf.extras.FlatAnimatedLafChange;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.SystemInfo;
import dev.sillyangel.calc.themes.*;
import dev.sillyangel.calc.utils.Utils;
public class Calculator extends JFrame implements KeyListener {
@@ -46,7 +46,8 @@ public class Calculator extends JFrame implements KeyListener {
public final CalculatorHistory history;
public final List<String> undoStack = new ArrayList<>();
public int undoIndex = -1;
public utils calculatorUtils;
public Utils calculatorUtils;
public BaseConverter bconvert;
public static String getVersion() {
return APPLICATION_VERSION;
@@ -55,7 +56,6 @@ public class Calculator extends JFrame implements KeyListener {
public static void main(String[] args) {
// Load saved theme preference
String savedTheme = prefs.get(PREF_THEME, "MacDarkBlue");
// Apply saved theme on startup
try {
switch (savedTheme) {
@@ -86,6 +86,7 @@ public class Calculator extends JFrame implements KeyListener {
try {
Calculator frame = new Calculator();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
@@ -94,18 +95,19 @@ public class Calculator extends JFrame implements KeyListener {
}
public Calculator() {
history = new CalculatorHistory();
calculatorUtils = new utils(this);
calculatorUtils = new Utils(this);
bconvert = new BaseConverter(this);
setBackground(new Color(32, 32, 32));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setIconImage(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon.png")));
List<Image> icons = new ArrayList<>();
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon16.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon32.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon48.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon256.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon512.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon1024.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon16.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon32.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon48.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon256.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon512.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon1024.png")));
setIconImages(icons);
setTitle("AAC");
@@ -161,7 +163,7 @@ public class Calculator extends JFrame implements KeyListener {
// Menu Bar
JMenuBar menubar = new JMenuBar();
JMenu help = new JMenu("Help");
JMenu view = new JMenu("View");
JMenu file = new JMenu("File");
JMenu edit = new JMenu("Edit");
/*
@@ -187,6 +189,14 @@ public class Calculator extends JFrame implements KeyListener {
about.setMnemonic('A');
about.addActionListener(e -> aboutActionPerformed());
JMenuItem baseconv = new JMenuItem("Base Converter");
baseconv.setMnemonic('B');
baseconv.addActionListener(e -> bconvert.BaseConverterGUI());
JMenuItem viewhistory = new JMenuItem("View History");
viewhistory.setMnemonic('V');
viewhistory.addActionListener(e -> calculatorUtils.showHistoryDialog());
JMenuItem undo = new JMenuItem("Undo");
JMenuItem redo = new JMenuItem("Redo");
JMenuItem cut = new JMenuItem("Cut");
@@ -213,12 +223,14 @@ public class Calculator extends JFrame implements KeyListener {
file.add(Exit);
file.setMnemonic('F');
help.add(about);
help.setMnemonic('H');
view.add(about);
view.add(baseconv);
view.add(viewhistory);
view.setMnemonic('H');
edit.setMnemonic('E');
menubar.add(file);
menubar.add(edit);
menubar.add(help);
menubar.add(view);
setJMenuBar(menubar);
String[] modes = new String[]{"Standard", "Scientific", "Data calculation"};
@@ -339,21 +351,6 @@ public class Calculator extends JFrame implements KeyListener {
// History dialog
private void clearHistoryAction() {
int result = JOptionPane.showConfirmDialog(this,
"Are you sure you want to clear all calculation history?",
"Clear History", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (result == JOptionPane.YES_OPTION) {
history.clearHistory();
JOptionPane.showMessageDialog(this,
"History cleared successfully",
"Success", JOptionPane.INFORMATION_MESSAGE);
}
}
private void PreferencesAction() {
JDialog dialog = new JDialog(this, "Preferences", true);
dialog.setSize(400, 280);
@@ -404,6 +401,10 @@ public class Calculator extends JFrame implements KeyListener {
prefs.getBoolean(PREF_ALWAYS_ON_TOP, false)
);
JButton cleear = new JButton("Clear");
cleear.addActionListener(e -> history.clearHistory());
panel.add(new JLabel("Color Theme:"));
panel.add(colorThemeBox);
@@ -416,6 +417,9 @@ public class Calculator extends JFrame implements KeyListener {
panel.add(new JLabel(""));
panel.add(alwaysOnTopBox);
panel.add(new JLabel("Clear History"));
panel.add(cleear);
JButton apply = new JButton("Apply");
JButton close = new JButton("Close");
@@ -514,42 +518,6 @@ public class Calculator extends JFrame implements KeyListener {
}
private void loadPreferences() {
int fontSize = prefs.getInt(PREF_FONT_SIZE, 22);
boolean alwaysOnTop = prefs.getBoolean(PREF_ALWAYS_ON_TOP, false);
display.setFont(new Font("Segoe UI", Font.PLAIN, fontSize));
setAlwaysOnTop(alwaysOnTop);
}
private void changeThemes(String theme) {
boolean dark = switch (theme.toLowerCase()) {
case "dark", "darcula", "macdarkblue", "macdarkred" -> true;
default -> false;
};
// Only switch if needed
if (FlatLaf.isLafDark() != dark || isCustomMacTheme(theme)) {
EventQueue.invokeLater(() -> {
FlatAnimatedLafChange.showSnapshot();
try {
switch (theme.toLowerCase()) {
case "light" -> FlatIntelliJLaf.setup();
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();
} finally {
FlatAnimatedLafChange.hideSnapshotWithAnimation();
}
});
}
}
/**
* Determines if a theme is dark mode
*/
@@ -582,14 +550,7 @@ public class Calculator extends JFrame implements KeyListener {
return theme;
}
private boolean isCustomMacTheme(String theme) {
String lower = theme.toLowerCase();
return lower.equals("macdarkblue") || lower.equals("macdarkred") ||
lower.equals("maclightblue") || lower.equals("maclightred");
}
// Implement the keyPressed method
// Implement the keyPressed method
@Override
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();