From 5c886cee6000dc9f5d8c2f193bc640a97c7adf1b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 31 Jul 2017 16:48:04 -0700 Subject: [PATCH 01/13] Create new fxml file and controller for it. --- .../java/org/nwapw/abacus/fx/AbacusController.java | 5 +++++ src/main/resources/abacus.fxml | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/main/java/org/nwapw/abacus/fx/AbacusController.java create mode 100644 src/main/resources/abacus.fxml diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java new file mode 100644 index 0000000..789d623 --- /dev/null +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -0,0 +1,5 @@ +package org.nwapw.abacus.fx; + +public class AbacusController { + +} diff --git a/src/main/resources/abacus.fxml b/src/main/resources/abacus.fxml new file mode 100644 index 0000000..45f2b13 --- /dev/null +++ b/src/main/resources/abacus.fxml @@ -0,0 +1,14 @@ + + + + + + + + + + + From 0b173a68dd961d691422ad481a1e1b1631b80100 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 31 Jul 2017 16:50:39 -0700 Subject: [PATCH 02/13] Add FXML loading application. --- .../nwapw/abacus/fx/AbacusApplication.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/org/nwapw/abacus/fx/AbacusApplication.java diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusApplication.java b/src/main/java/org/nwapw/abacus/fx/AbacusApplication.java new file mode 100644 index 0000000..3f86fdd --- /dev/null +++ b/src/main/java/org/nwapw/abacus/fx/AbacusApplication.java @@ -0,0 +1,20 @@ +package org.nwapw.abacus.fx; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class AbacusApplication extends Application { + + @Override + public void start(Stage primaryStage) throws Exception { + Parent parent = FXMLLoader.load(getClass().getResource("/abacus.fxml")); + Scene mainScene = new Scene(parent, 320, 480); + primaryStage.setScene(mainScene); + primaryStage.setTitle("Abacus"); + primaryStage.show(); + } + +} From d42172ce0384c816b180ff2442b262fa174d8616 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 31 Jul 2017 16:52:34 -0700 Subject: [PATCH 03/13] Add initialization code to AbacusController --- .../java/org/nwapw/abacus/fx/AbacusController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index 789d623..e5a5923 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -1,5 +1,15 @@ package org.nwapw.abacus.fx; +import javafx.fxml.FXML; +import org.nwapw.abacus.Abacus; + public class AbacusController { + private Abacus abacus; + + @FXML + public void initialize(){ + abacus = new Abacus(); + } + } From 192fe7de769352b1e8d319d70fdd1405e2fe2bb2 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 31 Jul 2017 16:56:38 -0700 Subject: [PATCH 04/13] Add a tabbed pane as the main focus of the window. --- src/main/resources/abacus.fxml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/resources/abacus.fxml b/src/main/resources/abacus.fxml index 45f2b13..5e1d90f 100644 --- a/src/main/resources/abacus.fxml +++ b/src/main/resources/abacus.fxml @@ -1,14 +1,15 @@ - - - - - - + fx:controller="org.nwapw.abacus.fx.AbacusController"> +
+ + + + +
+ From 41395f09f99d54a46e901640752b15742c6bfe22 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 31 Jul 2017 17:08:16 -0700 Subject: [PATCH 05/13] Add the inputs to the calculator tab. --- src/main/resources/abacus.fxml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/resources/abacus.fxml b/src/main/resources/abacus.fxml index 5e1d90f..9883d94 100644 --- a/src/main/resources/abacus.fxml +++ b/src/main/resources/abacus.fxml @@ -2,14 +2,28 @@ +
- + + + + + + + + +
+
From 8c935983b210218a075349223240fcaf51494c6b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 31 Jul 2017 17:17:56 -0700 Subject: [PATCH 06/13] Link up the evaluation and the UI buttons. --- .../org/nwapw/abacus/fx/AbacusController.java | 34 +++++++++++++++++++ src/main/resources/abacus.fxml | 8 +++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index e5a5923..d21c034 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -1,10 +1,25 @@ package org.nwapw.abacus.fx; import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.scene.text.Text; import org.nwapw.abacus.Abacus; +import org.nwapw.abacus.number.NumberInterface; +import org.nwapw.abacus.tree.TreeNode; public class AbacusController { + private static final String ERR_SYNTAX = "Syntax Error"; + private static final String ERR_EVAL = "Evaluation Error"; + + @FXML + private Text outputText; + @FXML + private TextField inputField; + @FXML + private Button inputButton; + private Abacus abacus; @FXML @@ -12,4 +27,23 @@ public class AbacusController { abacus = new Abacus(); } + @FXML + private void performCalculation(){ + inputButton.setDisable(true); + TreeNode constructedTree = abacus.parseString(inputField.getText()); + if(constructedTree == null){ + outputText.setText(ERR_SYNTAX); + inputButton.setDisable(false); + return; + } + NumberInterface evaluatedNumber = abacus.evaluateTree(constructedTree); + if(constructedTree == null){ + outputText.setText(ERR_EVAL); + inputButton.setDisable(false); + return; + } + inputButton.setDisable(false); + outputText.setText(evaluatedNumber.toString()); + } + } diff --git a/src/main/resources/abacus.fxml b/src/main/resources/abacus.fxml index 9883d94..ee4a28f 100644 --- a/src/main/resources/abacus.fxml +++ b/src/main/resources/abacus.fxml @@ -4,6 +4,7 @@ + @@ -15,9 +16,10 @@ + - -