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

Added error msg to income and expenses in case of

IOexceptions
parent d49e796f
No related branches found
No related tags found
3 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
......@@ -108,6 +108,9 @@ public class IncomeExpenseController implements FinanceController {
@FXML
private Label title;
@FXML
private Label errorMsg;
@FXML
private MenuItem editIncomeMenu;
......@@ -136,31 +139,37 @@ public class IncomeExpenseController implements FinanceController {
@FXML
private PieChart incomePieChart;
FileHandling fileHandling;
@FXML
public void initialize() throws IOException {
public void initialize() {
fileHandling = new FileHandling();
//Initialize columns
setColumns();
//Initialize registers and tableview
incomeRegister = loadIncomeDataFromFile("Income");
income = FXCollections.observableArrayList(incomeRegister.getItems());
incomeTableView.setItems(income);
try {
//Initialize registers and tableview
incomeRegister = loadIncomeDataFromFile("Income");
income = FXCollections.observableArrayList(incomeRegister.getItems());
incomeTableView.setItems(income);
expenseRegister = loadExpenseDataFromFile("Expense");
expenses = FXCollections.observableArrayList(expenseRegister.getItems());
expenseTableView.setItems(expenses);
expenseRegister = loadExpenseDataFromFile("Expense");
expenses = FXCollections.observableArrayList(expenseRegister.getItems());
expenseTableView.setItems(expenses);
//Setting pie chart values to correspond with the registers
incomePieChart.setLegendSide(Side.RIGHT);
//Setting pie chart values to correspond with the registers
incomePieChart.setLegendSide(Side.RIGHT);
expensePieChart.setLegendSide(Side.RIGHT);
expensePieChart.setLabelLineLength(10);
expensePieChart.setLegendSide(Side.RIGHT);
expensePieChart.setLabelLineLength(10);
refreshPieCharts();
} catch(IOException ioe) {
errorMsg.setOpacity(1);
}
refreshPieCharts();
refreshProgress();
formatDatePicker();
......@@ -320,7 +329,8 @@ public class IncomeExpenseController implements FinanceController {
// Set the Dialog's content to the loaded FXML file
dialog.getDialogPane().setContent(loader.load());
} catch (IOException e) {
e.printStackTrace();
errorMsg.setText("Error in loading in dialog box");
errorMsg.setOpacity(1);
}
// Get the controller for the loaded FXML file
......@@ -355,7 +365,8 @@ public class IncomeExpenseController implements FinanceController {
// Set the Dialog's content to the loaded FXML file
dialog.getDialogPane().setContent(loader.load());
} catch (IOException e) {
e.printStackTrace();
errorMsg.setText("Error in loading in dialog box");
errorMsg.setOpacity(1);
}
// Get the controller for the loaded FXML file
......@@ -544,18 +555,23 @@ public class IncomeExpenseController implements FinanceController {
/**
* Switches scenes back to main menu, by loading a new FXML file and setting the scene to this location.
* @param event A button click on the return to main menu button
* @throws IOException If an error occurs with loading any of the FXML files.
*/
@FXML
public void returnToMainMenu(javafx.event.ActionEvent event) throws IOException {
saveDataToFile();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
public void returnToMainMenu(javafx.event.ActionEvent event) {
try {
saveDataToFile();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
} catch(IOException ioe) {
errorMsg.setText("Error in saving to file");
errorMsg.setOpacity(1);
}
Parent root = loader.load();
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
......@@ -63,11 +63,16 @@
</Pane>
</left>
<center>
<Label fx:id="title" text="INCOME AND EXPENSES" textAlignment="CENTER" BorderPane.alignment="CENTER">
<font>
<Font name="Lucida Console" size="48.0" />
</font>
</Label>
<Pane BorderPane.alignment="CENTER">
<children>
<Label fx:id="title" layoutX="100.0" layoutY="47.0" text="INCOME AND EXPENSES" textAlignment="CENTER">
<font>
<Font name="Lucida Console" size="48.0" />
</font>
</Label>
<Label fx:id="errorMsg" layoutX="309.0" layoutY="112.0" opacity="0.0" text="Couldn't load saved data" textAlignment="CENTER" textFill="#f20808" />
</children>
</Pane>
</center>
<VBox.margin>
<Insets left="15.0" />
......@@ -155,11 +160,6 @@
</ContextMenu>
</contextMenu>
</TableView>
<Label fx:id="inSum" text="Sum: ">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Label>
</children>
</VBox>
<Pane GridPane.columnIndex="1" GridPane.rowIndex="1">
......@@ -179,6 +179,11 @@
<Font name="Lucida Console" size="14.0" />
</font>
</Text>
<Label fx:id="inSum" layoutX="64.0" layoutY="4.0" text="Sum: ">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Label>
</children>
</Pane>
<VBox GridPane.rowIndex="3">
......@@ -205,7 +210,7 @@
</TableView>
<Label fx:id="expSum" text="Sum: ">
<font>
<Font name="Lucida Console" size="14.0" />
<Font name="Lucida Console" size="12.0" />
</font>
</Label>
</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