Update src/main/java/dev/sillyangel/calc/utils.java
Some checks failed
Build the Jar / build (push) Failing after 7s
Some checks failed
Build the Jar / build (push) Failing after 7s
This commit is contained in:
@@ -5,6 +5,7 @@ import java.awt.datatransfer.Clipboard;
|
|||||||
import java.awt.datatransfer.DataFlavor;
|
import java.awt.datatransfer.DataFlavor;
|
||||||
import java.awt.datatransfer.StringSelection;
|
import java.awt.datatransfer.StringSelection;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class utils {
|
public class utils {
|
||||||
// private double result;
|
// private double result;
|
||||||
@@ -186,5 +187,44 @@ public class utils {
|
|||||||
public void clearEntry() {
|
public void clearEntry() {
|
||||||
ci.display.setText("");
|
ci.display.setText("");
|
||||||
}
|
}
|
||||||
|
public void showHistoryDialog() {
|
||||||
|
JDialog historyDialog = new JDialog(this.ci, "Calculation History", true);
|
||||||
|
historyDialog.setSize(500, 400);
|
||||||
|
historyDialog.setLocationRelativeTo(this.ci);
|
||||||
|
historyDialog.setLayout(new BorderLayout(10, 10));
|
||||||
|
|
||||||
|
List<String> historyList = history.getCalculationHistory();
|
||||||
|
|
||||||
|
if (historyList.isEmpty()) {
|
||||||
|
JLabel emptyLabel = new JLabel("No calculation history yet", SwingConstants.CENTER);
|
||||||
|
emptyLabel.setFont(new Font("Segoe UI", Font.PLAIN, 14));
|
||||||
|
historyDialog.add(emptyLabel, BorderLayout.CENTER);
|
||||||
|
} else {
|
||||||
|
JTextArea historyTextArea = new JTextArea();
|
||||||
|
historyTextArea.setEditable(false);
|
||||||
|
historyTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
|
||||||
|
|
||||||
|
StringBuilder historyText = new StringBuilder();
|
||||||
|
for (String entry : historyList) {
|
||||||
|
historyText.append(entry).append("\n");
|
||||||
|
}
|
||||||
|
historyTextArea.setText(historyText.toString());
|
||||||
|
|
||||||
|
JScrollPane scrollPane = new JScrollPane(historyTextArea);
|
||||||
|
historyDialog.add(scrollPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
// Status label
|
||||||
|
JLabel statusLabel = new JLabel("Total calculations: " + historyList.size());
|
||||||
|
statusLabel.setBorder(new EmptyBorder(5, 10, 5, 10));
|
||||||
|
historyDialog.add(statusLabel, BorderLayout.NORTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||||
|
JButton closeButton = new JButton("Close");
|
||||||
|
closeButton.addActionListener(e -> historyDialog.dispose());
|
||||||
|
buttonPanel.add(closeButton);
|
||||||
|
|
||||||
|
historyDialog.add(buttonPanel, BorderLayout.SOUTH);
|
||||||
|
historyDialog.setVisible(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user