1
0
mirror of https://github.com/DanilaFe/abacus synced 2026-01-13 10:25:20 +00:00

Format code.

This commit is contained in:
2017-07-30 21:11:32 -07:00
parent 03eb669eb3
commit a278e5bb9a
39 changed files with 695 additions and 561 deletions

View File

@@ -2,9 +2,7 @@ package org.nwapw.abacus.window;
import org.nwapw.abacus.tree.TreeNode;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import java.util.ArrayList;
import java.util.List;
@@ -31,30 +29,6 @@ public class HistoryTableModel extends AbstractTableModel {
TreeNode.class,
String.class
};
/**
* Class used specifically to hold data about
* the previous entries into the calculator.
*/
public static class HistoryEntry {
public String input;
public TreeNode parsedInput;
public String output;
public HistoryEntry(String input, TreeNode parsedInput, String output){
this.input = input;
this.parsedInput = parsedInput;
this.output = output;
}
Object nthValue(int n){
if(n == 0) return input;
if(n == 1) return parsedInput;
if(n == 2) return output;
return null;
}
}
/**
* The list of entries.
*/
@@ -69,9 +43,10 @@ public class HistoryTableModel extends AbstractTableModel {
/**
* Adds an entry to the model.
*
* @param entry the entry to add.
*/
public void addEntry(HistoryEntry entry){
public void addEntry(HistoryEntry entry) {
entries.add(entry);
}
@@ -105,4 +80,27 @@ public class HistoryTableModel extends AbstractTableModel {
return entries.get(rowIndex).nthValue(columnIndex);
}
/**
* Class used specifically to hold data about
* the previous entries into the calculator.
*/
public static class HistoryEntry {
public String input;
public TreeNode parsedInput;
public String output;
public HistoryEntry(String input, TreeNode parsedInput, String output) {
this.input = input;
this.parsedInput = parsedInput;
this.output = output;
}
Object nthValue(int n) {
if (n == 0) return input;
if (n == 1) return parsedInput;
if (n == 2) return output;
return null;
}
}
}

View File

@@ -119,12 +119,12 @@ public class Window extends JFrame {
*/
private ActionListener evaluateListener = (event) -> {
TreeNode parsedExpression = abacus.parseString(inputField.getText());
if(parsedExpression == null){
if (parsedExpression == null) {
lastOutputArea.setText(SYNTAX_ERR_STRING);
return;
}
NumberInterface numberInterface = abacus.evaluateTree(parsedExpression);
if(numberInterface == null) {
if (numberInterface == null) {
lastOutputArea.setText(EVAL_ERR_STRING);
return;
}
@@ -146,9 +146,10 @@ public class Window extends JFrame {
/**
* Creates a new window with the given manager.
*
* @param abacus the calculator instance to interact with other components.
*/
public Window(Abacus abacus){
public Window(Abacus abacus) {
this();
this.abacus = abacus;
}
@@ -218,11 +219,11 @@ public class Window extends JFrame {
inputField.setEnabled(enabled);
inputEnterButton.setEnabled(enabled);
for(ActionListener removingListener : inputEnterButton.getActionListeners()){
for (ActionListener removingListener : inputEnterButton.getActionListeners()) {
inputEnterButton.removeActionListener(removingListener);
inputField.removeActionListener(removingListener);
}
if(listener != null){
if (listener != null) {
inputEnterButton.addActionListener(listener);
inputField.addActionListener(listener);
}
@@ -236,7 +237,7 @@ public class Window extends JFrame {
@Override
public void mouseClicked(MouseEvent e) {
Point clickPoint = e.getPoint();
if(e.getClickCount() == 2){
if (e.getClickCount() == 2) {
int row = historyTable.rowAtPoint(clickPoint);
int column = historyTable.columnAtPoint(clickPoint);
String toCopy = historyTable.getValueAt(row, column).toString();