Skip to content
Snippets Groups Projects
Commit 9a4213a9 authored by Harry Linrui XU's avatar Harry Linrui XU
Browse files

"Added javadoc to AddBudgetController. Refactored method name and changed buttonname"

parent c4072799
No related branches found
No related tags found
8 merge requests!43Merging frontend-testing into master,!38"Made progressbar dynamic in accordance to spending. Added balance field....,!37Made the sub progress bars respond to changes in expense,!32Added input validation to add dialog boxes.,!30Redesigned scenes,!29Redesigned scenes,!28Redesigned scenes,!26Redesigned Main menu and expense/income windows
......@@ -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();
......
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment