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 { ...@@ -108,6 +108,9 @@ public class IncomeExpenseController implements FinanceController {
@FXML @FXML
private Label title; private Label title;
@FXML
private Label errorMsg;
@FXML @FXML
private MenuItem editIncomeMenu; private MenuItem editIncomeMenu;
...@@ -136,31 +139,37 @@ public class IncomeExpenseController implements FinanceController { ...@@ -136,31 +139,37 @@ public class IncomeExpenseController implements FinanceController {
@FXML @FXML
private PieChart incomePieChart; private PieChart incomePieChart;
FileHandling fileHandling; FileHandling fileHandling;
@FXML @FXML
public void initialize() throws IOException { public void initialize() {
fileHandling = new FileHandling(); fileHandling = new FileHandling();
//Initialize columns //Initialize columns
setColumns(); setColumns();
//Initialize registers and tableview try {
incomeRegister = loadIncomeDataFromFile("Income"); //Initialize registers and tableview
income = FXCollections.observableArrayList(incomeRegister.getItems()); incomeRegister = loadIncomeDataFromFile("Income");
incomeTableView.setItems(income); income = FXCollections.observableArrayList(incomeRegister.getItems());
incomeTableView.setItems(income);
expenseRegister = loadExpenseDataFromFile("Expense");
expenses = FXCollections.observableArrayList(expenseRegister.getItems());
expenseTableView.setItems(expenses);
expenseRegister = loadExpenseDataFromFile("Expense"); //Setting pie chart values to correspond with the registers
expenses = FXCollections.observableArrayList(expenseRegister.getItems()); incomePieChart.setLegendSide(Side.RIGHT);
expenseTableView.setItems(expenses);
//Setting pie chart values to correspond with the registers expensePieChart.setLegendSide(Side.RIGHT);
incomePieChart.setLegendSide(Side.RIGHT); expensePieChart.setLabelLineLength(10);
expensePieChart.setLegendSide(Side.RIGHT); refreshPieCharts();
expensePieChart.setLabelLineLength(10); } catch(IOException ioe) {
errorMsg.setOpacity(1);
}
refreshPieCharts();
refreshProgress(); refreshProgress();
formatDatePicker(); formatDatePicker();
...@@ -320,7 +329,8 @@ public class IncomeExpenseController implements FinanceController { ...@@ -320,7 +329,8 @@ public class IncomeExpenseController implements FinanceController {
// Set the Dialog's content to the loaded FXML file // Set the Dialog's content to the loaded FXML file
dialog.getDialogPane().setContent(loader.load()); dialog.getDialogPane().setContent(loader.load());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); errorMsg.setText("Error in loading in dialog box");
errorMsg.setOpacity(1);
} }
// Get the controller for the loaded FXML file // Get the controller for the loaded FXML file
...@@ -355,7 +365,8 @@ public class IncomeExpenseController implements FinanceController { ...@@ -355,7 +365,8 @@ public class IncomeExpenseController implements FinanceController {
// Set the Dialog's content to the loaded FXML file // Set the Dialog's content to the loaded FXML file
dialog.getDialogPane().setContent(loader.load()); dialog.getDialogPane().setContent(loader.load());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); errorMsg.setText("Error in loading in dialog box");
errorMsg.setOpacity(1);
} }
// Get the controller for the loaded FXML file // Get the controller for the loaded FXML file
...@@ -544,18 +555,23 @@ public class IncomeExpenseController implements FinanceController { ...@@ -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. * 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 * @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 @FXML
public void returnToMainMenu(javafx.event.ActionEvent event) throws IOException { public void returnToMainMenu(javafx.event.ActionEvent event) {
saveDataToFile(); try {
FXMLLoader loader = new FXMLLoader(); saveDataToFile();
loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml")); 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 @@ ...@@ -63,11 +63,16 @@
</Pane> </Pane>
</left> </left>
<center> <center>
<Label fx:id="title" text="INCOME AND EXPENSES" textAlignment="CENTER" BorderPane.alignment="CENTER"> <Pane BorderPane.alignment="CENTER">
<font> <children>
<Font name="Lucida Console" size="48.0" /> <Label fx:id="title" layoutX="100.0" layoutY="47.0" text="INCOME AND EXPENSES" textAlignment="CENTER">
</font> <font>
</Label> <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> </center>
<VBox.margin> <VBox.margin>
<Insets left="15.0" /> <Insets left="15.0" />
...@@ -155,11 +160,6 @@ ...@@ -155,11 +160,6 @@
</ContextMenu> </ContextMenu>
</contextMenu> </contextMenu>
</TableView> </TableView>
<Label fx:id="inSum" text="Sum: ">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Label>
</children> </children>
</VBox> </VBox>
<Pane GridPane.columnIndex="1" GridPane.rowIndex="1"> <Pane GridPane.columnIndex="1" GridPane.rowIndex="1">
...@@ -179,6 +179,11 @@ ...@@ -179,6 +179,11 @@
<Font name="Lucida Console" size="14.0" /> <Font name="Lucida Console" size="14.0" />
</font> </font>
</Text> </Text>
<Label fx:id="inSum" layoutX="64.0" layoutY="4.0" text="Sum: ">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Label>
</children> </children>
</Pane> </Pane>
<VBox GridPane.rowIndex="3"> <VBox GridPane.rowIndex="3">
...@@ -205,7 +210,7 @@ ...@@ -205,7 +210,7 @@
</TableView> </TableView>
<Label fx:id="expSum" text="Sum: "> <Label fx:id="expSum" text="Sum: ">
<font> <font>
<Font name="Lucida Console" size="14.0" /> <Font name="Lucida Console" size="12.0" />
</font> </font>
</Label> </Label>
</children> </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