Update src/main/java/dev/sillyangel/calc/Calculator.java
Some checks failed
Build the Jar / build (push) Failing after 19s
Some checks failed
Build the Jar / build (push) Failing after 19s
This commit is contained in:
@@ -4,7 +4,6 @@ package dev.sillyangel.calc;
|
|||||||
// java to javax, com, dev
|
// java to javax, com, dev
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.awt.datatransfer.*;
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -26,6 +25,7 @@ import com.formdev.flatlaf.extras.FlatAnimatedLafChange;
|
|||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
import dev.sillyangel.calc.themes.*;
|
import dev.sillyangel.calc.themes.*;
|
||||||
|
import dev.sillyangel.calc.utils.Utils;
|
||||||
|
|
||||||
public class Calculator extends JFrame implements KeyListener {
|
public class Calculator extends JFrame implements KeyListener {
|
||||||
|
|
||||||
@@ -46,7 +46,8 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
public final CalculatorHistory history;
|
public final CalculatorHistory history;
|
||||||
public final List<String> undoStack = new ArrayList<>();
|
public final List<String> undoStack = new ArrayList<>();
|
||||||
public int undoIndex = -1;
|
public int undoIndex = -1;
|
||||||
public utils calculatorUtils;
|
public Utils calculatorUtils;
|
||||||
|
public BaseConverter bconvert;
|
||||||
|
|
||||||
public static String getVersion() {
|
public static String getVersion() {
|
||||||
return APPLICATION_VERSION;
|
return APPLICATION_VERSION;
|
||||||
@@ -55,7 +56,6 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Load saved theme preference
|
// Load saved theme preference
|
||||||
String savedTheme = prefs.get(PREF_THEME, "MacDarkBlue");
|
String savedTheme = prefs.get(PREF_THEME, "MacDarkBlue");
|
||||||
|
|
||||||
// Apply saved theme on startup
|
// Apply saved theme on startup
|
||||||
try {
|
try {
|
||||||
switch (savedTheme) {
|
switch (savedTheme) {
|
||||||
@@ -69,7 +69,7 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FlatMacDarkLaf.setup();
|
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("---------------------------------");
|
||||||
@@ -86,6 +86,7 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
try {
|
try {
|
||||||
Calculator frame = new Calculator();
|
Calculator frame = new Calculator();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -94,18 +95,19 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
}
|
}
|
||||||
public Calculator() {
|
public Calculator() {
|
||||||
history = new CalculatorHistory();
|
history = new CalculatorHistory();
|
||||||
calculatorUtils = new utils(this);
|
calculatorUtils = new Utils(this);
|
||||||
|
bconvert = new BaseConverter(this);
|
||||||
|
|
||||||
setBackground(new Color(32, 32, 32));
|
setBackground(new Color(32, 32, 32));
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
//setIconImage(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon.png")));
|
//setIconImage(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon.png")));
|
||||||
List<Image> icons = new ArrayList<>();
|
List<Image> icons = new ArrayList<>();
|
||||||
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon16.png")));
|
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon16.png")));
|
||||||
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon32.png")));
|
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon32.png")));
|
||||||
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon48.png")));
|
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon48.png")));
|
||||||
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon256.png")));
|
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon256.png")));
|
||||||
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon512.png")));
|
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon512.png")));
|
||||||
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("/images/appIcon1024.png")));
|
icons.add(Toolkit.getDefaultToolkit().getImage(Calculator.class.getResource("appIcon1024.png")));
|
||||||
setIconImages(icons);
|
setIconImages(icons);
|
||||||
|
|
||||||
setTitle("AAC");
|
setTitle("AAC");
|
||||||
@@ -161,7 +163,7 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
// Menu Bar
|
// Menu Bar
|
||||||
JMenuBar menubar = new JMenuBar();
|
JMenuBar menubar = new JMenuBar();
|
||||||
|
|
||||||
JMenu help = new JMenu("Help");
|
JMenu view = new JMenu("View");
|
||||||
JMenu file = new JMenu("File");
|
JMenu file = new JMenu("File");
|
||||||
JMenu edit = new JMenu("Edit");
|
JMenu edit = new JMenu("Edit");
|
||||||
/*
|
/*
|
||||||
@@ -186,6 +188,14 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
JMenuItem about = new JMenuItem("About");
|
JMenuItem about = new JMenuItem("About");
|
||||||
about.setMnemonic('A');
|
about.setMnemonic('A');
|
||||||
about.addActionListener(e -> aboutActionPerformed());
|
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 undo = new JMenuItem("Undo");
|
||||||
JMenuItem redo = new JMenuItem("Redo");
|
JMenuItem redo = new JMenuItem("Redo");
|
||||||
@@ -213,12 +223,14 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
|
|
||||||
file.add(Exit);
|
file.add(Exit);
|
||||||
file.setMnemonic('F');
|
file.setMnemonic('F');
|
||||||
help.add(about);
|
view.add(about);
|
||||||
help.setMnemonic('H');
|
view.add(baseconv);
|
||||||
|
view.add(viewhistory);
|
||||||
|
view.setMnemonic('H');
|
||||||
edit.setMnemonic('E');
|
edit.setMnemonic('E');
|
||||||
menubar.add(file);
|
menubar.add(file);
|
||||||
menubar.add(edit);
|
menubar.add(edit);
|
||||||
menubar.add(help);
|
menubar.add(view);
|
||||||
setJMenuBar(menubar);
|
setJMenuBar(menubar);
|
||||||
|
|
||||||
String[] modes = new String[]{"Standard", "Scientific", "Data calculation"};
|
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() {
|
private void PreferencesAction() {
|
||||||
JDialog dialog = new JDialog(this, "Preferences", true);
|
JDialog dialog = new JDialog(this, "Preferences", true);
|
||||||
dialog.setSize(400, 280);
|
dialog.setSize(400, 280);
|
||||||
@@ -403,6 +400,10 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
"Always on top",
|
"Always on top",
|
||||||
prefs.getBoolean(PREF_ALWAYS_ON_TOP, false)
|
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(new JLabel("Color Theme:"));
|
||||||
panel.add(colorThemeBox);
|
panel.add(colorThemeBox);
|
||||||
@@ -415,7 +416,10 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
|
|
||||||
panel.add(new JLabel(""));
|
panel.add(new JLabel(""));
|
||||||
panel.add(alwaysOnTopBox);
|
panel.add(alwaysOnTopBox);
|
||||||
|
|
||||||
|
panel.add(new JLabel("Clear History"));
|
||||||
|
panel.add(cleear);
|
||||||
|
|
||||||
JButton apply = new JButton("Apply");
|
JButton apply = new JButton("Apply");
|
||||||
JButton close = new JButton("Close");
|
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
|
* Determines if a theme is dark mode
|
||||||
*/
|
*/
|
||||||
@@ -582,14 +550,7 @@ public class Calculator extends JFrame implements KeyListener {
|
|||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCustomMacTheme(String theme) {
|
// Implement the keyPressed method
|
||||||
String lower = theme.toLowerCase();
|
|
||||||
return lower.equals("macdarkblue") || lower.equals("macdarkred") ||
|
|
||||||
lower.equals("maclightblue") || lower.equals("maclightred");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Implement the keyPressed method
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
int keyCode = e.getKeyCode();
|
int keyCode = e.getKeyCode();
|
||||||
|
|||||||
Reference in New Issue
Block a user