Skip to content

Commit

Permalink
Merge pull request #32 from Wyrkx/master
Browse files Browse the repository at this point in the history
Add simple UI and sample data. Codecov can be ignored for changes that are not practical to test.
  • Loading branch information
Wyrkx authored Mar 18, 2024
2 parents e0dd3c4 + c991221 commit eb1a73b
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id 'jacoco'
}

mainClassName = 'address.Main'
mainClassName = 'tutorpro.Main'

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "src/main/java/tutorpro/ui/StudentCard.java"
6 changes: 6 additions & 0 deletions src/main/java/tutorpro/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import java.util.Objects;
import java.util.Set;

import javafx.scene.layout.Region;
import tutorpro.commons.util.CollectionUtil;
import tutorpro.commons.util.ToStringBuilder;
import tutorpro.model.tag.Tag;
import tutorpro.ui.PersonCard;
import tutorpro.ui.UiPart;

/**
* Represents a Person in the address book.
Expand Down Expand Up @@ -118,4 +121,7 @@ public String toString() {
.toString();
}

public UiPart<Region> getCard(int displayIndex) {
return new PersonCard(this, displayIndex);
}
}
5 changes: 5 additions & 0 deletions src/main/java/tutorpro/model/person/student/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public boolean equals(Object other) {
return value.equals(otherLevel.value);
}

@Override
public String toString() {
return value;
}

/**
* Returns true if the given String is a valid Level.
*/
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/tutorpro/model/person/student/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import java.util.HashSet;
import java.util.Set;

import javafx.scene.layout.Region;
import tutorpro.commons.util.CollectionUtil;
import tutorpro.model.person.Address;
import tutorpro.model.person.Email;
import tutorpro.model.person.Name;
import tutorpro.model.person.Person;
import tutorpro.model.person.Phone;
import tutorpro.model.tag.Tag;
import tutorpro.ui.StudentCard;
import tutorpro.ui.UiPart;

/**
* Represents a Student in TutorPro.
Expand Down Expand Up @@ -59,4 +62,13 @@ public boolean equals(Object other) {
Student otherStudent = (Student) other;
return level.equals(otherStudent.level) && subjects.equals(otherStudent.subjects);
}

/**
* Returns a UI representation of the person.
* @param displayIndex The index to be displayed on the card.
*/
@Override
public UiPart<Region> getCard(int displayIndex) {
return new StudentCard(this, displayIndex);
}
}
5 changes: 5 additions & 0 deletions src/main/java/tutorpro/model/person/student/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public boolean equals(Object other) {
return value.equals(otherLevel.value);
}

@Override
public String toString() {
return value;
}

/**
* Returns true if the given String is a valid Level.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tutorpro/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Student[] getSampleStudents() {
getTagSet(), new Level("J1"), getSubjectSet("Physics")),
new Student(new Name("David Li"), new Phone("91031282"), new Email("[email protected]"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
getTagSet(), new Level("UNI"), getSubjectSet("Chemistry, Biology")),
getTagSet(), new Level("UNI"), getSubjectSet("Chemistry", "Biology")),
new Student(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("[email protected]"),
new Address("Blk 47 Tampines Street 20, #17-35"),
getTagSet(), new Level("K2"), getSubjectSet("Reading")),
Expand All @@ -68,7 +68,7 @@ public static Student[] getSampleStudents() {

public static ReadOnlyAddressBook getSampleAddressBook() {
AddressBook sampleAb = new AddressBook();
for (Person samplePerson : getSamplePersons()) {
for (Person samplePerson : getSampleStudents()) {
sampleAb.addPerson(samplePerson);
}
return sampleAb;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tutorpro/ui/PersonListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected void updateItem(Person person, boolean empty) {
setGraphic(null);
setText(null);
} else {
setGraphic(new PersonCard(person, getIndex() + 1).getRoot());
setGraphic(person.getCard(getIndex() + 1).getRoot());
}
}
}
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/tutorpro/ui/StudentCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package tutorpro.ui;

import java.util.Comparator;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import tutorpro.model.person.student.Student;

/**
* An UI component that displays information of a {@code Person}.
*/
public class StudentCard extends UiPart<Region> {

private static final String FXML = "StudentListCard.fxml";

/**
* Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX.
* As a consequence, UI elements' variable names cannot be set to such keywords
* or an exception will be thrown by JavaFX during runtime.
*
* @see <a href="https://github.com/se-edu/addressbook-level4/issues/336">The issue on AddressBook level 4</a>
*/

public final Student student;

@FXML
private HBox cardPane;
@FXML
private Label name;
@FXML
private Label id;
@FXML
private Label phone;
@FXML
private Label address;
@FXML
private Label email;
@FXML
private FlowPane tags;
@FXML
private Label level;
@FXML
private FlowPane subjects;

/**
* Creates a {@code PersonCode} with the given {@code Person} and index to display.
*/
public StudentCard(Student student, int displayedIndex) {
super(FXML);
this.student = student;
id.setText(displayedIndex + ". ");
name.setText(student.getName().fullName);
phone.setText(student.getPhone().value);
address.setText(student.getAddress().value);
email.setText(student.getEmail().value);
level.setText(student.getLevel().toString());
student.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
student.getSubjects().stream()
.sorted(Comparator.comparing(subject -> subject.toString()))
.forEach(subject -> subjects.getChildren().add(new Label(subject.toString())));
}
}
14 changes: 14 additions & 0 deletions src/main/resources/view/DarkTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,17 @@
-fx-background-radius: 2;
-fx-font-size: 11;
}

#subjects {
-fx-hgap: 7;
-fx-vgap: 3;
}

#subjects .label {
-fx-text-fill: white;
-fx-background-color: #8b0000;
-fx-padding: 1 3 1 3;
-fx-border-radius: 2;
-fx-background-radius: 2;
-fx-font-size: 11;
}
38 changes: 38 additions & 0 deletions src/main/resources/view/StudentListCard.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.VBox?>

<HBox id="cardPane" fx:id="cardPane" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<GridPane HBox.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
</columnConstraints>
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<padding>
<Insets top="5" right="5" bottom="5" left="15" />
</padding>
<HBox spacing="5" alignment="CENTER_LEFT">
<Label fx:id="id" styleClass="cell_big_label">
<minWidth>
<!-- Ensures that the label text is never truncated -->
<Region fx:constant="USE_PREF_SIZE" />
</minWidth>
</Label>
<Label fx:id="name" text="\$first" styleClass="cell_big_label" />
</HBox>
<FlowPane fx:id="tags" />
<FlowPane fx:id="subjects" />
<Label fx:id="level" styleClass="cell_small_label" text="\$level" />
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" />
<Label fx:id="address" styleClass="cell_small_label" text="\$address" />
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
</VBox>
</GridPane>
</HBox>
14 changes: 14 additions & 0 deletions src/test/java/tutorpro/model/person/PersonTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tutorpro.model.person;

import static org.junit.jupiter.api.Assertions.fail;
import static tutorpro.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB;
import static tutorpro.logic.commands.CommandTestUtil.VALID_EMAIL_BOB;
import static tutorpro.logic.commands.CommandTestUtil.VALID_NAME_BOB;
Expand All @@ -12,6 +13,7 @@
import tutorpro.model.tag.Tag;
import tutorpro.testutil.Assert;
import tutorpro.testutil.PersonBuilder;
import tutorpro.testutil.StudentBuilder;
import tutorpro.testutil.TypicalPersons;

public class PersonTest {
Expand Down Expand Up @@ -104,4 +106,16 @@ public void addTags() {
person.addTags(tag);
Assertions.assertTrue(person.getTags().contains(tag));
}

@Test
public void getCard() {
try {
new StudentBuilder().build().getCard(1);
fail();
} catch (ExceptionInInitializerError e) {
return;
} catch (NoClassDefFoundError e) {
return;
}
}
}
20 changes: 20 additions & 0 deletions src/test/java/tutorpro/model/person/student/LevelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,24 @@ public void equals() {
// different values -> returns false
assertFalse(level.equals(new Level("J1")));
}

@Test
public void testToString() {
Level level = new Level("P6");

// same values -> returns true
assertTrue(level.toString().equals(new Level("P6").toString()));

// same object -> returns true
assertTrue(level.toString().equals(level.toString()));

// null -> returns false
assertFalse(level.toString().equals(null));

// different types -> returns false
assertFalse(level.toString().equals(5.0f));

// different values -> returns false
assertFalse(level.toString().equals(new Level("J1").toString()));
}
}
13 changes: 13 additions & 0 deletions src/test/java/tutorpro/model/person/student/StudentTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tutorpro.model.person.student;

import static org.junit.jupiter.api.Assertions.fail;
import static tutorpro.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB;
import static tutorpro.logic.commands.CommandTestUtil.VALID_EMAIL_BOB;
import static tutorpro.logic.commands.CommandTestUtil.VALID_LEVEL_UNI;
Expand Down Expand Up @@ -75,4 +76,16 @@ public void equals() {
editedAlice = new StudentBuilder(TypicalStudents.ALICE).withLevel(VALID_LEVEL_UNI).build();
Assertions.assertFalse(TypicalStudents.ALICE.equals(editedAlice));
}

@Test
public void getCard() {
try {
new StudentBuilder().build().getCard(1);
fail();
} catch (ExceptionInInitializerError e) {
return;
} catch (NoClassDefFoundError e) {
return;
}
}
}
20 changes: 20 additions & 0 deletions src/test/java/tutorpro/model/person/student/SubjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,24 @@ public void equals() {
// different values -> returns false
assertFalse(subject.equals(new Subject("Other Valid Subject")));
}

@Test
public void testToString() {
Subject subject = new Subject("Valid Subject");

// same values -> returns true
assertTrue(subject.toString().equals(new Subject("Valid Subject").toString()));

// same object -> returns true
assertTrue(subject.toString().equals(subject.toString()));

// null -> returns false
assertFalse(subject.toString().equals(null));

// different types -> returns false
assertFalse(subject.toString().equals(5.0f));

// different values -> returns false
assertFalse(subject.toString().equals(new Subject("Other Valid Subject").toString()));
}
}

0 comments on commit eb1a73b

Please sign in to comment.