From d2056513327060fbed004c6cb7ddf1fbc0ca2ff2 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 1 Aug 2017 11:52:48 -0700 Subject: [PATCH] Add a number implementation selector box. --- .../org/nwapw/abacus/config/Configuration.java | 8 ++++++++ .../org/nwapw/abacus/fx/AbacusController.java | 18 +++++++++++++++++- src/main/resources/abacus.fxml | 10 +++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/config/Configuration.java b/src/main/java/org/nwapw/abacus/config/Configuration.java index 3b3ef16..6253632 100644 --- a/src/main/java/org/nwapw/abacus/config/Configuration.java +++ b/src/main/java/org/nwapw/abacus/config/Configuration.java @@ -72,4 +72,12 @@ public class Configuration { public String getNumberImplementation() { return numberImplementation; } + + /** + * Sets the number implementation for the configuration + * @param numberImplementation the number implementation. + */ + public void setNumberImplementation(String numberImplementation) { + this.numberImplementation = numberImplementation; + } } diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index 7c9d539..10ac77b 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -30,9 +30,13 @@ public class AbacusController { private TextField inputField; @FXML private Button inputButton; + @FXML + private ComboBox numberImplementationBox; private ObservableList historyData; + private ObservableList numberImplementationOptions; + private Abacus abacus; @FXML @@ -40,9 +44,15 @@ public class AbacusController { Callback, TableCell> cellFactory = param -> new CopyableCell<>(); - abacus = new Abacus(); historyData = FXCollections.observableArrayList(); historyTable.setItems(historyData); + numberImplementationOptions = FXCollections.observableArrayList(); + numberImplementationBox.setItems(numberImplementationOptions); + numberImplementationBox.valueProperty().addListener((observable, oldValue, newValue) + -> { + abacus.getConfiguration().setNumberImplementation(newValue); + abacus.getConfiguration().saveTo(Abacus.CONFIG_FILE); + }); historyTable.getSelectionModel().setCellSelectionEnabled(true); inputColumn.setCellFactory(cellFactory); inputColumn.setCellValueFactory(cell -> cell.getValue().inputProperty()); @@ -50,6 +60,12 @@ public class AbacusController { parsedColumn.setCellValueFactory(cell -> cell.getValue().parsedProperty()); outputColumn.setCellFactory(cellFactory); outputColumn.setCellValueFactory(cell -> cell.getValue().outputProperty()); + + abacus = new Abacus(); + numberImplementationOptions.addAll(abacus.getPluginManager().getAllNumbers()); + String actualImplementation = abacus.getConfiguration().getNumberImplementation(); + String toSelect = (numberImplementationOptions.contains(actualImplementation)) ? actualImplementation : "naive"; + numberImplementationBox.getSelectionModel().select(toSelect); } @FXML diff --git a/src/main/resources/abacus.fxml b/src/main/resources/abacus.fxml index 9a68947..183e247 100644 --- a/src/main/resources/abacus.fxml +++ b/src/main/resources/abacus.fxml @@ -5,6 +5,8 @@ + + @@ -39,7 +41,13 @@ - + + + + +