Skip to content

Commit

Permalink
Merge d5009eb into 2559b1f
Browse files Browse the repository at this point in the history
  • Loading branch information
wn committed Oct 28, 2018
2 parents 2559b1f + d5009eb commit bbfa319
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/main/java/loanbook/model/loan/Loan.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public Loan(Name name,
LoanStatus loanStatus,
Set<Tag> tags) {

HashSet<Tag> dataTags = new HashSet<>();
dataTags.add(new Tag(loanStatus.toString()));

requireAllNonNull(name, nric, phone, email, address, bike, rate, startTime, loanStatus, tags);
this.name = name;
this.nric = nric;
Expand All @@ -63,6 +66,7 @@ public Loan(Name name,
this.endTime = endTime;
this.loanStatus = loanStatus;
this.tags.addAll(tags);
this.tags.addAll(dataTags);
}

/**
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/loanbook/ui/LoanCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
public class LoanCard extends UiPart<Region> {

private static final String FXML = "LoanListCard.fxml";
private static final String[] LOANSTATUS_TAG_COLOR_STYLES = {"red", "green", "orange"};
private static final String[] TAG_COLOR_STYLES =
{"teal", "red", "yellow", "blue", "orange", "brown", "green", "pink", "black", "grey"};
{"teal", "yellow", "blue", "brown", "pink", "black", "grey"};

/**
* Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX.
Expand Down Expand Up @@ -71,7 +72,17 @@ public LoanCard(Loan loan, int displayedIndex) {
private String getTagColorStyleFor(String tagName) {
// we use the hash code of the tag name to generate a random color, so that the color remain consistent
// between different runs of the program while still making it random enough between tags.
return TAG_COLOR_STYLES[Math.abs(tagName.hashCode()) % TAG_COLOR_STYLES.length];
switch (tagName) {
case "Ongoing":
return LOANSTATUS_TAG_COLOR_STYLES[2];
case "Returned":
return LOANSTATUS_TAG_COLOR_STYLES[1];
case "Deleted":
return LOANSTATUS_TAG_COLOR_STYLES[0];
default:
// All user defined tags are set to brown colour.
return TAG_COLOR_STYLES[3];
}
}

/**
Expand Down
15 changes: 9 additions & 6 deletions src/test/java/loanbook/ui/testutil/GuiTestAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,22 @@ public static void assertCardDisplaysLoan(Loan expectedLoan, LoanCardHandle actu
*/
private static String getTagColorStyleFor(String tagName) {
switch (tagName) {
case "classmates":
case "tag1":
case "owesMoney":
return "teal";
case "colleagues":
case "classmates":
case "neighbours":
return "yellow";
case "family":
case "friend":
return "orange";
case "friends":
return "brown";
case "husband":
return "grey";
return "brown";
case "Ongoing":
return "orange";
case "Returned":
return "green";
case "Deleted":
return "red";
default:
throw new AssertionError(tagName + " does not have a color assigned.");
}
Expand Down

0 comments on commit bbfa319

Please sign in to comment.