From e8c44d53078c43fde652e17277db502e64bc8255 Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Sun, 14 Apr 2024 02:53:46 +0800 Subject: [PATCH 01/11] Remove print statements in GUI code --- src/main/java/seedu/address/model/ModelManager.java | 4 ---- src/main/java/seedu/address/ui/MainWindow.java | 5 ----- 2 files changed, 9 deletions(-) diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 803a10edc39..ba167f6c23e 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -234,7 +234,6 @@ public BooleanProperty getIsLoansTab() { @Override public void setIsLoansTab(Boolean isLoansTab) { - System.out.println("Method setIsLoansTab called inside ModelManager"); if (isLoansTab) { this.isAnalyticsTab.setValue(false); this.isPersonTab.setValue(false); @@ -249,7 +248,6 @@ public BooleanProperty getIsAnalyticsTab() { @Override public void setToPersonTab() { - System.out.println("Method setToPersonTab called inside ModelManager"); this.isLoansTab.setValue(false); this.isAnalyticsTab.setValue(false); this.updateFilteredLoanList(PREDICATE_SHOW_NO_LOANS); @@ -286,7 +284,6 @@ public BooleanProperty getIsPersonTab() { @Override public void setIsPersonTab(Boolean isPersonTab) { - System.out.println("Method setIsPersonTab called inside ModelManager"); if (isPersonTab) { this.isLoansTab.setValue(false); this.isAnalyticsTab.setValue(false); @@ -296,7 +293,6 @@ public void setIsPersonTab(Boolean isPersonTab) { @Override public void setDualPanel() { - System.out.println("Method setDualPanel called inside ModelManager"); this.isLoansTab.setValue(true); this.isPersonTab.setValue(true); this.isAnalyticsTab.setValue(false); diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index d13f8551666..bf900515a48 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -149,7 +149,6 @@ void fillInnerParts() { this.loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getLoaneeInfoFlag()); logic.getLoaneeInfoFlag().addListener((observable, oldValue, newValue) -> { this.loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getLoaneeInfoFlag()); - System.out.println("Loanee info flag changed to: " + newValue); }); analyticsPanel = new AnalyticsPanel(logic.getAnalytics()); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); @@ -209,8 +208,6 @@ private void toggleTabs() { personListPanelPlaceholder.setMaxHeight(105); personListPanelPlaceholder.setMinHeight(105); VBox.setVgrow(personList, Priority.NEVER); - - System.out.println("Both tabs are active"); } else if (isPersonTab.getValue()) { // Default to person list panel clearAllPlaceholders(); @@ -219,7 +216,6 @@ private void toggleTabs() { VBox.setVgrow(loanList, Priority.NEVER); VBox.setVgrow(analytics, Priority.NEVER); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); - System.out.println("Only person tab is active"); } else if (this.isLoansTab.getValue()) { clearAllPlaceholders(); VBox.setVgrow(loanList, Priority.ALWAYS); @@ -227,7 +223,6 @@ private void toggleTabs() { VBox.setVgrow(analytics, Priority.NEVER); loanListPanelPlaceholder.getChildren().add(loanListPanel.getRoot()); personListPanelPlaceholder.setMinHeight(0); - System.out.println("Only loans tab is active"); } else { clearAllPlaceholders(); VBox.setVgrow(analytics, Priority.ALWAYS); From c459cb9ba421bdf218681b017c8ea7122f670ac8 Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Sun, 14 Apr 2024 02:58:42 +0800 Subject: [PATCH 02/11] Reorganize MainWindow.java --- .../java/seedu/address/ui/MainWindow.java | 93 +++++++++++-------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index bf900515a48..3081d71cde8 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -146,10 +146,7 @@ void fillInnerParts() { // Initial value of isAnalyticsTab is false by default assert (!this.isAnalyticsTab.getValue()); personListPanel = new PersonListPanel(logic.getFilteredPersonList()); - this.loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getLoaneeInfoFlag()); - logic.getLoaneeInfoFlag().addListener((observable, oldValue, newValue) -> { - this.loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getLoaneeInfoFlag()); - }); + loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getLoaneeInfoFlag()); analyticsPanel = new AnalyticsPanel(logic.getAnalytics()); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); resultDisplay = new ResultDisplay(); @@ -170,12 +167,9 @@ private void initializePlaceholderSettings() { } private void initializeLocalListeners() { - // Add listener to tab flags this.isLoansTab = logic.getIsLoansTab(); this.isAnalyticsTab = logic.getIsAnalyticsTab(); this.isPersonTab = logic.getIsPersonTab(); - - // Add listener to loaneeInfoFlag this.loaneeInfoFlag = logic.getLoaneeInfoFlag(); logic.setIsAnalyticsTab(false); @@ -190,46 +184,65 @@ private void initializeLocalListeners() { this.isAnalyticsTab.addListener((observable, oldValue, newValue) -> { toggleTabs(); }); + + logic.getLoaneeInfoFlag().addListener((observable, oldValue, newValue) -> { + this.loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getLoaneeInfoFlag()); + }); + } + + private void activateDualPanelView() { + clearAllPlaceholders(); + VBox.setVgrow(personList, Priority.ALWAYS); + VBox.setVgrow(loanList, Priority.NEVER); + VBox.setVgrow(analytics, Priority.NEVER); + personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + VBox.setVgrow(loanList, Priority.ALWAYS); + loanListPanelPlaceholder.getChildren().add(loanListPanel.getRoot()); + VBox.setVgrow(analytics, Priority.NEVER); + personListPanelPlaceholder.setMaxHeight(105); + personListPanelPlaceholder.setMinHeight(105); + VBox.setVgrow(personList, Priority.NEVER); + } + + private void activatePersonListOnlyView() { + clearAllPlaceholders(); + personListPanelPlaceholder.setMaxHeight(Double.POSITIVE_INFINITY); + VBox.setVgrow(personList, Priority.ALWAYS); + VBox.setVgrow(loanList, Priority.NEVER); + VBox.setVgrow(analytics, Priority.NEVER); + personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + } + + private void activateAnalyticsView() { + clearAllPlaceholders(); + VBox.setVgrow(analytics, Priority.ALWAYS); + VBox.setVgrow(personList, Priority.NEVER); + VBox.setVgrow(loanList, Priority.NEVER); + personListPanelPlaceholder.setMinHeight(0); + analyticsPanelPlaceholder.getChildren().add(analyticsPanel.getRoot()); + } + + private void activateLoanListOnlyView() { + clearAllPlaceholders(); + VBox.setVgrow(loanList, Priority.ALWAYS); + VBox.setVgrow(personList, Priority.NEVER); + VBox.setVgrow(analytics, Priority.NEVER); + loanListPanelPlaceholder.getChildren().add(loanListPanel.getRoot()); + personListPanelPlaceholder.setMinHeight(0); } private void toggleTabs() { // At most one of these can be active at a time assert (!(this.isLoansTab.getValue() && this.isAnalyticsTab.getValue())); - if (isPersonTab.getValue() && isLoansTab.getValue()) { - // Default to person list panel - clearAllPlaceholders(); - VBox.setVgrow(personList, Priority.ALWAYS); - VBox.setVgrow(loanList, Priority.NEVER); - VBox.setVgrow(analytics, Priority.NEVER); - personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); - VBox.setVgrow(loanList, Priority.ALWAYS); - loanListPanelPlaceholder.getChildren().add(loanListPanel.getRoot()); - VBox.setVgrow(analytics, Priority.NEVER); - personListPanelPlaceholder.setMaxHeight(105); - personListPanelPlaceholder.setMinHeight(105); - VBox.setVgrow(personList, Priority.NEVER); + + if (isPersonTab.getValue() && isLoansTab.getValue()) { // Dual panel view + activateDualPanelView(); } else if (isPersonTab.getValue()) { - // Default to person list panel - clearAllPlaceholders(); - personListPanelPlaceholder.setMaxHeight(Double.POSITIVE_INFINITY); - VBox.setVgrow(personList, Priority.ALWAYS); - VBox.setVgrow(loanList, Priority.NEVER); - VBox.setVgrow(analytics, Priority.NEVER); - personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + activatePersonListOnlyView(); } else if (this.isLoansTab.getValue()) { - clearAllPlaceholders(); - VBox.setVgrow(loanList, Priority.ALWAYS); - VBox.setVgrow(personList, Priority.NEVER); - VBox.setVgrow(analytics, Priority.NEVER); - loanListPanelPlaceholder.getChildren().add(loanListPanel.getRoot()); - personListPanelPlaceholder.setMinHeight(0); + activateLoanListOnlyView(); } else { - clearAllPlaceholders(); - VBox.setVgrow(analytics, Priority.ALWAYS); - VBox.setVgrow(personList, Priority.NEVER); - VBox.setVgrow(loanList, Priority.NEVER); - personListPanelPlaceholder.setMinHeight(0); - analyticsPanelPlaceholder.getChildren().add(analyticsPanel.getRoot()); + activateAnalyticsView(); } } @@ -305,8 +318,6 @@ private CommandResult executeCommand(String commandText) throws CommandException if (commandResult.isExit()) { handleExit(); } - // Enable/Disable the loan tab based on whether command is loan related - // logic.setIsLoansTab(commandResult.isLoanRelated()); return commandResult; } catch (CommandException | ParseException e) { From 85190ca80096a25319c6ff66b687225f802a5fbc Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Sun, 14 Apr 2024 03:01:11 +0800 Subject: [PATCH 03/11] Reorganize AnalyticsPanel.java --- src/main/java/seedu/address/ui/AnalyticsPanel.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/address/ui/AnalyticsPanel.java b/src/main/java/seedu/address/ui/AnalyticsPanel.java index 4565eab21a0..d15bd01a4fb 100644 --- a/src/main/java/seedu/address/ui/AnalyticsPanel.java +++ b/src/main/java/seedu/address/ui/AnalyticsPanel.java @@ -61,7 +61,7 @@ private void initializeCharts() { urgencyChart.setLegendVisible(false); } - private void updateChart(DashboardData data) { + private void updateReliability(DashboardData data) { Analytics analytics = data.getAnalytics(); if (analytics.getNumActiveLoans() == 0) { reliabilityIndex.setText("No active loans to analyze"); @@ -75,8 +75,9 @@ private void updateChart(DashboardData data) { reliabilityChart.setData(reliabilityData); reliabilityIndex.setText(String.format("%.2f", (1 - analytics.getPropOverdueLoans()) * 100) + "%"); } + } - + private void updateImpact(DashboardData data) { if (data.getMaxLoanValue().compareTo(BigDecimal.ZERO) == 0) { impactIndex.setText("No loans to analyze"); impactChart.setVisible(false); @@ -89,6 +90,9 @@ private void updateChart(DashboardData data) { impactChart.setData(impactData); impactIndex.setText(String.format("%.2f", data.getImpactIndex().doubleValue() * 100) + "%"); } + } + + private void updateUrgency(DashboardData data) { if (data.getUrgencyIndex() == null) { urgencyIndex.setText("No due loans to analyze"); urgencyChart.setVisible(false); @@ -102,4 +106,10 @@ private void updateChart(DashboardData data) { urgencyIndex.setText(String.format("%.2f", data.getUrgencyIndex() * 100) + "%"); } } + + private void updateChart(DashboardData data) { + updateReliability(data); + updateImpact(data); + updateUrgency(data); + } } From 597aae00054586985bb9231570f1c7cb05e2d20f Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Sun, 14 Apr 2024 03:03:58 +0800 Subject: [PATCH 04/11] Remove unused attributes in LoanListPanel.java --- src/main/java/seedu/address/ui/LoanListPanel.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/seedu/address/ui/LoanListPanel.java b/src/main/java/seedu/address/ui/LoanListPanel.java index 68575e5a08f..13c68611ee6 100644 --- a/src/main/java/seedu/address/ui/LoanListPanel.java +++ b/src/main/java/seedu/address/ui/LoanListPanel.java @@ -22,10 +22,7 @@ public class LoanListPanel extends UiPart { @FXML private ListView loanListView; - @FXML - private ListView personListView; - - private BooleanProperty loaneeInfoFlag; + private final BooleanProperty loaneeInfoFlag; /** * Creates a {@code PersonListPanel} with the given {@code ObservableList}. @@ -41,7 +38,6 @@ public LoanListPanel(ObservableList loanList, BooleanProperty loaneeInfoFl * Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}. */ class LoanListViewCell extends ListCell { - @Override protected void updateItem(Loan loan, boolean empty) { super.updateItem(loan, empty); From 3dd3f122ef77f64ef7a85e6651841f3828a9a319 Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Sun, 14 Apr 2024 03:11:46 +0800 Subject: [PATCH 05/11] Set variables in DashboardData to final --- src/main/java/seedu/address/model/analytics/DashboardData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/analytics/DashboardData.java b/src/main/java/seedu/address/model/analytics/DashboardData.java index 0d8585ceaaf..ecf4fab7256 100644 --- a/src/main/java/seedu/address/model/analytics/DashboardData.java +++ b/src/main/java/seedu/address/model/analytics/DashboardData.java @@ -63,7 +63,7 @@ public BigDecimal getImpactIndex() { * @return urgency index between 0 and 1 */ public Float getUrgencyIndex() { - // Should take extra measures to ensure no overdue loans are used for calculations + // both variables can be null if the lists are empty if (analytics.getEarliestReturnDate() == null || earliestReturnDate == null) { return null; } From c08a104d0f5bfda0ef18e5e08af0aefa2623fc63 Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Sun, 14 Apr 2024 15:24:42 +0800 Subject: [PATCH 06/11] Remove unused methods in Analytics.java --- .../seedu/address/model/person/Analytics.java | 40 ------------------- .../java/seedu/address/ui/LoanListPanel.java | 1 - .../address/model/person/AnalyticsTest.java | 9 ----- 3 files changed, 50 deletions(-) diff --git a/src/main/java/seedu/address/model/person/Analytics.java b/src/main/java/seedu/address/model/person/Analytics.java index 8559df171c1..9641973aa78 100644 --- a/src/main/java/seedu/address/model/person/Analytics.java +++ b/src/main/java/seedu/address/model/person/Analytics.java @@ -157,14 +157,6 @@ public static Analytics getAnalytics(ObservableList loanList) { return analytics; } - public int getNumLoans() { - return numLoans; - } - - public int getNumOverdueLoans() { - return numOverdueLoans; - } - public int getNumActiveLoans() { return numActiveLoans; } @@ -177,46 +169,14 @@ public float getPropActiveLoans() { return propActiveLoans; } - public BigDecimal getTotalValueLoaned() { - return totalValueLoaned; - } - - public BigDecimal getTotalValueOverdue() { - return totalValueOverdue; - } - - public BigDecimal getTotalValueActive() { - return totalValueActive; - } - public BigDecimal getAverageLoanValue() { return averageLoanValue; } - public BigDecimal getAverageOverdueValue() { - return averageOverdueValue; - } - - public BigDecimal getAverageActiveValue() { - return averageActiveValue; - } - - public Date getEarliestLoanDate() { - return earliestLoanDate; - } - public Date getEarliestReturnDate() { return earliestReturnDate; } - public Date getLatestLoanDate() { - return latestLoanDate; - } - - public Date getLatestReturnDate() { - return latestReturnDate; - } - @Override public String toString() { return "Number of loans: " + numLoans + "\n" diff --git a/src/main/java/seedu/address/ui/LoanListPanel.java b/src/main/java/seedu/address/ui/LoanListPanel.java index 13c68611ee6..6234a29d65c 100644 --- a/src/main/java/seedu/address/ui/LoanListPanel.java +++ b/src/main/java/seedu/address/ui/LoanListPanel.java @@ -10,7 +10,6 @@ import javafx.scene.layout.Region; import seedu.address.commons.core.LogsCenter; import seedu.address.model.person.Loan; -import seedu.address.model.person.Person; /** * Panel containing the list of persons. diff --git a/src/test/java/seedu/address/model/person/AnalyticsTest.java b/src/test/java/seedu/address/model/person/AnalyticsTest.java index 16740513a6d..e79f3bd9238 100644 --- a/src/test/java/seedu/address/model/person/AnalyticsTest.java +++ b/src/test/java/seedu/address/model/person/AnalyticsTest.java @@ -23,9 +23,6 @@ public void constructor_null_throwsNullPointerException() { public void emptyLoanList() { // Empty loan list should not throw any exceptions Analytics test = Analytics.getAnalytics(new UniqueLoanList().asUnmodifiableObservableList()); - - assertEquals(0, test.getNumLoans()); // No loans - assertEquals(0, test.getNumOverdueLoans()); // No overdue loans assertEquals(0, test.getNumActiveLoans()); // No active loans assertEquals(0, test.getPropOverdueLoans()); // Proportion of overdue loans is 0 (default) assertEquals(0, test.getPropActiveLoans()); // Proportion of active loans is 0 (default) @@ -40,8 +37,6 @@ public void singleLoan() { UniqueLoanList loanList = new UniqueLoanList(); loanList.addLoan(loan); Analytics test = Analytics.getAnalytics(loanList.asUnmodifiableObservableList()); - assertEquals(1, test.getNumLoans()); // 1 loan - assertEquals(0, test.getNumOverdueLoans()); // No overdue loans assertEquals(1, test.getNumActiveLoans()); // 1 active loan assertEquals(0, test.getPropOverdueLoans()); // Proportion of overdue loans is 0 (default) assertEquals(1, test.getPropActiveLoans()); // Proportion of active loans is 1 @@ -62,8 +57,6 @@ public void multipleActiveLoans() { loanList.addLoan(loan3); loanList.addLoan(loan4); Analytics test = Analytics.getAnalytics(loanList.asUnmodifiableObservableList()); - assertEquals(4, test.getNumLoans()); // 4 loans - assertEquals(1, test.getNumOverdueLoans()); // 1 overdue loans assertEquals(4, test.getNumActiveLoans()); // 4 active loans assertEquals(0.25, test.getPropOverdueLoans()); // Proportion of overdue loans is 0.25 assertEquals(1, test.getPropActiveLoans()); // Proportion of active loans is 1 @@ -89,8 +82,6 @@ public void withInactiveLoans() { loanList.addLoan(loan3); loanList.addLoan(loan4); Analytics test = Analytics.getAnalytics(loanList.asUnmodifiableObservableList()); - assertEquals(4, test.getNumLoans()); // 4 loans - assertEquals(0, test.getNumOverdueLoans()); // 1 overdue loan but is returned so should be zero assertEquals(3, test.getNumActiveLoans()); // 3 active loans assertEquals(0, test.getPropOverdueLoans()); // Proportion of overdue loans is 0 (loan4 is returned) assertEquals(0.75, test.getPropActiveLoans()); // Proportion of active loans is 1 From d163a1a8b4a9a851b66fefabd633f0c3d4efa831 Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Sun, 14 Apr 2024 15:59:49 +0800 Subject: [PATCH 07/11] Rename loaneeInfoFlag to isShowLoaneeInfo --- src/main/java/seedu/address/logic/Logic.java | 2 +- .../seedu/address/logic/LogicManager.java | 4 +- .../logic/commands/ViewLoanCommand.java | 2 +- .../logic/commands/ViewLoansCommand.java | 2 +- src/main/java/seedu/address/model/Model.java | 4 +- .../seedu/address/model/ModelManager.java | 10 ++-- .../java/seedu/address/ui/AnalyticsPanel.java | 49 ++++++++++--------- .../java/seedu/address/ui/LoanListPanel.java | 8 +-- .../java/seedu/address/ui/MainWindow.java | 9 ++-- .../logic/commands/AddCommandTest.java | 4 +- 10 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index ee29fa30e0b..563fa5881c9 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -69,5 +69,5 @@ public interface Logic { BooleanProperty getIsPersonTab(); - BooleanProperty getLoaneeInfoFlag(); + BooleanProperty getIsShowLoaneeInfo(); } diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 3cad3fa7fe0..8832ba085de 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -126,7 +126,7 @@ public BooleanProperty getIsPersonTab() { } @Override - public BooleanProperty getLoaneeInfoFlag() { - return model.getLoaneeInfoFlag(); + public BooleanProperty getIsShowLoaneeInfo() { + return model.getIsShowLoaneeInfo(); } } diff --git a/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java b/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java index 6a65399b6e1..a482b91d322 100644 --- a/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewLoanCommand.java @@ -47,7 +47,7 @@ public CommandResult execute(Model model) throws CommandException { model.updateFilteredPersonList(person -> person.equals(personToShowLoan)); model.updateFilteredLoanList(loan -> loan.isAssignedTo(personToShowLoan), isShowAllLoans); model.setDualPanel(); - model.setLoaneeInfoFlag(false); + model.setIsShowLoaneeInfo(false); return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(personToShowLoan)), false, false, true); } diff --git a/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java b/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java index 12f26b4dca3..ceb7d0d3e23 100644 --- a/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java +++ b/src/main/java/seedu/address/logic/commands/ViewLoansCommand.java @@ -23,7 +23,7 @@ public CommandResult execute(Model model) { model.updateFilteredPersonList(PREDICATE_SHOW_NO_PERSONS); model.updateFilteredLoanList(unused -> true, isShowAllLoans); model.setIsLoansTab(true); - model.setLoaneeInfoFlag(true); + model.setIsShowLoaneeInfo(true); return new CommandResult(MESSAGE_SUCCESS, false, false, true); } } diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index bf8477c8ccf..700709457e0 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -185,7 +185,7 @@ public interface Model { void setDualPanel(); - BooleanProperty getLoaneeInfoFlag(); + BooleanProperty getIsShowLoaneeInfo(); - void setLoaneeInfoFlag(Boolean loaneeInfoFlag); + void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index ba167f6c23e..1e9ec4cce8f 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -40,7 +40,7 @@ public class ModelManager implements Model { private final BooleanProperty isAnalyticsTab = new SimpleBooleanProperty(false); private final BooleanProperty isPersonTab = new SimpleBooleanProperty(false); private final BooleanProperty isShowAllLoans = new SimpleBooleanProperty(false); - private final BooleanProperty loaneeInfoFlag = new SimpleBooleanProperty(true); + private final BooleanProperty isShowLoaneeInfo = new SimpleBooleanProperty(true); private final ObjectProperty dashboardData = new SimpleObjectProperty<>(); @@ -299,12 +299,12 @@ public void setDualPanel() { } @Override - public BooleanProperty getLoaneeInfoFlag() { - return this.loaneeInfoFlag; + public BooleanProperty getIsShowLoaneeInfo() { + return this.isShowLoaneeInfo; } @Override - public void setLoaneeInfoFlag(Boolean loaneeInfoFlag) { - this.loaneeInfoFlag.setValue(loaneeInfoFlag); + public void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo) { + this.isShowLoaneeInfo.setValue(isShowLoaneeInfo); } } diff --git a/src/main/java/seedu/address/ui/AnalyticsPanel.java b/src/main/java/seedu/address/ui/AnalyticsPanel.java index d15bd01a4fb..8bbd5fa0429 100644 --- a/src/main/java/seedu/address/ui/AnalyticsPanel.java +++ b/src/main/java/seedu/address/ui/AnalyticsPanel.java @@ -66,45 +66,46 @@ private void updateReliability(DashboardData data) { if (analytics.getNumActiveLoans() == 0) { reliabilityIndex.setText("No active loans to analyze"); reliabilityChart.setVisible(false); - } else { - reliabilityChart.setVisible(true); - ObservableList reliabilityData = FXCollections.observableArrayList( - new PieChart.Data("Reliability Index", analytics.getPropOverdueLoans()), - new PieChart.Data("", 1 - analytics.getPropOverdueLoans()) - ); - reliabilityChart.setData(reliabilityData); - reliabilityIndex.setText(String.format("%.2f", (1 - analytics.getPropOverdueLoans()) * 100) + "%"); + return; } + reliabilityChart.setVisible(true); + ObservableList reliabilityData = FXCollections.observableArrayList( + new PieChart.Data("Reliability Index", analytics.getPropOverdueLoans()), + new PieChart.Data("", 1 - analytics.getPropOverdueLoans()) + ); + reliabilityChart.setData(reliabilityData); + reliabilityIndex.setText(String.format("%.2f", (1 - analytics.getPropOverdueLoans()) * 100) + "%"); + } private void updateImpact(DashboardData data) { if (data.getMaxLoanValue().compareTo(BigDecimal.ZERO) == 0) { impactIndex.setText("No loans to analyze"); impactChart.setVisible(false); - } else { - impactChart.setVisible(true); - ObservableList impactData = FXCollections.observableArrayList( - new PieChart.Data("Impact Index", data.getImpactIndex().doubleValue()), - new PieChart.Data("", 1 - data.getImpactIndex().doubleValue()) - ); - impactChart.setData(impactData); - impactIndex.setText(String.format("%.2f", data.getImpactIndex().doubleValue() * 100) + "%"); + return; } + impactChart.setVisible(true); + ObservableList impactData = FXCollections.observableArrayList( + new PieChart.Data("Impact Index", data.getImpactIndex().doubleValue()), + new PieChart.Data("", 1 - data.getImpactIndex().doubleValue()) + ); + impactChart.setData(impactData); + impactIndex.setText(String.format("%.2f", data.getImpactIndex().doubleValue() * 100) + "%"); } private void updateUrgency(DashboardData data) { if (data.getUrgencyIndex() == null) { urgencyIndex.setText("No due loans to analyze"); urgencyChart.setVisible(false); - } else { - urgencyChart.setVisible(true); - ObservableList urgencyData = FXCollections.observableArrayList( - new PieChart.Data("Urgency Index", data.getUrgencyIndex()), - new PieChart.Data("", 1 - data.getUrgencyIndex()) - ); - urgencyChart.setData(urgencyData); - urgencyIndex.setText(String.format("%.2f", data.getUrgencyIndex() * 100) + "%"); + return; } + urgencyChart.setVisible(true); + ObservableList urgencyData = FXCollections.observableArrayList( + new PieChart.Data("Urgency Index", data.getUrgencyIndex()), + new PieChart.Data("", 1 - data.getUrgencyIndex()) + ); + urgencyChart.setData(urgencyData); + urgencyIndex.setText(String.format("%.2f", data.getUrgencyIndex() * 100) + "%"); } private void updateChart(DashboardData data) { diff --git a/src/main/java/seedu/address/ui/LoanListPanel.java b/src/main/java/seedu/address/ui/LoanListPanel.java index 6234a29d65c..b0568a24051 100644 --- a/src/main/java/seedu/address/ui/LoanListPanel.java +++ b/src/main/java/seedu/address/ui/LoanListPanel.java @@ -21,16 +21,16 @@ public class LoanListPanel extends UiPart { @FXML private ListView loanListView; - private final BooleanProperty loaneeInfoFlag; + private final BooleanProperty isShowLoaneeInfo; /** * Creates a {@code PersonListPanel} with the given {@code ObservableList}. */ - public LoanListPanel(ObservableList loanList, BooleanProperty loaneeInfoFlag) { + public LoanListPanel(ObservableList loanList, BooleanProperty isShowLoaneeInfo) { super(FXML); loanListView.setItems(loanList); loanListView.setCellFactory(listView -> new LoanListViewCell()); - this.loaneeInfoFlag = loaneeInfoFlag; + this.isShowLoaneeInfo = isShowLoaneeInfo; } /** @@ -45,7 +45,7 @@ protected void updateItem(Loan loan, boolean empty) { setGraphic(null); setText(null); } else { - setGraphic(new LoanCard(loan, getIndex() + 1, loaneeInfoFlag.getValue()).getRoot()); + setGraphic(new LoanCard(loan, getIndex() + 1, isShowLoaneeInfo.getValue()).getRoot()); } } } diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 3081d71cde8..8fcdc357f23 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -77,7 +77,7 @@ public class MainWindow extends UiPart { private BooleanProperty isPersonTab; - private BooleanProperty loaneeInfoFlag; + private BooleanProperty isShowLoaneeInfo; /** * Creates a {@code MainWindow} with the given {@code Stage} and {@code Logic}. @@ -146,7 +146,7 @@ void fillInnerParts() { // Initial value of isAnalyticsTab is false by default assert (!this.isAnalyticsTab.getValue()); personListPanel = new PersonListPanel(logic.getFilteredPersonList()); - loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getLoaneeInfoFlag()); + loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getIsShowLoaneeInfo()); analyticsPanel = new AnalyticsPanel(logic.getAnalytics()); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); resultDisplay = new ResultDisplay(); @@ -170,7 +170,6 @@ private void initializeLocalListeners() { this.isLoansTab = logic.getIsLoansTab(); this.isAnalyticsTab = logic.getIsAnalyticsTab(); this.isPersonTab = logic.getIsPersonTab(); - this.loaneeInfoFlag = logic.getLoaneeInfoFlag(); logic.setIsAnalyticsTab(false); logic.setIsLoansTab(false); @@ -185,8 +184,8 @@ private void initializeLocalListeners() { toggleTabs(); }); - logic.getLoaneeInfoFlag().addListener((observable, oldValue, newValue) -> { - this.loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getLoaneeInfoFlag()); + logic.getIsShowLoaneeInfo().addListener((observable, oldValue, newValue) -> { + this.loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getIsShowLoaneeInfo()); }); } diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 0fb9c259046..db1aff4e0f8 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -231,12 +231,12 @@ public void setDualPanel() { } @Override - public BooleanProperty getLoaneeInfoFlag() { + public BooleanProperty getIsShowLoaneeInfo() { throw new AssertionError("This method should not be called."); } @Override - public void setLoaneeInfoFlag(Boolean loaneeInfoFlag) { + public void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo) { throw new AssertionError("This method should not be called."); } From e0e8022a1ae23e2b7f65fa2b0b22bce0c35c6c80 Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Sun, 14 Apr 2024 19:46:46 +0800 Subject: [PATCH 08/11] Create TabIndicator.java --- .../model/tabindicator/TabIndicator.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/main/java/seedu/address/model/tabindicator/TabIndicator.java diff --git a/src/main/java/seedu/address/model/tabindicator/TabIndicator.java b/src/main/java/seedu/address/model/tabindicator/TabIndicator.java new file mode 100644 index 00000000000..7fb21e6224a --- /dev/null +++ b/src/main/java/seedu/address/model/tabindicator/TabIndicator.java @@ -0,0 +1,102 @@ +package seedu.address.model.tabindicator; + +/** + * Represents the tab indicator of the dashboard. + * Determines which tab is currently shown in the GUI. + */ +public class TabIndicator { + private final boolean isLoansTab; + private final boolean isAnalyticsTab; + private final boolean isPersonTab; + private final boolean isShowAllLoans; + private final boolean isShowLoaneeInfo; + + /** + * Default constructor for TabIndicator. + * + * @param loans Whether the loans tab is shown. + * @param analytics Whether the analytics tab is shown. + * @param person Whether the person tab is shown. + * @param showAllLoans Whether to show all loans or only active loans. + * @param showLoaneeInfo Whether to show loanee information. + */ + public TabIndicator(boolean loans, boolean analytics, boolean person, boolean showAllLoans, + boolean showLoaneeInfo) { + this.isLoansTab = loans; + this.isAnalyticsTab = analytics; + this.isPersonTab = person; + this.isShowAllLoans = showAllLoans; + this.isShowLoaneeInfo = showLoaneeInfo; + } + + public boolean getIsLoansTab() { + return isLoansTab; + } + + public TabIndicator setIsLoansTab(boolean newIsLoansTab) { + if (newIsLoansTab) { + return new TabIndicator(newIsLoansTab, false, false, this.isShowAllLoans, this.isShowLoaneeInfo); + } + return new TabIndicator(newIsLoansTab, isAnalyticsTab, isPersonTab, this.isShowAllLoans, this.isShowLoaneeInfo); + + } + + public boolean getIsAnalyticsTab() { + return isAnalyticsTab; + } + + public TabIndicator setIsAnalyticsTab(boolean newIsAnalyticsTab) { + if (newIsAnalyticsTab) { + return new TabIndicator(false, newIsAnalyticsTab, false, this.isShowAllLoans, this.isShowLoaneeInfo); + } + return new TabIndicator(this.isLoansTab, newIsAnalyticsTab, this.isPersonTab, this.isShowAllLoans, this.isShowLoaneeInfo); + } + + public boolean getIsPersonTab() { + return isPersonTab; + } + + public TabIndicator setIsPersonTab(boolean newIsPersonTab) { + if (newIsPersonTab) { + return new TabIndicator(false, false, newIsPersonTab, this.isShowAllLoans, this.isShowLoaneeInfo); + } + return new TabIndicator(this.isLoansTab, this.isAnalyticsTab, newIsPersonTab, this.isShowAllLoans, this.isShowLoaneeInfo); + } + + public boolean getIsShowAllLoans() { + return isShowAllLoans; + } + + public TabIndicator setIsShowAllLoans(boolean newIsShowAllLoans) { + return new TabIndicator(this.isLoansTab, this.isAnalyticsTab, this.isPersonTab, + newIsShowAllLoans, this.isShowLoaneeInfo); + } + + public boolean getIsShowLoaneeInfo() { + return isShowLoaneeInfo; + } + + public TabIndicator setIsShowLoaneeInfo(boolean newIsShowLoaneeInfo) { + return new TabIndicator(this.isLoansTab, this.isAnalyticsTab, this.isPersonTab, + this.isShowAllLoans, newIsShowLoaneeInfo); + } + + public TabIndicator setDualPanelView() { + return new TabIndicator(true, false, true, this.isShowAllLoans, this.isShowLoaneeInfo); + } + + /** + * Returns a string representation of the TabIndicator. + * + * @return String representation of the TabIndicator. + */ + public String toString() { + return "Loans: " + isLoansTab + "\n" + + " Analytics: " + isAnalyticsTab + "\n" + + " Person: " + isPersonTab + "\n" + + " ShowAllLoans: " + isShowAllLoans + "\n" + + " ShowLoaneeInfo: " + isShowLoaneeInfo + "\n"; + } + + +} From dea3e00af6e682a003f087338c080f7d02683c41 Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Sun, 14 Apr 2024 19:46:57 +0800 Subject: [PATCH 09/11] Refactor tab switching logic using TabIndicator --- src/main/java/seedu/address/logic/Logic.java | 14 +--- .../seedu/address/logic/LogicManager.java | 31 +------- .../address/logic/commands/EditCommand.java | 5 +- src/main/java/seedu/address/model/Model.java | 32 +++++---- .../seedu/address/model/ModelManager.java | 71 ++++--------------- .../java/seedu/address/ui/LoanListPanel.java | 13 ++-- .../java/seedu/address/ui/MainWindow.java | 47 ++++-------- 7 files changed, 63 insertions(+), 150 deletions(-) diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 563fa5881c9..69f80525834 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -2,7 +2,6 @@ import java.nio.file.Path; -import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; @@ -13,6 +12,7 @@ import seedu.address.model.analytics.DashboardData; import seedu.address.model.person.Loan; import seedu.address.model.person.Person; +import seedu.address.model.tabindicator.TabIndicator; /** * API of the Logic component @@ -57,17 +57,7 @@ public interface Logic { ObservableList getSortedLoanList(); - void setIsLoansTab(boolean isLoansTab); - - BooleanProperty getIsLoansTab(); - - void setIsAnalyticsTab(boolean isAnalyticsTab); - - BooleanProperty getIsAnalyticsTab(); - ObjectProperty getAnalytics(); - BooleanProperty getIsPersonTab(); - - BooleanProperty getIsShowLoaneeInfo(); + ObjectProperty getTabIndicator(); } diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 8832ba085de..a68ecca60b7 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -5,7 +5,6 @@ import java.nio.file.Path; import java.util.logging.Logger; -import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; @@ -21,6 +20,7 @@ import seedu.address.model.person.Loan; import seedu.address.model.person.Person; import seedu.address.storage.Storage; +import seedu.address.model.tabindicator.TabIndicator; /** * The main LogicManager of the app. @@ -95,38 +95,13 @@ public ObservableList getSortedLoanList() { return model.getSortedLoanList(); } - @Override - public void setIsLoansTab(boolean isLoansTab) { - model.setIsLoansTab(isLoansTab); - } - - @Override - public BooleanProperty getIsLoansTab() { - return model.getIsLoansTab(); - } - @Override public ObjectProperty getAnalytics() { return model.getDashboardData(); } @Override - public BooleanProperty getIsAnalyticsTab() { - return model.getIsAnalyticsTab(); - } - - @Override - public void setIsAnalyticsTab(boolean isAnalyticsTab) { - model.setIsAnalyticsTab(isAnalyticsTab); - } - - @Override - public BooleanProperty getIsPersonTab() { - return model.getIsPersonTab(); - } - - @Override - public BooleanProperty getIsShowLoaneeInfo() { - return model.getIsShowLoaneeInfo(); + public ObjectProperty getTabIndicator() { + return model.getTabIndicator(); } } diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index a2cf7e72377..34661300c9c 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -83,7 +83,7 @@ public CommandResult execute(Model model) throws CommandException { } model.setPerson(personToEdit, editedPerson); - if (model.getIsLoansTab().get()) { + if (model.getTabIndicator().getValue().getIsLoansTab()) { model.updateFilteredPersonList(person -> person.isSamePerson(editedPerson)); model.updateFilteredLoanList(loan -> loan.isAssignedTo(editedPerson)); } @@ -141,7 +141,8 @@ public static class EditPersonDescriptor { private Address address; private Set tags; - public EditPersonDescriptor() {} + public EditPersonDescriptor() { + } /** * Copy constructor. diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 700709457e0..4fdbb5f0189 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -1,10 +1,8 @@ package seedu.address.model; import java.nio.file.Path; -import java.util.List; import java.util.function.Predicate; -import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; @@ -13,6 +11,7 @@ import seedu.address.model.person.Analytics; import seedu.address.model.person.Loan; import seedu.address.model.person.Person; +import seedu.address.model.tabindicator.TabIndicator; /** * The API of the Model component. @@ -159,16 +158,25 @@ public interface Model { */ void updateFilteredLoanList(Predicate predicate, boolean isShowAllLoans); - void setLoanList(List loanList); - - BooleanProperty getIsLoansTab(); - + /** + * Sets the tab to the loans tab. + * + * @param isLoansTab + */ void setIsLoansTab(Boolean isLoansTab); - BooleanProperty getIsAnalyticsTab(); - + /** + * Sets the tab to the analytics tab. + * + * @param isAnalyticsTab + */ void setIsAnalyticsTab(Boolean isAnalyticsTab); + /** + * Sets the tab to the person tab. + * + * @param isPersonTab + */ void setToPersonTab(); void markLoan(Loan loanToMark); @@ -179,13 +187,9 @@ public interface Model { ObjectProperty getDashboardData(); - BooleanProperty getIsPersonTab(); - - void setIsPersonTab(Boolean isPersonTab); - void setDualPanel(); - BooleanProperty getIsShowLoaneeInfo(); - void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo); + + ObjectProperty getTabIndicator(); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 1e9ec4cce8f..dbb45ffc5e2 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -6,13 +6,10 @@ import java.math.BigDecimal; import java.nio.file.Path; import java.util.Date; -import java.util.List; import java.util.function.Predicate; import java.util.logging.Logger; -import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; @@ -24,6 +21,7 @@ import seedu.address.model.person.Analytics; import seedu.address.model.person.Loan; import seedu.address.model.person.Person; +import seedu.address.model.tabindicator.TabIndicator; /** * Represents the in-memory model of the address book data. @@ -36,11 +34,8 @@ public class ModelManager implements Model { private final FilteredList filteredPersons; private final FilteredList filteredLoans; private final SortedList sortedLoans; - private final BooleanProperty isLoansTab = new SimpleBooleanProperty(false); - private final BooleanProperty isAnalyticsTab = new SimpleBooleanProperty(false); - private final BooleanProperty isPersonTab = new SimpleBooleanProperty(false); - private final BooleanProperty isShowAllLoans = new SimpleBooleanProperty(false); - private final BooleanProperty isShowLoaneeInfo = new SimpleBooleanProperty(true); + private final ObjectProperty tabIndicator = new SimpleObjectProperty<>(new TabIndicator(false, + false, true, false, false)); private final ObjectProperty dashboardData = new SimpleObjectProperty<>(); @@ -192,14 +187,15 @@ public ObservableList getSortedLoanList() { public void updateFilteredLoanList(Predicate predicate) { requireNonNull(predicate); Predicate secondPredicate = - isShowAllLoans.get() ? PREDICATE_SHOW_ALL_LOANS : PREDICATE_SHOW_ALL_ACTIVE_LOANS; + this.tabIndicator.getValue().getIsShowAllLoans() ? PREDICATE_SHOW_ALL_LOANS + : PREDICATE_SHOW_ALL_ACTIVE_LOANS; filteredLoans.setPredicate(predicate.and(secondPredicate)); } @Override public void updateFilteredLoanList(Predicate predicate, boolean isShowAllLoans) { requireNonNull(predicate); - this.isShowAllLoans.setValue(isShowAllLoans); + this.tabIndicator.setValue(this.tabIndicator.getValue().setIsShowAllLoans(isShowAllLoans)); updateFilteredLoanList(predicate); } @@ -221,48 +217,25 @@ public boolean equals(Object other) { && sortedLoans.equals(otherModelManager.sortedLoans); } - @Override - public void setLoanList(List loanList) { - filteredLoans.clear(); - filteredLoans.setAll(loanList); - } - - @Override - public BooleanProperty getIsLoansTab() { - return this.isLoansTab; - } - @Override public void setIsLoansTab(Boolean isLoansTab) { - if (isLoansTab) { - this.isAnalyticsTab.setValue(false); - this.isPersonTab.setValue(false); - } - this.isLoansTab.setValue(isLoansTab); + this.tabIndicator.setValue(this.tabIndicator.getValue().setIsLoansTab(isLoansTab)); } - @Override - public BooleanProperty getIsAnalyticsTab() { - return this.isAnalyticsTab; - } @Override public void setToPersonTab() { - this.isLoansTab.setValue(false); - this.isAnalyticsTab.setValue(false); this.updateFilteredLoanList(PREDICATE_SHOW_NO_LOANS); - this.setIsPersonTab(true); + this.tabIndicator.setValue(this.tabIndicator.getValue().setIsPersonTab(true)); } @Override public void setIsAnalyticsTab(Boolean isAnalyticsTab) { if (isAnalyticsTab) { - this.isLoansTab.setValue(false); - this.isPersonTab.setValue(false); this.updateFilteredPersonList(PREDICATE_SHOW_NO_PERSONS); this.updateFilteredLoanList(PREDICATE_SHOW_NO_LOANS); } - this.isAnalyticsTab.setValue(isAnalyticsTab); + this.tabIndicator.setValue(this.tabIndicator.getValue().setIsAnalyticsTab(isAnalyticsTab)); } @Override @@ -277,34 +250,18 @@ public void generateDashboardData(Analytics analytics) { dashboardData.setValue(new DashboardData(analytics, impactBenchmark, urgencyBenchmark)); } - @Override - public BooleanProperty getIsPersonTab() { - return this.isPersonTab; - } - - @Override - public void setIsPersonTab(Boolean isPersonTab) { - if (isPersonTab) { - this.isLoansTab.setValue(false); - this.isAnalyticsTab.setValue(false); - } - this.isPersonTab.setValue(isPersonTab); - } - @Override public void setDualPanel() { - this.isLoansTab.setValue(true); - this.isPersonTab.setValue(true); - this.isAnalyticsTab.setValue(false); + this.tabIndicator.setValue(this.tabIndicator.getValue().setDualPanelView()); } @Override - public BooleanProperty getIsShowLoaneeInfo() { - return this.isShowLoaneeInfo; + public void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo) { + this.tabIndicator.setValue(this.tabIndicator.getValue().setIsShowLoaneeInfo(isShowLoaneeInfo)); } @Override - public void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo) { - this.isShowLoaneeInfo.setValue(isShowLoaneeInfo); + public ObjectProperty getTabIndicator() { + return this.tabIndicator; } } diff --git a/src/main/java/seedu/address/ui/LoanListPanel.java b/src/main/java/seedu/address/ui/LoanListPanel.java index b0568a24051..81eeeefce0f 100644 --- a/src/main/java/seedu/address/ui/LoanListPanel.java +++ b/src/main/java/seedu/address/ui/LoanListPanel.java @@ -2,7 +2,7 @@ import java.util.logging.Logger; -import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.ListCell; @@ -10,6 +10,7 @@ import javafx.scene.layout.Region; import seedu.address.commons.core.LogsCenter; import seedu.address.model.person.Loan; +import seedu.address.model.tabindicator.TabIndicator; /** * Panel containing the list of persons. @@ -21,16 +22,17 @@ public class LoanListPanel extends UiPart { @FXML private ListView loanListView; - private final BooleanProperty isShowLoaneeInfo; + // private final BooleanProperty isShowLoaneeInfo; + private final ObjectProperty tabIndicator; /** * Creates a {@code PersonListPanel} with the given {@code ObservableList}. */ - public LoanListPanel(ObservableList loanList, BooleanProperty isShowLoaneeInfo) { + public LoanListPanel(ObservableList loanList, ObjectProperty tabIndicator) { super(FXML); loanListView.setItems(loanList); loanListView.setCellFactory(listView -> new LoanListViewCell()); - this.isShowLoaneeInfo = isShowLoaneeInfo; + this.tabIndicator = tabIndicator; } /** @@ -45,7 +47,8 @@ protected void updateItem(Loan loan, boolean empty) { setGraphic(null); setText(null); } else { - setGraphic(new LoanCard(loan, getIndex() + 1, isShowLoaneeInfo.getValue()).getRoot()); + setGraphic(new LoanCard(loan, getIndex() + 1, + tabIndicator.getValue().getIsShowLoaneeInfo()).getRoot()); } } } diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 8fcdc357f23..8dc67799b6b 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -2,7 +2,7 @@ import java.util.logging.Logger; -import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.MenuItem; @@ -19,6 +19,7 @@ import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.tabindicator.TabIndicator; /** * The Main Window. Provides the basic application layout containing @@ -70,14 +71,7 @@ public class MainWindow extends UiPart { private VBox analytics; @FXML private VBox personList; - - private BooleanProperty isLoansTab; - - private BooleanProperty isAnalyticsTab; - - private BooleanProperty isPersonTab; - - private BooleanProperty isShowLoaneeInfo; + private ObjectProperty tabIndicator; /** * Creates a {@code MainWindow} with the given {@code Stage} and {@code Logic}. @@ -142,11 +136,12 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) { void fillInnerParts() { initializeLocalListeners(); // Initial value of isLoansTab is false by default - assert (!this.isLoansTab.getValue()); + assert (!this.tabIndicator.getValue().getIsLoansTab()); // Initial value of isAnalyticsTab is false by default - assert (!this.isAnalyticsTab.getValue()); + assert (!this.tabIndicator.getValue().getIsAnalyticsTab()); personListPanel = new PersonListPanel(logic.getFilteredPersonList()); - loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getIsShowLoaneeInfo()); + + loanListPanel = new LoanListPanel(logic.getSortedLoanList(), this.tabIndicator); analyticsPanel = new AnalyticsPanel(logic.getAnalytics()); personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); resultDisplay = new ResultDisplay(); @@ -167,26 +162,14 @@ private void initializePlaceholderSettings() { } private void initializeLocalListeners() { - this.isLoansTab = logic.getIsLoansTab(); - this.isAnalyticsTab = logic.getIsAnalyticsTab(); - this.isPersonTab = logic.getIsPersonTab(); - - logic.setIsAnalyticsTab(false); - logic.setIsLoansTab(false); + this.tabIndicator = logic.getTabIndicator(); - this.isPersonTab.addListener((observable, oldValue, newValue) -> { - toggleTabs(); - }); - this.isLoansTab.addListener((observable, oldValue, newValue) -> { - toggleTabs(); - }); - this.isAnalyticsTab.addListener((observable, oldValue, newValue) -> { + this.tabIndicator.addListener((observable, oldValue, newValue) -> { + System.out.println("Value changed!" + newValue); toggleTabs(); }); - logic.getIsShowLoaneeInfo().addListener((observable, oldValue, newValue) -> { - this.loanListPanel = new LoanListPanel(logic.getSortedLoanList(), logic.getIsShowLoaneeInfo()); - }); + } private void activateDualPanelView() { @@ -232,13 +215,13 @@ private void activateLoanListOnlyView() { private void toggleTabs() { // At most one of these can be active at a time - assert (!(this.isLoansTab.getValue() && this.isAnalyticsTab.getValue())); + assert (!(this.tabIndicator.getValue().getIsLoansTab() && this.tabIndicator.getValue().getIsAnalyticsTab())); - if (isPersonTab.getValue() && isLoansTab.getValue()) { // Dual panel view + if (this.tabIndicator.getValue().getIsPersonTab() && this.tabIndicator.getValue().getIsLoansTab()) { activateDualPanelView(); - } else if (isPersonTab.getValue()) { + } else if (this.tabIndicator.getValue().getIsPersonTab()) { activatePersonListOnlyView(); - } else if (this.isLoansTab.getValue()) { + } else if (this.tabIndicator.getValue().getIsLoansTab()) { activateLoanListOnlyView(); } else { activateAnalyticsView(); From 2b2c3aee3f4768b915aa3e76bc870c346ec624ed Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Sun, 14 Apr 2024 19:50:33 +0800 Subject: [PATCH 10/11] Fix checkstyle errors --- .../seedu/address/logic/LogicManager.java | 3 +- src/main/java/seedu/address/model/Model.java | 5 --- .../model/tabindicator/TabIndicator.java | 12 ++++--- .../logic/commands/AddCommandTest.java | 33 ++----------------- 4 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index a68ecca60b7..f926387dfb9 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -19,8 +19,9 @@ import seedu.address.model.analytics.DashboardData; import seedu.address.model.person.Loan; import seedu.address.model.person.Person; -import seedu.address.storage.Storage; import seedu.address.model.tabindicator.TabIndicator; +import seedu.address.storage.Storage; + /** * The main LogicManager of the app. diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 4fdbb5f0189..41252360041 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -172,11 +172,6 @@ public interface Model { */ void setIsAnalyticsTab(Boolean isAnalyticsTab); - /** - * Sets the tab to the person tab. - * - * @param isPersonTab - */ void setToPersonTab(); void markLoan(Loan loanToMark); diff --git a/src/main/java/seedu/address/model/tabindicator/TabIndicator.java b/src/main/java/seedu/address/model/tabindicator/TabIndicator.java index 7fb21e6224a..b19e6c3db65 100644 --- a/src/main/java/seedu/address/model/tabindicator/TabIndicator.java +++ b/src/main/java/seedu/address/model/tabindicator/TabIndicator.java @@ -47,9 +47,11 @@ public boolean getIsAnalyticsTab() { public TabIndicator setIsAnalyticsTab(boolean newIsAnalyticsTab) { if (newIsAnalyticsTab) { - return new TabIndicator(false, newIsAnalyticsTab, false, this.isShowAllLoans, this.isShowLoaneeInfo); + return new TabIndicator(false, newIsAnalyticsTab, false, + this.isShowAllLoans, this.isShowLoaneeInfo); } - return new TabIndicator(this.isLoansTab, newIsAnalyticsTab, this.isPersonTab, this.isShowAllLoans, this.isShowLoaneeInfo); + return new TabIndicator(this.isLoansTab, newIsAnalyticsTab, this.isPersonTab, + this.isShowAllLoans, this.isShowLoaneeInfo); } public boolean getIsPersonTab() { @@ -58,9 +60,11 @@ public boolean getIsPersonTab() { public TabIndicator setIsPersonTab(boolean newIsPersonTab) { if (newIsPersonTab) { - return new TabIndicator(false, false, newIsPersonTab, this.isShowAllLoans, this.isShowLoaneeInfo); + return new TabIndicator(false, false, newIsPersonTab, + this.isShowAllLoans, this.isShowLoaneeInfo); } - return new TabIndicator(this.isLoansTab, this.isAnalyticsTab, newIsPersonTab, this.isShowAllLoans, this.isShowLoaneeInfo); + return new TabIndicator(this.isLoansTab, this.isAnalyticsTab, newIsPersonTab, + this.isShowAllLoans, this.isShowLoaneeInfo); } public boolean getIsShowAllLoans() { diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index db1aff4e0f8..1133bd16283 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -10,12 +10,10 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import java.util.function.Predicate; import org.junit.jupiter.api.Test; -import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; @@ -29,6 +27,7 @@ import seedu.address.model.person.Analytics; import seedu.address.model.person.Loan; import seedu.address.model.person.Person; +import seedu.address.model.tabindicator.TabIndicator; import seedu.address.testutil.PersonBuilder; public class AddCommandTest { @@ -169,12 +168,6 @@ public void updateFilteredPersonList(Predicate predicate) { throw new AssertionError("This method should not be called."); } - - @Override - public void setLoanList(List loanList) { - throw new AssertionError("This method should not be called."); - } - @Override public ObservableList getSortedLoanList() { throw new AssertionError("This method should not be called."); @@ -190,11 +183,6 @@ public void updateFilteredLoanList(Predicate predicate, boolean isShowAllL throw new AssertionError("This method should not be called."); } - @Override - public BooleanProperty getIsLoansTab() { - throw new AssertionError("This method should not be called."); - } - @Override public void setIsLoansTab(Boolean isLoansTab) { throw new AssertionError("This method should not be called."); @@ -215,28 +203,18 @@ public ObjectProperty getDashboardData() { throw new AssertionError("This method should not be called."); } - @Override - public BooleanProperty getIsPersonTab() { - throw new AssertionError("This method should not be called."); - } - - @Override - public void setIsPersonTab(Boolean isPersonTab) { - throw new AssertionError("This method should not be called."); - } - @Override public void setDualPanel() { throw new AssertionError("This method should not be called."); } @Override - public BooleanProperty getIsShowLoaneeInfo() { + public void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo) { throw new AssertionError("This method should not be called."); } @Override - public void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo) { + public ObjectProperty getTabIndicator() { throw new AssertionError("This method should not be called."); } @@ -260,11 +238,6 @@ public void setIsAnalyticsTab(Boolean isAnalyticsTab) { throw new AssertionError("This method should not be called."); } - @Override - public BooleanProperty getIsAnalyticsTab() { - throw new AssertionError("This method should not be called."); - } - @Override public void setToPersonTab() { throw new AssertionError("This method should not be called."); From 37eb7a0255db75b9c547c29c9233a645a98f911f Mon Sep 17 00:00:00 2001 From: marcus-ny Date: Sun, 14 Apr 2024 21:35:22 +0800 Subject: [PATCH 11/11] Remove print statement in MainWindow.java --- src/main/java/seedu/address/ui/MainWindow.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 8dc67799b6b..08fa4cb18f5 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -165,7 +165,6 @@ private void initializeLocalListeners() { this.tabIndicator = logic.getTabIndicator(); this.tabIndicator.addListener((observable, oldValue, newValue) -> { - System.out.println("Value changed!" + newValue); toggleTabs(); });