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

"Added legends to pie charts. Implemented saveDataToFile and refreshTableView methods"

parent a625608e
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
Pipeline #213974 passed
......@@ -46,8 +46,7 @@ public interface FinanceController {
/**
* Saves the changes made to the tableview by writing the information to a file.
* @param fileName The name of the file that is written to.
* @throws IOException If an error occurs while writing to the file.
*/
void saveDataToFile(String fileName) throws IOException;
void saveDataToFile() throws IOException;
}
......@@ -142,17 +142,17 @@ public class IncomeExpenseController implements FinanceController {
expenseTableView.setItems(expenses);
incomePieChart.getData().addAll(createIncomePyChart());
expensePieChart.getData().addAll(createExpensePyChart());
incomePieChart.setTitle("Income");
incomePieChart.setLegendSide(Side.RIGHT);
incomePieChart.setLegendSide(Side.LEFT);
expensePieChart.setData(createExpensePyChart());
expensePieChart.setTitle("Expenses");
expensePieChart.setLegendSide(Side.LEFT);
expensePieChart.setLegendSide(Side.RIGHT);
expensePieChart.setLabelLineLength(10);
//Initialize sum field under the tableview
// inSum.setText(String.valueOf(incomeRegister.getTotalSum()));
//expSum.setText(String.valueOf(expenseRegister.getTotalSum()));
}
private void setColumns() {
......@@ -170,33 +170,19 @@ public class IncomeExpenseController implements FinanceController {
}
private ObservableList<PieChart.Data> createExpensePyChart() {
ObservableList<PieChart.Data> expensePieChartData =
FXCollections.observableArrayList(
new PieChart.Data("Food", expenseRegister.getExpenseByCategory(ExpenseCategory.FOOD).getTotalSum()),
new PieChart.Data("Books", expenseRegister.getExpenseByCategory(ExpenseCategory.BOOKS).getTotalSum()),
new PieChart.Data("Clothes", expenseRegister.getExpenseByCategory(ExpenseCategory.CLOTHES).getTotalSum()),
new PieChart.Data("Other", expenseRegister.getExpenseByCategory(ExpenseCategory.OTHER).getTotalSum())
);
expensePieChartData.forEach(data ->
data.nameProperty().bind(
Bindings.concat(
data.getName() + " " + data.pieValueProperty())
));
return expensePieChartData;
return FXCollections.observableArrayList(
new Data("Food", expenseRegister.getExpenseByCategory(ExpenseCategory.FOOD).getTotalSum()),
new Data("Books", expenseRegister.getExpenseByCategory(ExpenseCategory.BOOKS).getTotalSum()),
new Data("Clothes", expenseRegister.getExpenseByCategory(ExpenseCategory.CLOTHES).getTotalSum()),
new Data("Other", expenseRegister.getExpenseByCategory(ExpenseCategory.OTHER).getTotalSum())
);
}
private ObservableList<PieChart.Data> createIncomePyChart() {
ObservableList<PieChart.Data> incomePieChartData =
FXCollections.observableArrayList(
new PieChart.Data("Food", incomeRegister.getIncomeByCategory(IncomeCategory.GIFT).getTotalSum()),
new PieChart.Data("Books", incomeRegister.getIncomeByCategory(IncomeCategory.SALARY).getTotalSum())
);
incomePieChartData.forEach(data ->
data.nameProperty().bind(
Bindings.concat(
data.getName() + " " + data.pieValueProperty())
));
return incomePieChartData;
return FXCollections.observableArrayList(
new Data("Food", incomeRegister.getIncomeByCategory(IncomeCategory.STUDENT_LOAN).getTotalSum()),
new Data("Books", incomeRegister.getIncomeByCategory(IncomeCategory.SALARY).getTotalSum())
);
}
/**
......@@ -226,7 +212,6 @@ public class IncomeExpenseController implements FinanceController {
*/
@Override
public void handleDeleteBtn(ActionEvent event) {
}
/**
......@@ -236,7 +221,11 @@ public class IncomeExpenseController implements FinanceController {
*/
@Override
public void refreshTableView() {
this.income.setAll(incomeRegister.getItems());
//this.sum.setText(String.valueOf(incomeRegister.getTotalSum()));
this.expenses.setAll(expenseRegister.getItems());
//this.sum.setText(String.valueOf(incomeRegister.getTotalSum()));
}
/**
......@@ -252,13 +241,12 @@ public class IncomeExpenseController implements FinanceController {
/**
* Saves the changes made to the tableview by writing the information to a file.
*
* @param fileName The name of the file that is written to.
* @throws IOException If an error occurs while writing to the file.
*/
@Override
public void saveDataToFile(String fileName) throws IOException {
public void saveDataToFile() throws IOException {
fileHandling.writeItemRegisterToFile(incomeRegister, "Income");
fileHandling.writeItemRegisterToFile(expenseRegister, "Expense");
}
/**
......@@ -327,6 +315,7 @@ public class IncomeExpenseController implements FinanceController {
*/
@FXML
private void returnToMainMenu(javafx.event.ActionEvent event) throws IOException {
saveDataToFile();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/view/MainMenuNew.fxml"));
......
......@@ -8,3 +8,8 @@ amount=100.0
isRecurring=Recurring
category=OTHER
date=2023-03-30
amount=200.0
isRecurring=Not recurring
category=BOOKS
......@@ -189,8 +189,16 @@
</VBox>
</children>
</GridPane>
<PieChart fx:id="incomePieChart" prefHeight="175.0" prefWidth="175.0" GridPane.columnIndex="1" />
<PieChart fx:id="expensePieChart" prefHeight="175.0" prefWidth="175.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Pane GridPane.columnIndex="1">
<children>
<PieChart fx:id="incomePieChart" layoutX="4.0" layoutY="-18.0" legendSide="RIGHT" maxHeight="226.0" maxWidth="512.0" prefHeight="214.0" prefWidth="350.0" />
</children>
</Pane>
<Pane GridPane.columnIndex="1" GridPane.rowIndex="1">
<children>
<PieChart fx:id="expensePieChart" layoutX="-2.0" layoutY="-27.0" legendSide="RIGHT" maxHeight="247.0" maxWidth="519.0" prefHeight="227.0" prefWidth="350.0" />
</children>
</Pane>
</children>
<padding>
<Insets left="10.0" />
......
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