diff --git a/src/main/java/seedu/address/model/person/Student.java b/src/main/java/seedu/address/model/person/Student.java index 5358d64e498..255821c8ed6 100644 --- a/src/main/java/seedu/address/model/person/Student.java +++ b/src/main/java/seedu/address/model/person/Student.java @@ -1,5 +1,6 @@ package seedu.address.model.person; +import java.util.HashSet; import java.util.Objects; import java.util.Set; @@ -27,13 +28,19 @@ public class Student extends Person { */ public Student(Name name, Phone phone, Email email, Address address, Set tags, Subject subject, Set 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 addStudentTag(Set tags) { + Set modifiedTags = new HashSet<>(tags); + modifiedTags.add(new Tag("student")); + return modifiedTags; + } + public Subject getSubject() { return subject; } diff --git a/src/main/java/seedu/address/model/person/Teacher.java b/src/main/java/seedu/address/model/person/Teacher.java index 3c134f362bc..23fdc4eae4c 100644 --- a/src/main/java/seedu/address/model/person/Teacher.java +++ b/src/main/java/seedu/address/model/person/Teacher.java @@ -1,5 +1,6 @@ package seedu.address.model.person; +import java.util.HashSet; import java.util.Objects; import java.util.Set; @@ -32,7 +33,7 @@ public class Teacher extends Person { */ public Teacher(Name name, Gender gender, Phone phone, Email email, Address address, Set tags, Subject subject, Set 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"); @@ -45,6 +46,12 @@ public Gender getGender() { return this.gender; } + private static Set addTeacherTag(Set tags) { + Set modifiedTags = new HashSet<>(tags); + modifiedTags.add(new Tag("teacher")); + return modifiedTags; + } + public Subject getSubject() { return this.subject; } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 094c42cda82..85f7f7e1e94 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -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; @@ -47,13 +45,26 @@ public class PersonCard extends UiPart { 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"); + } 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"); + } 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"); + } + + // 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))); } + } diff --git a/src/main/java/seedu/address/ui/PersonListPanel.java b/src/main/java/seedu/address/ui/PersonListPanel.java index f4c501a897b..7e08efcfb2e 100644 --- a/src/main/java/seedu/address/ui/PersonListPanel.java +++ b/src/main/java/seedu/address/ui/PersonListPanel.java @@ -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. @@ -38,12 +40,34 @@ protected void updateItem(Person person, boolean empty) { 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 } 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()); + + // Remove any previous styles applied to the cell + getStyleClass().removeAll("student-card", "teacher-card"); + + // 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"); + + } else if (person instanceof Teacher) { + // Apply inline style for teacher + setStyle("-fx-background-color: #269e2e;"); + } else { + // Optionally, clear the style for other types of people + setStyle(""); + } } } + } } diff --git a/src/main/resources/view/DarkTheme.css b/src/main/resources/view/DarkTheme.css index 36e6b001cd8..59ed9b9f185 100644 --- a/src/main/resources/view/DarkTheme.css +++ b/src/main/resources/view/DarkTheme.css @@ -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; } diff --git a/src/test/java/seedu/address/model/person/StudentTest.java b/src/test/java/seedu/address/model/person/StudentTest.java index e45986b3290..ff39d0d3343 100644 --- a/src/test/java/seedu/address/model/person/StudentTest.java +++ b/src/test/java/seedu/address/model/person/StudentTest.java @@ -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()); } @@ -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()); } diff --git a/src/test/java/seedu/address/model/person/TeacherTest.java b/src/test/java/seedu/address/model/person/TeacherTest.java index b3d56fa90c7..dd44a9a426a 100644 --- a/src/test/java/seedu/address/model/person/TeacherTest.java +++ b/src/test/java/seedu/address/model/person/TeacherTest.java @@ -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