Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GUI Color Coding #65

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/java/seedu/address/model/person/Student.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.model.person;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

Expand Down Expand Up @@ -27,13 +28,19 @@ public class Student extends Person {
*/
public Student(Name name, Phone phone, Email email, Address address, Set<Tag> tags,
Subject subject, Set<String> classes) {
super(name, phone, email, address, tags);
super(name, phone, email, address, addStudentTag(tags));
Objects.requireNonNull(subject, "Subject must not be null");
Objects.requireNonNull(classes, "Classes must not be null");
this.subject = subject;
this.classes = classes;
}

private static Set<Tag> addStudentTag(Set<Tag> tags) {
Set<Tag> modifiedTags = new HashSet<>(tags);
modifiedTags.add(new Tag("student"));
return modifiedTags;
}

public Subject getSubject() {
return subject;
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/seedu/address/model/person/Teacher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.model.person;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

Expand Down Expand Up @@ -32,7 +33,7 @@ public class Teacher extends Person {
*/
public Teacher(Name name, Gender gender, Phone phone, Email email, Address address, Set<Tag> tags,
Subject subject, Set<String> classes) {
super(name, phone, email, address, tags);
super(name, phone, email, address, addTeacherTag(tags));
Objects.requireNonNull(gender, "Gender cannot be null");
this.gender = gender;
Objects.requireNonNull(subject, "Subject cannot be null");
Expand All @@ -45,6 +46,12 @@ public Gender getGender() {
return this.gender;
}

private static Set<Tag> addTeacherTag(Set<Tag> tags) {
Set<Tag> modifiedTags = new HashSet<>(tags);
modifiedTags.add(new Tag("teacher"));
return modifiedTags;
}

public Subject getSubject() {
return this.subject;
}
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package seedu.address.ui;

import java.util.Comparator;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
Expand Down Expand Up @@ -47,13 +45,26 @@
public PersonCard(Person person, int displayedIndex) {
super(FXML);
this.person = person;

// Check the tags for "student" or "teacher"
if (person.getTags().stream().anyMatch(tag -> tag.tagName.equals("student"))) {
cardPane.setStyle("-fx-background-color: #349beb;"); // Inline style for student
System.out.println("student");

Check warning on line 52 in src/main/java/seedu/address/ui/PersonCard.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/PersonCard.java#L51-L52

Added lines #L51 - L52 were not covered by tests
} else if (person.getTags().stream().anyMatch(tag -> tag.tagName.equals("teacher"))) {
cardPane.setStyle("-fx-background-color: #269e2e;"); // Inline style for teacher
System.out.println("teacher");

Check warning on line 55 in src/main/java/seedu/address/ui/PersonCard.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/PersonCard.java#L54-L55

Added lines #L54 - L55 were not covered by tests
} else {
// Optional: Set default style for other persons without "student" or "teacher" tags
cardPane.setStyle("-fx-background-color: #494a46;"); // Default style
System.out.println("default");

Check warning on line 59 in src/main/java/seedu/address/ui/PersonCard.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/PersonCard.java#L58-L59

Added lines #L58 - L59 were not covered by tests
}

// Set other UI components
id.setText(displayedIndex + ". ");
name.setText(person.getName().fullName);
phone.setText(person.getPhone().value);
address.setText(person.getAddress().value);
email.setText(person.getEmail().value);
person.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
}

}
26 changes: 25 additions & 1 deletion src/main/java/seedu/address/ui/PersonListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.person.Person;
import seedu.address.model.person.Student;
import seedu.address.model.person.Teacher;

/**
* Panel containing the list of persons.
Expand Down Expand Up @@ -38,12 +40,34 @@
super.updateItem(person, empty);

if (empty || person == null) {
// Clear the cell if it's empty
setGraphic(null);
setText(null);
getStyleClass().removeAll("student-card", "teacher-card"); // Clear any previous styles

Check warning on line 46 in src/main/java/seedu/address/ui/PersonListPanel.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/PersonListPanel.java#L46

Added line #L46 was not covered by tests
} else {
setGraphic(new PersonCard(person, getIndex() + 1).getRoot());
// Set the PersonCard as the graphic for the ListCell
PersonCard personCard = new PersonCard(person, getIndex() + 1);
setGraphic(personCard.getRoot());

Check warning on line 50 in src/main/java/seedu/address/ui/PersonListPanel.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/PersonListPanel.java#L49-L50

Added lines #L49 - L50 were not covered by tests

// Remove any previous styles applied to the cell
getStyleClass().removeAll("student-card", "teacher-card");

Check warning on line 53 in src/main/java/seedu/address/ui/PersonListPanel.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/PersonListPanel.java#L53

Added line #L53 was not covered by tests

// Apply the appropriate style based on whether the person is a Student or Teacher
if (person instanceof Student) {
// Apply inline style for student
setStyle("-fx-background-color: #349beb;");
System.out.println("student");

Check warning on line 59 in src/main/java/seedu/address/ui/PersonListPanel.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/PersonListPanel.java#L58-L59

Added lines #L58 - L59 were not covered by tests

} else if (person instanceof Teacher) {
// Apply inline style for teacher
setStyle("-fx-background-color: #269e2e;");

Check warning on line 63 in src/main/java/seedu/address/ui/PersonListPanel.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/PersonListPanel.java#L63

Added line #L63 was not covered by tests
} else {
// Optionally, clear the style for other types of people
setStyle("");

Check warning on line 66 in src/main/java/seedu/address/ui/PersonListPanel.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/ui/PersonListPanel.java#L66

Added line #L66 was not covered by tests
}
}
}

}

}
10 changes: 10 additions & 0 deletions src/main/resources/view/DarkTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@
-fx-padding: 0 0 0 0;
}

.student-card {
-fx-background-color: #349beb; /* Blue background for students */
-fx-text-fill: white; /* Ensure text is readable on the blue background */
}

.teacher-card {
-fx-background-color: #269e2e; /* Green background for teachers */
-fx-text-fill: white; /* Ensure text is readable on the green background */
}

.list-cell:filled:even {
-fx-background-color: #3c3e3f;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/model/person/StudentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void testStudentCreation() {
assertEquals(new Email("amy@gmail.com"), student.getEmail());
assertEquals(new Address("123, Jurong West Ave 6, #08-111"), student.getAddress());
assertEquals(new Subject("Mathematics"), student.getSubject());
assertEquals(0, student.getTags().size());
assertEquals(1, student.getTags().size());
assertEquals(0, student.getClasses().size());
}

Expand All @@ -38,7 +38,7 @@ public void testStudentWithCustomDetails() {
assertEquals(new Email("john@example.com"), student.getEmail());
assertEquals(new Address("456, Clementi Ave 3, #12-34"), student.getAddress());
assertEquals(new Subject("Physics"), student.getSubject());
assertEquals(2, student.getTags().size());
assertEquals(3, student.getTags().size());
assertEquals(2, student.getClasses().size());
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/address/model/person/TeacherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public void createTeacher_success() {
assertEquals("johndoe@hotmail.com", teacher.getEmail().toString());
assertEquals("123 Main St", teacher.getAddress().toString());
assertEquals("Math", teacher.getSubject().toString());
assertEquals(1, teacher.getTags().size());
assertEquals(2, teacher.getTags().size());
assertEquals(1, teacher.getClasses().size());
assertEquals("seedu.address.model.person.Teacher{name=John Doe, gender=male, phone=12345678, "
+ "email=johndoe@hotmail.com, address=123 Main St, tags=[[Friends]], subject=Math, classes=[1A]}",
teacher.toString());
+ "email=johndoe@hotmail.com, address=123 Main St, tags=[[teacher],"
+ " [Friends]], subject=Math, classes=[1A]}", teacher.toString());
}

@Test
Expand Down