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

"Refactored method names and added new handleAddButton method"

parent 9a4213a9
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
...@@ -75,8 +75,7 @@ public class BudgetController { ...@@ -75,8 +75,7 @@ public class BudgetController {
/** /**
* Initializes the budget register, the observable budget list and the tableview, along with all dynamic fields that relates to the tableview. * Initializes the budget register, the observable budget list and the tableview, along with the values of the dropbox used for filtering the tableview.
* The method is called each time the FXML of this scene is loaded.
* @throws IOException If there occurs any exception when loading the budget register from a file. * @throws IOException If there occurs any exception when loading the budget register from a file.
*/ */
@FXML @FXML
...@@ -95,13 +94,17 @@ public class BudgetController { ...@@ -95,13 +94,17 @@ public class BudgetController {
sum.setText(String.valueOf(general.totalSum())); sum.setText(String.valueOf(general.totalSum()));
} }
@FXML
protected void handleAddButton(ActionEvent event) {
handleEditButton(event);
}
/** /**
* Adds or edits a budget item, depending on what mode the DialogMode enum is at. The method brings up a dialog box popup in which the user can fill and choose * Adds or edits a budget item, depending on what mode the DialogMode enum is at. The method brings up a dialog box popup in which the user can fill and choose
* values that the budget item will have. Open exiting the popup, the changes the saved to the tableview. * values that the budget item will have. Open exiting the popup, the changes the saved to the tableview.
* @param event A button click on either the add or delete button. * @param event A button click on either the add or delete button.
*/ */
@FXML @FXML
public void switchAddBudget(ActionEvent event) { public void handleEditButton(ActionEvent event) {
BudgetItem item = null; BudgetItem item = null;
String dialogTitle = ""; String dialogTitle = "";
DialogMode dialogMode; DialogMode dialogMode;
...@@ -124,7 +127,6 @@ public class BudgetController { ...@@ -124,7 +127,6 @@ public class BudgetController {
if(event.getSource().equals(addBudget)){ if(event.getSource().equals(addBudget)){
dialogMode = DialogMode.ADD; dialogMode = DialogMode.ADD;
dialogTitle = "New Budget"; dialogTitle = "New Budget";
} }
else if (event.getSource().equals(editBudget) && budgetTableView.getSelectionModel().getSelectedItem() != null) { else if (event.getSource().equals(editBudget) && budgetTableView.getSelectionModel().getSelectedItem() != null) {
dialogMode = DialogMode.EDIT; dialogMode = DialogMode.EDIT;
...@@ -138,6 +140,7 @@ public class BudgetController { ...@@ -138,6 +140,7 @@ public class BudgetController {
} }
dialog.setTitle(dialogTitle); dialog.setTitle(dialogTitle);
// Show the Dialog and wait for the user to close it
dialog.showAndWait(); dialog.showAndWait();
//Adds the new item to the register //Adds the new item to the register
...@@ -153,23 +156,13 @@ public class BudgetController { ...@@ -153,23 +156,13 @@ public class BudgetController {
refreshTableView(); refreshTableView();
} }
/**
* Closes the popup window.
* @param event A button click on the close button
*/
@FXML
public void closeButton(ActionEvent event) {
final Node source = (Node) event.getSource();
final Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
/** /**
* Deletes an entry from the tableview, if an entry has been selected. The method brings up a popup window, asking for confirmation for deleting the entry. * Deletes an entry from the tableview, if an entry has been selected. The method brings up a popup window, asking for confirmation for deleting the entry.
* @param event A button click on the delete button * @param event A button click on the delete button
*/ */
@FXML @FXML
public void deleteButton(ActionEvent event) { public void handleDeleteBtn(ActionEvent event) {
//Gets the selected item from the tableview //Gets the selected item from the tableview
BudgetItem item = budgetTableView.getSelectionModel().getSelectedItem(); BudgetItem item = budgetTableView.getSelectionModel().getSelectedItem();
//Exits the method if nothing is selected //Exits the method if nothing is selected
...@@ -184,9 +177,19 @@ public class BudgetController { ...@@ -184,9 +177,19 @@ public class BudgetController {
} }
} }
/**
* Method for synching the register with the tableview. The observable list to which the tableview is set, is being refilled with all the entries
* in the register, keeping it updated with new changes.
*/
protected void refreshTableView(){
this.budgetList.setAll(general.getBudgetItems());
//Refreshing the sum of the amounts of the budget
this.sum.setText(String.valueOf(general.totalSum()));
}
/** /**
* Returns an optional, which is a popup alert box, asking for confirmation for deleting an entry. * Returns an optional, which is a popup alert box, asking for confirmation for deleting an entry.
* @return An alertbox, asking for confirmation for deleting the selected entry of the tableview. * @return An alert box, asking for confirmation for deleting the selected entry of the tableview.
*/ */
private Optional<ButtonType> showConfirmationDialog() { private Optional<ButtonType> showConfirmationDialog() {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION); Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
...@@ -240,17 +243,6 @@ public class BudgetController { ...@@ -240,17 +243,6 @@ public class BudgetController {
fileHandlingBudget.writeGeneralBudgetToFile(fileName, general); fileHandlingBudget.writeGeneralBudgetToFile(fileName, general);
} }
/**
* Method for synching the register with the tableview. The observable list to which the tableview is set, is being refilled with all the entries
* in the register, keeping it updated with new changes.
*/
protected void refreshTableView(){
this.budgetList.setAll(general.getBudgetItems());
//Refreshing the sum of the amounts of the budget
this.sum.setText(String.valueOf(general.totalSum()));
}
/** /**
* Switches scenes from the budget scene to another, by loading a new FXML file and setting the scene to this location. * Switches scenes from the budget scene to another, by loading a new FXML file and setting the scene to this location.
* The destination depends entirely on which button is pressed. * The destination depends entirely on which button is pressed.
......
...@@ -35,9 +35,9 @@ ...@@ -35,9 +35,9 @@
<children> <children>
<HBox alignment="TOP_CENTER" prefHeight="98.0" prefWidth="600.0" spacing="40.0" GridPane.rowIndex="3"> <HBox alignment="TOP_CENTER" prefHeight="98.0" prefWidth="600.0" spacing="40.0" GridPane.rowIndex="3">
<children> <children>
<Button fx:id="addBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#switchAddBudget" prefWidth="100.0" text="Add" /> <Button fx:id="addBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#handleEditButton" prefWidth="100.0" text="Add" />
<Button fx:id="editBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#switchAddBudget" prefWidth="100.0" text="Edit" /> <Button fx:id="editBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#handleEditButton" prefWidth="100.0" text="Edit" />
<Button fx:id="deleteBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#deleteButton" prefWidth="100.0" text="Delete" /> <Button fx:id="deleteBudget" minHeight="60.0" minWidth="100.0" mnemonicParsing="false" onAction="#handleDeleteBtn" prefWidth="100.0" text="Delete" />
<Button minHeight="60.0" minWidth="100.0" mnemonicParsing="false" prefWidth="100.0" text="Save/Back" /> <Button minHeight="60.0" minWidth="100.0" mnemonicParsing="false" prefWidth="100.0" text="Save/Back" />
</children> </children>
</HBox> </HBox>
......
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
<children> <children>
<HBox alignment="BOTTOM_LEFT" prefWidth="410.0" spacing="5.0"> <HBox alignment="BOTTOM_LEFT" prefWidth="410.0" spacing="5.0">
<children> <children>
<Button fx:id="addBudget" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#switchAddBudget" text="Add" textAlignment="CENTER"> <Button fx:id="addBudget" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleAddButton" text="Add" textAlignment="CENTER">
<graphic> <graphic>
<ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true"> <ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image> <image>
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>
<Button fx:id="editBudget" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#switchAddBudget" text="Edit" textAlignment="CENTER"> <Button fx:id="editBudget" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleEditButton" text="Edit" textAlignment="CENTER">
<graphic> <graphic>
<ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true"> <ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image> <image>
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>
<Button fx:id="deleteBtn" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#deleteButton" text="Delete" textAlignment="CENTER"> <Button fx:id="deleteBtn" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete" textAlignment="CENTER">
<graphic> <graphic>
<ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true"> <ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<image> <image>
......
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