From 9a4213a9085d4af9f0bd34a8a9e9b4af2d0fcb8f Mon Sep 17 00:00:00 2001 From: Harry Linrui XU <xulr0820@hotmail.com> Date: Mon, 27 Mar 2023 13:52:27 +0200 Subject: [PATCH] "Added javadoc to AddBudgetController. Refactored method name and changed buttonname" --- .../demo/controller/AddBudgetController.java | 33 +++++++++++++++++-- src/main/resources/view/AddBudget.fxml | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/main/java/no/ntnu/idatt1002/demo/controller/AddBudgetController.java b/src/main/java/no/ntnu/idatt1002/demo/controller/AddBudgetController.java index 600d4a37..03dd2771 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/controller/AddBudgetController.java +++ b/src/main/java/no/ntnu/idatt1002/demo/controller/AddBudgetController.java @@ -13,6 +13,10 @@ import javafx.stage.Stage; import no.ntnu.idatt1002.demo.data.Budget.BudgetItem; import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory; +/** + * Class that represents the popup dialog box that appears whenever a budget item is to be added or edited. + * The dialog contains various fields that are used to create a new item or edit an existing item. + */ public class AddBudgetController { BudgetItem newBudgetItem = null; @@ -27,11 +31,15 @@ public class AddBudgetController { @FXML - private Button addButton; + private Button okBtn; @FXML private Button cancelButton; + /** + * Initializes the category drop box by filling it with all the values from the ExpenseCategory enum. + * It then sets a prompt text on the box. + */ @FXML public void initialize(){ ObservableList<ExpenseCategory> expenseCategories = FXCollections.observableArrayList( @@ -48,14 +56,22 @@ public class AddBudgetController { return this.newBudgetItem; } + /** + * Adds a new to the budget tableview or edits an existing entry in table if the OK button is pressed. + * An entry is edited as the selected entry of the table is bounded to another budget item in this class. If this budget item + * is altered, the budget item in the tableview will automatically respond with the same changes. + * @param event If the OK button is pressed. + */ @FXML - public void addBudget(ActionEvent event) { + public void pressOkBtn(ActionEvent event) { + //Instantiates a new budget item if(newBudgetItem == null){ ExpenseCategory category = getCategory(); double amount = Double.parseDouble(amountVariable.getText()); String description = descriptionVariable.getText(); newBudgetItem = new BudgetItem(amount, description, category); } + //Sets the value of the budget(chosenBudgetItem) that is bounded to the chosen budget item (not chosenBudgetItem) in the tableview if(chosenBudgetItem != null){ chosenBudgetItem.setBudgetAmount(Double.parseDouble(amountVariable.getText())); chosenBudgetItem.setBudgetDescription(descriptionVariable.getText()); @@ -66,17 +82,30 @@ public class AddBudgetController { stage.close(); } + /** + * Binds the item that is taken in as the argument with a budget item from this class. The item of this class is instantiated + * as a deep copy of the argument. Each attribute of their attributes are then bounded. The text fields and category boxes + * in the dialog window are then set to the values of the chosen item, as to not display empty values. + * @param item The item that is chosen to be edited. + */ @FXML public void setBudget(BudgetItem item){ + //Deep copying item and then binding the two items chosenBudgetItem = new BudgetItem(item.getBudgetAmount(), item.getBudgetDescription(), item.getBudgetCategory()); chosenBudgetItem.getAmountProperty().bindBidirectional(item.getAmountProperty()); chosenBudgetItem.getDescriptionProperty().bindBidirectional(item.getDescriptionProperty()); chosenBudgetItem.getCategoryProperty().bindBidirectional(item.getCategoryProperty()); + + //Set the values of the input fields of the dialog box amountVariable.textProperty().set(String.valueOf(item.getBudgetAmount())); descriptionVariable.textProperty().set(item.getBudgetDescription()); categoryVariable.setValue(item.getBudgetCategory()); } + /** + * Closes the dialog box. + * @param actionEvent A button click on the close button. + */ public void closeButton(ActionEvent actionEvent) { final Node source = (Node) actionEvent.getSource(); final Stage stage = (Stage) source.getScene().getWindow(); diff --git a/src/main/resources/view/AddBudget.fxml b/src/main/resources/view/AddBudget.fxml index 96e52a73..e2f1e248 100644 --- a/src/main/resources/view/AddBudget.fxml +++ b/src/main/resources/view/AddBudget.fxml @@ -48,7 +48,7 @@ <HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="15.0" GridPane.columnIndex="3" GridPane.rowIndex="1"> <children> <Button fx:id="cancelButton" mnemonicParsing="false" onAction="#closeButton" text="Cancel" /> - <Button fx:id="addButton" mnemonicParsing="false" onAction="#addBudget" text="Add New Budget" /> + <Button fx:id="okBtn" mnemonicParsing="false" onAction="#pressOkBtn" prefWidth="57.0" text="OK" /> </children> </HBox> </children> -- GitLab