Skip to content

Commit

Permalink
Add UI component files for viewlsn
Browse files Browse the repository at this point in the history
  • Loading branch information
Nijnxw committed Oct 6, 2020
1 parent f34c107 commit b343c43
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/StudentCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class StudentCard extends UiPart<Region> {
@FXML
private Label studentNumber;


/**
* Creates a {@code StudentCard} with the given {@code Student} and index to display.
*/
Expand Down Expand Up @@ -54,4 +53,5 @@ public boolean equals(Object other) {
return id.getText().equals(card.id.getText())
&& student.equals(card.student);
}

}
62 changes: 62 additions & 0 deletions src/main/java/seedu/address/ui/StudentInfoCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package seedu.address.ui;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import seedu.address.model.group.StudentInfo;

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

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

public final StudentInfo studentInfo;

@FXML
private HBox cardPane;
@FXML
private Label name;
@FXML
private Label id;
@FXML
private Label studentNumber;
@FXML
private Label attendance;
@FXML
private Label participation;

/**
* Creates a {@code StudentCard} with the given {@code Student} and index to display.
*/
public StudentInfoCard(StudentInfo studentInfo, int displayedIndex) {
super(FXML);
this.studentInfo = studentInfo;
id.setText(displayedIndex + ". ");
name.setText(studentInfo.getStudent().getName());
studentNumber.setText(studentInfo.getStudent().getStudentNumber());
attendance.setText(studentInfo.getAttendance().getAttendance() ? "Present" : "Absent");
participation.setText(String.valueOf(studentInfo.getParticipation().getScore()));
}

@Override
public boolean equals(Object other) {
// short circuit if same object
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof StudentInfoCard)) {
return false;
}

// state check
StudentInfoCard card = (StudentInfoCard) other;
return id.getText().equals(card.id.getText())
&& studentInfo.equals(card.studentInfo);
}

}
51 changes: 51 additions & 0 deletions src/main/java/seedu/address/ui/StudentInfoListPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package seedu.address.ui;

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.group.StudentInfo;

import java.util.logging.Logger;

/**
* Panel containing the list of student information.
*/
public class StudentInfoListPanel extends UiPart<Region> {

private static final String FXML = "StudentInfoListPanel.fxml";
private final Logger logger = LogsCenter.getLogger(StudentInfoListPanel.class);

@FXML
private ListView<StudentInfo> studentInfoListView;

/**
* Creates a {@code StudentInfoListPanel} with the given {@code ObservableList}.
*/
public StudentInfoListPanel(ObservableList<StudentInfo> studentInfoList) {
super(FXML);
studentInfoListView.setItems(studentInfoList);
studentInfoListView.setCellFactory(listView -> new StudentInfoListPanel.StudentInfoListViewCell());
}

/**
* Custom {@code ListCell} that displays the graphics of a {@code StudentInfo} using a {@code StudentInfoCard}.
*/
class StudentInfoListViewCell extends ListCell<StudentInfo> {

@Override
protected void updateItem(StudentInfo studentInfo, boolean empty) {
super.updateItem(studentInfo, empty);

if (empty || studentInfo == null) {
setGraphic(null);
setText(null);
} else {
setGraphic(new StudentInfoCard(studentInfo, getIndex() + 1).getRoot());
}
}
}

}
36 changes: 36 additions & 0 deletions src/main/resources/view/StudentInfoListCard.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>

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


<HBox id="cardPane" fx:id="cardPane" xmlns="http://javafx.com/javafx/8" 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" styleClass="cell_big_label" text="\$name" />
<Label fx:id="studentNumber" styleClass="cell_small_label" text="\$studentNumber" />
<Label fx:id="attendance" styleClass="cell_small_label" text="\$attendance" />
<Label fx:id="participation" styleClass="cell_small_label" text="\$participation" />
</HBox>
</VBox>
</GridPane>
</HBox>
8 changes: 8 additions & 0 deletions src/main/resources/view/StudentInfoListPanel.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.VBox?>

<VBox xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<ListView fx:id="studentInfoListView" VBox.vgrow="ALWAYS" />
</VBox>
1 change: 0 additions & 1 deletion src/main/resources/view/StudentListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<?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?>
Expand Down

0 comments on commit b343c43

Please sign in to comment.