Skip to content

Commit

Permalink
Merge pull request #65 from nihalramesh12629/mvp-add-student
Browse files Browse the repository at this point in the history
Add GUI Color Coding
  • Loading branch information
nihalramesh authored Oct 17, 2024
2 parents c27d128 + 25c2508 commit b80bcbd
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 13 deletions.
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 class PersonCard extends UiPart<Region> {
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)));
}

}
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 @@ 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("");
}
}
}

}

}
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

0 comments on commit b80bcbd

Please sign in to comment.