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

"Added context menus to income and expenses"

parent 6674f11b
No related branches found
No related tags found
5 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.,!31Added input validation to tableviews
......@@ -113,6 +113,19 @@ public class IncomeExpenseController implements FinanceController {
@FXML
private Label title;
@FXML
private MenuItem editIncomeMenu;
@FXML
private MenuItem deleteIncomeMenu;
@FXML
private MenuItem editExpenseMenu;
@FXML
private MenuItem deleteExpenseMenu;
private IncomeRegister incomeRegister;
private ExpenseRegister expenseRegister;
......@@ -232,23 +245,32 @@ public class IncomeExpenseController implements FinanceController {
* @param event A button click on the edit button.
*/
@Override
public void handleEditBtn(javafx.event.ActionEvent event) {
public void handleEditBtn(javafx.event.ActionEvent event) {
System.out.println(event.getSource());
Income chosenIncome = incomeTableView.getSelectionModel().getSelectedItem();
Expense chosenExpense = expenseTableView.getSelectionModel().getSelectedItem();
if (event.getSource() == editBtn) {
if (chosenIncome!= null) {
System.out.println(chosenIncome);
System.out.println(chosenExpense);
if (chosenIncome != null) {
if (event.getSource() == editBtn || event.getSource() == editIncomeMenu) {
handleEditIncome(chosenIncome);
} else if (chosenExpense != null) {
handleEditExpense(chosenExpense);
} else return;
} else if (event.getSource() == deleteBtn) {
if (chosenIncome != null) {
System.out.println(1);
} else if (event.getSource() == deleteIncomeMenu) {
handleDeleteIncome(chosenIncome);
} else if (chosenExpense != null) {
System.out.println(2);
} else return;
} else if (chosenExpense != null) {
if (event.getSource() == editBtn || event.getSource() == editExpenseMenu) {
handleEditExpense(chosenExpense);
System.out.println(3);
} else if (event.getSource() == deleteExpenseMenu) {
handleDeleteExpense(chosenExpense);
System.out.println(4);
} else return;
}
} else return;
//Updates the tableview and pie chart using the register
refreshTableView();
refreshPieCharts();
......
......@@ -2,8 +2,15 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.chart.PieChart?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuButton?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.image.Image?>
......@@ -13,17 +20,15 @@
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatt1002.demo.controller.IncomeController">
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="695.0" prefWidth="1130.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatt1002.demo.controller.IncomeExpenseController">
<children>
<ImageView fitHeight="400.0" fitWidth="600.0" pickOnBounds="true">
<ImageView fitHeight="695.0" fitWidth="1130.0" pickOnBounds="true">
<image>
<Image url="@../Images/backgroundMini.jpg" />
</image>
......@@ -31,72 +36,78 @@
<Cursor fx:constant="DEFAULT" />
</cursor>
</ImageView>
<BorderPane prefHeight="400.0" prefWidth="600.0">
<top>
<HBox BorderPane.alignment="CENTER">
<children>
<Button fx:id="returnBtn" mnemonicParsing="false" onAction="#switchScene" text="Return ">
<opaqueInsets>
<Insets left="100.0" />
</opaqueInsets>
<HBox.margin>
<Insets left="10.0" top="10.0" />
</HBox.margin>
</Button>
<Region prefHeight="70.0" prefWidth="141.0" />
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Income" textAlignment="CENTER" wrappingWidth="174.6796875">
<HBox.margin>
<Insets />
</HBox.margin>
<VBox prefHeight="695.0" prefWidth="1100.0">
<children>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="143.0" prefWidth="1100.0">
<right>
<Pane BorderPane.alignment="CENTER">
<children>
<Label fx:id="daysLeftLbl" layoutX="27.0" layoutY="83.0" text="Days left: 31">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Label>
<DatePicker fx:id="date" layoutX="-4.0" layoutY="55.0" prefWidth="175.0" />
</children>
</Pane>
</right>
<left>
<Pane prefWidth="175.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="returnBtn" alignment="CENTER" layoutX="-2.0" layoutY="58.0" mnemonicParsing="false" onAction="#returnToMainMenu" text="Return to Main Menu">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Button>
</children>
</Pane>
</left>
<center>
<Label fx:id="title" text="INCOME AND EXPENSES" textAlignment="CENTER" BorderPane.alignment="CENTER">
<font>
<Font size="48.0" />
<Font name="Lucida Console" size="48.0" />
</font>
</Text>
</children>
<opaqueInsets>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</opaqueInsets>
</HBox>
</top>
<center>
<GridPane BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="40.0" left="40.0" right="40.0" />
</BorderPane.margin>
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" maxWidth="485.3333231608073" minWidth="10.0" prefWidth="427.33335367838544" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="111.33333333333331" minWidth="10.0" prefWidth="92.66664632161456" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="65.33334064483643" minHeight="10.0" prefHeight="65.33334064483643" vgrow="SOMETIMES" />
<RowConstraints maxHeight="298.66665744781494" minHeight="10.0" prefHeight="214.00004069010413" vgrow="SOMETIMES" />
<RowConstraints maxHeight="298.66665744781494" minHeight="10.0" prefHeight="29.999959309895814" vgrow="SOMETIMES" />
<RowConstraints maxHeight="298.66665744781494" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<HBox alignment="BOTTOM_LEFT" prefWidth="410.0" spacing="5.0">
</Label>
</center>
<VBox.margin>
<Insets left="15.0" />
</VBox.margin>
</BorderPane>
<BorderPane prefHeight="64.0" prefWidth="1100.0">
<left>
<HBox prefHeight="100.0" prefWidth="200.0" spacing="10.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="addBtn" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleAddButton" text="Add" textAlignment="CENTER">
<MenuButton mnemonicParsing="false" prefHeight="25.0" prefWidth="50.0">
<items>
<MenuItem fx:id="addIncome" mnemonicParsing="false" onAction="#handleAddBtn" text="Income" />
<MenuItem fx:id="addExpense" mnemonicParsing="false" onAction="#handleAddBtn" text="Expense" />
</items>
<graphic>
<ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<ImageView fitHeight="30.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../Images/add_image.png" />
<Image url="@../Images/add.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="editBtn" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleEditButton" text="Edit" textAlignment="CENTER">
</MenuButton>
<Button fx:id="editBtn" mnemonicParsing="false" onAction="#handleEditBtn" prefHeight="25.0" prefWidth="60.0">
<font>
<Font name="Lucida Console" size="12.0" />
</font>
<graphic>
<ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<ImageView fitHeight="30.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../Images/edit.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="deleteBtn" alignment="TOP_CENTER" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete" textAlignment="CENTER">
<Button fx:id="deleteBtn" mnemonicParsing="false" onAction="#handleDeleteBtn" prefHeight="25.0" prefWidth="60.0">
<font>
<Font name="Lucida Console" size="12.0" />
</font>
<graphic>
<ImageView fitHeight="19.0" fitWidth="16.0" pickOnBounds="true" preserveRatio="true">
<ImageView fitHeight="30.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../Images/delete.png" />
</image>
......@@ -104,86 +115,143 @@
</graphic>
</Button>
</children>
<opaqueInsets>
<Insets />
</opaqueInsets>
<padding>
<Insets bottom="5.0" />
</padding>
<BorderPane.margin>
<Insets left="30.0" />
</BorderPane.margin>
</HBox>
<VBox alignment="BOTTOM_LEFT" prefHeight="200.0" prefWidth="100.0" spacing="5.0" GridPane.columnIndex="1">
</left>
<right>
<Pane BorderPane.alignment="CENTER">
<children>
<ComboBox fx:id="show" prefWidth="150.0" promptText="Show ">
<ProgressBar fx:id="budgetProgress" prefWidth="200.0" progress="0.0" />
</children>
</Pane>
</right>
<opaqueInsets>
<Insets />
</opaqueInsets>
<VBox.margin>
<Insets left="10.0" right="15.0" />
</VBox.margin>
<center>
<Pane BorderPane.alignment="CENTER">
<children>
<ComboBox fx:id="filter" layoutX="134.0" layoutY="2.0" prefWidth="150.0" promptText="Show">
<opaqueInsets>
<Insets />
</opaqueInsets>
<VBox.margin>
<Insets bottom="5.0" />
</VBox.margin>
</ComboBox>
</children>
</Pane>
</center>
</BorderPane>
<GridPane prefHeight="473.0" prefWidth="1055.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" percentHeight="5.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" percentHeight="4.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<VBox maxWidth="490.0" prefHeight="215.0" prefWidth="490.0" GridPane.rowIndex="1">
<children>
<TableView fx:id="incomeTableView" maxHeight="175.0" prefHeight="175.0" prefWidth="264.0">
<columns>
<TableColumn fx:id="inDateCol" prefWidth="75.0" text="Date" />
<TableColumn fx:id="inAmountCol" prefWidth="75.0" text="Amount" />
<TableColumn fx:id="inCategoryCol" prefWidth="75.0" text="Category" />
<TableColumn fx:id="inDescriptionCol" prefWidth="75.0" text="Description" />
<TableColumn fx:id="inRecurringCol" prefWidth="75.0" text="Recurring" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<contextMenu>
<ContextMenu>
<items>
<MenuItem mnemonicParsing="false" onAction="#handleEditBtn" text="Edit" />
<MenuItem fx:id="handleDeleteIncome" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete " />
</items>
</ContextMenu>
</contextMenu>
</TableView>
<Label text="Sum: ">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Label>
</children>
</VBox>
<HBox prefHeight="100.0" prefWidth="200.0" GridPane.columnSpan="2" GridPane.rowIndex="3">
<Pane GridPane.columnIndex="1" GridPane.rowIndex="1">
<children>
<Button disable="true" mnemonicParsing="false" text="Income" />
<Button fx:id="budgetBtn" mnemonicParsing="false" onAction="#switchScene" text="Budget" />
<Button fx:id="expenseBtn" mnemonicParsing="false" onAction="#switchScene" text="Expenses" />
<Button mnemonicParsing="false" onAction="#switchScene" text="Next">
<HBox.margin>
<Insets left="170.0" />
</HBox.margin>
</Button>
<PieChart fx:id="incomePieChart" layoutX="4.0" layoutY="-41.0" legendSide="RIGHT" maxHeight="244.0" maxWidth="512.0" prefHeight="244.0" prefWidth="350.0" title="Income" />
</children>
<padding>
<Insets top="10.0" />
</padding>
</HBox>
<TableView fx:id="incomeTableView" prefHeight="260.0" prefWidth="485.0" GridPane.columnSpan="2" GridPane.rowIndex="1">
<columns>
<TableColumn fx:id="dateColumn" prefWidth="75.0" text="Date" />
<TableColumn fx:id="amountColumn" prefWidth="75.0" text="Amount" />
<TableColumn fx:id="categoryColumn" prefWidth="75.0" text="Category" />
<TableColumn fx:id="descriptionColumn" prefWidth="75.0" text="Description" />
<TableColumn fx:id="recurringColumn" prefWidth="75.0" text="Recurring" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<StackPane GridPane.rowIndex="2">
</Pane>
<Pane GridPane.columnIndex="1" GridPane.rowIndex="3">
<children>
<PieChart fx:id="expensePieChart" layoutX="-2.0" layoutY="-37.0" legendSide="RIGHT" maxHeight="261.0" maxWidth="519.0" prefHeight="237.0" prefWidth="350.0" title="Expenses" />
</children>
</Pane>
<Pane prefHeight="20.0" prefWidth="1046.0">
<children>
<Text layoutY="16.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Income" textAlignment="CENTER">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Text>
</children>
</Pane>
<VBox GridPane.rowIndex="3">
<children>
<TableView fx:id="expenseTableView" maxHeight="175.0" maxWidth="490.0" prefHeight="172.0" prefWidth="264.0">
<columns>
<TableColumn fx:id="expDateCol" prefWidth="75.0" text="Date" />
<TableColumn fx:id="expAmountCol" prefWidth="75.0" text="Amount" />
<TableColumn fx:id="expCategoryCol" prefWidth="75.0" text="Category" />
<TableColumn fx:id="expDescriptionCol" prefWidth="75.0" text="Description" />
<TableColumn fx:id="expRecurringCol" prefWidth="75.0" text="Recurring" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<contextMenu>
<ContextMenu>
<items>
<MenuItem mnemonicParsing="false" onAction="#handleEditBtn" text="Edit" />
<MenuItem fx:id="handleDeleteExpense" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete" />
</items>
</ContextMenu>
</contextMenu>
</TableView>
<Label text="Sum: ">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Label>
</children>
</VBox>
<Pane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="2">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="#f8f8f8" height="18.0" stroke="#d9cccc" strokeType="INSIDE" width="209.0" StackPane.alignment="CENTER_LEFT" />
<HBox prefHeight="18.0" prefWidth="517.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Sum: ">
<HBox.margin>
<Insets left="2.0" />
</HBox.margin>
</Text>
<Region prefHeight="18.0" prefWidth="74.0" />
<Text fx:id="sum" strokeType="OUTSIDE" strokeWidth="0.0" text="Text" />
</children>
</HBox>
<Text layoutY="14.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Expenses" textAlignment="CENTER">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Text>
</children>
</StackPane>
</Pane>
</children>
<padding>
<Insets left="10.0" />
</padding>
<VBox.margin>
<Insets left="30.0" right="30.0" />
</VBox.margin>
</GridPane>
</center>
<opaqueInsets>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</opaqueInsets>
<left>
<Region prefHeight="330.0" prefWidth="1.0" BorderPane.alignment="CENTER" />
</left>
<right>
<Region prefHeight="357.0" prefWidth="0.0" BorderPane.alignment="CENTER" />
</right>
<bottom>
<Region prefHeight="0.0" prefWidth="600.0" BorderPane.alignment="CENTER" />
</bottom>
</BorderPane>
</children>
</VBox>
</children>
<opaqueInsets>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</opaqueInsets>
</AnchorPane>
......@@ -173,7 +173,8 @@
<contextMenu>
<ContextMenu>
<items>
<MenuItem mnemonicParsing="false" text="Unspecified Action" />
<MenuItem fx:id="editIncomeMenu" mnemonicParsing="false" onAction="#handleEditBtn" text="Edit" />
<MenuItem fx:id="deleteIncomeMenu" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete " />
</items>
</ContextMenu>
</contextMenu>
......@@ -220,7 +221,8 @@
<contextMenu>
<ContextMenu>
<items>
<MenuItem mnemonicParsing="false" text="Unspecified Action" />
<MenuItem fx:id="editExpenseMenu" mnemonicParsing="false" onAction="#handleEditBtn" text="Edit" />
<MenuItem fx:id="deleteExpenseMenu" mnemonicParsing="false" onAction="#handleDeleteBtn" text="Delete" />
</items>
</ContextMenu>
</contextMenu>
......
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