From d220b0c6a5973cc09f88ce72536dee02e08a3f50 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 7 Aug 2017 22:39:12 -0700 Subject: [PATCH] Switch HistoryModel to Kotlin to avoid boilerplate. --- .../org/nwapw/abacus/fx/AbacusController.java | 6 +- .../org/nwapw/abacus/fx/HistoryModel.java | 97 ------------------- .../org/nwapw/abacus/fx/HistoryModel.kt | 32 ++++++ 3 files changed, 35 insertions(+), 100 deletions(-) delete mode 100644 src/main/java/org/nwapw/abacus/fx/HistoryModel.java create mode 100644 src/main/kotlin/org/nwapw/abacus/fx/HistoryModel.kt diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index 976f8c7..7c3d6b7 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -243,11 +243,11 @@ public class AbacusController implements PluginListener { enabledPluginView.setItems(enabledPlugins); enabledPluginView.setCellFactory(pluginCellFactory); inputColumn.setCellFactory(cellFactory); - inputColumn.setCellValueFactory(cell -> cell.getValue().inputProperty()); + inputColumn.setCellValueFactory(cell -> cell.getValue().getInputProperty()); parsedColumn.setCellFactory(cellFactory); - parsedColumn.setCellValueFactory(cell -> cell.getValue().parsedProperty()); + parsedColumn.setCellValueFactory(cell -> cell.getValue().getParsedProperty()); outputColumn.setCellFactory(cellFactory); - outputColumn.setCellValueFactory(cell -> cell.getValue().outputProperty()); + outputColumn.setCellValueFactory(cell -> cell.getValue().getOutputProperty()); coreTabPane.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { if (oldValue.equals(settingsTab)) alertIfApplyNeeded(true); }); diff --git a/src/main/java/org/nwapw/abacus/fx/HistoryModel.java b/src/main/java/org/nwapw/abacus/fx/HistoryModel.java deleted file mode 100644 index 1e86853..0000000 --- a/src/main/java/org/nwapw/abacus/fx/HistoryModel.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.nwapw.abacus.fx; - -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; - -/** - * The data model used for storing history entries. - */ -public class HistoryModel { - - /** - * The property used for displaying the column - * for the user input. - */ - private final StringProperty input; - /** - * The property used for displaying the column - * that contains the parsed input. - */ - private final StringProperty parsed; - /** - * The property used for displaying the column - * that contains the program output. - */ - private final StringProperty output; - - /** - * Creates a new history model with the given variables. - * - * @param input the user input - * @param parsed the parsed input - * @param output the program output. - */ - public HistoryModel(String input, String parsed, String output) { - this.input = new SimpleStringProperty(); - this.parsed = new SimpleStringProperty(); - this.output = new SimpleStringProperty(); - this.input.setValue(input); - this.parsed.setValue(parsed); - this.output.setValue(output); - } - - /** - * Gets the input property. - * - * @return the input property. - */ - public StringProperty inputProperty() { - return input; - } - - /** - * Gets the input. - * - * @return the input. - */ - public String getInput() { - return input.get(); - } - - /** - * Gets the parsed input property. - * - * @return the parsed input property. - */ - public StringProperty parsedProperty() { - return parsed; - } - - /** - * Gets the parsed input. - * - * @return the parsed input. - */ - public String getParsed() { - return parsed.get(); - } - - /** - * Gets the output property. - * - * @return the output property. - */ - public StringProperty outputProperty() { - return output; - } - - /** - * Gets the program output. - * - * @return the output. - */ - public String getOutput() { - return output.get(); - } - -} diff --git a/src/main/kotlin/org/nwapw/abacus/fx/HistoryModel.kt b/src/main/kotlin/org/nwapw/abacus/fx/HistoryModel.kt new file mode 100644 index 0000000..e8b11b6 --- /dev/null +++ b/src/main/kotlin/org/nwapw/abacus/fx/HistoryModel.kt @@ -0,0 +1,32 @@ +package org.nwapw.abacus.fx + +import javafx.beans.property.SimpleStringProperty + +/** + * A model representing an input / output in the calculator. + * + * The HistoryModel class stores a record of a single user-provided input, + * its parsed form as it was interpreted by the calculator, and the output + * that was provided by the calculator. These are represented as properties + * to allow easy access by JavaFX cells. + * + * @param input the user input + * @param parsed the parsed version of the input. + * @param output the output string. + */ +class HistoryModel(input: String, parsed: String, output: String){ + + /** + * The property that holds the input. + */ + val inputProperty = SimpleStringProperty(input) + /** + * The property that holds the parsed input. + */ + val parsedProperty = SimpleStringProperty(parsed) + /** + * The property that holds the output. + */ + val outputProperty = SimpleStringProperty(output) + +} \ No newline at end of file