Skip to content

Commit

Permalink
Merge pull request #210 from marcus-ny/branch-refactor-GUI-code
Browse files Browse the repository at this point in the history
Refactor GUI-related code
  • Loading branch information
kjw142857 authored Apr 14, 2024
2 parents 5d7907f + 37eb7a0 commit f4c7534
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 308 deletions.
14 changes: 2 additions & 12 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -57,17 +57,7 @@ public interface Logic {

ObservableList<Loan> getSortedLoanList();

void setIsLoansTab(boolean isLoansTab);

BooleanProperty getIsLoansTab();

void setIsAnalyticsTab(boolean isAnalyticsTab);

BooleanProperty getIsAnalyticsTab();

ObjectProperty<DashboardData> getAnalytics();

BooleanProperty getIsPersonTab();

BooleanProperty getLoaneeInfoFlag();
ObjectProperty<TabIndicator> getTabIndicator();
}
32 changes: 4 additions & 28 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,8 +19,10 @@
import seedu.address.model.analytics.DashboardData;
import seedu.address.model.person.Loan;
import seedu.address.model.person.Person;
import seedu.address.model.tabindicator.TabIndicator;
import seedu.address.storage.Storage;


/**
* The main LogicManager of the app.
*/
Expand Down Expand Up @@ -95,38 +96,13 @@ public ObservableList<Loan> getSortedLoanList() {
return model.getSortedLoanList();
}

@Override
public void setIsLoansTab(boolean isLoansTab) {
model.setIsLoansTab(isLoansTab);
}

@Override
public BooleanProperty getIsLoansTab() {
return model.getIsLoansTab();
}

@Override
public ObjectProperty<DashboardData> 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 getLoaneeInfoFlag() {
return model.getLoaneeInfoFlag();
public ObjectProperty<TabIndicator> getTabIndicator() {
return model.getTabIndicator();
}
}
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -141,7 +141,8 @@ public static class EditPersonDescriptor {
private Address address;
private Set<Tag> tags;

public EditPersonDescriptor() {}
public EditPersonDescriptor() {
}

/**
* Copy constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
27 changes: 13 additions & 14 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -159,14 +158,18 @@ public interface Model {
*/
void updateFilteredLoanList(Predicate<Loan> predicate, boolean isShowAllLoans);

void setLoanList(List<Loan> 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);

void setToPersonTab();
Expand All @@ -179,13 +182,9 @@ public interface Model {

ObjectProperty<DashboardData> getDashboardData();

BooleanProperty getIsPersonTab();

void setIsPersonTab(Boolean isPersonTab);

void setDualPanel();

BooleanProperty getLoaneeInfoFlag();
void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo);

void setLoaneeInfoFlag(Boolean loaneeInfoFlag);
ObjectProperty<TabIndicator> getTabIndicator();
}
75 changes: 14 additions & 61 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -36,11 +34,8 @@ public class ModelManager implements Model {
private final FilteredList<Person> filteredPersons;
private final FilteredList<Loan> filteredLoans;
private final SortedList<Loan> 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 loaneeInfoFlag = new SimpleBooleanProperty(true);
private final ObjectProperty<TabIndicator> tabIndicator = new SimpleObjectProperty<>(new TabIndicator(false,
false, true, false, false));

private final ObjectProperty<DashboardData> dashboardData = new SimpleObjectProperty<>();

Expand Down Expand Up @@ -192,14 +187,15 @@ public ObservableList<Loan> getSortedLoanList() {
public void updateFilteredLoanList(Predicate<Loan> predicate) {
requireNonNull(predicate);
Predicate<Loan> 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<Loan> predicate, boolean isShowAllLoans) {
requireNonNull(predicate);
this.isShowAllLoans.setValue(isShowAllLoans);
this.tabIndicator.setValue(this.tabIndicator.getValue().setIsShowAllLoans(isShowAllLoans));
updateFilteredLoanList(predicate);
}

Expand All @@ -221,50 +217,25 @@ public boolean equals(Object other) {
&& sortedLoans.equals(otherModelManager.sortedLoans);
}

@Override
public void setLoanList(List<Loan> loanList) {
filteredLoans.clear();
filteredLoans.setAll(loanList);
}

@Override
public BooleanProperty getIsLoansTab() {
return this.isLoansTab;
}

@Override
public void setIsLoansTab(Boolean isLoansTab) {
System.out.println("Method setIsLoansTab called inside ModelManager");
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() {
System.out.println("Method setToPersonTab called inside ModelManager");
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
Expand All @@ -279,36 +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) {
System.out.println("Method setIsPersonTab called inside ModelManager");
if (isPersonTab) {
this.isLoansTab.setValue(false);
this.isAnalyticsTab.setValue(false);
}
this.isPersonTab.setValue(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);
this.tabIndicator.setValue(this.tabIndicator.getValue().setDualPanelView());
}

@Override
public BooleanProperty getLoaneeInfoFlag() {
return this.loaneeInfoFlag;
public void setIsShowLoaneeInfo(Boolean isShowLoaneeInfo) {
this.tabIndicator.setValue(this.tabIndicator.getValue().setIsShowLoaneeInfo(isShowLoaneeInfo));
}

@Override
public void setLoaneeInfoFlag(Boolean loaneeInfoFlag) {
this.loaneeInfoFlag.setValue(loaneeInfoFlag);
public ObjectProperty<TabIndicator> getTabIndicator() {
return this.tabIndicator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit f4c7534

Please sign in to comment.